I18n translation from CakePHP 3
Context
I want to translate my application into French and English. I followed exactly the CakePHP 3 documentation , but it doesn't work.
What have I done so far
For my development, I use a vagrant box to easily get up and work with CakePHP 3. This box is called vagrant-chef
/config/bootstrap.php
I changed line 100 to use French as my default language.
ini_set('intl.default_locale', 'fr_CA');
/ Src / controller / PagesController
I added this method to the standard 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'); ?>
Generation .pot files
From the terminal, I enter this command bin/cake i18n extract
. CakePHP has created 2 files in /src/Locale/
. These files cake.pot
and default.pot
. I translated the default.pot file as follows:
...
msgid "Hey, bonjour"
msgstr "Hey, hello"
...
Locales directory structure
The file now /src/Locale
looks like this:
/en
/default.pot
Despite my attempts to translate my application, I didn't get anything. I assumed it was a cache issue, so I deleted the files in /tmp/cache/persistent/
.
Thank.
source to share