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

Handle nil translation key #40788

Merged
merged 1 commit into from Dec 16, 2020
Merged

Conversation

jonathanhefner
Copy link
Member

@jonathanhefner jonathanhefner commented Dec 10, 2020

I18n.translate returns nil when given a nil key, unless a default is also specified. If a default is specified, the nil key is treated as a missing key.

In Rails 6.0, the translate helper always returned nil when given a nil key. After #40773, the translate helper always raised an I18n::ArgumentError when given a nil key. This commit fixes the translate helper to mirror the I18n.translate behavior when given a nil key, with and without a default.

Fixes #40773 (comment).


Since this changes the behavior of the translate helper when both a nil key and a default are specified, I've added a CHANGELOG entry. If we do not want to change this for 6.1.1, I can create a separate PR against 6-1-stable that restores the Rails 6.0 behavior for nil keys.

@rails-bot rails-bot bot added the actionview label Dec 10, 2020
`I18n.translate` returns `nil` when given a `nil` key, *unless* a
`default` is also specified.  If a `default` is specified, the `nil` key
is treated as a missing key.

In Rails 6.0, the `translate` helper always returned `nil` when given a
`nil` key.  After rails#40773, the `translate` helper always raised an
`I18n::ArgumentError` when given a `nil` key.  This commit fixes the
`translate` helper to mirror the `I18n.translate` behavior when given a
`nil` key, with and without a `default`.
@rafaelfranca rafaelfranca merged commit 3701930 into rails:master Dec 16, 2020
rafaelfranca added a commit that referenced this pull request Dec 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants