---
title: "Beast 中文化成功"
author: "thegiive"
date: "2007-05-04T16:01:45Z"
tags: ["Rails"]
slug: "beast"
draft: false
lastmod: "2007-05-04T16:01:45Z"
id: 77055
url: "https://thegiive.iteye.com/blog/77055"
---

[![](http://bp3.blogger.com/_8vS0KjIsbko/RjtV1WklRlI/AAAAAAAAAGk/uJr_i5f_kO8/s320/%E6%93%B7%E5%9C%96_1.png)](http://bp3.blogger.com/_8vS0KjIsbko/RjtV1WklRlI/AAAAAAAAAGk/uJr_i5f_kO8/s1600-h/%E6%93%B7%E5%9C%96_1.png)  
介紹完[怎麼安裝 Beast](http://lightyror.thegiive.net/2007/04/beast-lighty.html) ，我們廢話不多說，直接進入 Beast 中文化。Beast 的 I18N 是採用 GETTEXT 來做的，意思就是只要寫一個 po 檔即可處理大部份的中文化東西。不過還是有很多小地方沒有中文化，依舊需要一一 check。右圖就是成品，這裡就是 [po檔下載點](http://arbor.ee.ntu.edu.tw/%7Ewisely/download/beast_tw.po)。實做方式以及po檔均參考 JavaEye 的 Suninny 先生撰寫的 [\[分享\]Beast中文Gettext PO档](http://www.iteye.com/topic/65034)，感謝他的付出。

中文化方式如下

1. 採用之前[說好的方式](http://lightyror.thegiive.net/2007/04/beast-lighty.html)安裝 beast。
2. 安裝 GETTEXT GEM  
   gem i gettext
3. 撰寫轉換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
   ```
4. 新增一個資料夾 po/zh\_tw/ ，將這個[po檔](http://arbor.ee.ntu.edu.tw/%7Ewisely/download/beast_tw.po)放入這個資料夾裡面
5. 產生相對應的 mo 檔，請打入  
   rake makemo
6. 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
   ```
7. 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 就是你指定的語系
8. 重起 server 即可

如此就沒問題了。Beast I18N 做的不錯，唯一缺點就是 doc 太少，花了點時間才找到相關資料。