语言国家代码转换

有谁知道如何将语言国家代码(如下所示)转换为实际语言的名称?</ p >

  en_US 
de_DE
en_GB
it_IT
fr_FR
</ code> </ pre>

我有动态输入,需要转换语言国家/地区 代码到相应的语言名称(即en_US =英语,fr_FR =法语)。</ p>
</ div>

展开原文

原文

Does anyone know how to convert language country codes like the ones below into the name of the actual language?

en_US
de_DE
en_GB
it_IT
fr_FR

I have a dynamic input and would need to convert the language country code to the corresponding name of the language (i.e en_US = English, fr_FR = French).

php
douyun6399
douyun6399 msdn.microsoft.com/en-us/library/ms533052%28v=vs.85%29.aspx
8 年多之前 回复

3个回答

Check this code and it works fine i have used the codes from http://msdn.microsoft.com/en-us/library/ms533052%28v=vs.85%29.aspx

<?php
    $strLcodes = '<tr><td>af</td><td>Afrikaans </td><td>sq</td><td>Albanian </td></tr>
    <tr><td>ar-sa</td><td>Arabic (Saudi Arabia) </td><td>ar-iq</td><td>Arabic (Iraq) </td></tr>
    <tr><td>ar-eg</td><td>Arabic (Egypt) </td><td>ar-ly</td><td>Arabic (Libya) </td></tr>
    <tr><td>ar-dz</td><td>Arabic (Algeria) </td><td>ar-ma</td><td>Arabic (Morocco) </td></tr>

    <tr><td>ar-tn</td><td>Arabic (Tunisia) </td><td>ar-om</td><td>Arabic (Oman) </td></tr>
    <tr><td>ar-ye</td><td>Arabic (Yemen) </td><td>ar-sy</td><td>Arabic (Syria) </td></tr>
    <tr><td>ar-jo</td><td>Arabic (Jordan) </td><td>ar-lb</td><td>Arabic (Lebanon) </td></tr>
    <tr><td>ar-kw</td><td>Arabic (Kuwait) </td><td>ar-ae</td><td>Arabic (U.A.E.) </td></tr>

    <tr><td>ar-bh</td><td>Arabic (Bahrain) </td><td>ar-qa</td><td>Arabic (Qatar) </td></tr>
    <tr><td>eu</td><td>Basque </td><td>bg</td><td>Bulgarian </td></tr>
    <tr><td>be</td><td>Belarusian </td><td>ca</td><td>Catalan </td></tr>
    <tr><td>zh-tw</td><td>Chinese (Taiwan) </td><td>zh-cn</td><td>Chinese (PRC) </td></tr>

    <tr><td>zh-hk</td><td>Chinese (Hong Kong SAR) </td><td>zh-sg</td><td>Chinese (Singapore) </td></tr>
    <tr><td>hr</td><td>Croatian </td><td>cs</td><td>Czech </td></tr>
    <tr><td>da</td><td>Danish </td><td>nl</td><td>Dutch (Standard) </td></tr>
    <tr><td>nl-be</td><td>Dutch (Belgium) </td><td>en</td><td>English </td></tr>

    <tr><td>en-us</td><td>English (United States) </td><td>en-gb</td><td>English (United Kingdom) </td></tr>
    <tr><td>en-au</td><td>English (Australia) </td><td>en-ca</td><td>English (Canada) </td></tr>
    <tr><td>en-nz</td><td>English (New Zealand) </td><td>en-ie</td><td>English (Ireland) </td></tr>
    <tr><td>en-za</td><td>English (South Africa) </td><td>en-jm</td><td>English (Jamaica) </td></tr>

    <tr><td>en</td><td>English (Caribbean) </td><td>en-bz</td><td>English (Belize) </td></tr>
    <tr><td>en-tt</td><td>English (Trinidad) </td><td>et</td><td>Estonian </td></tr>
    <tr><td>fo</td><td>Faeroese </td><td>fa</td><td>Farsi </td></tr>
    <tr><td>fi</td><td>Finnish </td><td>fr</td><td>French (Standard) </td></tr>

    <tr><td>fr-be</td><td>French (Belgium) </td><td>fr-ca</td><td>French (Canada) </td></tr>
    <tr><td>fr-ch</td><td>French (Switzerland) </td><td>fr-lu</td><td>French (Luxembourg) </td></tr>
    <tr><td>gd</td><td>Gaelic (Scotland) </td><td>ga</td><td>Irish </td></tr>
    <tr><td>de</td><td>German (Standard) </td><td>de-ch</td><td>German (Switzerland) </td></tr>

    <tr><td>de-at</td><td>German (Austria) </td><td>de-lu</td><td>German (Luxembourg) </td></tr>
    <tr><td>de-li</td><td>German (Liechtenstein) </td><td>el</td><td>Greek </td></tr>
    <tr><td>he</td><td>Hebrew </td><td>hi</td><td>Hindi </td></tr>
    <tr><td>hu</td><td>Hungarian </td><td>is</td><td>Icelandic </td></tr>

    <tr><td>id</td><td>Indonesian </td><td>it</td><td>Italian (Standard) </td></tr>
    <tr><td>it-ch</td><td>Italian (Switzerland) </td><td>ja</td><td>Japanese </td></tr>
    <tr><td>ko</td><td>Korean </td><td>ko</td><td>Korean (Johab) </td></tr>
    <tr><td>lv</td><td>Latvian </td><td>lt</td><td>Lithuanian </td></tr>

    <tr><td>mk</td><td>Macedonian (FYROM)</td><td>ms</td><td>Malaysian </td></tr>
    <tr><td>mt</td><td>Maltese </td><td>no</td><td>Norwegian (Bokmal) </td></tr>
    <tr><td>no</td><td>Norwegian (Nynorsk) </td><td>pl</td><td>Polish </td></tr>
    <tr><td>pt-br</td><td>Portuguese (Brazil) </td><td>pt</td><td>Portuguese (Portugal) </td></tr>

    <tr><td>rm</td><td>Rhaeto-Romanic </td><td>ro</td><td>Romanian </td></tr>
    <tr><td>ro-mo</td><td>Romanian (Republic of Moldova) </td><td>ru</td><td>Russian </td></tr>
    <tr><td>ru-mo</td><td>Russian (Republic of Moldova) </td><td>sz</td><td>Sami (Lappish) </td></tr>
    <tr><td>sr</td><td>Serbian (Cyrillic) </td><td>sr</td><td>Serbian (Latin) </td></tr>

    <tr><td>sk</td><td>Slovak </td><td>sl</td><td>Slovenian </td></tr>
    <tr><td>sb</td><td>Sorbian </td><td>es</td><td>Spanish (Spain) </td></tr>
    <tr><td>es-mx</td><td>Spanish (Mexico) </td><td>es-gt</td><td>Spanish (Guatemala) </td></tr>
    <tr><td>es-cr</td><td>Spanish (Costa Rica) </td><td>es-pa</td><td>Spanish (Panama) </td></tr>

    <tr><td>es-do</td><td>Spanish (Dominican Republic) </td><td>es-ve</td><td>Spanish (Venezuela) </td></tr>
    <tr><td>es-co</td><td>Spanish (Colombia) </td><td>es-pe</td><td>Spanish (Peru) </td></tr>
    <tr><td>es-ar</td><td>Spanish (Argentina) </td><td>es-ec</td><td>Spanish (Ecuador) </td></tr>
    <tr><td>es-cl</td><td>Spanish (Chile) </td><td>es-uy</td><td>Spanish (Uruguay) </td></tr>

    <tr><td>es-py</td><td>Spanish (Paraguay) </td><td>es-bo</td><td>Spanish (Bolivia) </td></tr>
    <tr><td>es-sv</td><td>Spanish (El Salvador) </td><td>es-hn</td><td>Spanish (Honduras) </td></tr>
    <tr><td>es-ni</td><td>Spanish (Nicaragua) </td><td>es-pr</td><td>Spanish (Puerto Rico) </td></tr>
    <tr><td>sx</td><td>Sutu </td><td>sv</td><td>Swedish </td></tr>

    <tr><td>sv-fi</td><td>Swedish (Finland) </td><td>th</td><td>Thai </td></tr>
    <tr><td>ts</td><td>Tsonga </td><td>tn</td><td>Tswana </td></tr>
    <tr><td>tr</td><td>Turkish </td><td>uk</td><td>Ukrainian </td></tr>
    <tr><td>ur</td><td>Urdu </td><td>ve</td><td>Venda </td></tr>

    <tr><td>vi</td><td>Vietnamese </td><td>xh</td><td>Xhosa </td></tr>
    <tr><td>ji</td><td>Yiddish </td><td>zu</td><td>Zulu </td></tr>
    ';
    error_reporting(E_PARSE | E_ERROR);
    $dom = new DOMDocument();
    $dom->loadHTML($strLcodes);

    $xml = simplexml_import_dom($dom);
    $path = $xml->xpath('//td');
    echo "<pre>";
    $strpath  = implode('|',$path);

    echo str_replace(' |', '<br/>',$strpath);
    echo "</pre>";

?>

展开原文

dongpo1846
dongpo1846 嗨@simple,谢谢你。 但是如何用PHP将像en_US这样的代码转换为“英语”呢?
8 年多之前 回复



如果您想有更多选择(例如用其他语言显示的语言名称等等),请选择 通过Unicode Consortium查看公共语言数据存储库(CLDR)</ em>。</ p>

  http://unicode.org/cldr/trac/browser  / trunk / common / main 
</ code> </ pre>

您将找到易于解析的XML文件,其中包含有关遍布全球的许多人收集的那些代码(以及其他内容)的信息。 目的是让它更易于访问。</ p>

您可以使用 svn </ code>轻松检出目录,使用 RecursiveDirectoryIterator </ code> 然后 DOMDocument </ code>和 DOMXPath </ code>来获取 信息。</ p>
</ div>

展开原文

原文

If you want to have more choice (e.g. the name of the languages for display in other languages and so on and so forth), take a look into the Common Language Data Repository (CLDR) by the Unicode Consortium.

http://unicode.org/cldr/trac/browser/trunk/common/main

You will find easily parseable XML files that contain information about those codes (and other stuff) collected by many individuals all over the planet with the aim to make this more accessible.

You can easily checkout the directories out from there with svn, use RecursiveDirectoryIterator and then DOMDocument and DOMXPath to aquire the information.

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问