mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #19421 from jcoyne/translate_defaults_with_nil
Strip nils out of default translations. Fixes #19419
This commit is contained in:
parent
013b716f38
commit
7815fe4634
3 changed files with 14 additions and 1 deletions
|
@ -1,3 +1,11 @@
|
|||
* `translate` should accept nils as members of the `:default`
|
||||
parameter without raising a translation missing error. Fixes a
|
||||
regression introduced 362557e.
|
||||
|
||||
Fixes #19419
|
||||
|
||||
*Justin Coyne*
|
||||
|
||||
* `number_to_percentage` does not crash with `Float::NAN` or `Float::INFINITY`
|
||||
as input when `precision: 0` is used.
|
||||
|
||||
|
|
|
@ -38,7 +38,7 @@ module ActionView
|
|||
def translate(key, options = {})
|
||||
options = options.dup
|
||||
has_default = options.has_key?(:default)
|
||||
remaining_defaults = Array(options.delete(:default))
|
||||
remaining_defaults = Array(options.delete(:default)).compact
|
||||
|
||||
if has_default && !remaining_defaults.first.kind_of?(Symbol)
|
||||
options[:default] = remaining_defaults.shift
|
||||
|
|
|
@ -190,6 +190,11 @@ class TranslationHelperTest < ActiveSupport::TestCase
|
|||
assert_equal 'A Generic String', translation
|
||||
end
|
||||
|
||||
def test_translate_with_array_of_defaults_with_nil
|
||||
translation = translate(:'translations.missing', default: [:'also_missing', nil, 'A Generic String'])
|
||||
assert_equal 'A Generic String', translation
|
||||
end
|
||||
|
||||
def test_translate_does_not_change_options
|
||||
options = {}
|
||||
translate(:'translations.missing', options)
|
||||
|
|
Loading…
Reference in a new issue