提交 6f3c65f6 编写于 作者: A Adam Prescott

Allow an array to be a default translation value.

4.2.1 introduced a change to the way `translate`/`t` works with an
option of `default: [[]]`. In 4.2.0, this would give a default value of
`[]`, but in 4.2.1, it leads to a missing translation.

`default: [[]]` is again allowed for cases where a default of `[]` is
needed.

This addresses GitHub issue 19640.
上级 191facc8
* `translate` now allows `default: [[]]` again for a default value of `[]`.
Fixes a regression introduced in 4.2.1.
See #19640 and the fix in #19649.
*Adam Prescott*
* `translate` should accept nils as members of the `:default`
parameter without raising a translation missing error. Fixes a
regression introduced 362557e.
......
......@@ -41,7 +41,7 @@ def translate(key, options = {})
remaining_defaults = Array(options.delete(:default)).compact
if has_default && !remaining_defaults.first.kind_of?(Symbol)
options[:default] = remaining_defaults.shift
options[:default] = remaining_defaults
end
# If the user has explicitly decided to NOT raise errors, pass that option to I18n.
......
......@@ -195,6 +195,11 @@ def test_translate_with_array_of_defaults_with_nil
assert_equal 'A Generic String', translation
end
def test_translate_with_array_of_array_default
translation = translate(:'translations.missing', default: [[]])
assert_equal [], translation
end
def test_translate_does_not_change_options
options = {}
translate(:'translations.missing', options)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册