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?
ISO 639 is a standardized nomenclature used to classify languages. Each language is assigned a two-letter (639-1) and three-letter (639-2 and 639-3) lowercase abbreviation, amended in later versions of the nomenclature. This table lists all of: ISO 639-1: two-letter codes, one per language for ISO 639 macrolanguage.
The three official languages of the ISO are English, French, and Russian.
That's why, since 1947, we have had three official languages: English, French and Russian.
There are 487 entries in the list of ISO 639-2 codes.
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');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With