From d0b7363de550f039ec5ae59a7725a2a23d15e1dc Mon Sep 17 00:00:00 2001 From: Olivier Dony Date: Mon, 15 Jan 2024 01:10:01 +0100 Subject: [PATCH] [IMP] conf: special case alt lang links for legal terms Legal terms live under specific URL as their translations are not managed in the same manner. Layout is like this: /terms/enterprise.html (EN) /terms/i18n/enterprise_fr.html (FR) This commit adapts the generation of alternative languages links for each "legal terms page", so that it targets the correct i18n link, or goes back to the canonical EN one, depending on the target language. closes odoo/documentation#7382 closes odoo/documentation#7384 closes odoo/documentation#7387 Signed-off-by: Olivier Dony (odo) --- conf.py | 16 ++++++++++++++++ .../odoo_theme/layout_templates/legal.html | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/conf.py b/conf.py index 658ef26d1..c68e1ea87 100644 --- a/conf.py +++ b/conf.py @@ -478,8 +478,24 @@ def _generate_alternate_urls(app, pagename, templatename, context, doctree): _version = _version or app.config.version _lang = _lang or app.config.language or 'en' _canonical_page = f'{pagename}.html' + + # legal translations have different URLs schemes as they are not managed on transifex + # e.g. FR translation of /terms/enterprise => /fr/terms/enterprise_fr + if pagename.startswith('legal/terms/'): + if _lang in legal_translations and not pagename.endswith(f"_{_lang}"): + # remove language code for current translation, set target one + _page = re.sub("_[a-z]{2}$", "", pagename) + if 'terms/i18n' not in _page: + _page = _page.replace("/terms/", "/terms/i18n/") + _canonical_page = f'{_page}_{_lang}.html' + elif _lang == 'en' and pagename.endswith(tuple(f"_{l}" for l in legal_translations)): + # remove language code for current translation, link to original EN one + _page = re.sub("_[a-z]{2}$", "", pagename) + _canonical_page = f'{_page.replace("/i18n/", "/")}.html' + if app.config.is_remote_build: _canonical_page = _canonical_page.replace('index.html', '') + return f'{_root}' \ f'{f"/{_version}" if app.config.versions else ""}' \ f'{f"/{_lang}" if _lang != "en" else ""}' \ diff --git a/extensions/odoo_theme/layout_templates/legal.html b/extensions/odoo_theme/layout_templates/legal.html index 355040f70..4b128cb1f 100644 --- a/extensions/odoo_theme/layout_templates/legal.html +++ b/extensions/odoo_theme/layout_templates/legal.html @@ -40,7 +40,7 @@ {{ _("Read") }} {%- else %} {{ _("Read") }} - {{ _("English") }} + {{ _("English") }} {%- endif %}