CakePHP2系をサクッと日本語化する方法
概要
CakePHPは自動コーディングが出来て便利だし、エラー内容も分かりやすいし、書籍も多いので開発しやすいんだけど、英語なのがなー。ということで多言語対応(日本語化)してみた。
手順
1.ディレクトリを作成する
[app/Locale]の下に[jpn]フォルダを作り、さらにその下に[LC_MESSAGES]フォルダを作る。
このコマンドが便利。
mkdir -p Locale/jpn/LC_MESSAGES
2.i18nコマンドでpotファイルを作成する
cakeコマンドを実行する。
./cake i18n
potファイルを作成するのでEを選択。
[E]xtract POT file from sources [I]nitialize i18n database table [H]elp [Q]uit What would you like to do? (E/I/H/Q) > E
コアからも書き出すのでYを選択。
Would you like to extract the messages from the CakePHP core? (y/n) [n] > y
先ほど作成したフォルダ内にpotファイルを書き出すので、パスを指定する。
What is the path you would like to output? [Q]uit [/pub/cakephp3/app/Locale] > /pub/cakephp3/app/Locale/jpn/LC_MESSAGES/
出力されるファイルをひとつにまとめたいので、Yを選択。
Would you like to merge all domain and category strings into the default.pot file? (y/n) [n] > y
以上でpotファイルが[app/Locale/jpn/LC_MESSAGES/]フォルダ内に抽出される。
フォルダ内に[default.pot]があるので、[default.po]に名前を変更する。これ注意。
3.実際に日本語化してみる
あとは[default.po]ファイルを適宜変更する。
例えば[View]を[詳細]などに日本語化する場合はこんな感じ。
#: View/Customers/index.ctp:16 #: View/Customers/view.ctp:62 msgid "View" msgstr "詳細"
ファイルはUTF-8で保存するのを忘れずに。