1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Merge pull request #7082 from jalkoby/lazy_lookup_in_abstract_controller

add lazy look up in abstract controller's translate method
This commit is contained in:
José Valim 2012-07-18 00:38:35 -07:00
commit 1b39d39af2
2 changed files with 20 additions and 1 deletions

View file

@ -1,6 +1,12 @@
module AbstractController
module Translation
def translate(*args)
key = args.first
if key.is_a?(String) && (key[0] == '.')
key = "#{ controller_path.gsub('/', '.') }.#{ action_name }#{ key }"
args[0] = key
end
I18n.translate(*args)
end
alias :t :translate
@ -10,4 +16,4 @@ module AbstractController
end
alias :l :localize
end
end
end

View file

@ -23,4 +23,17 @@ class TranslationControllerTest < ActiveSupport::TestCase
def test_action_controller_base_responds_to_l
assert_respond_to @controller, :l
end
def test_lazy_lookup
expected = 'bar'
@controller.stubs(:action_name => :index)
I18n.stubs(:translate).with('action_controller.base.index.foo').returns(expected)
assert_equal expected, @controller.t('.foo')
end
def test_default_translation
key, expected = 'one.two' 'bar'
I18n.stubs(:translate).with(key).returns(expected)
assert_equal expected, @controller.t(key)
end
end