Method: Worldwide::I18nExceptionHandler#call
- Defined in:
- lib/worldwide/i18n_exception_handler.rb
#call(exception, locale, key, options, context = I18n) ⇒ Object
I18n.exception_handler is needed in cases where the lookup has gone through the fallback chain. In that case, we want to do the lookup in the default locale.
It’s a common misconception that we should add the default locale to the fallbacks chain. Instead, you catch the exception and do the lookup in the source locale.
12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/worldwide/i18n_exception_handler.rb', line 12 def call(exception, locale, key, , context = I18n) if exception.is_a?(I18n::MissingTranslation) # We've already tried the default locale, so we don't want to try it again. if locale.to_s == context.default_locale.to_s handle_missing_translation(exception, locale, key, ) else handle_default_locale_fallback(exception, locale, key, , context) end else super(exception, locale, key, ) end end |