Search code examples
phptranslationlocalemultilingual

PHP get name for locale


I want to get a localized name for a locale. For example:

I have an array of locales (in real the array is much bigger):

$languageAndRegion = array (
    'de',
    'de_AT',
    'de_CH',
    'de_DE',
    'de_LI',
    'de_LU'
);

And now i want to get something like that:

foreach ($languageAndRegion as &$value) {
    $name = magicFunction($value, 'en');
    echo $name;
}

The output should be like that:

German
German (Austria)
German (Germany)
German (Swiss)
...

Solution

  • locale_get_display_name($value, 'en');?