- What I want
What I want to do is, based on the Accept-Language sent by the user's browser, to translate both the in-code strings (__('translatable string')) and the fields I have configured from tables that have the TranslateBehavior.
- What I did
Added
DispatcherFactory::add('LocaleSelector', ['locales' => ['en_US', 'el_GR']]);
in bootstrap.php in order to set the locale automatically, using the Accept-Language that is sent by the user's browser. This works just fine and sets the locale to either en_US or el_GR.
I also have setup i18n (following http://book.cakephp.org/3.0/en/orm/behaviors/translate.html) because I want some fields of a table of mine to be translatable.
Of course, I have strings in my code that do not come from the database and need to be translated. I use the __() function for that.
- The problem
Let's say the user, through Accept-Language, requests Greek (el_GR), then the locale will be set to el_GR. The function __() will work out of the box, because it is exactly what it needs.
But, the TranslateBehavior will not work, because it needs gre, not el_GR.
How can I make those 2 work at the same time, while they expect different locale value for the same language?