在我的 Rails 3.2.2 应用程序中,我正在尝试使用 i18n,但有些东西无法正常工作。
实际上“t”方法不起作用,只有“i18n.t”起作用。
因此,例如:
t(:login)
=> login
反而:
i18n.t(:login)
=> Provide the necessary login info
你能帮我弄清楚我做错了什么吗?
谢谢,奥古斯托
更新
我用 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: :Helpers::TranslationHelper 可见性: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
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