论坛首页 编程语言技术论坛

rails2.2的i18n真是无爹妈的孩子啊

浏览 4437 次
精华帖 (0) :: 良好帖 (2) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2008-11-27   最后修改:2008-11-27
今天试着升级到rails2.2,按http://blog.xdite.net/?p=785上的说明,拉了一个demo app下来,把里面的locals文件复制到项目目录:
git clone git://github.com/clemens/i18n_demo_app.git
cp config/locals ~/myapp/config -r

设置为使用zh-CN后,出错信息死活没办法出现中文,后来看文档,有这样一句:
Then ActiveRecord will look for messages in this order:
activerecord.errors.models.admin.attributes.title.blank
activerecord.errors.models.admin.blank
activerecord.errors.models.user.attributes.title.blank
activerecord.errors.models.user.blank
activerecord.errors.messages.blank

而在zh-CN.yml或zh-CN.rb文件中,这个message的路径是在
active_record.error_messages
估计这个demo写的比较早。

修改为activerecord.errors.messages后正常了。

看了一下rails最新源代码,在/activerecord/lib/active_record/locale/en.yml中,也是activerecord.errors.messages,之前比较

看来i18n的API变化后没人去统一一下,汗啊。

================
后来发现更好的解决方法,同时推荐一个插件i18n_generators:
   http://github.com/amatsuda/i18n_generators/tree/master
可以直接生成zh-CN的本地化文件。
安装这个plugin需要先sudo gem install gettext。

安装完成插件后,使用generate:
  script/generate i18n zh-CN
就会在config/locales目录生成zh-CN.yml和models_zh-CN.yml,其中models_zh-CN.yml中有所有model的字段,而且。。。已经翻译好了,当然需要手工再调整一下。
   发表时间:2008-11-27  
俺用的这个
http://mod-i18n.googlecode.com
0 请登录后投票
   发表时间:2008-11-27  
哦,这个应该也是一个比较早的解决方案吧,我说是的rails2.2内建的那个i18n.
0 请登录后投票
   发表时间:2008-11-28  
不是有Guide吗?http://rails-i18n.org/pages/i18n-rails-guide
虽没有详细的API说明,基本的都有了。
0 请登录后投票
   发表时间:2008-12-01  
我参考过这个guide,但是,没有提供zh-CN.yml文件。
0 请登录后投票
   发表时间:2008-12-05   最后修改:2008-12-05
这个有:
http://github.com/svenfuchs/rails-i18n/tree/master
0 请登录后投票
   发表时间:2008-12-23  
我很想 知道 rails2.2.2自带的国际化功能 支不支持  传参数。
zh_CN: 欢迎{user},谢谢!
en: Welcome {user},thank you!
0 请登录后投票
   发表时间:2008-12-30  
当然支持了,这是最基本的,你看看那些验证的资源,也是带参数的。
0 请登录后投票
论坛首页 编程语言技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics