在Java中,你可以调用Locale.getAvailableLocales()
来获取可用的语言环境列表。
我期待从PHP等效语言环境类,但没能找到。
有没有办法让所有有效语言环境的数组?
在Java中,你可以调用Locale.getAvailableLocales()
来获取可用的语言环境列表。
我期待从PHP等效语言环境类,但没能找到。
有没有办法让所有有效语言环境的数组?
这里的混乱的部分原因是,PHP有两个概念,所谓的“语言环境”是几乎完全分开。
首先是旧的一个,它基本上只是使用C语言环境的功能。 这就是背后setlocale
和一些PHP的功能区域设置的支持(如money_format
为例)。 这是什么,提运行其他的答案locale -a
命令行中使用setlocale
都在谈论。
PHP的Locale
类和从其他相关功能intl
推广是较新的,不相同的方式工作。 而不是使用libc中的locale设置的,它使用一种称为ICU库,船舶自身的语言环境数据。 PHP 确实提供了一种方法来确定哪些语言环境是由本系统支持: 资源包:: getLocales 。 该文档是有点毛茸茸这里,但你可以把这个作为一个静态方法并传递空字符串使用ICU的默认资源,从而获得了所支持的语言列表intl
:
ResourceBundle::getLocales('');
我不认为有一个内置该功能。 你要问要安装的语言环境的操作系统。
例如,如果在UNIX系统上运行,你需要执行以下命令:
$ locale -a
我现在也解决了这个问题。 这里发生了什么事。
<?php
return array(
'aa_DJ' => 'Afar (Djibouti)',
'aa_ER' => 'Afar (Eritrea)',
'aa_ET' => 'Afar (Ethiopia)',
'af_ZA' => 'Afrikaans (South Africa)',
'sq_AL' => 'Albanian (Albania)',
'sq_MK' => 'Albanian (Macedonia)',
'am_ET' => 'Amharic (Ethiopia)',
'ar_DZ' => 'Arabic (Algeria)',
'ar_BH' => 'Arabic (Bahrain)',
'ar_EG' => 'Arabic (Egypt)',
'ar_IN' => 'Arabic (India)',
'ar_IQ' => 'Arabic (Iraq)',
'ar_JO' => 'Arabic (Jordan)',
'ar_KW' => 'Arabic (Kuwait)',
'ar_LB' => 'Arabic (Lebanon)',
'ar_LY' => 'Arabic (Libya)',
'ar_MA' => 'Arabic (Morocco)',
'ar_OM' => 'Arabic (Oman)',
'ar_QA' => 'Arabic (Qatar)',
'ar_SA' => 'Arabic (Saudi Arabia)',
'ar_SD' => 'Arabic (Sudan)',
'ar_SY' => 'Arabic (Syria)',
'ar_TN' => 'Arabic (Tunisia)',
'ar_AE' => 'Arabic (United Arab Emirates)',
'ar_YE' => 'Arabic (Yemen)',
'an_ES' => 'Aragonese (Spain)',
'hy_AM' => 'Armenian (Armenia)',
'as_IN' => 'Assamese (India)',
'ast_ES' => 'Asturian (Spain)',
'az_AZ' => 'Azerbaijani (Azerbaijan)',
'az_TR' => 'Azerbaijani (Turkey)',
'eu_FR' => 'Basque (France)',
'eu_ES' => 'Basque (Spain)',
'be_BY' => 'Belarusian (Belarus)',
'bem_ZM' => 'Bemba (Zambia)',
'bn_BD' => 'Bengali (Bangladesh)',
'bn_IN' => 'Bengali (India)',
'ber_DZ' => 'Berber (Algeria)',
'ber_MA' => 'Berber (Morocco)',
'byn_ER' => 'Blin (Eritrea)',
'bs_BA' => 'Bosnian (Bosnia and Herzegovina)',
'br_FR' => 'Breton (France)',
'bg_BG' => 'Bulgarian (Bulgaria)',
'my_MM' => 'Burmese (Myanmar [Burma])',
'ca_AD' => 'Catalan (Andorra)',
'ca_FR' => 'Catalan (France)',
'ca_IT' => 'Catalan (Italy)',
'ca_ES' => 'Catalan (Spain)',
'zh_CN' => 'Chinese (China)',
'zh_HK' => 'Chinese (Hong Kong SAR China)',
'zh_SG' => 'Chinese (Singapore)',
'zh_TW' => 'Chinese (Taiwan)',
'cv_RU' => 'Chuvash (Russia)',
'kw_GB' => 'Cornish (United Kingdom)',
'crh_UA' => 'Crimean Turkish (Ukraine)',
'hr_HR' => 'Croatian (Croatia)',
'cs_CZ' => 'Czech (Czech Republic)',
'da_DK' => 'Danish (Denmark)',
'dv_MV' => 'Divehi (Maldives)',
'nl_AW' => 'Dutch (Aruba)',
'nl_BE' => 'Dutch (Belgium)',
'nl_NL' => 'Dutch (Netherlands)',
'dz_BT' => 'Dzongkha (Bhutan)',
'en_AG' => 'English (Antigua and Barbuda)',
'en_AU' => 'English (Australia)',
'en_BW' => 'English (Botswana)',
'en_CA' => 'English (Canada)',
'en_DK' => 'English (Denmark)',
'en_HK' => 'English (Hong Kong SAR China)',
'en_IN' => 'English (India)',
'en_IE' => 'English (Ireland)',
'en_NZ' => 'English (New Zealand)',
'en_NG' => 'English (Nigeria)',
'en_PH' => 'English (Philippines)',
'en_SG' => 'English (Singapore)',
'en_ZA' => 'English (South Africa)',
'en_GB' => 'English (United Kingdom)',
'en_US' => 'English (United States)',
'en_ZM' => 'English (Zambia)',
'en_ZW' => 'English (Zimbabwe)',
'eo' => 'Esperanto',
'et_EE' => 'Estonian (Estonia)',
'fo_FO' => 'Faroese (Faroe Islands)',
'fil_PH' => 'Filipino (Philippines)',
'fi_FI' => 'Finnish (Finland)',
'fr_BE' => 'French (Belgium)',
'fr_CA' => 'French (Canada)',
'fr_FR' => 'French (France)',
'fr_LU' => 'French (Luxembourg)',
'fr_CH' => 'French (Switzerland)',
'fur_IT' => 'Friulian (Italy)',
'ff_SN' => 'Fulah (Senegal)',
'gl_ES' => 'Galician (Spain)',
'lg_UG' => 'Ganda (Uganda)',
'gez_ER' => 'Geez (Eritrea)',
'gez_ET' => 'Geez (Ethiopia)',
'ka_GE' => 'Georgian (Georgia)',
'de_AT' => 'German (Austria)',
'de_BE' => 'German (Belgium)',
'de_DE' => 'German (Germany)',
'de_LI' => 'German (Liechtenstein)',
'de_LU' => 'German (Luxembourg)',
'de_CH' => 'German (Switzerland)',
'el_CY' => 'Greek (Cyprus)',
'el_GR' => 'Greek (Greece)',
'gu_IN' => 'Gujarati (India)',
'ht_HT' => 'Haitian (Haiti)',
'ha_NG' => 'Hausa (Nigeria)',
'iw_IL' => 'Hebrew (Israel)',
'he_IL' => 'Hebrew (Israel)',
'hi_IN' => 'Hindi (India)',
'hu_HU' => 'Hungarian (Hungary)',
'is_IS' => 'Icelandic (Iceland)',
'ig_NG' => 'Igbo (Nigeria)',
'id_ID' => 'Indonesian (Indonesia)',
'ia' => 'Interlingua',
'iu_CA' => 'Inuktitut (Canada)',
'ik_CA' => 'Inupiaq (Canada)',
'ga_IE' => 'Irish (Ireland)',
'it_IT' => 'Italian (Italy)',
'it_CH' => 'Italian (Switzerland)',
'ja_JP' => 'Japanese (Japan)',
'kl_GL' => 'Kalaallisut (Greenland)',
'kn_IN' => 'Kannada (India)',
'ks_IN' => 'Kashmiri (India)',
'csb_PL' => 'Kashubian (Poland)',
'kk_KZ' => 'Kazakh (Kazakhstan)',
'km_KH' => 'Khmer (Cambodia)',
'rw_RW' => 'Kinyarwanda (Rwanda)',
'ky_KG' => 'Kirghiz (Kyrgyzstan)',
'kok_IN' => 'Konkani (India)',
'ko_KR' => 'Korean (South Korea)',
'ku_TR' => 'Kurdish (Turkey)',
'lo_LA' => 'Lao (Laos)',
'lv_LV' => 'Latvian (Latvia)',
'li_BE' => 'Limburgish (Belgium)',
'li_NL' => 'Limburgish (Netherlands)',
'lt_LT' => 'Lithuanian (Lithuania)',
'nds_DE' => 'Low German (Germany)',
'nds_NL' => 'Low German (Netherlands)',
'mk_MK' => 'Macedonian (Macedonia)',
'mai_IN' => 'Maithili (India)',
'mg_MG' => 'Malagasy (Madagascar)',
'ms_MY' => 'Malay (Malaysia)',
'ml_IN' => 'Malayalam (India)',
'mt_MT' => 'Maltese (Malta)',
'gv_GB' => 'Manx (United Kingdom)',
'mi_NZ' => 'Maori (New Zealand)',
'mr_IN' => 'Marathi (India)',
'mn_MN' => 'Mongolian (Mongolia)',
'ne_NP' => 'Nepali (Nepal)',
'se_NO' => 'Northern Sami (Norway)',
'nso_ZA' => 'Northern Sotho (South Africa)',
'nb_NO' => 'Norwegian Bokmål (Norway)',
'nn_NO' => 'Norwegian Nynorsk (Norway)',
'oc_FR' => 'Occitan (France)',
'or_IN' => 'Oriya (India)',
'om_ET' => 'Oromo (Ethiopia)',
'om_KE' => 'Oromo (Kenya)',
'os_RU' => 'Ossetic (Russia)',
'pap_AN' => 'Papiamento (Netherlands Antilles)',
'ps_AF' => 'Pashto (Afghanistan)',
'fa_IR' => 'Persian (Iran)',
'pl_PL' => 'Polish (Poland)',
'pt_BR' => 'Portuguese (Brazil)',
'pt_PT' => 'Portuguese (Portugal)',
'pa_IN' => 'Punjabi (India)',
'pa_PK' => 'Punjabi (Pakistan)',
'ro_RO' => 'Romanian (Romania)',
'ru_RU' => 'Russian (Russia)',
'ru_UA' => 'Russian (Ukraine)',
'sa_IN' => 'Sanskrit (India)',
'sc_IT' => 'Sardinian (Italy)',
'gd_GB' => 'Scottish Gaelic (United Kingdom)',
'sr_ME' => 'Serbian (Montenegro)',
'sr_RS' => 'Serbian (Serbia)',
'sid_ET' => 'Sidamo (Ethiopia)',
'sd_IN' => 'Sindhi (India)',
'si_LK' => 'Sinhala (Sri Lanka)',
'sk_SK' => 'Slovak (Slovakia)',
'sl_SI' => 'Slovenian (Slovenia)',
'so_DJ' => 'Somali (Djibouti)',
'so_ET' => 'Somali (Ethiopia)',
'so_KE' => 'Somali (Kenya)',
'so_SO' => 'Somali (Somalia)',
'nr_ZA' => 'South Ndebele (South Africa)',
'st_ZA' => 'Southern Sotho (South Africa)',
'es_AR' => 'Spanish (Argentina)',
'es_BO' => 'Spanish (Bolivia)',
'es_CL' => 'Spanish (Chile)',
'es_CO' => 'Spanish (Colombia)',
'es_CR' => 'Spanish (Costa Rica)',
'es_DO' => 'Spanish (Dominican Republic)',
'es_EC' => 'Spanish (Ecuador)',
'es_SV' => 'Spanish (El Salvador)',
'es_GT' => 'Spanish (Guatemala)',
'es_HN' => 'Spanish (Honduras)',
'es_MX' => 'Spanish (Mexico)',
'es_NI' => 'Spanish (Nicaragua)',
'es_PA' => 'Spanish (Panama)',
'es_PY' => 'Spanish (Paraguay)',
'es_PE' => 'Spanish (Peru)',
'es_ES' => 'Spanish (Spain)',
'es_US' => 'Spanish (United States)',
'es_UY' => 'Spanish (Uruguay)',
'es_VE' => 'Spanish (Venezuela)',
'sw_KE' => 'Swahili (Kenya)',
'sw_TZ' => 'Swahili (Tanzania)',
'ss_ZA' => 'Swati (South Africa)',
'sv_FI' => 'Swedish (Finland)',
'sv_SE' => 'Swedish (Sweden)',
'tl_PH' => 'Tagalog (Philippines)',
'tg_TJ' => 'Tajik (Tajikistan)',
'ta_IN' => 'Tamil (India)',
'tt_RU' => 'Tatar (Russia)',
'te_IN' => 'Telugu (India)',
'th_TH' => 'Thai (Thailand)',
'bo_CN' => 'Tibetan (China)',
'bo_IN' => 'Tibetan (India)',
'tig_ER' => 'Tigre (Eritrea)',
'ti_ER' => 'Tigrinya (Eritrea)',
'ti_ET' => 'Tigrinya (Ethiopia)',
'ts_ZA' => 'Tsonga (South Africa)',
'tn_ZA' => 'Tswana (South Africa)',
'tr_CY' => 'Turkish (Cyprus)',
'tr_TR' => 'Turkish (Turkey)',
'tk_TM' => 'Turkmen (Turkmenistan)',
'ug_CN' => 'Uighur (China)',
'uk_UA' => 'Ukrainian (Ukraine)',
'hsb_DE' => 'Upper Sorbian (Germany)',
'ur_PK' => 'Urdu (Pakistan)',
'uz_UZ' => 'Uzbek (Uzbekistan)',
've_ZA' => 'Venda (South Africa)',
'vi_VN' => 'Vietnamese (Vietnam)',
'wa_BE' => 'Walloon (Belgium)',
'cy_GB' => 'Welsh (United Kingdom)',
'fy_DE' => 'Western Frisian (Germany)',
'fy_NL' => 'Western Frisian (Netherlands)',
'wo_SN' => 'Wolof (Senegal)',
'xh_ZA' => 'Xhosa (South Africa)',
'yi_US' => 'Yiddish (United States)',
'yo_NG' => 'Yoruba (Nigeria)',
'zu_ZA' => 'Zulu (South Africa)'
);
在Windows中,你可以尝试调用setlocale()
PHP函数与以下列表中的所有项目:
http://msdn.microsoft.com/en-us/goglobal/bb895996.aspx
下面是一个代码sniplet列出基于Windows的主机上的所有可用语言:
<?php
header( 'Content-Type: text/html; charset=utf-8' );
// source of the list:
// http://msdn.microsoft.com/en-us/library/39cwe7zf(v=vs.90).aspx
$langs = array(
// language, sublanguage, codes
array( 'Chinese', 'Chinese', array( 'chinese' ) ),
array( 'Chinese', 'Chinese (simplified)', array( 'chinese-simplified', 'chs' ) ),
array( 'Chinese', 'Chinese (traditional)', array( 'chinese-traditional', 'cht' ) ),
array( 'Czech', 'Czech', array( 'csy', 'czech' ) ),
array( 'Danish', 'Danish', array( 'dan', 'danish' ) ),
array( 'Dutch', 'Dutch (default)', array( 'dutch', 'nld' ) ),
array( 'Dutch', 'Dutch (Belgium)', array( 'belgian', 'dutch-belgian', 'nlb' ) ),
array( 'English', 'English (default)', array( 'english' ) ),
array( 'English', 'English (Australia)', array( 'australian', 'ena', 'english-aus' ) ),
array( 'English', 'English (Canada)', array( 'canadian', 'enc', 'english-can' ) ),
array( 'English', 'English (New Zealand)', array( 'english-nz', 'enz' ) ),
array( 'English', 'English (United Kingdom)', array( 'eng', 'english-uk', 'uk' ) ),
array( 'English', 'English (United States)', array( 'american', 'american english', 'american-english', 'english-american', 'english-us', 'english-usa', 'enu', 'us', 'usa' ) ),
array( 'Finnish', 'Finnish', array( 'fin', 'finnish' ) ),
array( 'French', 'French (default)', array( 'fra', 'french' ) ),
array( 'French', 'French (Belgium)', array( 'frb', 'french-belgian' ) ),
array( 'French', 'French (Canada)', array( 'frc', 'french-canadian' ) ),
array( 'French', 'French (Switzerland)', array( 'french-swiss', 'frs' ) ),
array( 'German', 'German (default)', array( 'deu', 'german' ) ),
array( 'German', 'German (Austria)', array( 'dea', 'german-austrian' ) ),
array( 'German', 'German (Switzerland)', array( 'des', 'german-swiss', 'swiss' ) ),
array( 'Greek', 'Greek', array( 'ell', 'greek' ) ),
array( 'Hungarian', 'Hungarian', array( 'hun', 'hungarian' ) ),
array( 'Icelandic', 'Icelandic', array( 'icelandic', 'isl' ) ),
array( 'Italian', 'Italian (default)', array( 'ita', 'italian' ) ),
array( 'Italian', 'Italian (Switzerland)', array( 'italian-swiss', 'its' ) ),
array( 'Japanese', 'Japanese', array( 'japanese', 'jpn' ) ),
array( 'Korean', 'Korean', array( 'kor', 'korean' ) ),
array( 'Norwegian', 'Norwegian (default)', array( 'norwegian' ) ),
array( 'Norwegian', 'Norwegian (Bokmal)', array( 'nor', 'norwegian-bokmal' ) ),
array( 'Norwegian', 'Norwegian (Nynorsk)', array( 'non', 'norwegian-nynorsk' ) ),
array( 'Polish', 'Polish', array( 'plk', 'polish' ) ),
array( 'Portuguese', 'Portuguese (default)', array( 'portuguese', 'ptg' ) ),
array( 'Portuguese', 'Portuguese (Brazil)', array( 'portuguese-brazilian', 'ptb' ) ),
array( 'Russian', 'Russian (default)', array( 'rus', 'russian' ) ),
array( 'Slovak', 'Slovak', array( 'sky', 'slovak' ) ),
array( 'Spanish', 'Spanish (default)', array( 'esp', 'spanish' ) ),
array( 'Spanish', 'Spanish (Mexico)', array( 'esm', 'spanish-mexican' ) ),
array( 'Spanish', 'Spanish (Modern)', array( 'esn', 'spanish-modern' ) ),
array( 'Swedish', 'Swedish', array( 'sve', 'swedish' ) ),
array( 'Turkish', 'Turkish', array( 'trk', 'turkish' ) )
);
echo '<table>'."\n";
echo '<tr>'."\n";
echo ' <th>Languange</th>'."\n";
echo ' <th>Sub-Languange</th>'."\n";
echo ' <th>Languange String</th>'."\n";
echo '</tr>'."\n";
foreach ( $langs as $lang ) {
echo '<tr>'."\n";
echo ' <td>'.$lang[0].'</td>'."\n";
echo ' <td>'.$lang[1].'</td>'."\n";
$a = array();
foreach ( $lang[2] as $lang_code ) {
$loc = setlocale( LC_ALL, $lang_code );
$a []= $lang_code.' '.( false === $loc ? '✖' : '✔ - '.$loc );
}
echo ' <td>'.implode( '<br>', $a ).'</td>'."\n";
echo '</tr>'."\n";
}
echo '</table>'."\n";
// Note: Norvegian (Bokmal) is Norvegian (Bokmål), see: http://en.wikipedia.org/wiki/Bokmål
?>
system("locale -a|grep XX");
其中XX
是语言代码,即。 system("locale -a|grep de");