From bc2d7909b1b401d166f42b7fa3fed01ba47cb557 Mon Sep 17 00:00:00 2001 From: Jan Brasna <1784648+janbrasna@users.noreply.github.com> Date: Thu, 29 Aug 2024 00:55:57 +0200 Subject: [PATCH] Fix root active locales --- bedrock/base/templates/404-locale.html | 2 +- lib/l10n_utils/__init__.py | 4 +++- lib/l10n_utils/fluent.py | 5 +++++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/bedrock/base/templates/404-locale.html b/bedrock/base/templates/404-locale.html index c71c2ed1f72..c3665291995 100644 --- a/bedrock/base/templates/404-locale.html +++ b/bedrock/base/templates/404-locale.html @@ -57,7 +57,7 @@

diff --git a/lib/l10n_utils/__init__.py b/lib/l10n_utils/__init__.py index d5719b2be87..741054f3c5e 100644 --- a/lib/l10n_utils/__init__.py +++ b/lib/l10n_utils/__init__.py @@ -169,7 +169,9 @@ def render(request, template, context=None, ftl_files=None, activation_files=Non translations.update(ftl_active_locales(af)) translations = sorted(translations) # `sorted` returns a list. elif l10n: - translations = l10n.active_locales + translations = l10n.active_locales if not is_root_path_with_no_language_clues(request) else l10n.active_home_locales + allowed = settings.PROD_LANGUAGES if not settings.DEV else settings.DEV_LANGUAGES + translations = set(translations).intersection(allowed) # if `add_active_locales` is given then add it to the translations for the template if "add_active_locales" in context: diff --git a/lib/l10n_utils/fluent.py b/lib/l10n_utils/fluent.py index a42b78c4d7e..ad9e0b1e6cd 100644 --- a/lib/l10n_utils/fluent.py +++ b/lib/l10n_utils/fluent.py @@ -84,6 +84,11 @@ def active_locales(self): # first resource is the one to check for activation return get_active_locales(self.resource_ids[0]) + @cached_property + def active_home_locales(self): + # use mozorg/home to check for activation + return get_active_locales("mozorg/home.ftl") + @cached_property def percent_translated(self): if not self._message_ids: