i18n translation with CakePHP 3

被刻印的时光 ゝ 提交于 2019-12-07 13:59:53

问题


Context

I want to translate my app in french and english. I followed exactly the CakePHP 3 documentation but it is not working.

What I did so far

For my development, I'm using a vagrant box to easily get up and running with CakePHP 3. This box is named vagrant-chef

/config/bootstrap.php

I modified the line 100 to use french as the default language.

ini_set('intl.default_locale', 'fr_CA');

/src/Controller/PagesController

I added this method to the default PagesController

public function initialize() {
    I18n::locale('en');
}

/src/Template/Pages/home.ctp

I added these 2 lines

    <?php echo __('Hey, bonjour'); ?>
    <?php echo __('Je teste la traduction'); ?>

.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 directory structure

The /src/Locale file looks like this now:

/en
   /default.pot

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/.

Thanks.


回答1:


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.



来源:https://stackoverflow.com/questions/31822817/i18n-translation-with-cakephp-3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!