Contao news

Read the official Contao announcements.

Which locale to register when translating Contao?

by Leo Feyer – Current issues

Extended locales such as "en_US" are already supported in the Contao Check and will be supported in the Contao core in the upcoming feature release (Contao 3.1). But when do they make sense?

Let us take German as an example, which is mainly spoken in Germany (de_DE), Austria (de_AT) and Switzer­land (de_CH). It is not a problem to register the three translations on transifex.com or to create web site root pages for the different regions in the Contao site structure. However, there is also a two-character locale (de), which one of the three translations has to be mapped to.

Define a default variant

If there is more than one variant, you (the translator teams) have to make one of them the default one. In my example above, this would be "de_DE", because most of the German-speaking people live in Germany.

Register the two-character locale

The default variant is then registered with its two-character locale only, which means that there will never be a "de_DE" translation, because it is already represented by just "de". (Yes, I did that wrong in the Contao Check myself.) Once there is a default translation, other variants like "de_CH" can be added to e.g. create a Swiss-German translation.

Two-character locales are obligatory

Even if it is likely that your translation will not be the default, e.g. if there was no German translation yet and you would start with the Swiss German one, you would have to register your translation as "de" and not as "de_CH". It is no problem at all to change the locale later if other variants are added, but it would be a prob­lem if there was only a "de_CH" translation and no "de" translation: German-speaking users outside Switzer­land would never see the German labels.

Show all news

Comments

Comment by Cyril |

Hi Leo,

it seems that the gettext extension uses only the locales which are installed on the system. My host provider has only these locales installed: en_US.utf8, fr_FR, fr_FR.iso88591, fr_FR.iso885915@euro, fr_FR.utf8, fr_FR@euro, français, french.

Then, when I run Contao Check I have only messages in english because en_US is the language fallback. If I use "check/?lng=de" or "check/?lng=fr" or "check/?lng=it", the messages are always in english. Are you sure that using gettext extension is the better solution ?

Reply by Leo Feyer

That's strange. The locales are correct and should suffice to use the French translation. I have the same fr_* locales on my test system and the script correctly loads the French translation (although stored as "fr" in the Contao Check) if I append "/?lng=fr" to the URL.

Add a comment

Please add 7 and 6.