[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) <odo@odoo.com>
This commit is contained in:
Olivier Dony 2024-01-15 01:10:01 +01:00
parent 05be4c72db
commit 856a60cd24
No known key found for this signature in database
GPG Key ID: CD556E25E8A6D0D4
2 changed files with 17 additions and 1 deletions

16
conf.py
View File

@ -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 ""}' \

View File

@ -40,7 +40,7 @@
<a class="btn btn-primary" href="{{ enterprise_agreement_path_en }}" role="button">{{ _("Read") }}</a>
{%- else %}
<a class="btn btn-primary" href="{{ 'legal/terms/i18n/enterprise_%s.html' % language_code }}" role="button">{{ _("Read") }}</a>
<a class="btn btn-light text-primary" href="{{ enterprise_agreement_path_en }}">{{ _("English") }}</a>
<a class="btn btn-light text-primary" href="../{{ enterprise_agreement_path_en }}">{{ _("English") }}</a>
{%- endif %}
</div>
</div>