Reputation: 1740
I'm developing a site that uses the following CakePHP functionality:
One thing I am unsure even though I have read the docs is how to uniformly refer to the languages in different places.
Taking German as an example, what would replace the ?
below:
Setting the locale so CakePHP knows which po file to use
Configure::write('Config.language', '?');
my guess is deu
The path for po files
/app/locale/?/LC_MESSAGES/default.po
my guess is deu
Saving in a specific language
$this->Post->locale = '?';
This one confuses me as the example shows de_de. Does this automatically map to my Config.language
?
If so, where can I find these mappings?
Upvotes: 0
Views: 1218
Reputation: 3106
In Cake 1.3, I have used
Configure::write ('Config.language', 'ger');
Which looks for /locale/ger/LC_MESSAGES/default.po; in hindsight this was wrong as the 'official' code for German is 'deu', as you pointed out. However, I think you can use any identifier for your language as long as it is in the proper subdirectory.
The interesting part happens when you want to use the locale() functions to format numbers, dates, etc. with:
setlocale (LC_TIME, 'de_DE');
setlocale (LC_MONETARY, 'de_DE');
However, heed the warning at http://php.net/manual/en/function.setlocale.php about using setlocale.
--- Amendement
You must remember that a locale is something completely different than a language. A locale specifies how you format numbers, time, money, compare string and sort them. And yes, the locale also has the LC_MESSAGES category which is used for translations. But hear me out.
A language can be spoken in many countries, so you'd think you can use your translations for all those countries. But you quickly run into problems. For example, English is spoken in the UK, USA, Canada and a whole lot of other countries with minor differences. But printing the date is a different matter. The USA use the month/day/year format, while the UK uses day/month/year. Some countries use slashes between the fields, others use dashes or dots; some use the name of the month and not a number. Et cetera.
So, localization is used for a specific country, not a language. However, there are countries where more than one language is spoken. That's why a localization string has two parts: the first part is the language, the second the country (for example de_BE, fr_BE, nl_BE and even wa_BE).
The IMO confusing part is that message translation is also part of the locale. For some languages this makes sense, for example Portuguese which is spoken in both Portugal and Brazil but is sufficiently different to warrant different translation files (pt_PT vs pt_BR). French, on the other hand, is to my knowledge 99.99% the same everywhere, but it would be rather cumbersome to duplicate the same language file for France, Canada, Switzerland, Belgium and Luxembourg. So most programmers decide on a 'language' file when building a multilingual site and swoop the countries together. CakePHP has a similar halfbaked (if you'll excuse the pun...) approach: both language files and localization.
To get back to your post: if there is talk about localization, you should use the 'de_DE' style strings. When merely talking about a language, the 3 letter codes from ISO 639:2 should work.... It may also help to keep the two apart.
Upvotes: 1