Language codes¶
This is the one that trips everyone up. Eurotext does not speak BCP-47. It has its
own codes. Most are just lowercase BCP-47 (de-DE → de-de), but a chunk of them
aren't, and there's no rule you can derive them from — you have to look them up.
The always-correct source is GET /info/languages. LanguageMap covers the
common locales so you don't have to hit the API for every conversion.
use Eurotext\LanguageMap;
LanguageMap::toEurotext('de-DE'); // 'de-de'
LanguageMap::toEurotext('mt-MT'); // 'mlt' <- not "mt-mt"
LanguageMap::toEurotext('de-de'); // 'de-de' (already Eurotext form, passes through)
LanguageMap::toEurotext('xx-YY'); // throws InvalidArgumentException
The ones that bite¶
If you only remember a handful, remember that these are not lowercase BCP-47:
| Locale | Eurotext | Locale | Eurotext | |
|---|---|---|---|---|
mt-MT |
mlt |
ga-IE |
gai |
|
da-DK |
da |
cs-CZ |
cz-cz |
|
vi-VN |
vn |
id-ID |
ind |
|
ms-MY |
msa |
hi-IN |
hin |
|
is-IS |
ice |
cy-GB |
wel |
|
ca-ES |
cat |
gl-ES |
glg |
|
af-ZA |
afr |
sq-AL |
alb |
Plenty of single-region languages also drop the region entirely: pl-PL → pl,
hu-HU → hu, tr-TR → tr, uk-UA → uk, el-GR → el, and so on.
Common ones that behave¶
These are exactly what you'd guess — lowercase the whole thing:
de-DE→de-de, de-AT→de-at, de-CH→de-ch, en-GB→en-gb,
en-US→en-us, fr-FR→fr-fr, es-ES→es-es, es-MX→es-mx,
it-IT→it-it, nl-NL→nl-nl, pt-PT→pt-pt, pt-BR→pt-br,
ru-RU→ru-ru, zh-CN→zh-cn, zh-TW→zh-tw, ja-JP→ja, ko-KR→ko-kr.
The full mapping lives in src/LanguageMap.php. If you hit a locale it doesn't
know, add it there (and pull the exact code from /info/languages).
When to trust the live list over the table¶
The table in LanguageMap is a convenience copy and can drift if Eurotext adds
languages. If you're building anything that lets a user pick a target language,
populate the dropdown from GET /info/languages at runtime rather than from the
static table.