You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I overwrited the I18n::ExceptionHandler to make a custom exception handling of translations in a Rails project.
When I overwrited the method without calling super, i got a MissingTranslation with key :"i18n.plural.rule" when the translation actually exists.
The given translation is resolved when not overwritting the handler, but raises when i overwrited with a dummy raise behaviour.
module I18n
class CustomTranslationExceptionHandler < I18n::ExceptionHandler
def call(exception, _locale, key, _options)
if exception.is_a?(MissingTranslation)
if Rails.env.test?
super
elsif Rails.env.development?
raise exception
else
super
end
else
raise exception
end
end
end
end
I18n.exception_handler = I18n::CustomTranslationExceptionHandler.new
What I expected to happen
I expect that is the translation is not missing and the Exception Handler is overriden it does not throws error.
What actually happened
It throws #<I18n::MissingTranslation: Translation missing: es.i18n.plural.rule> error
Versions of i18n, rails, and anything else you think is necessary
Rails 6.1.7.6
What i actually belive it is happening is that in the file /lib/i18n/backend/pluralization.rb:82 it is called
So in I18n::Backend::Pluralization#pluralize an error is raised when calling #pluralizer when a given pruralizer is not defined.
This is a annoying bug because does not permitt overriding the error handler in an easy and expected way because this extra error is raised form the inner behaviour of the I18n library when the Translation it does get resolved. Maybe you could wrap the exception to avoid beign throwed, or define a custom i18n.plural.rule by default so the error is not raised.
Thanks! ❤️
The text was updated successfully, but these errors were encountered:
What I tried to do
I overwrited the
I18n::ExceptionHandler
to make a custom exception handling of translations in a Rails project.When I overwrited the method without calling super, i got a
MissingTranslation
with key:"i18n.plural.rule"
when the translation actually exists.The given translation is resolved when not overwritting the handler, but raises when i overwrited with a dummy raise behaviour.
What I expected to happen
I expect that is the translation is not missing and the Exception Handler is overriden it does not throws error.
What actually happened
It throws
#<I18n::MissingTranslation: Translation missing: es.i18n.plural.rule>
errorVersions of i18n, rails, and anything else you think is necessary
Rails 6.1.7.6
What i actually belive it is happening is that in the file
/lib/i18n/backend/pluralization.rb:82
it is calledSo in
I18n::Backend::Pluralization#pluralize
an error is raised when calling#pluralizer
when a given pruralizer is not defined.This is a annoying bug because does not permitt overriding the error handler in an easy and expected way because this extra error is raised form the inner behaviour of the I18n library when the Translation it does get resolved. Maybe you could wrap the exception to avoid beign throwed, or define a custom
i18n.plural.rule
by default so the error is not raised.Thanks! ❤️
The text was updated successfully, but these errors were encountered: