discourse/config/initializers/i18n.rb
Kane York 6119d9fdc0 FIX: Fallbacks for missing interpolation arguments
This takes effect when an interpolation is removed from a translation in
a Discourse update.

The I18n::Backend::Fallbacks loops with a catch(:exception), so calling
throw(:exception) will cause it to use the next locale, until it reaches
English which is assumed to be correct.

Also, enable fallbacks in everything except development (#3724 for more
discussion) - we should be able to test this
2015-09-11 09:39:40 -07:00

37 lines
1,005 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
class NoFallbackLocaleList < FallbackLocaleList
def [](locale)
[locale]
end
end
if Rails.env.development?
I18n.fallbacks = NoFallbackLocaleList.new
else
I18n.fallbacks = FallbackLocaleList.new
I18n.config.missing_interpolation_argument_handler = proc { throw(:exception) }
end