FIX: Using the default_locale in locale fallbacks caused problems

Locale files get precompiled after deployment and they contained translations from the `default_locale`. That's especially bad in multisites, because the initial `default_locale` is `en_US`. Sites where the `default_locale` isn't `en_US` could see missing translations. The same thing could happen when users are allowed to chose a different locale.

This change simplifies the logic by not using the `default_locale` in the locale chain. It always falls back to `en` in case of missing translations.
This commit is contained in:
Gerhard Schlager
2020-05-06 22:57:14 +02:00
parent 15a938e861
commit ec2f3169ff
6 changed files with 72 additions and 64 deletions

View File

@@ -6,19 +6,15 @@ module I18n
class FallbackLocaleList < Hash
def [](locale)
locale = locale.to_sym
return [locale] if locale == :en
locale_list = [locale]
return locale_list if locale == :en
fallback_locale = LocaleSiteSetting.fallback_locale(locale)
site_locale = SiteSetting.default_locale.to_sym
locale_list =
if locale == site_locale || site_locale == :en || fallback_locale == :en
[locale, fallback_locale, :en]
else
site_fallback_locale = LocaleSiteSetting.fallback_locale(site_locale)
[locale, fallback_locale, site_locale, site_fallback_locale, :en]
end
while (fallback_locale = LocaleSiteSetting.fallback_locale(locale))
locale_list << fallback_locale
locale = fallback_locale
end
locale_list << :en
locale_list.uniq.compact
end
end