Browse files

Merge pull request #19102 from ulissesalmeida/fix-regression-default-…


Fix regression when passing a value different of String.
  • Loading branch information...
rafaelfranca committed Feb 27, 2015
1 parent c5cbc69 commit 93a763dee36a208fe9fa274e2d131a1bc7d099aa
@@ -36,8 +36,12 @@ module TranslationHelper
# you know what kind of output to expect when you call translate in a template.
def translate(key, options = {})
options = options.dup
has_default = options.has_key?(:default)
remaining_defaults = Array(options.delete(:default))
options[:default] = remaining_defaults.shift if remaining_defaults.first.kind_of? String
if has_default && !remaining_defaults.first.kind_of?(Symbol)
options[:default] = remaining_defaults.shift
# If the user has explicitly decided to NOT raise errors, pass that option to I18n.
# Otherwise, tell I18n to raise an exception, which we rescue further in this method.
@@ -176,6 +176,11 @@ def test_translate_with_string_default
assert_equal 'A Generic String', translation
def test_translate_with_object_default
translation = translate(:'translations.missing', default: 123)
assert_equal 123, translation
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

0 comments on commit 93a763d

Please sign in to comment.