开发者

Rails localization: works for t() but not for ActiveRecord attribute

Localization of the Rails3 ERB form for my user_info model works for "explanation" but not for "familyname":

<%= t("explanation") %>             # Works
<%= form_for(@user_info) do |f| %>
  <%= f.label :familyname %>                 # Does not work, renders: Familyname
  <%= f.text_field :familyname %>
  <%= f.submit t("update") %>
<% end %>

ja.yml in config/locales:

ja:
  explanation: ここで説明を書く予定です
  activerecord:
    attributes:
      user_info:
        familyname:名字

Why would it work for with t() but not for ActiveRecord? I double-c开发者_开发百科hecked the indentation, I am quite sure I am right doing ja→activerecord→attributes→user_info→familyname

I have another model, really similar, where ActiveRecord attributes are localized with no problem.


The indentation looks slightly different than what is given in the i18n Rails doc. Please check.

Also, open up the rails console and try this command:

I18n.t('activerecord.attributes')

This should list all the key/value pair of all the model attribute translations.


For model attributes, you can use the human_attribute_for method

User.human_attribute_for :familyname
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜