Rails 3 I18n label_tag 翻译
人们可能会认为以下代码将访问 I18n:
= label_tag(:person_name)
并查找 en.helpers.label.person_name 或类似的内容。然而,rails 代码似乎没有使用任何 I18n:
159: def label_tag(name = nil, content_or_options = nil, options = nil, &block)
160: options = content_or_options if block_given? && content_or_options.is_a?(Hash)
161: options ||= {}
162: options.stringify_keys!
163: options["for"] = sanitize_to_id(name) unless name.blank? || options.has_key?("for")
164: content_tag :label, content_or_options || name.to_s.humanize, options, &block
165: end
所以似乎唯一的选择是显式调用 label_tag(:person_name, I18n.t(:person_name))
。这似乎没有必要,所以我在这里遗漏了一些东西还是应该在 Rails 补丁上工作?任何意见都会受到赞赏。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
= label_tag(:person_name)
将不起作用。但是您可以使用t()
方法来实现工作。
然后可以添加翻译:
然后在文件
en.yml
中:您还可以将翻译与其所在的视图联系起来:
在
app/views/something/index.html.haml< /code>
将在文件
en.yml
中查找此翻译:= label_tag(:person_name)
will not work. But you can use thet()
method to get this towork.
The translation can then be added:
Then in file
en.yml
:You could also tie the translation to the view it is in:
In
app/views/something/index.html.haml
would look for this translation in file
en.yml
: