Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

standard function to translate iso-639 codes to language name?

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?

like image 304
Hagen von Eitzen Avatar asked Mar 07 '13 16:03

Hagen von Eitzen


People also ask

What is the standard for language codes?

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.

What is the official language used by the ISO?

The three official languages of the ISO are English, French, and Russian.

What are the three 3 official languages of ISO?

That's why, since 1947, we have had three official languages: English, French and Russian.

How many ISO 639-2 codes are there?

There are 487 entries in the list of ISO 639-2 codes.


1 Answers

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');
like image 171
akky Avatar answered Nov 14 '22 23:11

akky