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

会有一股神秘感。 提交于 2019-12-21 12:27:38

问题


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?


回答1:


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');


来源:https://stackoverflow.com/questions/15276101/standard-function-to-translate-iso-639-codes-to-language-name

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!