Skip to content

Commit

Permalink
scope_key_by_partial fix for Ruby 1.9 when there's virtual_path
Browse files Browse the repository at this point in the history
[#4202 state:committed]

Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
  • Loading branch information
spastorino authored and jeremy committed Mar 16, 2010
1 parent 2310aef commit 9cfa875
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
5 changes: 3 additions & 2 deletions actionpack/lib/action_view/helpers/translation_helper.rb
Expand Up @@ -29,8 +29,9 @@ def localize(*args)

private
def scope_key_by_partial(key)
if (key.respond_to?(:join) ? key.join : key.to_s).first == "."
template.path_without_format_and_extension.gsub(%r{/_?}, ".") + key.to_s
strkey = key.respond_to?(:join) ? key.join : key.to_s
if strkey.first == "."
template.path_without_format_and_extension.gsub(%r{/_?}, ".") + strkey
else
key
end
Expand Down
1 change: 1 addition & 0 deletions actionpack/test/fixtures/test/scoped_array_translation.erb
@@ -0,0 +1 @@
<%= t(['.foo', '.bar']) %>
6 changes: 6 additions & 0 deletions actionpack/test/template/translation_helper_test.rb
Expand Up @@ -41,4 +41,10 @@ def test_scoping_by_partial
I18n.expects(:translate).with("people.index.foo", :locale => 'en', :raise => true).returns("")
translate ".foo", :locale => 'en'
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 9cfa875

Please sign in to comment.