Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

translate helper method using an array is deprecated

Signed-off-by: José Valim <jose.valim@gmail.com>
  • Loading branch information...
commit 4986d5ed04dba1480fe1f4a0368f099028404b20 1 parent 4fef5af
@spastorino spastorino authored josevalim committed
View
3  actionpack/lib/action_view/helpers/translation_helper.rb
@@ -11,6 +11,9 @@ module TranslationHelper
# to translate many keys within the same partials and gives you a simple framework for scoping them consistently. If you don't
# prepend the key with a period, nothing is converted.
def translate(keys, options = {})
+ if keys.is_a?(Array)
+ ActiveSupport::Deprecation.warn "Giving an array to translate is deprecated, please give a symbol or a string instead", caller
+ end
options[:raise] = true
are_keys_a_string = keys.is_a?(String)
keys = scope_keys_by_partial(keys)
View
26 actionpack/test/template/translation_helper_test.rb
@@ -19,16 +19,20 @@ def test_returns_missing_translation_message_wrapped_into_span
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"])
+ assert_deprecated do
+ I18n.expects(:translate).with(["foo", "bar"], :raise => true).returns(["foo", "bar"])
+ assert_equal ["foo", "bar"], translate(["foo", "bar"])
+ end
end
def test_translation_of_an_array_with_html
- translate_expected = ['<a href="#">foo</a>', '<a href="#">bar</a>', '<a href="#">baz</a>']
- I18n.expects(:translate).with(["foo", "bar", "baz_html"], :raise => true).returns(translate_expected)
- @view = ActionView::Base.new(ActionController::Base.view_paths, {})
- expected = '<a href="#">foo</a>, <a href="#">bar</a>, <a href="#">baz</a>'
- assert_equal expected, @view.render(:file => "test/array_translation")
+ assert_deprecated do
+ translate_expected = ['<a href="#">foo</a>', '<a href="#">bar</a>', '<a href="#">baz</a>']
+ I18n.expects(:translate).with(["foo", "bar", "baz_html"], :raise => true).returns(translate_expected)
+ @view = ActionView::Base.new(ActionController::Base.view_paths, {})
+ expected = '<a href="#">foo</a>, <a href="#">bar</a>, <a href="#">baz</a>'
+ assert_equal expected, @view.render(:file => "test/array_translation")
+ end
end
def test_delegates_localize_to_i18n
@@ -44,9 +48,11 @@ def test_scoping_by_partial
end
def test_scoping_by_partial_of_an_array
- I18n.expects(:translate).with(["test.scoped_array_translation.foo", "test.scoped_array_translation.bar"], :raise => true).returns(["foo", "bar"])
- @view = ActionView::Base.new(ActionController::Base.view_paths, {})
- assert_equal "foo, bar", @view.render(:file => "test/scoped_array_translation")
+ assert_deprecated do
+ I18n.expects(:translate).with(["test.scoped_array_translation.foo", "test.scoped_array_translation.bar"], :raise => true).returns(["foo", "bar"])
+ @view = ActionView::Base.new(ActionController::Base.view_paths, {})
+ assert_equal "foo, bar", @view.render(:file => "test/scoped_array_translation")
+ end
end
def test_translate_does_not_mark_plain_text_as_safe_html
Please sign in to comment.
Something went wrong with that request. Please try again.