mirror of
https://github.com/discourse/discourse.git
synced 2024-11-27 18:33:37 +08:00
ecfa17b5a7
The FallbackLocaleList object tells I18n::Backend::Fallbacks what order the languages should be attempted in. Because of the translate_accelerator patch, the SiteSetting.default_locale is *not* guaranteed to be fully loaded after the server starts, so a call to ensure_loaded! is added after the locale is set for the current user. The declarations of config.i18n.fallbacks = true in the environment files were actually garbage, because the I18n.default_locale was SiteSetting.default_locale, so there was nothing to fall back to. *derp*
25 lines
751 B
Ruby
25 lines
751 B
Ruby
# order: after 02-freedom_patches.rb
|
|
|
|
# Include pluralization module
|
|
require 'i18n/backend/pluralization'
|
|
I18n::Backend::Simple.send(:include, I18n::Backend::Pluralization)
|
|
|
|
# Include fallbacks module
|
|
require 'i18n/backend/fallbacks'
|
|
I18n.backend.class.send(:include, I18n::Backend::Fallbacks)
|
|
|
|
# Configure custom fallback order
|
|
class FallbackLocaleList < Hash
|
|
def [](locale)
|
|
# user locale, site locale, english
|
|
# TODO - this can be extended to be per-language for a better user experience
|
|
# (e.g. fallback zh_TW to zh_CN / vice versa)
|
|
[locale, SiteSetting.default_locale.to_sym, :en].uniq.compact
|
|
end
|
|
|
|
def ensure_loaded!
|
|
self[I18n.locale].each { |l| I18n.ensure_loaded! l }
|
|
end
|
|
end
|
|
I18n.fallbacks = FallbackLocaleList.new
|