discourse/lib/i18n/backend/fallback_locale_list.rb
Gerhard Schlager 73015521e2 FIX: Correctly calculate fallback locale list
* English shouldn't fallback to any other locale
* Calculate fallback for default locale if it isn't English (useful for en_US)
* Reuse the fallback locale list when outputting translations to JavaScript
2019-05-13 09:36:05 +02:00

27 lines
726 B
Ruby

# frozen_string_literal: true
module I18n
module Backend
# Configure custom fallback order
class FallbackLocaleList < Hash
def [](locale)
locale = locale.to_sym
return [locale] 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
[locale, fallback_locale, :en]
else
site_fallback_locale = LocaleSiteSetting.fallback_locale(site_locale)
[locale, fallback_locale, site_locale, site_fallback_locale, :en]
end
locale_list.uniq.compact
end
end
end
end