提交 1b39d39a 编写于 作者: J José Valim

Merge pull request #7082 from jalkoby/lazy_lookup_in_abstract_controller

add lazy look up in abstract controller's translate method
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 @@ def localize(*args)
end
alias :l :localize
end
end
\ No newline at end of file
end
......@@ -23,4 +23,17 @@ def test_action_controller_base_responds_to_localize
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
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册