Add translate check for parent of topic
This commit is contained in:
parent
1c4c1a8494
commit
7707104da4
|
|
@ -16,6 +16,12 @@ class ModuleDoesNotExistException(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def translate_page(page: Page, locale: Locale):
|
||||||
|
translated_page = page.copy_for_translation(locale)
|
||||||
|
revision = translated_page.latest_revision
|
||||||
|
translated_page.publish(revision)
|
||||||
|
|
||||||
|
|
||||||
# todo: make this a django command
|
# todo: make this a django command
|
||||||
# todo: add language to translate to as an argument
|
# todo: add language to translate to as an argument
|
||||||
# todo: write a test maybe
|
# todo: write a test maybe
|
||||||
|
|
@ -45,9 +51,12 @@ def convert_page_to_translation(slug: str, original_slug: str, language_code="en
|
||||||
translated_topic = topic.get_translation(locale)
|
translated_topic = topic.get_translation(locale)
|
||||||
except Page.DoesNotExist:
|
except Page.DoesNotExist:
|
||||||
logger.debug("Creating topic translation")
|
logger.debug("Creating topic translation")
|
||||||
translated_topic = topic.copy_for_translation(locale)
|
try:
|
||||||
revision = translated_topic.latest_revision
|
translated_topic = translate_page(topic, locale)
|
||||||
translated_topic.publish(revision)
|
except Page.DoesNotExist:
|
||||||
|
# let's try to translate the parent page too
|
||||||
|
translate_page(topic.get_parent(), locale)
|
||||||
|
translated_topic = translate_page(topic, locale)
|
||||||
|
|
||||||
module.locale = locale
|
module.locale = locale
|
||||||
if original is not None:
|
if original is not None:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue