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

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

问题描述

这是一个极简主义的Devise + OmniAuth应用程序的整个源代码



如您所见,日语设计.ja.yml 位于 config / locales



问题:当我使用lang = ja访问该网站时,一些字符串不是日语,而是英文:





サインアップ正确显示,但密码确认等仍然是英文。其实我整个项目和我的整个.rvm目录都是grep:没有文件包含密码确认!这是令人困惑的。



这些字符串来自哪里?他们怎么不在devise.ja.yml?它是OmniAuth吗?

解决方案

其实他们来自你的默认语言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"

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

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