且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Rails3:Devise国际化不会本地化“密码确认”和别的

更新时间:2022-10-20 20:40:14

其实他们来自你的默认语言yml文件。设计区域设置文件只是具有警报消息和一些通知的区域设置。他们不提供表单属性的属性转换。



您可能想要访问



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



并下载足够的(您的情况下的日语)语言文件,并将其放在 ./ config / locales / / p>

然后在您的rails应用程序配置文件(./config/application.rb)中更改区域设置以使用日语区域设置文件。

  config.i18n.default_locale =:ja 

更改设置后,如果您希望任何属性具有日文名称,请添加如下所示的规则。

  activerecord:
属性:
用户:
电子邮件:日语电子邮件地址
密码:Jap中的密码anese
password_confirmation:日语密码确认


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:

"サインアップ" 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?

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"