i18n用CakePHP翻译3 [英] i18n translation with CakePHP 3
问题描述
我要翻译法语和英语的应用程式。我完全遵循 CakePHP 3文档
I want to translate my app in french and english. I followed exactly the CakePHP 3 documentation but it is not working.
对于我的发展,我使用一个vagrant盒子轻松地启动和运行CakePHP 3.这个框命名为 vagrant-chef < a>
For my development, I'm using a vagrant box to easily get up and running with CakePHP 3. This box is named vagrant-chef
我修改了第100行以使用french作为默认语言。
I modified the line 100 to use french as the default language.
ini_set('intl.default_locale', 'fr_CA');
/ src / Controller / PagesController
我添加了这个方法到默认的PagesController
/src/Controller/PagesController
I added this method to the default PagesController
public function initialize() {
I18n::locale('en');
}
/src/Template/Pages/home.ctp
我添加了这两行
/src/Template/Pages/home.ctp
I added these 2 lines
<?php echo __('Hey, bonjour'); ?>
<?php echo __('Je teste la traduction'); ?>
.pot文件生成
终端,我输入此命令 bin / cake i18n extract
。 CakePHP在 / src / Locale /
中创建了2个文件。这些文件是 cake.pot
和 default.pot
。我翻译了default.pot文件,如下:
.pot file generation
From the terminal, I input this command bin/cake i18n extract
. CakePHP created 2 files in /src/Locale/
. Those files are cake.pot
and default.pot
. I translated the default.pot file like that:
...
msgid "Hey, bonjour"
msgstr "Hey, hello"
...
Locales目录结构
/ src / Locale
文件现在如下:
/en
/default.pot
尝试翻译我的应用程序,我没有得到任何工作。我认为这是一个缓存问题,所以我删除了 / tmp / cache / persistent /
中的文件。
Despite my attempts to translate my app, I didn't get anything working. I supposed it was a Cache problem, so I deleted the files in /tmp/cache/persistent/
.
感谢。
推荐答案
.pot
> cake i18n extract 是模板文件。您的每个语言文件需要 .po
。所以根据你的例子应该是 src / Locale / en / default.po
。
The .pot
generated by cake i18n extract
is the template file. Your per language files needs to be .po
. So as per your example it should be src/Locale/en/default.po
.
这篇关于i18n用CakePHP翻译3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!