在我的Rails 3.2.2应用程序中我正在尝试使用i18n,但有些东西无法正常工作.
事实上,"t"方法不起作用,只有"i18n.t"有效.
所以,例如:
t(:login)
=> login
Run Code Online (Sandbox Code Playgroud)
代替:
i18n.t(:login)
=> Provide the necessary login info
Run Code Online (Sandbox Code Playgroud)
你能帮我搞清楚我做错了什么吗?
谢谢,奥古斯托
UPDATE
我使用pry来显示t帮助器的来源并得到了这个:
来自:/Users/phishman/.rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.2.2/lib/action_view/helpers/translation_helper.rb @第46行:行数:16所有者:ActionView: :助手:: TranslationHelper可见性:公众
def translate(key, options = {})
options.merge!(:rescue_format => :html) unless options.key?(:rescue_format)
if html_safe_translation_key?(key)
html_safe_options = options.dup
options.except(*I18n::RESERVED_KEYS).each do |name, value|
unless name == :count && value.is_a?(Numeric)
html_safe_options[name] = ERB::Util.html_escape(value.to_s)
end
end
translation = I18n.translate(scope_key_by_partial(key), html_safe_options)
translation.respond_to?(:html_safe) ? translation.html_safe : translation
else
I18n.translate(scope_key_by_partial(key), options)
end
end
3] pry(main)> show-source helper.t
From: /Users/phishman/.rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.2.2/lib/action_view/helpers/translation_helper.rb @ line 46:
Number of lines: 16
Owner: ActionView::Helpers::TranslationHelper
Visibility: public
def translate(key, options = {})
options.merge!(:rescue_format => :html) unless options.key?(:rescue_format)
if html_safe_translation_key?(key)
html_safe_options = options.dup
options.except(*I18n::RESERVED_KEYS).each do |name, value|
unless name == :count && value.is_a?(Numeric)
html_safe_options[name] = ERB::Util.html_escape(value.to_s)
end
end
translation = I18n.translate(scope_key_by_partial(key), html_safe_options)
translation.respond_to?(:html_safe) ? translation.html_safe : translation
else
I18n.translate(scope_key_by_partial(key), options)
end
end
Run Code Online (Sandbox Code Playgroud)