将iso-639代码转换为语言名称的标准功能? [英] standard function to translate iso-639 codes to language name?

查看:91
本文介绍了将iso-639代码转换为语言名称的标准功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想应该为此使用一些标准方法,以避免每个人都为自己的应用重新键入钝常数. ;) 我正在寻找一个函数(可以在Linux上的php Web应用程序中使用),该函数可以采用两个ISO639语言代码,并以 second 语言返回 first 语言的名称, IE foo("fr","de")应该返回"französisch",而foo("de","fr")应该返回"allemagne".

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".

在那里吗?

推荐答案

语言环境: :getDisplayLanguage 是您所需要的.它在PHP International Extension中,因此如果未打开,则必须打开php_intl.so(如果是Windows,则为dll).

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

这篇关于将iso-639代码转换为语言名称的标准功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆