# Multi language site

**URL:** <https://discourse.cakephp.org/t/multi-language-site/3830>\
**Category:** Need Help\
**Created:** [January 30, 2018, 9:13am UTC](https://discourse.cakephp.org/t/multi-language-site/3830 "2018-01-30T09:13:33Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![6120](https://avatars.discourse-cdn.com/v4/letter/6/278dde/32.png) [@6120](https://discourse.cakephp.org/u/6120)\
**Post date:** [January 30, 2018, 9:13am UTC](https://discourse.cakephp.org/t/multi-language-site/3830/1 "2018-01-30T09:13:33Z")

</div>

Is there somewhere a good tutorial on how to build a multi-language site (in cakephp 3.x) ?  
There are several questions about this topic but no real answer.

Thank you for helping.

---

<div class="post-metadata">

**Author:** ![zledwon](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/zledwon/32/599_2.png) [@zledwon](https://discourse.cakephp.org/u/zledwon)\
**Post date:** [February 3, 2018, 9:44am UTC](https://discourse.cakephp.org/t/multi-language-site/3830/2 "2018-02-03T09:44:07Z")

</div>

Can we help you with some specific problem?

---

<div class="post-metadata">

**Author:** ![6120](https://avatars.discourse-cdn.com/v4/letter/6/278dde/32.png) [@6120](https://discourse.cakephp.org/u/6120)\
**Post date:** [February 3, 2018, 1:41pm UTC](https://discourse.cakephp.org/t/multi-language-site/3830/3 "2018-02-03T13:41:29Z")

</div>

Well, I do not have a specific problem.  
I have been building web apps / sites with cakephp since 1.2.x but only single language (french).  
A new client is asking for several languages in a new website.  
What I would like to know is what are the best practices ?  
Should I create everything 2, 3 or more times ? Should I use a joining table ?  
How to localize things that are customized ?

I just don’t know where to begin ?

---

<div class="post-metadata">

**Author:** ![donnidani](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/donnidani/32/744_2.png) [@donnidani](https://discourse.cakephp.org/u/donnidani)\
**Post date:** [February 5, 2018, 7:29am UTC](https://discourse.cakephp.org/t/multi-language-site/3830/4 "2018-02-05T07:29:09Z")

</div>

not sure if this is what you looking for, here’s CakePHP3 translation and localization official documentation.

[https://book.cakephp.org/3.0/en/core-libraries/internationalization-and-localization.html](https://book.cakephp.org/3.0/en/core-libraries/internationalization-and-localization.html)  
[https://book.cakephp.org/3.0/en/orm/behaviors/translate.html](https://book.cakephp.org/3.0/en/orm/behaviors/translate.html)

hope it might help for you to start

---

<div class="post-metadata">

**Author:** ![littleylv](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/littleylv/32/494_2.png) [@littleylv](https://discourse.cakephp.org/u/littleylv)\
**Post date:** [February 5, 2018, 10:13am UTC](https://discourse.cakephp.org/t/multi-language-site/3830/5 "2018-02-05T10:13:28Z")

</div>

try this: [https://github.com/ADmad/cakephp-i18n](https://github.com/ADmad/cakephp-i18n)

---

<div class="post-metadata">

**Author:** ![6120](https://avatars.discourse-cdn.com/v4/letter/6/278dde/32.png) [@6120](https://discourse.cakephp.org/u/6120)\
**Post date:** [February 5, 2018, 10:30am UTC](https://discourse.cakephp.org/t/multi-language-site/3830/6 "2018-02-05T10:30:45Z")

</div>

Thank you for replying.  
donnidani : the first link is about translating strings and I already read this page. It’s not about methods and organization. The second link seems interesting and I missed it. I’ll take a look.

Thanks again all.

---

<div class="post-metadata">

**Author:** ![SKyer](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/skyer/32/734_2.png) [@SKyer](https://discourse.cakephp.org/u/SKyer)\
**Post date:** [February 6, 2018, 9:30am UTC](https://discourse.cakephp.org/t/multi-language-site/3830/7 "2018-02-06T09:30:03Z")

</div>

Hello!

> **[lklich/CallCenter](https://github.com/lklich/CallCenter)**
>
> Call Center system multiuser multilanguage. Contribute to lklich/CallCenter development by creating an account on GitHub.

  
There is my example simple multilanguage system (full source).

Define native language in config/app.conf \<- ‘defaultLocale’ =\> env(‘APP\_DEFAULT\_LOCALE’, ‘pl\_PL’), (polish is nativa lang of app).

In Template-\>Laypout-\>Default place switches with flags, for example:

\<?php //if (isset($lang) && ($lang == 'pl\_PL')) { echo '- ' . $this-\>Html-\>link($this-\>Html-\>image('PL.png'), ['action' =\> 'changeLang', 'pl\_PL'], array('escape' =\> false)) .'
'; echo '- ' . $this-\>Html-\>link($this-\>Html-\>image('GB.png'), ['action' =\> 'changeLang', 'en\_US'], array('escape' =\> false)) . '
'; echo '- ' . $this-\>Html-\>link($this-\>Html-\>image('DE.png'), ['action' =\> 'changeLang', 'de\_DE'], array('escape' =\> false)) . '
'; ?\>

In src/locale (create if not exist), place localisations folders, for example: en\_US, de\_DE, pl\_PL  
create single file named: default.po

\<?php msgid "Środowisko serwera" \<- native app lang msgstr "Environment" \<- translate msgid "Operator" msgstr "Employer" ?\>

in Controllers, Views: \_\_(‘Środowisko serwera’) \<- this can be translate to “Environment”.

in src/Controller/AppController.php create 2 functions:  
public function changeLang($lang = ‘pl\_PL’)  
{  
$this-\>Cookie-\>write(‘lang’, $lang);  
return $this-\>redirect($this-\>request-\>referer());  
}  
public function getLang($lang = ‘pl\_PL’)  
{  
$lang = $this-\>Cookie-\>read(‘lang’);  
if (empty($lang)) { return ‘pl\_PL’; } else return $lang;  
}

Regards  
Leszek

---

<div class="post-metadata">

**Author:** ![Graziel](https://avatars.discourse-cdn.com/v4/letter/g/71c47a/32.png) [@Graziel](https://discourse.cakephp.org/u/Graziel)\
**Post date:** [February 6, 2018, 4:58pm UTC](https://discourse.cakephp.org/t/multi-language-site/3830/8 "2018-02-06T16:58:41Z")

</div>

i did some multilanguage sites before and there are few tips i can give you:

1. add context to every string - use `__x()` and `__dx()`
2. add description in context to agruments ie. “{0} - city name” OR use named argument {cityName}
3. try to keep domains in some logic, ie. emails, logs
4. some of translation can expand text length by huge margin - can break your layout
5. some languages are gendered so its know beforehand if you want to expand translation to it
6. i add language to URL as route part ie [example.com/en\_GB/home](http://example.com/en_GB/home) but root path [example.com](http://example.com) is using HTTP\_ACCEPT\_LANGUAGE request header and redirects to best fit language
7. longer text are better in separate templates instead of using `__()` - ie. `ToS_en_GB.ctp`

---

<div class="post-metadata">

**Author:** ![6120](https://avatars.discourse-cdn.com/v4/letter/6/278dde/32.png) [@6120](https://discourse.cakephp.org/u/6120)\
**Post date:** [February 7, 2018, 8:36am UTC](https://discourse.cakephp.org/t/multi-language-site/3830/9 "2018-02-07T08:36:29Z")

</div>

SKyer, Graziel  
Thank you very much for sharing.  
This is very helpful.
