Skip to content
Browse files

scope_key_by_partial fix for Ruby 1.9 when there's virtual_path [#4202

…state:resolved]

Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
  • Loading branch information...
1 parent 7a5da21 commit 0c1ac36ccb7d72f3d17d950d030442a7e83d0708 @spastorino spastorino committed with jeremy Mar 16, 2010
View
5 actionpack/lib/action_view/helpers/translation_helper.rb
@@ -29,9 +29,10 @@ def localize(*args)
private
def scope_key_by_partial(key)
- if (key.respond_to?(:join) ? key.join : key.to_s).first == "."
+ strkey = key.respond_to?(:join) ? key.join : key.to_s
+ if strkey.first == "."
if @_virtual_path
- @_virtual_path.gsub(%r{/_?}, ".") + key.to_s
+ @_virtual_path.gsub(%r{/_?}, ".") + strkey
else
raise "Cannot use t(#{key.inspect}) shortcut because path is not available"
end
View
1 actionpack/test/fixtures/test/scoped_array_translation.erb
@@ -0,0 +1 @@
+<%= t(['.foo', '.bar']) %>
View
6 actionpack/test/template/translation_helper_test.rb
@@ -41,4 +41,10 @@ def test_scoping_by_partial
@view = ActionView::Base.new(ActionController::Base.view_paths, {})
assert_equal "helper", @view.render(:file => "test/translation")
end
+
+ def test_scoping_by_partial_of_an_array
+ I18n.expects(:translate).with("test.scoped_array_translation.foo.bar", :raise => true).returns(["foo", "bar"])
+ @view = ActionView::Base.new(ActionController::Base.view_paths, {})
+ assert_equal "foobar", @view.render(:file => "test/scoped_array_translation")
+ end
end

0 comments on commit 0c1ac36

Please sign in to comment.
Something went wrong with that request. Please try again.