aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2010-05-24 20:16:50 -0700
committerJeremy Kemper <jeremy@bitsweat.net>2010-05-24 20:30:21 -0700
commitf53a6d814966e0ea039bde680b0fc3814236641c (patch)
treeaf1afb10e38efd66514f4f692b17ed0e221d1a45 /actionpack
parentd8d38bedfd5716d55e50e85dc6c9a938b1848e66 (diff)
downloadrails-f53a6d814966e0ea039bde680b0fc3814236641c.tar.gz
rails-f53a6d814966e0ea039bde680b0fc3814236641c.tar.bz2
rails-f53a6d814966e0ea039bde680b0fc3814236641c.zip
i18n: t() handles single keys returning an Array, also
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/lib/action_view/helpers/translation_helper.rb7
-rw-r--r--actionpack/test/template/translation_helper_test.rb10
2 files changed, 15 insertions, 2 deletions
diff --git a/actionpack/lib/action_view/helpers/translation_helper.rb b/actionpack/lib/action_view/helpers/translation_helper.rb
index 6633ef295a..0d2b2aa7b1 100644
--- a/actionpack/lib/action_view/helpers/translation_helper.rb
+++ b/actionpack/lib/action_view/helpers/translation_helper.rb
@@ -18,7 +18,11 @@ module ActionView
def translate(key, options = {})
translation = I18n.translate(scope_key_by_partial(key), options.merge!(:raise => true))
- html_safe_translation_key?(key) ? translation.html_safe : translation
+ if html_safe_translation_key?(key) && translation.respond_to?(:html_safe)
+ translation.html_safe
+ else
+ translation
+ end
rescue I18n::MissingTranslationData => e
keys = I18n.normalize_keys(e.locale, e.key, e.options[:scope])
content_tag('span', keys.join(', '), :class => 'translation_missing')
@@ -32,7 +36,6 @@ module ActionView
alias :l :localize
private
-
def scope_key_by_partial(key)
if key.to_s.first == "."
if @_virtual_path
diff --git a/actionpack/test/template/translation_helper_test.rb b/actionpack/test/template/translation_helper_test.rb
index 89acdc9dd3..1be418a206 100644
--- a/actionpack/test/template/translation_helper_test.rb
+++ b/actionpack/test/template/translation_helper_test.rb
@@ -18,6 +18,11 @@ class TranslationHelperTest < ActiveSupport::TestCase
assert_equal expected, translate(:foo)
end
+ def test_translation_returning_an_array
+ I18n.expects(:translate).with(:foo, :raise => true).returns(["foo", "bar"])
+ assert_equal ["foo", "bar"], translate(:foo)
+ end
+
def test_delegates_localize_to_i18n
@time = Time.utc(2008, 7, 8, 12, 18, 38)
I18n.expects(:localize).with(@time)
@@ -50,4 +55,9 @@ class TranslationHelperTest < ActiveSupport::TestCase
I18n.expects(:translate).with("hello_html", :raise => true).returns("<a>Hello World</a>")
assert translate("hello_html").html_safe?
end
+
+ def test_translation_returning_an_array_ignores_html_suffix
+ I18n.expects(:translate).with(:foo_html, :raise => true).returns(["foo", "bar"])
+ assert_equal ["foo", "bar"], translate(:foo_html)
+ end
end