Internationalization in CakePHP 3

Em Português


Your Application Speaking Several Languages

CakePHP translation using the plugin localized

I will consider that you have installed according to this tutorial:
http://ribafs.org/portal/cakephp/plugins/control-default/control-default

And then this:
http://ribafs.org/portal/cakephp/plugins/cake-control/extra-resources

Create a folder on your Locale src
src/locale/pt_BR

Set the default locale (only if others than en_US):
edit config/bootstrap.php

Example to pt_BR
Change the line:
//ini_set('intl.default_locale 'Configure :: read (' App.defaultLocale '));

For:
ini_set ( 'intl.default_locale', 'pt_BR');

Copy the plugin file
vendor/cakephp/localized/src/locale/en/cake.po

For
src/locale/pt_BR/default.po

Note that the file was renamed cake.po to default.po

Access the application by the browser.

The generated code is already shown translated, but will need some adjustments.
Whenever you need to translate something add the string default.po.

Whenever you create code manually to make it translatable strings so use

Instead of doing so
<H1> Actions </h1>

Do like this:
<H1> <? = __ ( 'Action')?> </ H1>

But the string must exist in default.po.
If not, add.

Even code generated by Bake need to add strings and phrases that do not exist.

No need to re-generate the code, Cake takes the translate directly from default.po, if any.

Clear the Application Cache
Tip: After changing the default.po and the changes are not shown in the browser, then
clear the cache in the tmp folder / application cache and then go again for the browser and press Ctrl + R.

The following command clears the ORM cache most practical way

bin / cake clear orm_cache

Changing the Language

After all set to return to the default language (en_US), just edit
config/bootstrap.php and let the two lines like this:

//ini_set('intl.default_locale', 'pt_BR');
ini_set('intl.default_locale', Configure::read('App.defaultLocale'));


So, back to the browser and pressing F5 he returns to show in en_US.

References

http://book.cakephp.org/3.0/en/core-libraries/internationalization-and-localization.html