Replies: 2 comments 1 reply
|
Can be done as:
|
0 replies
|
Thanks @zerolab ! For us I think it would be useful to auto-sync translations when a page is saved, so that synchronised fields are always kept in sync. For example, we have a synchronised field that stores the lat/lng coordinates of a place, and it should be updated across translations whenever it is saved. I have done this with the following hook: @hooks.register('after_publish_page')
def after_publish_page_update_translations(request, page):
"""Update translations when original page is saved."""
if hasattr(page, "translation_key"):
# Update translation source (this stores synched fields, e.g. tags and coordinates)
TranslationSource.update_or_create_from_instance(page)
translated_pages = Page.objects.filter(
translation_key=page.translation_key).exclude(id=page.id)
for translated_page in translated_pages:
# Update each translation with the new synched field values
translation = Translation.objects.filter(
source__object_id=page.translation_key,
target_locale_id=translated_page.locale_id,
enabled=True,
).first()
if translation:
translation.save_target(request.user)Does this make sense to you? If so, is there an easier way to achieve it? I imagine there is a good reason this isn't default behaviour - please let me know if I'm missing something! |
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
I have the error:
Sorry to create an issue for this, but it seems like I need to run a translation sync, but I don't know how to do this, and couldn't find it in the docs.
All reactions