7

I guess there should be some standard method for this, just to avoid everybody retyping dull constants for their applications. ;) I am looking for a function (usable in a php web app on linux) that can take two ISO639 language codes and returns the name of the first language in the second language, i.e. foo("fr","de") should return "französisch" and foo("de","fr") should return "allemagne".

Is there?

Jenszcz
  • 547
  • 3
  • 9
Hagen von Eitzen
  • 2,109
  • 21
  • 25

1 Answers1

17

Locale::getDisplayLanguage is what you need. It is in PHP International Extension so if it is not on you have to turn on php_intl.so (or dll if Windows).

if (version_compare(PHP_VERSION, '5.3.0', '<')) {
    exit ('php_intl extension is available on PHP 5.3.0 or later.');
}    
if (!class_exists('Locale')) {
    exit ('You need to install php_intl extension.');
}

echo Locale::getDisplayLanguage('fr', 'de');
akky
  • 2,818
  • 21
  • 31
  • Thanks a Lot @akky – LuFFy Nov 03 '16 at 09:40
  • 1
    I wrote an answer for the opposite direction, [display name to iso code conversion](https://stackoverflow.com/questions/25041306/converting-language-name-to-locale-code/57989232) as well. – akky Sep 20 '19 at 02:15