cakephp3 翻訳ファイルの使い方
更新日 2021-05-05 22:32:05
cakephp3
bin/cake i18n extract を実行する
[demo@localhost cakephp]$ bin/cake i18n extract
Current paths: None
What is the path you would like to extract?
[Q]uit [D]one
[/path/to/cakephp/src/] > [そのままEnter]
Current paths: /path/to/cakephp/src/
What is the path you would like to extract?
[Q]uit [D]one
[D] > [そのままEnter]
Would you like to extract the messages from the CakePHP core? (y/n)
[n] > y
What is the path you would like to output?
[Q]uit
[/path/to/cakephp/src/Locale] > [そのままEnter]
Would you like to merge all domain strings into the default.pot file? (y/n)
[n] > y
Extracting...
---------------------------------------------------------------
Paths:
/path/to/cakephp/src/
/path/to/cakephp/vendor/cakephp/cakephp/src/
Output Directory: /path/to/cakephp/src/Locale/
---------------------------------------------------------------
==========================================================================> 100%
Done.
翻訳ファイルの生成が完了すると、cakephp/src 配下に Localeディレクトリが生成され、その配下に default.pot が生成される
それを以下のような階層にする(.pot => .po に変更する)
Locale/ja_JP/default.po
default.po
# LANGUAGE translation of CakePHP Application
# Copyright YEAR NAME
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PROJECT VERSION\n"
"PO-Revision-Date: YYYY-mm-DD HH:MM+ZZZZ\n"
"Last-Translator: NAME \n"
"Language-Team: LANGUAGE \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n"
#: Template/Error/error400.ctp:36
#: Template/Error/error500.ctp:41
#: Template/Layout/error.ctp:35
msgid "Error"
msgstr "エラー"
#: Template/Error/error400.ctp:37
msgid "The requested address {0} was not found on this server."
msgstr "要求されたアドレス {0} はこのサーバーで見つかりませんでした"
#: Template/Error/error500.ctp:39
msgid "An Internal Error Has Occurred"
msgstr "内部エラーが発生しました"
#: Controller/Component/AuthComponent.php:499
msgid "You are not authorized to access that location."
msgstr "あなたはその場所にアクセスする権限がありません"
...
翻訳ファイルを編集しても反映されない場合はキャッシュをクリアする
// キャッシュをクリアする
bin/cake cache clear_all