3

Handle nil translation key

 3 years ago
source link: https://github.com/rails/rails/pull/40788
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Member

jonathanhefner commented 11 days ago

edited

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.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK