Permalink
Browse files

i18n translate with arrays issue solved

  • Loading branch information...
1 parent 62c802c commit 397262a4ee92484e307c93d7450025a677891f08 @spastorino spastorino committed with Yehuda Katz Feb 19, 2010
@@ -12,7 +12,8 @@ module TranslationHelper
# prepend the key with a period, nothing is converted.
def translate(key, options = {})
options[:raise] = true
- I18n.translate(scope_key_by_partial(key), options).html_safe
+ translation = I18n.translate(scope_key_by_partial(key), options)
+ translation.is_a?(Array) ? translation.map { |entry| entry.html_safe } : translation.html_safe
rescue I18n::MissingTranslationData => e
keys = I18n.send(:normalize_translation_keys, e.locale, e.key, e.options[:scope])
content_tag('span', keys.join(', '), :class => 'translation_missing')
@@ -17,6 +17,11 @@ def test_returns_missing_translation_message_wrapped_into_span
expected = '<span class="translation_missing">en, foo</span>'
assert_equal expected, translate(:foo)
end
+
+ def test_translation_of_an_array
+ I18n.expects(:translate).with(["foo", "bar"], :raise => true).returns(["foo", "bar"])
+ assert_equal ["foo", "bar"], translate(["foo", "bar"])
+ end
def test_delegates_localize_to_i18n
@time = Time.utc(2008, 7, 8, 12, 18, 38)

0 comments on commit 397262a

Please sign in to comment.