Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[guides] Update missing translation example #38624

Conversation

geoffharcourt
Copy link
Contributor

Summary

The Rails Guides contain an example of how to raise for a missing
translation when I18n.t is called from anywhere, including
non-ActionView contexts. The example builds a custom exception handler
that catches and raises any instance of I18n::MissingTranslationData
and passes on any other exception to be handled by I18n as normally
happens.

Unfortunately, while I18n::MissingTranslationData is what eventually
should be raised for a missing translation, the initial exception the
handler sees is actually I18n::MissingTranslation, and
MissingTranslationData is the product of calling #to_exception on
that exception object. As a result, the example in the guides ends up
not raising for missing translations, silently resulting in the return
of the missing translation key. This issue appears to have first been captured in this issue: #13429.

This change updates the guides to with a working example, catching
I18n::MissingTranslation which results in a raise of
I18n::MissingTranslationData with the missing key.

Close #13429

The Rails Guides contain an example of how to raise for a missing
translation when `I18n.t` is called from anywhere, including
non-ActionView contexts. The example builds a custom exception handler
that catches and raises any instance of `I18n::MissingTranslationData`
and passes on any other exception to be handled by `I18n` as normally
happens.

Unfortunately, while `I18n::MissingTranslationData` is what eventually
should be raised for a missing translation, the initial exception the
handler sees is actually `I18n::MissingTranslation`, and
`MissingTranslationData` is the product of calling `#to_exception` on
that exception object. As a result, the example in the guides ends up
not raising for missing translations, silently resulting in the return
of the missing translation key.

This change updates the guides to with a working example, catching
`I18n::MissingTranslation` which results in a raise of
`I18n::MissingTranslationData` with the missing key.
@rails-bot rails-bot bot added the docs label Mar 3, 2020
@rafaelfranca rafaelfranca merged commit 9a82512 into rails:master Mar 4, 2020
rafaelfranca added a commit that referenced this pull request Mar 4, 2020
…anslation-examples

[guides] Update missing translation example
@geoffharcourt geoffharcourt deleted the guides-update-missing-translation-examples branch March 4, 2020 18:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[4.1.0.beta1] I18n Missing Translation Handler doesn't work
2 participants