9

Here is my whole source code for a minimalist Devise+OmniAuth app.

As you can see, the Japanese devise.ja.yml is in config/locales.

PROBLEM: When I visit the site with lang=ja, some strings are not in Japanese but English:

devise i18n password confirmation

"サインアップ" is displayed correctly, but "Password confirmation" and others are still in English. Actually, I grep'd my the whole project and my entire .rvm directory: No file contain "Password confirmation" ! That's baffling.

Where do those strings come from? How comes they are not in devise.ja.yml? Is it OmniAuth?

Nicolas Raoul
  • 58,567
  • 58
  • 222
  • 373

1 Answers1

14

Actually, they come from your default language yml file. Devise locale file just have locales for alert messages and some notices. They do not provide attribute translation for form attributes.

You probably want to visit

https://github.com/svenfuchs/rails-i18n/tree/f8606e62def45279f3498549f97699049135bd11/rails/locale

and download the adequate (Japanese in your case) language file and put it in ./config/locales/ folder

Then in your rails application configuration file (./config/application.rb) change locale setting to use the Japanese locale file.

config.i18n.default_locale = :ja

After changing the setting, if you want any attribute to have Japanese name, add the rules like shown below.

activerecord:
    attributes:
        user:
            email: "Email address in Japanese"
            password: "Password in Japanese"
            password_confirmation: "Password confirmation in Japanese"
user482594
  • 16,878
  • 21
  • 72
  • 108
  • Adding this activerecord paragraph indeed allows me to override these strings. But do I really need to find and translate all those strings by myself? If they are a part of the ActiveRecord project, haven't those been translated to Japanese already? – Nicolas Raoul Jun 29 '11 at 05:46
  • I guess you are already aware of this, but just to make it clear to other readers: those strings (for instance password_confirmation) are not contained in the svenfuchs/rails-i18n localization files. – Nicolas Raoul Jun 30 '11 at 02:34
  • Well, you never know what attribute names people are going to use, so localization yml file cannot contain every possible translations. Some users may use `password`, or `password_confirmation` or `phone` or `dateofbirth` or some random attribute name. For me, I was so convinced that adding one line of translation in the localization file will affect all the attributes in my view pages... – user482594 Jun 30 '11 at 22:23
  • I still don't understand how Rails knows that "password_confirmation" translates into "Password confirmation" in English... no file contains the string "Password confirmation". – Nicolas Raoul Jul 01 '11 at 08:06
  • 1
    @NicolasRaoul Rails just [humanizes](http://api.rubyonrails.org/classes/ActiveSupport/Inflector.html#method-i-humanize) the password_confirmation. – rkusa Aug 31 '11 at 12:00