简体   繁体   中英

using i18n with rails 3 problem

I've got some form for user registration and want to localize it via locales yml files. Especially errors from validations.

For example, locale file:

tr:
  activerecord:
    errors:
      models:
        user: 
          attributes:
            name:
              blank: "can't be blank"

it will return: name can't be blank in errors area:

<% @user.errors.each do |error| -%>
  <p><%= error %></p>
<% end -%>

Next step I want to create is to rename name attribute (and others) like that ( this is what don't work ):

tr:
  attributes:
    user:
      name: "Real name"

to get this error after validation: Real name can't be blank

So where I should locale attribute names to translate them in error messages

Try this:

tr:
    activerecord:
        attributes:
            modelname:
                attributename: "translation"

Substituting modelname with the name of your model, and attributename with the name of the attribute you want to provide a translation for, here name .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM