Beast 中文化成功

介紹完怎麼安裝 Beast ,我們廢話不多說,直接進入 Beast 中文化。Beast 的 I18N 是採用 GETTEXT 來做的,意思就是只要寫一個 po 檔即可處理大部份的中文化東西。不過還是有很多小地方沒有中文化,依舊需要一一 check。右圖就是成品,這裡就是 po檔下載點。實做方式以及po檔均參考 JavaEye 的 Suninny 先生撰寫的 [分享]Beast中文Gettext PO档,感謝他的付出。
中文化方式如下
-
採用之前說好的方式安裝 beast。
-
安裝 GETTEXT GEM
gem i gettext -
撰寫轉換rake file,新增一個檔案叫做 lib/tasks/gettext.rake,內容是
desc "Create mo-files for L10n" task :makemo do require 'gettext/utils' GetText.create_mofiles(true, "po", "locale") end -
新增一個資料夾 po/zh_tw/ ,將這個po檔放入這個資料夾裡面
-
產生相對應的 mo 檔,請打入
rake makemo -
config/enviroment.rb 裡面,下面這一段 gettext 的部份要註解起來,我也不確定為什麼,反正會產生 error
begin require 'gettext/rails' GetText.locale = "zh" # Change this to your preference language puts "GetText found!" rescue MissingSourceFile, LoadError puts "GetText not found. Using English." class ActionView::Base def _(s) s end end end -
app/controllers/application.rb 部份加上
class ApplicationController < ActionController::Base #init_gettext "beast" if Object.const_defined?(:GetText) require 'gettext/rails' init_gettext "beast" if Object.const_defined?(:GetText) GetText.locale = 'zh_tw' end裡面 zh_tw 就是你指定的語系
-
重起 server 即可
如此就沒問題了。Beast I18N 做的不錯,唯一缺點就是 doc 太少,花了點時間才找到相關資料。