`
lihbobo
  • 浏览: 65100 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

Ruby 和 Rails 的国际化与本地化技术

阅读更多
原文见此: https://www6.software.ibm.com/developerworks/cn/education/web/wa-rails-li/section4.html

安装 ruby-gettext gem 包;
编写 hello_i18n.rb 程序;
抽取代码中需要翻译的内容串,创建 POT 文件;
创建、翻译 PO 文件并创建 MO 文件;
运行本地化后的程序;

运行 gem install gettext 安装gettext 插件。

用以下命令检验是否按装成功:
irb(main):001:0> require 'rubygems'
=> true
irb(main):002:0> require 'gettext'
=> true
irb(main):003:0> GetText
=> GetText

编译Hello_i18n.rb 文件:
require 'rubygems'
require 'gettext'
include GetText

bindtextdomain("hello_i18n")
print _("Hello I18N World\n")

生成pot文件:
rgettext hello_i18n.rb -o hello_i18n.pot

Copy POT 文件成 Po 文件

翻译po 文件,记住必须以UTF-8的格式编码

创见MO文件,
记住最好位于 Ruby 安装文件夹下的 share/locale/zh_CN/LC_MESSAGES/
文件夹下,
用 rmsgfmt hello_i18n.po -o /usr/local/share/locale/zh_CN/LC_MESSAGES/hello_i18n.mo
或者 GUN的Msgfmt 程序来生成MO文件。

用 ruby -d hello_i18n.rb 来运行。
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics