mirror of
https://github.com/discourse/discourse.git
synced 2024-12-01 10:36:32 +08:00
73015521e2
* 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
27 lines
726 B
Ruby
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
|