close

安裝Ruby-GetText-Package

gem install gettext

設定: 建立lib/tasks/gettext.rake:

desc "Update pot/po files." 
task :updatepo do
  require 'gettext/utils'
# Windows需要下一行
#  ENV["MSGMERGE_PATH"] = 'rmsgmerge.cmd'
  GetText.update_pofiles("myapp", Dir.glob("{app,lib,bin}/**/*.{rb,rhtml}"), "myapp 1.0.0")
end

desc "Create mo-files." 
task :makemo do
  require 'gettext/utils'
  GetText.create_mofiles(true, "po", "locale")
end

在config/environment.rb加入:

$KCODE = 'u'
require 'jcode'
require 'gettext/rails'

在app/controller/application.rb加入init_gettext:

class ApplicationController < ActionController::Base
  init_gettext "myapp" 
end

執行

rake updatepo

會產生po/myapp.pot,將myapp.po複製成po/zh_TW/myapp.po。 執行

rake makemo

產生local/zh_TW/LC_MESSAGES/myapp.mo檔。之後若有修改程式中的字串,執行rake updatepo會更新po/myapp.pot和po/zh_TW/myapp.po。詳細的用法位於Ruby-GetText-Package HOWTO for Ruby on Rails

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 Forth 的頭像
    Forth

    不就是個blog

    Forth 發表在 痞客邦 留言(0) 人氣()