Locale.php 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Locale
  17. * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
  18. * @license http://framework.zend.com/license/new-bsd New BSD License
  19. * @version $Id$
  20. */
  21. /**
  22. * Base class for localization
  23. *
  24. * @category Zend
  25. * @package Zend_Locale
  26. * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
  27. * @license http://framework.zend.com/license/new-bsd New BSD License
  28. */
  29. class Zend_Locale
  30. {
  31. /**
  32. * Class wide Locale Constants
  33. *
  34. * @var array $_localeData
  35. */
  36. private static $_localeData = array(
  37. 'root' => true, 'aa_DJ' => true, 'aa_ER' => true, 'aa_ET' => true, 'aa' => true,
  38. 'af_NA' => true, 'af_ZA' => true, 'af' => true, 'agq_CM' => true, 'agq' => true,
  39. 'ak_GH' => true, 'ak' => true, 'am_ET' => true, 'am' => true, 'ar_001' => true,
  40. 'ar_AE' => true, 'ar_BH' => true, 'ar_DJ' => true, 'ar_DZ' => true, 'ar_EG' => true,
  41. 'ar_EH' => true, 'ar_ER' => true, 'ar_IL' => true, 'ar_IQ' => true, 'ar_JO' => true,
  42. 'ar_KM' => true, 'ar_KW' => true, 'ar_LB' => true, 'ar_LY' => true, 'ar_MA' => true,
  43. 'ar_MR' => true, 'ar_OM' => true, 'ar_PS' => true, 'ar_QA' => true, 'ar_SA' => true,
  44. 'ar_SD' => true, 'ar_SO' => true, 'ar_SY' => true, 'ar_TD' => true, 'ar_TN' => true,
  45. 'ar_YE' => true, 'ar' => true, 'as_IN' => true, 'as' => true, 'asa_TZ' => true,
  46. 'asa' => true, 'ast_ES' => true, 'ast' => true, 'az_AZ' => true, 'az' => true,
  47. 'bas_CM' => true, 'bas' => true, 'be_BY' => true, 'be' => true, 'bem_ZM' => true,
  48. 'bem' => true, 'bez_TZ' => true, 'bez' => true, 'bg_BG' => true, 'bg' => true,
  49. 'bm_ML' => true, 'bm' => true, 'bn_BD' => true, 'bn_IN' => true, 'bn' => true,
  50. 'bo_CN' => true, 'bo_IN' => true, 'bo' => true, 'br_FR' => true, 'br' => true,
  51. 'brx_IN' => true, 'brx' => true, 'bs_BA' => true, 'bs' => true, 'byn_ER' => true,
  52. 'byn' => true, 'ca_AD' => true, 'ca_ES' => true, 'ca' => true, 'cgg_UG' => true,
  53. 'cgg' => true, 'chr_US' => true, 'chr' => true, 'cs_CZ' => true, 'cs' => true,
  54. 'cy_GB' => true, 'cy' => true, 'da_DK' => true, 'da' => true, 'dav_KE' => true,
  55. 'dav' => true, 'de_AT' => true, 'de_BE' => true, 'de_CH' => true, 'de_DE' => true,
  56. 'de_LI' => true, 'de_LU' => true, 'de' => true, 'dje_NE' => true, 'dje' => true,
  57. 'dua_CM' => true, 'dua' => true, 'dyo_SN' => true, 'dyo' => true, 'dz_BT' => true,
  58. 'dz' => true, 'ebu_KE' => true, 'ebu' => true, 'ee_GH' => true, 'ee_TG' => true,
  59. 'ee' => true, 'el_CY' => true, 'el_GR' => true, 'el' => true, 'en_150' => true,
  60. 'en_AG' => true, 'en_AS' => true, 'en_AU' => true, 'en_BB' => true, 'en_BE' => true,
  61. 'en_BM' => true, 'en_BS' => true, 'en_BW' => true, 'en_BZ' => true, 'en_CA' => true,
  62. 'en_CM' => true, 'en_DM' => true, 'en_FJ' => true, 'en_FM' => true, 'en_GB' => true,
  63. 'en_GD' => true, 'en_GG' => true, 'en_GH' => true, 'en_GI' => true, 'en_GM' => true,
  64. 'en_GU' => true, 'en_GY' => true, 'en_HK' => true, 'en_IE' => true, 'en_IM' => true,
  65. 'en_IN' => true, 'en_JE' => true, 'en_JM' => true, 'en_KE' => true, 'en_KI' => true,
  66. 'en_KN' => true, 'en_KY' => true, 'en_LC' => true, 'en_LR' => true, 'en_LS' => true,
  67. 'en_MG' => true, 'en_MH' => true, 'en_MP' => true, 'en_MT' => true, 'en_MU' => true,
  68. 'en_MW' => true, 'en_NA' => true, 'en_NG' => true, 'en_NZ' => true, 'en_PG' => true,
  69. 'en_PH' => true, 'en_PK' => true, 'en_PR' => true, 'en_PW' => true, 'en_SB' => true,
  70. 'en_SC' => true, 'en_SG' => true, 'en_SL' => true, 'en_SS' => true, 'en_SZ' => true,
  71. 'en_TC' => true, 'en_TO' => true, 'en_TT' => true, 'en_TZ' => true, 'en_UG' => true,
  72. 'en_UM' => true, 'en_US' => true, 'en_VC' => true, 'en_VG' => true, 'en_VI' => true,
  73. 'en_VU' => true, 'en_WS' => true, 'en_ZA' => true, 'en_ZM' => true, 'en_ZW' => true,
  74. 'en' => true, 'eo' => true, 'es_419' => true, 'es_AR' => true, 'es_BO' => true,
  75. 'es_CL' => true, 'es_CO' => true, 'es_CR' => true, 'es_CU' => true, 'es_DO' => true,
  76. 'es_EA' => true, 'es_EC' => true, 'es_ES' => true, 'es_GQ' => true, 'es_GT' => true,
  77. 'es_HN' => true, 'es_IC' => true, 'es_MX' => true, 'es_NI' => true, 'es_PA' => true,
  78. 'es_PE' => true, 'es_PH' => true, 'es_PR' => true, 'es_PY' => true, 'es_SV' => true,
  79. 'es_US' => true, 'es_UY' => true, 'es_VE' => true, 'es' => true, 'et_EE' => true,
  80. 'et' => true, 'eu_ES' => true, 'eu' => true, 'ewo_CM' => true, 'ewo' => true,
  81. 'fa_AF' => true, 'fa_IR' => true, 'fa' => true, 'ff_SN' => true, 'ff' => true,
  82. 'fi_FI' => true, 'fi' => true, 'fil_PH'=> true, 'fil' => true, 'fo_FO' => true,
  83. 'fo' => true, 'fr_BE' => true, 'fr_BF' => true, 'fr_BI' => true, 'fr_BJ' => true,
  84. 'fr_BL' => true, 'fr_CA' => true, 'fr_CD' => true, 'fr_CF' => true, 'fr_CG' => true,
  85. 'fr_CH' => true, 'fr_CI' => true, 'fr_CM' => true, 'fr_DJ' => true, 'fr_DZ' => true,
  86. 'fr_FR' => true, 'fr_GA' => true, 'fr_GF' => true, 'fr_GN' => true, 'fr_GP' => true,
  87. 'fr_GQ' => true, 'fr_HT' => true, 'fr_KM' => true, 'fr_LU' => true, 'fr_MA' => true,
  88. 'fr_MC' => true, 'fr_MF' => true, 'fr_MG' => true, 'fr_ML' => true, 'fr_MQ' => true,
  89. 'fr_MR' => true, 'fr_MU' => true, 'fr_NC' => true, 'fr_NE' => true, 'fr_PF' => true,
  90. 'fr_RE' => true, 'fr_RW' => true, 'fr_SC' => true, 'fr_SN' => true, 'fr_SY' => true,
  91. 'fr_TD' => true, 'fr_TG' => true, 'fr_TN' => true, 'fr_VU' => true, 'fr_YT' => true,
  92. 'fr' => true, 'fur_IT'=> true, 'fur' => true, 'ga_IE' => true, 'ga' => true,
  93. 'gd_GB' => true, 'gd' => true, 'gl_ES' => true, 'gl' => true, 'gsw_CH'=> true,
  94. 'gsw' => true, 'gu_IN' => true, 'gu' => true, 'guz_KE' => true, 'guz' => true,
  95. 'gv_GB' => true, 'gv' => true, 'ha_GH' => true, 'ha_NE' => true, 'ha_NG' => true,
  96. 'ha' => true, 'haw_US'=> true, 'haw' => true, 'he_IL' => true, 'he' => true,
  97. 'hi_IN' => true, 'hi' => true, 'hr_BA' => true, 'hr_HR' => true, 'hr' => true,
  98. 'hu_HU' => true, 'hu' => true, 'hy_AM' => true, 'hy' => true, 'ia_FR' => true,
  99. 'ia' => true, 'id_ID' => true, 'id' => true, 'ig_NG' => true, 'ig' => true,
  100. 'ii_CN' => true, 'ii' => true, 'is_IS' => true, 'is' => true, 'it_CH' => true,
  101. 'it_IT' => true, 'it_SM' => true, 'it' => true, 'ja_JP' => true, 'ja' => true,
  102. 'jgo_CM' => true, 'jgo' => true, 'jmc_TZ' => true, 'jmc' => true, 'ka_GE' => true,
  103. 'ka' => true, 'kab_DZ' => true, 'kab' => true, 'kam_KE' => true, 'kam' => true,
  104. 'kde_TZ' => true, 'kde' => true, 'kea_CV' => true, 'kea' => true, 'khq_ML' => true,
  105. 'khq' => true, 'ki_KE' => true, 'ki' => true, 'kk_KZ' => true, 'kk' => true,
  106. 'kkj_CM' => true, 'kkj' => true, 'kl_GL' => true, 'kl' => true, 'kln_KE' => true,
  107. 'kln' => true, 'km_KH' => true, 'km' => true, 'kn_IN' => true, 'kn' => true,
  108. 'ko_KP' => true, 'ko_KR' => true, 'ko' => true, 'kok_IN'=> true, 'kok' => true,
  109. 'ks_IN'=> true, 'ks' => true, 'ksb_TZ' => true, 'ksb' => true, 'ksf_CM' => true,
  110. 'ksf' => true, 'ksh_DE' => true, 'ksh' => true, 'kw_GB' => true, 'kw' => true,
  111. 'ky_KG' => true, 'ky' => true, 'lag_TZ' => true, 'lag' => true, 'lg_UG' => true,
  112. 'lg' => true, 'ln_AO' => true, 'ln_CD' => true, 'ln_CF' => true, 'ln_CG' => true,
  113. 'ln' => true, 'lo_LA' => true, 'lo' => true, 'lt_LT' => true, 'lt' => true,
  114. 'lu_CD' => true, 'lu' => true, 'luo_KE' => true, 'luo' => true, 'luy_KE' => true,
  115. 'luy' => true, 'lv_LV' => true, 'lv' => true, 'mas_KE' => true, 'mas_TZ' => true,
  116. 'mas' => true, 'mer_KE' => true, 'mer' => true, 'mfe_MU' => true, 'mfe' => true,
  117. 'mg_MG' => true, 'mg' => true, 'mgh_MZ' => true, 'mgh' => true, 'mgo_CM' => true,
  118. 'mgo' => true, 'mk_MK' => true, 'mk' => true, 'ml_IN' => true, 'ml' => true,
  119. 'mn_MN' => true, 'mn' => true, 'mr_IN' => true, 'mr' => true, 'ms_BN' => true,
  120. 'ms_MY' => true, 'ms_SG' => true, 'ms' => true, 'mt_MT' => true, 'mt' => true,
  121. 'mua_CM' => true, 'mua' => true, 'my_MM' => true, 'my' => true, 'naq_NA' => true,
  122. 'naq' => true, 'nb_NO' => true, 'nb' => true, 'nd_ZW' => true, 'nd' => true,
  123. 'ne_IN' => true, 'ne_NP' => true, 'ne' => true, 'nl_AW' => true, 'nl_BE' => true,
  124. 'nl_CW' => true, 'nl_NL' => true, 'nl_SR' => true, 'nl_SX' => true, 'nl' => true,
  125. 'nmg_CM' => true, 'nmg' => true, 'nn_NO' => true, 'nn' => true, 'nnh_CM' => true,
  126. 'nnh' => true, 'nr_ZA' => true, 'nr' => true, 'nso_ZA'=> true, 'nso' => true,
  127. 'nus_SD' => true, 'nus' => true, 'nyn_UG' => true, 'nyn' => true, 'om_ET' => true,
  128. 'om_KE' => true, 'om' => true, 'or_IN' => true, 'or' => true, 'os_GE' => true,
  129. 'os_RU' => true, 'os' => true, 'pa_IN' => true, 'pa_PK' => true, 'pa' => true,
  130. 'pl_PL' => true, 'pl' => true, 'ps_AF' => true, 'ps' => true, 'pt_AO' => true,
  131. 'pt_BR' => true, 'pt_CV' => true, 'pt_GW' => true, 'pt_MO' => true, 'pt_MZ' => true,
  132. 'pt_PT' => true, 'pt_ST' => true, 'pt_TL' => true, 'pt' => true, 'rm_CH' => true,
  133. 'rm' => true, 'rn_BI' => true, 'rn' => true, 'ro_MD' => true, 'ro_RO' => true,
  134. 'ro' => true, 'rof_TZ' => true, 'rof' => true, 'ru_BY' => true, 'ru_KG' => true,
  135. 'ru_KZ' => true, 'ru_MD' => true, 'ru_RU' => true, 'ru_UA' => true, 'ru' => true,
  136. 'rw_RW' => true, 'rw' => true, 'rwk_TZ' => true, 'rwk' => true, 'sah_RU' => true,
  137. 'sah' => true, 'saq_KE' => true, 'saq' => true, 'sbp_TZ' => true, 'sbp' => true,
  138. 'se_FI' => true, 'se_NO' => true, 'se' => true, 'seh_MZ' => true, 'seh' => true,
  139. 'ses__ML' => true, 'ses' => true, 'sg_CF' => true, 'sg' => true, 'shi_MA' => true,
  140. 'shi' => true,
  141. 'si_LK' => true, 'si' => true, 'sk_SK' => true, 'sk' => true, 'sl_SI' => true,
  142. 'sl' => true, 'sn_ZW' => true, 'sn' => true, 'so_DJ' => true, 'so_ET' => true,
  143. 'so_KE' => true, 'so_SO' => true, 'so' => true, 'sq_AL' => true, 'sq_MK' => true,
  144. 'sq_XK' => true, 'sq' => true, 'sr_BA' => true, 'sr_ME' => true, 'sr_RS' => true,
  145. 'sr_XK' => true, 'sr' => true, 'ss_SZ' => true, 'ss_ZA' => true, 'ss' => true,
  146. 'ssy_ER' => true, 'ssy' => true, 'st_LS' => true, 'st_ZA' => true, 'st' => true,
  147. 'sv_AX' => true, 'sv_FI' => true, 'sv_SE' => true, 'sv' => true, 'sw_KE' => true,
  148. 'sw_TZ' => true, 'sw_UG' => true, 'sw' => true, 'swc_CD' => true, 'swc' => true,
  149. 'ta_IN' => true, 'ta_LK' => true, 'ta_MY' => true, 'ta_SG' => true, 'ta' => true,
  150. 'te_IN' => true, 'te' => true, 'teo_KE' => true, 'teo_UG' => true, 'teo' => true,
  151. 'tg_TJ' => true, 'tg' => true, 'th_TH' => true, 'th' => true, 'ti_ER' => true,
  152. 'ti_ET' => true, 'ti' => true, 'tig_ER'=> true, 'tig' => true, 'tn_BW' => true,
  153. 'tn_ZA' => true, 'tn' => true, 'to_TO' => true, 'to' => true, 'tr_CY' => true,
  154. 'tr_TR' => true, 'tr' => true, 'ts_ZA' => true, 'ts' => true, 'twq_NE' => true,
  155. 'twq' => true, 'tzm_MA' => true, 'tzm' => true, 'uk_UA' => true, 'uk' => true,
  156. 'ur_IN' => true, 'ur_PK' => true, 'ur' => true, 'uz_AF' => true, 'uz_UZ' => true,
  157. 'uz' => true, 'vai_LR' => true, 'vai' => true, 've_ZA' => true, 've' => true,
  158. 'vi_VN' => true, 'vi' => true, 'vo' => true, 'vun_TZ' => true, 'vun' => true,
  159. 'wae_CH' => true, 'wae' => true, 'wal_ET' => true, 'wal' => true, 'xh_ZA' => true,
  160. 'xh' => true, 'xog_UG' => true, 'xog' => true, 'yav_CM' => true, 'yav' => true,
  161. 'yo_NG' => true, 'yo' => true, 'zh_CN' => true, 'zh_HK' => true, 'zh_MO' => true,
  162. 'zh_SG' => true, 'zh_TW' => true, 'zh' => true, 'zu_ZA' => true, 'zu' => true
  163. );
  164. /**
  165. * Class wide Locale Constants
  166. *
  167. * @var array $_territoryData
  168. */
  169. private static $_territoryData = array(
  170. 'AD' => 'ca_AD', 'AE' => 'ar_AE', 'AF' => 'fa_AF', 'AG' => 'en_AG', 'AI' => 'en_AI',
  171. 'AL' => 'sq_AL', 'AM' => 'hy_AM', 'AN' => 'pap_AN', 'AO' => 'pt_AO', 'AQ' => 'und_AQ',
  172. 'AR' => 'es_AR', 'AS' => 'sm_AS', 'AT' => 'de_AT', 'AU' => 'en_AU', 'AW' => 'nl_AW',
  173. 'AX' => 'sv_AX', 'AZ' => 'az_Latn_AZ', 'BA' => 'bs_BA', 'BB' => 'en_BB', 'BD' => 'bn_BD',
  174. 'BE' => 'nl_BE', 'BF' => 'mos_BF', 'BG' => 'bg_BG', 'BH' => 'ar_BH', 'BI' => 'rn_BI',
  175. 'BJ' => 'fr_BJ', 'BL' => 'fr_BL', 'BM' => 'en_BM', 'BN' => 'ms_BN', 'BO' => 'es_BO',
  176. 'BR' => 'pt_BR', 'BS' => 'en_BS', 'BT' => 'dz_BT', 'BV' => 'und_BV', 'BW' => 'en_BW',
  177. 'BY' => 'be_BY', 'BZ' => 'en_BZ', 'CA' => 'en_CA', 'CC' => 'ms_CC', 'CD' => 'sw_CD',
  178. 'CF' => 'fr_CF', 'CG' => 'fr_CG', 'CH' => 'de_CH', 'CI' => 'fr_CI', 'CK' => 'en_CK',
  179. 'CL' => 'es_CL', 'CM' => 'fr_CM', 'CN' => 'zh_Hans_CN', 'CO' => 'es_CO', 'CR' => 'es_CR',
  180. 'CU' => 'es_CU', 'CV' => 'kea_CV', 'CX' => 'en_CX', 'CY' => 'el_CY', 'CZ' => 'cs_CZ',
  181. 'DE' => 'de_DE', 'DJ' => 'aa_DJ', 'DK' => 'da_DK', 'DM' => 'en_DM', 'DO' => 'es_DO',
  182. 'DZ' => 'ar_DZ', 'EC' => 'es_EC', 'EE' => 'et_EE', 'EG' => 'ar_EG', 'EH' => 'ar_EH',
  183. 'ER' => 'ti_ER', 'ES' => 'es_ES', 'ET' => 'en_ET', 'FI' => 'fi_FI', 'FJ' => 'hi_FJ',
  184. 'FK' => 'en_FK', 'FM' => 'chk_FM', 'FO' => 'fo_FO', 'FR' => 'fr_FR', 'GA' => 'fr_GA',
  185. 'GB' => 'en_GB', 'GD' => 'en_GD', 'GE' => 'ka_GE', 'GF' => 'fr_GF', 'GG' => 'en_GG',
  186. 'GH' => 'ak_GH', 'GI' => 'en_GI', 'GL' => 'iu_GL', 'GM' => 'en_GM', 'GN' => 'fr_GN',
  187. 'GP' => 'fr_GP', 'GQ' => 'fan_GQ', 'GR' => 'el_GR', 'GS' => 'und_GS', 'GT' => 'es_GT',
  188. 'GU' => 'en_GU', 'GW' => 'pt_GW', 'GY' => 'en_GY', 'HK' => 'zh_Hant_HK', 'HM' => 'und_HM',
  189. 'HN' => 'es_HN', 'HR' => 'hr_HR', 'HT' => 'ht_HT', 'HU' => 'hu_HU', 'ID' => 'id_ID',
  190. 'IE' => 'en_IE', 'IL' => 'he_IL', 'IM' => 'en_IM', 'IN' => 'hi_IN', 'IO' => 'und_IO',
  191. 'IQ' => 'ar_IQ', 'IR' => 'fa_IR', 'IS' => 'is_IS', 'IT' => 'it_IT', 'JE' => 'en_JE',
  192. 'JM' => 'en_JM', 'JO' => 'ar_JO', 'JP' => 'ja_JP', 'KE' => 'en_KE', 'KG' => 'ky_Cyrl_KG',
  193. 'KH' => 'km_KH', 'KI' => 'en_KI', 'KM' => 'ar_KM', 'KN' => 'en_KN', 'KP' => 'ko_KP',
  194. 'KR' => 'ko_KR', 'KW' => 'ar_KW', 'KY' => 'en_KY', 'KZ' => 'ru_KZ', 'LA' => 'lo_LA',
  195. 'LB' => 'ar_LB', 'LC' => 'en_LC', 'LI' => 'de_LI', 'LK' => 'si_LK', 'LR' => 'en_LR',
  196. 'LS' => 'st_LS', 'LT' => 'lt_LT', 'LU' => 'fr_LU', 'LV' => 'lv_LV', 'LY' => 'ar_LY',
  197. 'MA' => 'ar_MA', 'MC' => 'fr_MC', 'MD' => 'ro_MD', 'ME' => 'sr_Latn_ME', 'MF' => 'fr_MF',
  198. 'MG' => 'mg_MG', 'MH' => 'mh_MH', 'MK' => 'mk_MK', 'ML' => 'bm_ML', 'MM' => 'my_MM',
  199. 'MN' => 'mn_Cyrl_MN', 'MO' => 'zh_Hant_MO', 'MP' => 'en_MP', 'MQ' => 'fr_MQ', 'MR' => 'ar_MR',
  200. 'MS' => 'en_MS', 'MT' => 'mt_MT', 'MU' => 'mfe_MU', 'MV' => 'dv_MV', 'MW' => 'ny_MW',
  201. 'MX' => 'es_MX', 'MY' => 'ms_MY', 'MZ' => 'pt_MZ', 'NA' => 'kj_NA', 'NC' => 'fr_NC',
  202. 'NE' => 'ha_Latn_NE', 'NF' => 'en_NF', 'NG' => 'en_NG', 'NI' => 'es_NI', 'NL' => 'nl_NL',
  203. 'NO' => 'nb_NO', 'NP' => 'ne_NP', 'NR' => 'en_NR', 'NU' => 'niu_NU', 'NZ' => 'en_NZ',
  204. 'OM' => 'ar_OM', 'PA' => 'es_PA', 'PE' => 'es_PE', 'PF' => 'fr_PF', 'PG' => 'tpi_PG',
  205. 'PH' => 'fil_PH', 'PK' => 'ur_PK', 'PL' => 'pl_PL', 'PM' => 'fr_PM', 'PN' => 'en_PN',
  206. 'PR' => 'es_PR', 'PS' => 'ar_PS', 'PT' => 'pt_PT', 'PW' => 'pau_PW', 'PY' => 'gn_PY',
  207. 'QA' => 'ar_QA', 'RE' => 'fr_RE', 'RO' => 'ro_RO', 'RS' => 'sr_Cyrl_RS', 'RU' => 'ru_RU',
  208. 'RW' => 'rw_RW', 'SA' => 'ar_SA', 'SB' => 'en_SB', 'SC' => 'crs_SC', 'SD' => 'ar_SD',
  209. 'SE' => 'sv_SE', 'SG' => 'en_SG', 'SH' => 'en_SH', 'SI' => 'sl_SI', 'SJ' => 'nb_SJ',
  210. 'SK' => 'sk_SK', 'SL' => 'kri_SL', 'SM' => 'it_SM', 'SN' => 'fr_SN', 'SO' => 'sw_SO',
  211. 'SR' => 'srn_SR', 'ST' => 'pt_ST', 'SV' => 'es_SV', 'SY' => 'ar_SY', 'SZ' => 'en_SZ',
  212. 'TC' => 'en_TC', 'TD' => 'fr_TD', 'TF' => 'und_TF', 'TG' => 'fr_TG', 'TH' => 'th_TH',
  213. 'TJ' => 'tg_Cyrl_TJ', 'TK' => 'tkl_TK', 'TL' => 'pt_TL', 'TM' => 'tk_TM', 'TN' => 'ar_TN',
  214. 'TO' => 'to_TO', 'TR' => 'tr_TR', 'TT' => 'en_TT', 'TV' => 'tvl_TV', 'TW' => 'zh_Hant_TW',
  215. 'TZ' => 'sw_TZ', 'UA' => 'uk_UA', 'UG' => 'sw_UG', 'UM' => 'en_UM', 'US' => 'en_US',
  216. 'UY' => 'es_UY', 'UZ' => 'uz_Cyrl_UZ', 'VA' => 'it_VA', 'VC' => 'en_VC', 'VE' => 'es_VE',
  217. 'VG' => 'en_VG', 'VI' => 'en_VI', 'VU' => 'bi_VU', 'WF' => 'wls_WF', 'WS' => 'sm_WS',
  218. 'YE' => 'ar_YE', 'YT' => 'swb_YT', 'ZA' => 'en_ZA', 'ZM' => 'en_ZM', 'ZW' => 'sn_ZW'
  219. );
  220. /**
  221. * Autosearch constants
  222. */
  223. const BROWSER = 'browser';
  224. const ENVIRONMENT = 'environment';
  225. const ZFDEFAULT = 'default';
  226. /**
  227. * Defines if old behaviour should be supported
  228. * Old behaviour throws notices and will be deleted in future releases
  229. *
  230. * @var boolean
  231. */
  232. public static $compatibilityMode = false;
  233. /**
  234. * Internal variable
  235. *
  236. * @var boolean
  237. */
  238. private static $_breakChain = false;
  239. /**
  240. * Actual set locale
  241. *
  242. * @var string Locale
  243. */
  244. protected $_locale;
  245. /**
  246. * Automatic detected locale
  247. *
  248. * @var string Locales
  249. */
  250. protected static $_auto;
  251. /**
  252. * Browser detected locale
  253. *
  254. * @var string Locales
  255. */
  256. protected static $_browser;
  257. /**
  258. * Environment detected locale
  259. *
  260. * @var string Locales
  261. */
  262. protected static $_environment;
  263. /**
  264. * Default locale
  265. *
  266. * @var string Locales
  267. */
  268. protected static $_default = array('en' => true);
  269. /**
  270. * Generates a locale object
  271. * If no locale is given a automatic search is done
  272. * Then the most probable locale will be automatically set
  273. * Search order is
  274. * 1. Given Locale
  275. * 2. HTTP Client
  276. * 3. Server Environment
  277. * 4. Framework Standard
  278. *
  279. * @param string|Zend_Locale $locale (Optional) Locale for parsing input
  280. * @throws Zend_Locale_Exception When autodetection has been failed
  281. */
  282. public function __construct($locale = null)
  283. {
  284. $this->setLocale($locale);
  285. }
  286. /**
  287. * Serialization Interface
  288. *
  289. * @return string
  290. */
  291. public function serialize()
  292. {
  293. return serialize($this);
  294. }
  295. /**
  296. * Returns a string representation of the object
  297. *
  298. * @return string
  299. */
  300. public function toString()
  301. {
  302. return (string) $this->_locale;
  303. }
  304. /**
  305. * Returns a string representation of the object
  306. * Alias for toString
  307. *
  308. * @return string
  309. */
  310. public function __toString()
  311. {
  312. return $this->toString();
  313. }
  314. /**
  315. * Return the default locale
  316. *
  317. * @return array Returns an array of all locale string
  318. */
  319. public static function getDefault()
  320. {
  321. if ((self::$compatibilityMode === true) or (func_num_args() > 0)) {
  322. if (!self::$_breakChain) {
  323. self::$_breakChain = true;
  324. trigger_error('You are running Zend_Locale in compatibility mode... please migrate your scripts', E_USER_NOTICE);
  325. $params = func_get_args();
  326. $param = null;
  327. if (isset($params[0])) {
  328. $param = $params[0];
  329. }
  330. return self::getOrder($param);
  331. }
  332. self::$_breakChain = false;
  333. }
  334. return self::$_default;
  335. }
  336. /**
  337. * Sets a new default locale which will be used when no locale can be detected
  338. * If provided you can set a quality between 0 and 1 (or 2 and 100)
  339. * which represents the percent of quality the browser
  340. * requested within HTTP
  341. *
  342. * @param string|Zend_Locale $locale Locale to set
  343. * @param float $quality The quality to set from 0 to 1
  344. * @throws Zend_Locale_Exception When a autolocale was given
  345. * @throws Zend_Locale_Exception When a unknown locale was given
  346. * @return void
  347. */
  348. public static function setDefault($locale, $quality = 1)
  349. {
  350. if (($locale === 'auto') or ($locale === 'root') or ($locale === 'default') or
  351. ($locale === 'environment') or ($locale === 'browser')) {
  352. require_once 'Zend/Locale/Exception.php';
  353. throw new Zend_Locale_Exception('Only full qualified locales can be used as default!');
  354. }
  355. if (($quality < 0.1) or ($quality > 100)) {
  356. require_once 'Zend/Locale/Exception.php';
  357. throw new Zend_Locale_Exception("Quality must be between 0.1 and 100");
  358. }
  359. if ($quality > 1) {
  360. $quality /= 100;
  361. }
  362. $locale = self::_prepareLocale($locale);
  363. if (isset(self::$_localeData[(string) $locale]) === true) {
  364. self::$_default = array((string) $locale => $quality);
  365. } else {
  366. $elocale = explode('_', (string) $locale);
  367. if (isset(self::$_localeData[$elocale[0]]) === true) {
  368. self::$_default = array($elocale[0] => $quality);
  369. } else {
  370. require_once 'Zend/Locale/Exception.php';
  371. throw new Zend_Locale_Exception("Unknown locale '" . (string) $locale . "' can not be set as default!");
  372. }
  373. }
  374. self::$_auto = self::getBrowser() + self::getEnvironment() + self::getDefault();
  375. }
  376. /**
  377. * Expects the Systems standard locale
  378. *
  379. * For Windows:
  380. * f.e.: LC_COLLATE=C;LC_CTYPE=German_Austria.1252;LC_MONETARY=C
  381. * would be recognised as de_AT
  382. *
  383. * @return array
  384. */
  385. public static function getEnvironment()
  386. {
  387. if (self::$_environment !== null) {
  388. return self::$_environment;
  389. }
  390. require_once 'Zend/Locale/Data/Translation.php';
  391. $language = setlocale(LC_ALL, 0);
  392. $languages = explode(';', $language);
  393. $languagearray = array();
  394. foreach ($languages as $locale) {
  395. if (strpos($locale, '=') !== false) {
  396. $language = substr($locale, strpos($locale, '='));
  397. $language = substr($language, 1);
  398. }
  399. if ($language !== 'C') {
  400. if (strpos($language, '.') !== false) {
  401. $language = substr($language, 0, strpos($language, '.'));
  402. } else if (strpos($language, '@') !== false) {
  403. $language = substr($language, 0, strpos($language, '@'));
  404. }
  405. $language = str_ireplace(
  406. array_keys(Zend_Locale_Data_Translation::$languageTranslation),
  407. array_values(Zend_Locale_Data_Translation::$languageTranslation),
  408. (string) $language
  409. );
  410. $language = str_ireplace(
  411. array_keys(Zend_Locale_Data_Translation::$regionTranslation),
  412. array_values(Zend_Locale_Data_Translation::$regionTranslation),
  413. $language
  414. );
  415. if (isset(self::$_localeData[$language]) === true) {
  416. $languagearray[$language] = 1;
  417. if (strpos($language, '_') !== false) {
  418. $languagearray[substr($language, 0, strpos($language, '_'))] = 1;
  419. }
  420. }
  421. }
  422. }
  423. self::$_environment = $languagearray;
  424. return $languagearray;
  425. }
  426. /**
  427. * Return an array of all accepted languages of the client
  428. * Expects RFC compilant Header !!
  429. *
  430. * The notation can be :
  431. * de,en-UK-US;q=0.5,fr-FR;q=0.2
  432. *
  433. * @return array - list of accepted languages including quality
  434. */
  435. public static function getBrowser()
  436. {
  437. if (self::$_browser !== null) {
  438. return self::$_browser;
  439. }
  440. $httplanguages = getenv('HTTP_ACCEPT_LANGUAGE');
  441. if (empty($httplanguages) && array_key_exists('HTTP_ACCEPT_LANGUAGE', $_SERVER)) {
  442. $httplanguages = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
  443. }
  444. $languages = array();
  445. if (empty($httplanguages)) {
  446. return $languages;
  447. }
  448. $accepted = preg_split('/,\s*/', $httplanguages);
  449. foreach ($accepted as $accept) {
  450. $match = null;
  451. $result = preg_match('/^([a-z]{1,8}(?:[-_][a-z]{1,8})*)(?:;\s*q=(0(?:\.[0-9]{1,3})?|1(?:\.0{1,3})?))?$/i',
  452. $accept, $match);
  453. if ($result < 1) {
  454. continue;
  455. }
  456. if (isset($match[2]) === true) {
  457. $quality = (float) $match[2];
  458. } else {
  459. $quality = 1.0;
  460. }
  461. $countrys = explode('-', $match[1]);
  462. $region = array_shift($countrys);
  463. $country2 = explode('_', $region);
  464. $region = array_shift($country2);
  465. foreach ($countrys as $country) {
  466. $languages[$region . '_' . strtoupper($country)] = $quality;
  467. }
  468. foreach ($country2 as $country) {
  469. $languages[$region . '_' . strtoupper($country)] = $quality;
  470. }
  471. if ((isset($languages[$region]) === false) || ($languages[$region] < $quality)) {
  472. $languages[$region] = $quality;
  473. }
  474. }
  475. self::$_browser = $languages;
  476. return $languages;
  477. }
  478. /**
  479. * Sets a new locale
  480. *
  481. * @param string|Zend_Locale $locale (Optional) New locale to set
  482. * @return void
  483. */
  484. public function setLocale($locale = null)
  485. {
  486. $locale = self::_prepareLocale($locale);
  487. if (isset(self::$_localeData[(string) $locale]) === false) {
  488. $region = substr((string) $locale, 0, 3);
  489. if (isset($region[2]) === true) {
  490. if (($region[2] === '_') or ($region[2] === '-')) {
  491. $region = substr($region, 0, 2);
  492. }
  493. }
  494. if (isset(self::$_localeData[(string) $region]) === true) {
  495. $this->_locale = $region;
  496. } else {
  497. $this->_locale = 'root';
  498. }
  499. } else {
  500. $this->_locale = $locale;
  501. }
  502. }
  503. /**
  504. * Returns the language part of the locale
  505. *
  506. * @return string
  507. */
  508. public function getLanguage()
  509. {
  510. $locale = explode('_', $this->_locale);
  511. return $locale[0];
  512. }
  513. /**
  514. * Returns the region part of the locale if available
  515. *
  516. * @return string|false - Regionstring
  517. */
  518. public function getRegion()
  519. {
  520. $locale = explode('_', $this->_locale);
  521. if (isset($locale[1]) === true) {
  522. return $locale[1];
  523. }
  524. return false;
  525. }
  526. /**
  527. * Return the accepted charset of the client
  528. *
  529. * @return string
  530. */
  531. public static function getHttpCharset()
  532. {
  533. $httpcharsets = getenv('HTTP_ACCEPT_CHARSET');
  534. $charsets = array();
  535. if ($httpcharsets === false) {
  536. return $charsets;
  537. }
  538. $accepted = preg_split('/,\s*/', $httpcharsets);
  539. foreach ($accepted as $accept) {
  540. if (empty($accept) === true) {
  541. continue;
  542. }
  543. if (strpos($accept, ';') !== false) {
  544. $quality = (float) substr($accept, (strpos($accept, '=') + 1));
  545. $pos = substr($accept, 0, strpos($accept, ';'));
  546. $charsets[$pos] = $quality;
  547. } else {
  548. $quality = 1.0;
  549. $charsets[$accept] = $quality;
  550. }
  551. }
  552. return $charsets;
  553. }
  554. /**
  555. * Returns true if both locales are equal
  556. *
  557. * @param Zend_Locale $object Locale to check for equality
  558. * @return boolean
  559. */
  560. public function equals(Zend_Locale $object)
  561. {
  562. if ($object->toString() === $this->toString()) {
  563. return true;
  564. }
  565. return false;
  566. }
  567. /**
  568. * Returns localized informations as array, supported are several
  569. * types of informations.
  570. * For detailed information about the types look into the documentation
  571. *
  572. * @param string $path (Optional) Type of information to return
  573. * @param string|Zend_Locale $locale (Optional) Locale|Language for which this informations should be returned
  574. * @param string $value (Optional) Value for detail list
  575. * @return array Array with the wished information in the given language
  576. */
  577. public static function getTranslationList($path = null, $locale = null, $value = null)
  578. {
  579. require_once 'Zend/Locale/Data.php';
  580. $locale = self::findLocale($locale);
  581. $result = Zend_Locale_Data::getList($locale, $path, $value);
  582. if (empty($result) === true) {
  583. return false;
  584. }
  585. return $result;
  586. }
  587. /**
  588. * Returns an array with the name of all languages translated to the given language
  589. *
  590. * @param string|Zend_Locale $locale (Optional) Locale for language translation
  591. * @return array
  592. * @deprecated
  593. */
  594. public static function getLanguageTranslationList($locale = null)
  595. {
  596. trigger_error("The method getLanguageTranslationList is deprecated. Use getTranslationList('language', $locale) instead", E_USER_NOTICE);
  597. return self::getTranslationList('language', $locale);
  598. }
  599. /**
  600. * Returns an array with the name of all scripts translated to the given language
  601. *
  602. * @param string|Zend_Locale $locale (Optional) Locale for script translation
  603. * @return array
  604. * @deprecated
  605. */
  606. public static function getScriptTranslationList($locale = null)
  607. {
  608. trigger_error("The method getScriptTranslationList is deprecated. Use getTranslationList('script', $locale) instead", E_USER_NOTICE);
  609. return self::getTranslationList('script', $locale);
  610. }
  611. /**
  612. * Returns an array with the name of all countries translated to the given language
  613. *
  614. * @param string|Zend_Locale $locale (Optional) Locale for country translation
  615. * @return array
  616. * @deprecated
  617. */
  618. public static function getCountryTranslationList($locale = null)
  619. {
  620. trigger_error("The method getCountryTranslationList is deprecated. Use getTranslationList('territory', $locale, 2) instead", E_USER_NOTICE);
  621. return self::getTranslationList('territory', $locale, 2);
  622. }
  623. /**
  624. * Returns an array with the name of all territories translated to the given language
  625. * All territories contains other countries.
  626. *
  627. * @param string|Zend_Locale $locale (Optional) Locale for territory translation
  628. * @return array
  629. * @deprecated
  630. */
  631. public static function getTerritoryTranslationList($locale = null)
  632. {
  633. trigger_error("The method getTerritoryTranslationList is deprecated. Use getTranslationList('territory', $locale, 1) instead", E_USER_NOTICE);
  634. return self::getTranslationList('territory', $locale, 1);
  635. }
  636. /**
  637. * Returns a localized information string, supported are several types of informations.
  638. * For detailed information about the types look into the documentation
  639. *
  640. * @param string $value Name to get detailed information about
  641. * @param string $path (Optional) Type of information to return
  642. * @param string|Zend_Locale $locale (Optional) Locale|Language for which this informations should be returned
  643. * @return string|false The wished information in the given language
  644. */
  645. public static function getTranslation($value = null, $path = null, $locale = null)
  646. {
  647. require_once 'Zend/Locale/Data.php';
  648. $locale = self::findLocale($locale);
  649. $result = Zend_Locale_Data::getContent($locale, $path, $value);
  650. if (empty($result) === true && '0' !== $result) {
  651. return false;
  652. }
  653. return $result;
  654. }
  655. /**
  656. * Returns the localized language name
  657. *
  658. * @param string $value Name to get detailed information about
  659. * @param string $locale (Optional) Locale for language translation
  660. * @return array
  661. * @deprecated
  662. */
  663. public static function getLanguageTranslation($value, $locale = null)
  664. {
  665. trigger_error("The method getLanguageTranslation is deprecated. Use getTranslation($value, 'language', $locale) instead", E_USER_NOTICE);
  666. return self::getTranslation($value, 'language', $locale);
  667. }
  668. /**
  669. * Returns the localized script name
  670. *
  671. * @param string $value Name to get detailed information about
  672. * @param string $locale (Optional) locale for script translation
  673. * @return array
  674. * @deprecated
  675. */
  676. public static function getScriptTranslation($value, $locale = null)
  677. {
  678. trigger_error("The method getScriptTranslation is deprecated. Use getTranslation($value, 'script', $locale) instead", E_USER_NOTICE);
  679. return self::getTranslation($value, 'script', $locale);
  680. }
  681. /**
  682. * Returns the localized country name
  683. *
  684. * @param string $value Name to get detailed information about
  685. * @param string|Zend_Locale $locale (Optional) Locale for country translation
  686. * @return array
  687. * @deprecated
  688. */
  689. public static function getCountryTranslation($value, $locale = null)
  690. {
  691. trigger_error("The method getCountryTranslation is deprecated. Use getTranslation($value, 'country', $locale) instead", E_USER_NOTICE);
  692. return self::getTranslation($value, 'country', $locale);
  693. }
  694. /**
  695. * Returns the localized territory name
  696. * All territories contains other countries.
  697. *
  698. * @param string $value Name to get detailed information about
  699. * @param string|Zend_Locale $locale (Optional) Locale for territory translation
  700. * @return array
  701. * @deprecated
  702. */
  703. public static function getTerritoryTranslation($value, $locale = null)
  704. {
  705. trigger_error("The method getTerritoryTranslation is deprecated. Use getTranslation($value, 'territory', $locale) instead", E_USER_NOTICE);
  706. return self::getTranslation($value, 'territory', $locale);
  707. }
  708. /**
  709. * Returns an array with translated yes strings
  710. *
  711. * @param string|Zend_Locale $locale (Optional) Locale for language translation (defaults to $this locale)
  712. * @return array
  713. */
  714. public static function getQuestion($locale = null)
  715. {
  716. require_once 'Zend/Locale/Data.php';
  717. $locale = self::findLocale($locale);
  718. $quest = Zend_Locale_Data::getList($locale, 'question');
  719. $yes = explode(':', $quest['yes']);
  720. $no = explode(':', $quest['no']);
  721. $quest['yes'] = $yes[0];
  722. $quest['yesarray'] = $yes;
  723. $quest['no'] = $no[0];
  724. $quest['noarray'] = $no;
  725. $quest['yesexpr'] = self::_prepareQuestionString($yes);
  726. $quest['noexpr'] = self::_prepareQuestionString($no);
  727. return $quest;
  728. }
  729. /**
  730. * Internal function for preparing the returned question regex string
  731. *
  732. * @param string $input Regex to parse
  733. * @return string
  734. */
  735. private static function _prepareQuestionString($input)
  736. {
  737. $regex = '';
  738. if (is_array($input) === true) {
  739. $regex = '^';
  740. $start = true;
  741. foreach ($input as $row) {
  742. if ($start === false) {
  743. $regex .= '|';
  744. }
  745. $start = false;
  746. $regex .= '(';
  747. $one = null;
  748. if (strlen($row) > 2) {
  749. $one = true;
  750. }
  751. foreach (str_split($row, 1) as $char) {
  752. $regex .= '[' . $char;
  753. $regex .= strtoupper($char) . ']';
  754. if ($one === true) {
  755. $one = false;
  756. $regex .= '(';
  757. }
  758. }
  759. if ($one === false) {
  760. $regex .= ')';
  761. }
  762. $regex .= '?)';
  763. }
  764. }
  765. return $regex;
  766. }
  767. /**
  768. * Checks if a locale identifier is a real locale or not
  769. * Examples:
  770. * "en_XX" refers to "en", which returns true
  771. * "XX_yy" refers to "root", which returns false
  772. *
  773. * @param string|Zend_Locale $locale Locale to check for
  774. * @param boolean $strict (Optional) If true, no rerouting will be done when checking
  775. * @param boolean $compatible (DEPRECATED) Only for internal usage, brakes compatibility mode
  776. * @return boolean If the locale is known dependend on the settings
  777. */
  778. public static function isLocale($locale, $strict = false, $compatible = true)
  779. {
  780. if (($locale instanceof Zend_Locale)
  781. || (is_string($locale) && array_key_exists($locale, self::$_localeData))
  782. ) {
  783. return true;
  784. }
  785. if (($locale === null) || (!is_string($locale) and !is_array($locale))) {
  786. return false;
  787. }
  788. try {
  789. $locale = self::_prepareLocale($locale, $strict);
  790. } catch (Zend_Locale_Exception $e) {
  791. return false;
  792. }
  793. if (($compatible === true) and (self::$compatibilityMode === true)) {
  794. trigger_error('You are running Zend_Locale in compatibility mode... please migrate your scripts', E_USER_NOTICE);
  795. if (isset(self::$_localeData[$locale]) === true) {
  796. return $locale;
  797. } else if (!$strict) {
  798. $locale = explode('_', $locale);
  799. if (isset(self::$_localeData[$locale[0]]) === true) {
  800. return $locale[0];
  801. }
  802. }
  803. } else {
  804. if (isset(self::$_localeData[$locale]) === true) {
  805. return true;
  806. } else if (!$strict) {
  807. $locale = explode('_', $locale);
  808. if (isset(self::$_localeData[$locale[0]]) === true) {
  809. return true;
  810. }
  811. }
  812. }
  813. return false;
  814. }
  815. /**
  816. * Finds the proper locale based on the input
  817. * Checks if it exists, degrades it when necessary
  818. * Detects registry locale and when all fails tries to detect a automatic locale
  819. * Returns the found locale as string
  820. *
  821. * @param string $locale
  822. * @throws Zend_Locale_Exception When the given locale is no locale or the autodetection fails
  823. * @return string
  824. */
  825. public static function findLocale($locale = null)
  826. {
  827. if ($locale === null) {
  828. require_once 'Zend/Registry.php';
  829. if (Zend_Registry::isRegistered('Zend_Locale')) {
  830. $locale = Zend_Registry::get('Zend_Locale');
  831. }
  832. }
  833. if ($locale === null) {
  834. $locale = new Zend_Locale();
  835. }
  836. if (!Zend_Locale::isLocale($locale, true, false)) {
  837. if (!Zend_Locale::isLocale($locale, false, false)) {
  838. $locale = Zend_Locale::getLocaleToTerritory($locale);
  839. if (empty($locale)) {
  840. require_once 'Zend/Locale/Exception.php';
  841. throw new Zend_Locale_Exception("The locale '$locale' is no known locale");
  842. }
  843. } else {
  844. $locale = new Zend_Locale($locale);
  845. }
  846. }
  847. $locale = self::_prepareLocale($locale);
  848. return $locale;
  849. }
  850. /**
  851. * Returns the expected locale for a given territory
  852. *
  853. * @param string $territory Territory for which the locale is being searched
  854. * @return string|null Locale string or null when no locale has been found
  855. */
  856. public static function getLocaleToTerritory($territory)
  857. {
  858. $territory = strtoupper($territory);
  859. if (array_key_exists($territory, self::$_territoryData)) {
  860. return self::$_territoryData[$territory];
  861. }
  862. return null;
  863. }
  864. /**
  865. * Returns a list of all known locales where the locale is the key
  866. * Only real locales are returned, the internal locales 'root', 'auto', 'browser'
  867. * and 'environment' are suppressed
  868. *
  869. * @return array List of all Locales
  870. */
  871. public static function getLocaleList()
  872. {
  873. $list = self::$_localeData;
  874. unset($list['root']);
  875. unset($list['auto']);
  876. unset($list['browser']);
  877. unset($list['environment']);
  878. return $list;
  879. }
  880. /**
  881. * Returns the set cache
  882. *
  883. * @return Zend_Cache_Core The set cache
  884. */
  885. public static function getCache()
  886. {
  887. require_once 'Zend/Locale/Data.php';
  888. return Zend_Locale_Data::getCache();
  889. }
  890. /**
  891. * Sets a cache
  892. *
  893. * @param Zend_Cache_Core $cache Cache to set
  894. * @return void
  895. */
  896. public static function setCache(Zend_Cache_Core $cache)
  897. {
  898. require_once 'Zend/Locale/Data.php';
  899. Zend_Locale_Data::setCache($cache);
  900. }
  901. /**
  902. * Returns true when a cache is set
  903. *
  904. * @return boolean
  905. */
  906. public static function hasCache()
  907. {
  908. require_once 'Zend/Locale/Data.php';
  909. return Zend_Locale_Data::hasCache();
  910. }
  911. /**
  912. * Removes any set cache
  913. *
  914. * @return void
  915. */
  916. public static function removeCache()
  917. {
  918. require_once 'Zend/Locale/Data.php';
  919. Zend_Locale_Data::removeCache();
  920. }
  921. /**
  922. * Clears all set cache data
  923. *
  924. * @param string $tag Tag to clear when the default tag name is not used
  925. * @return void
  926. */
  927. public static function clearCache($tag = null)
  928. {
  929. require_once 'Zend/Locale/Data.php';
  930. Zend_Locale_Data::clearCache($tag);
  931. }
  932. /**
  933. * Disables the set cache
  934. *
  935. * @param boolean $flag True disables any set cache, default is false
  936. * @return void
  937. */
  938. public static function disableCache($flag)
  939. {
  940. require_once 'Zend/Locale/Data.php';
  941. Zend_Locale_Data::disableCache($flag);
  942. }
  943. /**
  944. * Internal function, returns a single locale on detection
  945. *
  946. * @param string|Zend_Locale $locale (Optional) Locale to work on
  947. * @param boolean $strict (Optional) Strict preparation
  948. * @throws Zend_Locale_Exception When no locale is set which is only possible when the class was wrong extended
  949. * @return string
  950. */
  951. private static function _prepareLocale($locale, $strict = false)
  952. {
  953. if ($locale instanceof Zend_Locale) {
  954. $locale = $locale->toString();
  955. }
  956. if (is_array($locale)) {
  957. return '';
  958. }
  959. if (empty(self::$_auto) === true) {
  960. self::$_browser = self::getBrowser();
  961. self::$_environment = self::getEnvironment();
  962. self::$_breakChain = true;
  963. self::$_auto = self::getBrowser() + self::getEnvironment() + self::getDefault();
  964. }
  965. if (!$strict) {
  966. if ($locale === 'browser') {
  967. $locale = self::$_browser;
  968. }
  969. if ($locale === 'environment') {
  970. $locale = self::$_environment;
  971. }
  972. if ($locale === 'default') {
  973. $locale = self::$_default;
  974. }
  975. if (($locale === 'auto') or ($locale === null)) {
  976. $locale = self::$_auto;
  977. }
  978. if (is_array($locale) === true) {
  979. $locale = key($locale);
  980. }
  981. }
  982. // This can only happen when someone extends Zend_Locale and erases the default
  983. if ($locale === null) {
  984. require_once 'Zend/Locale/Exception.php';
  985. throw new Zend_Locale_Exception('Autodetection of Locale has been failed!');
  986. }
  987. if (strpos($locale, '-') !== false) {
  988. $locale = strtr($locale, '-', '_');
  989. }
  990. $parts = explode('_', $locale);
  991. if (!isset(self::$_localeData[$parts[0]])) {
  992. if ((count($parts) == 1) && array_key_exists($parts[0], self::$_territoryData)) {
  993. return self::$_territoryData[$parts[0]];
  994. }
  995. return '';
  996. }
  997. foreach($parts as $key => $value) {
  998. if ((strlen($value) < 2) || (strlen($value) > 3)) {
  999. unset($parts[$key]);
  1000. }
  1001. }
  1002. $locale = implode('_', $parts);
  1003. return (string) $locale;
  1004. }
  1005. /**
  1006. * Search the locale automatically and return all used locales
  1007. * ordered by quality
  1008. *
  1009. * Standard Searchorder is Browser, Environment, Default
  1010. *
  1011. * @param string $searchorder (Optional) Searchorder
  1012. * @return array Returns an array of all detected locales
  1013. */
  1014. public static function getOrder($order = null)
  1015. {
  1016. switch ($order) {
  1017. case self::ENVIRONMENT:
  1018. self::$_breakChain = true;
  1019. $languages = self::getEnvironment() + self::getBrowser() + self::getDefault();
  1020. break;
  1021. case self::ZFDEFAULT:
  1022. self::$_breakChain = true;
  1023. $languages = self::getDefault() + self::getEnvironment() + self::getBrowser();
  1024. break;
  1025. default:
  1026. self::$_breakChain = true;
  1027. $languages = self::getBrowser() + self::getEnvironment() + self::getDefault();
  1028. break;
  1029. }
  1030. return $languages;
  1031. }
  1032. }