# Internationalization

**URL:** <https://discourse.cakephp.org/t/internationalization/4616>\
**Category:** Need Help\
**Tags:** i18n\
**Created:** [July 24, 2018, 8:20am UTC](https://discourse.cakephp.org/t/internationalization/4616 "2018-07-24T08:20:50Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Snoopy87](https://avatars.discourse-cdn.com/v4/letter/s/ecc23a/32.png) [@Snoopy87](https://discourse.cakephp.org/u/Snoopy87)\
**Post date:** [July 24, 2018, 8:20am UTC](https://discourse.cakephp.org/t/internationalization/4616/1 "2018-07-24T08:20:51Z")

</div>

Hi,

I’m trying to use internationalization in my CakePHP(3.6) app. I have followed the official [documentation](https://book.cakephp.org/3.0/en/core-libraries/internationalization-and-localization.html).

I have created two po files :

1. src/Locale/en/default.po  
msgid “accueil\_main\_title”  
msgstr “Welcomel”

2. src/Locale/fr/default.po  
msgid “accueil\_main\_title”  
msgstr “Bienvenue”

After in a view I have written the following code :

\< h1 class=“title-page text-center”\>\<?= \_\_('accueil\_main\_title')?\>

I have modified the app.php file as follow :  
‘App’ =\> [  
‘namespace’ =\> ‘App’,  
‘encoding’ =\> env(‘APP\_ENCODING’, ‘UTF-8’),  
‘defaultLocale’ =\> env(‘APP\_DEFAULT\_LOCALE’, ‘fr’),  
‘defaultTimezone’ =\> env(‘APP\_DEFAULT\_TIMEZONE’, ‘UTC’),  
‘base’ =\> false,  
‘dir’ =\> ‘src’,  
‘webroot’ =\> ‘webroot’,  
‘wwwRoot’ =\> WWW\_ROOT,  
//‘baseUrl’ =\> env(‘SCRIPT\_NAME’),  
‘fullBaseUrl’ =\> false,  
‘imageBaseUrl’ =\> ‘img/’,  
‘cssBaseUrl’ =\> ‘css/’,  
‘jsBaseUrl’ =\> ‘js/’,  
‘paths’ =\> [  
‘plugins’ =\> [ROOT . DS . ‘plugins’ . DS],  
‘templates’ =\> [APP . ‘Template’ . DS],  
‘locales’ =\> [APP . ‘Locale’ . DS],  
],  
],  
…

And now when I run my app, I get on my view the text “accueil\_main\_title”. I expect to get “Bienvenue” or “Welcome”. What did I do wrong ?

Regards,

Snoopy

---

<div class="post-metadata">

**Author:** ![rrd](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/rrd/32/113_2.png) [@rrd](https://discourse.cakephp.org/u/rrd)\
**Post date:** [July 24, 2018, 11:02am UTC](https://discourse.cakephp.org/t/internationalization/4616/2 "2018-07-24T11:02:59Z")

</div>

I would reccomend you to extract the translation strings by the cake console as described in the cookbook, and try with them.

---

<div class="post-metadata">

**Author:** ![Snoopy87](https://avatars.discourse-cdn.com/v4/letter/s/ecc23a/32.png) [@Snoopy87](https://discourse.cakephp.org/u/Snoopy87)\
**Post date:** [July 24, 2018, 12:55pm UTC](https://discourse.cakephp.org/t/internationalization/4616/3 "2018-07-24T12:55:53Z")

</div>

I try with the command line bin/cake i18n extract. POT files are generated correctly in the folder /src/Locale/fr, but I still get 'accueil\_main\_title" on my view.

---

<div class="post-metadata">

**Author:** ![rrd](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/rrd/32/113_2.png) [@rrd](https://discourse.cakephp.org/u/rrd)\
**Post date:** [July 25, 2018, 2:16pm UTC](https://discourse.cakephp.org/t/internationalization/4616/4 "2018-07-25T14:16:03Z")

</div>

You should have a `default.pot` at `/src/Locale`, and `default.po` and `default.mo` in `/src/Locale/fr`. After this You should open your `/src/Locale/fr/default.po` file with Poedit, refresh it from your pot file, do a translation. Delete your cake cache, and after that it should work.

---

<div class="post-metadata">

**Author:** ![Snoopy87](https://avatars.discourse-cdn.com/v4/letter/s/ecc23a/32.png) [@Snoopy87](https://discourse.cakephp.org/u/Snoopy87)\
**Post date:** [July 26, 2018, 4:30am UTC](https://discourse.cakephp.org/t/internationalization/4616/5 "2018-07-26T04:30:20Z")

</div>

Ho great !!! It’s working now !! 😀

Thanks you very much

---

<div class="post-metadata">

**Author:** ![rrd](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/rrd/32/113_2.png) [@rrd](https://discourse.cakephp.org/u/rrd)\
**Post date:** [July 26, 2018, 7:11am UTC](https://discourse.cakephp.org/t/internationalization/4616/6 "2018-07-26T07:11:05Z")

</div>

Great 😀

I would reccomend you to do not use placeholder texts. Just pick up a base language and use it. So what I would do is use \_\_(‘Welcome’) instead of \_\_(‘accueil\_main\_title’).

By that you have a default language what does not require translation and that will be the fallback for all non translated texts. In this case English will go to your pot file.

---

<div class="post-metadata">

**Author:** ![Snoopy87](https://avatars.discourse-cdn.com/v4/letter/s/ecc23a/32.png) [@Snoopy87](https://discourse.cakephp.org/u/Snoopy87)\
**Post date:** [July 26, 2018, 8:49am UTC](https://discourse.cakephp.org/t/internationalization/4616/7 "2018-07-26T08:49:53Z")

</div>

I use placeholder because I want to translate a full paragraph and not only one word. For instance in my view I wrote something like this :

\_\_(‘Accueil\_paragraph\_1’)

and then in the po file I have this:

msgid “Accueil\_paragraph\_1”  
msgstr “Lorem ipsum dolor fse sit amet, consectetur adipiscing elit. Duis eu imperdiet lorem, non tincidunt nibh. Phasellus quis massa eget erat tempus interdum id ut sem. Nam tristique purus massa, et scelerisque urna rutru…”

Is it a bad approach ?

---

<div class="post-metadata">

**Author:** ![rrd](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/rrd/32/113_2.png) [@rrd](https://discourse.cakephp.org/u/rrd)\
**Post date:** [July 26, 2018, 10:59am UTC](https://discourse.cakephp.org/t/internationalization/4616/8 "2018-07-26T10:59:49Z")

</div>

I would not do that. Why do not you put there the whole paragraph? From your placeholder nobody will know (exept you) what to put there as a translation. That is why we use a default language.

---

<div class="post-metadata">

**Author:** ![Snoopy87](https://avatars.discourse-cdn.com/v4/letter/s/ecc23a/32.png) [@Snoopy87](https://discourse.cakephp.org/u/Snoopy87)\
**Post date:** [July 26, 2018, 12:52pm UTC](https://discourse.cakephp.org/t/internationalization/4616/9 "2018-07-26T12:52:53Z")

</div>

I try as you said and it is still working 🙂 !!

Thanks for your advice.
