Rails3:设计国际化不本地化“密码确认";和别的 [英] Rails3: Devise internationalization does not localize "Password confirmation" and others

查看:28
本文介绍了Rails3:设计国际化不本地化“密码确认";和别的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的

并下载适当的(在您的情况下为日语)语言文件并将其放入 ./config/locales/ 文件夹中

然后在您的 Rails 应用程序配置文件 (./config/application.rb) 中更改语言环境设置以使用日语语言环境文件.

config.i18n.default_locale = :ja

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

活动记录:属性:用户:email: "日文邮箱地址"密码:日文密码"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"

这篇关于Rails3:设计国际化不本地化“密码确认";和别的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆