Reputation: 3710
I am building an app, using I18n for different languages display. In this moment, the validation message shown in this way.
en
USERNAME CAN'T BE BLANK
zh-CN
USERNAME 不能为空字符
I would like to translate the attribute USERNAME to some other string. So I followed the instruction in Rails Guide and added the following lines in my locale files.
en:
activerecord:
attributes:
user:
username: "User Name"
zh-CN:
activerecord:
attributes:
user:
username: "用户名"
When I run the human_attribute_name command, it can be translated.
ruby-1.9.2-p290 :001 > User.human_attribute_name("username")
=> "Username"
But in the validation message, it just capitalized all the characters of attribute name.
CURRENT_PASSWORD 不能为空字符
Did I missed anything? How can I fix it?
Thank all. :)
Upvotes: 0
Views: 777
Reputation: 3710
I made a mistake. I added a custom helper to handle the validation message. The I18n translation in question is correct. I can use human_attribute_name to translate the arribute.
Upvotes: 0
Reputation: 3224
I think you may need
en:
activerecord:
errors:
models:
user:
attributes:
username: "User Name"
Upvotes: 1