Permalink
Browse files

Merge pull request #19421 from jcoyne/translate_defaults_with_nil

Strip nils out of default translations. Fixes #19419
  • Loading branch information...
rafaelfranca committed Mar 20, 2015
1 parent 26b6fc6 commit 1a91917176716cd99447e6d0132e52cb1444b675
View
@@ -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.
@@ -37,7 +37,7 @@ module TranslationHelper
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
@@ -185,4 +185,9 @@ def test_translate_with_array_of_string_defaults
translation = translate(:'translations.missing', default: ['A Generic String', 'Second generic string'])
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
end

0 comments on commit 1a91917

Please sign in to comment.