Locale.php 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147
  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', 'VN' => 'vi_VN', 'VU' => 'bi_VU', 'WF' => 'wls_WF',
  218. 'WS' => 'sm_WS', 'YE' => 'ar_YE', 'YT' => 'swb_YT', 'ZA' => 'en_ZA', 'ZM' => 'en_ZM',
  219. 'ZW' => 'sn_ZW'
  220. );
  221. /**
  222. * Autosearch constants
  223. */
  224. const BROWSER = 'browser';
  225. const ENVIRONMENT = 'environment';
  226. const ZFDEFAULT = 'default';
  227. /**
  228. * Defines if old behaviour should be supported
  229. * Old behaviour throws notices and will be deleted in future releases
  230. *
  231. * @var boolean
  232. */
  233. public static $compatibilityMode = false;
  234. /**
  235. * Internal variable
  236. *
  237. * @var boolean
  238. */
  239. private static $_breakChain = false;
  240. /**
  241. * Actual set locale
  242. *
  243. * @var string Locale
  244. */
  245. protected $_locale;
  246. /**
  247. * Automatic detected locale
  248. *
  249. * @var string Locales
  250. */
  251. protected static $_auto;
  252. /**
  253. * Browser detected locale
  254. *
  255. * @var string Locales
  256. */
  257. protected static $_browser;
  258. /**
  259. * Environment detected locale
  260. *
  261. * @var string Locales
  262. */
  263. protected static $_environment;
  264. /**
  265. * Default locale
  266. *
  267. * @var string Locales
  268. */
  269. protected static $_default = array('en' => true);
  270. /**
  271. * Generates a locale object
  272. * If no locale is given a automatic search is done
  273. * Then the most probable locale will be automatically set
  274. * Search order is
  275. * 1. Given Locale
  276. * 2. HTTP Client
  277. * 3. Server Environment
  278. * 4. Framework Standard
  279. *
  280. * @param string|Zend_Locale $locale (Optional) Locale for parsing input
  281. * @throws Zend_Locale_Exception When autodetection has been failed
  282. */
  283. public function __construct($locale = null)
  284. {
  285. $this->setLocale($locale);
  286. }
  287. /**
  288. * Serialization Interface
  289. *
  290. * @return string
  291. */
  292. public function serialize()
  293. {
  294. return serialize($this);
  295. }
  296. /**
  297. * Returns a string representation of the object
  298. *
  299. * @return string
  300. */
  301. public function toString()
  302. {
  303. return (string) $this->_locale;
  304. }
  305. /**
  306. * Returns a string representation of the object
  307. * Alias for toString
  308. *
  309. * @return string
  310. */
  311. public function __toString()
  312. {
  313. return $this->toString();
  314. }
  315. /**
  316. * Return the default locale
  317. *
  318. * @return array Returns an array of all locale string
  319. */
  320. public static function getDefault()
  321. {
  322. if ((self::$compatibilityMode === true) or (func_num_args() > 0)) {
  323. if (!self::$_breakChain) {
  324. self::$_breakChain = true;
  325. trigger_error('You are running Zend_Locale in compatibility mode... please migrate your scripts', E_USER_NOTICE);
  326. $params = func_get_args();
  327. $param = null;
  328. if (isset($params[0])) {
  329. $param = $params[0];
  330. }
  331. return self::getOrder($param);
  332. }
  333. self::$_breakChain = false;
  334. }
  335. return self::$_default;
  336. }
  337. /**
  338. * Sets a new default locale which will be used when no locale can be detected
  339. * If provided you can set a quality between 0 and 1 (or 2 and 100)
  340. * which represents the percent of quality the browser
  341. * requested within HTTP
  342. *
  343. * @param string|Zend_Locale $locale Locale to set
  344. * @param float $quality The quality to set from 0 to 1
  345. * @throws Zend_Locale_Exception When a autolocale was given
  346. * @throws Zend_Locale_Exception When a unknown locale was given
  347. * @return void
  348. */
  349. public static function setDefault($locale, $quality = 1)
  350. {
  351. if (($locale === 'auto') or ($locale === 'root') or ($locale === 'default') or
  352. ($locale === 'environment') or ($locale === 'browser')) {
  353. require_once 'Zend/Locale/Exception.php';
  354. throw new Zend_Locale_Exception('Only full qualified locales can be used as default!');
  355. }
  356. if (($quality < 0.1) or ($quality > 100)) {
  357. require_once 'Zend/Locale/Exception.php';
  358. throw new Zend_Locale_Exception("Quality must be between 0.1 and 100");
  359. }
  360. if ($quality > 1) {
  361. $quality /= 100;
  362. }
  363. $locale = self::_prepareLocale($locale);
  364. if (isset(self::$_localeData[(string) $locale]) === true) {
  365. self::$_default = array((string) $locale => $quality);
  366. } else {
  367. $elocale = explode('_', (string) $locale);
  368. if (isset(self::$_localeData[$elocale[0]]) === true) {
  369. self::$_default = array($elocale[0] => $quality);
  370. } else {
  371. require_once 'Zend/Locale/Exception.php';
  372. throw new Zend_Locale_Exception("Unknown locale '" . (string) $locale . "' can not be set as default!");
  373. }
  374. }
  375. self::$_auto = self::getBrowser() + self::getEnvironment() + self::getDefault();
  376. }
  377. /**
  378. * Expects the Systems standard locale
  379. *
  380. * For Windows:
  381. * f.e.: LC_COLLATE=C;LC_CTYPE=German_Austria.1252;LC_MONETARY=C
  382. * would be recognised as de_AT
  383. *
  384. * @return array
  385. */
  386. public static function getEnvironment()
  387. {
  388. if (self::$_environment !== null) {
  389. return self::$_environment;
  390. }
  391. require_once 'Zend/Locale/Data/Translation.php';
  392. $language = setlocale(LC_ALL, 0);
  393. $languages = explode(';', $language);
  394. $languagearray = array();
  395. foreach ($languages as $locale) {
  396. if (strpos($locale, '=') !== false) {
  397. $language = substr($locale, strpos($locale, '='));
  398. $language = substr($language, 1);
  399. }
  400. if ($language !== 'C') {
  401. if (strpos($language, '.') !== false) {
  402. $language = substr($language, 0, strpos($language, '.'));
  403. } else if (strpos($language, '@') !== false) {
  404. $language = substr($language, 0, strpos($language, '@'));
  405. }
  406. $language = str_ireplace(
  407. array_keys(Zend_Locale_Data_Translation::$languageTranslation),
  408. array_values(Zend_Locale_Data_Translation::$languageTranslation),
  409. (string) $language
  410. );
  411. $language = str_ireplace(
  412. array_keys(Zend_Locale_Data_Translation::$regionTranslation),
  413. array_values(Zend_Locale_Data_Translation::$regionTranslation),
  414. $language
  415. );
  416. if (isset(self::$_localeData[$language]) === true) {
  417. $languagearray[$language] = 1;
  418. if (strpos($language, '_') !== false) {
  419. $languagearray[substr($language, 0, strpos($language, '_'))] = 1;
  420. }
  421. }
  422. }
  423. }
  424. self::$_environment = $languagearray;
  425. return $languagearray;
  426. }
  427. /**
  428. * Return an array of all accepted languages of the client
  429. * Expects RFC compilant Header !!
  430. *
  431. * The notation can be :
  432. * de,en-UK-US;q=0.5,fr-FR;q=0.2
  433. *
  434. * @return array - list of accepted languages including quality
  435. */
  436. public static function getBrowser()
  437. {
  438. if (self::$_browser !== null) {
  439. return self::$_browser;
  440. }
  441. $httplanguages = getenv('HTTP_ACCEPT_LANGUAGE');
  442. if (empty($httplanguages) && array_key_exists('HTTP_ACCEPT_LANGUAGE', $_SERVER)) {
  443. $httplanguages = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
  444. }
  445. $languages = array();
  446. if (empty($httplanguages)) {
  447. return $languages;
  448. }
  449. $accepted = preg_split('/,\s*/', $httplanguages);
  450. foreach ($accepted as $accept) {
  451. $match = null;
  452. $result = preg_match('/^([a-z]{1,8}(?:[-_][a-z]{1,8})*)(?:;\s*q=(0(?:\.[0-9]{1,3})?|1(?:\.0{1,3})?))?$/i',
  453. $accept, $match);
  454. if ($result < 1) {
  455. continue;
  456. }
  457. if (isset($match[2]) === true) {
  458. $quality = (float) $match[2];
  459. } else {
  460. $quality = 1.0;
  461. }
  462. $countrys = explode('-', $match[1]);
  463. $region = array_shift($countrys);
  464. $country2 = explode('_', $region);
  465. $region = array_shift($country2);
  466. foreach ($countrys as $country) {
  467. $languages[$region . '_' . strtoupper($country)] = $quality;
  468. }
  469. foreach ($country2 as $country) {
  470. $languages[$region . '_' . strtoupper($country)] = $quality;
  471. }
  472. if ((isset($languages[$region]) === false) || ($languages[$region] < $quality)) {
  473. $languages[$region] = $quality;
  474. }
  475. }
  476. self::$_browser = $languages;
  477. return $languages;
  478. }
  479. /**
  480. * Sets a new locale
  481. *
  482. * @param string|Zend_Locale $locale (Optional) New locale to set
  483. * @return void
  484. */
  485. public function setLocale($locale = null)
  486. {
  487. $locale = self::_prepareLocale($locale);
  488. if (isset(self::$_localeData[(string) $locale]) === false) {
  489. $region = substr((string) $locale, 0, 3);
  490. if (isset($region[2]) === true) {
  491. if (($region[2] === '_') or ($region[2] === '-')) {
  492. $region = substr($region, 0, 2);
  493. }
  494. }
  495. if (isset(self::$_localeData[(string) $region]) === true) {
  496. $this->_locale = $region;
  497. } else {
  498. $this->_locale = 'root';
  499. }
  500. } else {
  501. $this->_locale = $locale;
  502. }
  503. }
  504. /**
  505. * Returns the language part of the locale
  506. *
  507. * @return string
  508. */
  509. public function getLanguage()
  510. {
  511. $locale = explode('_', $this->_locale);
  512. return $locale[0];
  513. }
  514. /**
  515. * Returns the region part of the locale if available
  516. *
  517. * @return string|false - Regionstring
  518. */
  519. public function getRegion()
  520. {
  521. $locale = explode('_', $this->_locale);
  522. if (isset($locale[1]) === true) {
  523. return $locale[1];
  524. }
  525. return false;
  526. }
  527. /**
  528. * Return the accepted charset of the client
  529. *
  530. * @return string
  531. */
  532. public static function getHttpCharset()
  533. {
  534. $httpcharsets = getenv('HTTP_ACCEPT_CHARSET');
  535. $charsets = array();
  536. if ($httpcharsets === false) {
  537. return $charsets;
  538. }
  539. $accepted = preg_split('/,\s*/', $httpcharsets);
  540. foreach ($accepted as $accept) {
  541. if (empty($accept) === true) {
  542. continue;
  543. }
  544. if (strpos($accept, ';') !== false) {
  545. $quality = (float) substr($accept, (strpos($accept, '=') + 1));
  546. $pos = substr($accept, 0, strpos($accept, ';'));
  547. $charsets[$pos] = $quality;
  548. } else {
  549. $quality = 1.0;
  550. $charsets[$accept] = $quality;
  551. }
  552. }
  553. return $charsets;
  554. }
  555. /**
  556. * Returns true if both locales are equal
  557. *
  558. * @param Zend_Locale $object Locale to check for equality
  559. * @return boolean
  560. */
  561. public function equals(Zend_Locale $object)
  562. {
  563. if ($object->toString() === $this->toString()) {
  564. return true;
  565. }
  566. return false;
  567. }
  568. /**
  569. * Returns localized informations as array, supported are several
  570. * types of informations.
  571. * For detailed information about the types look into the documentation
  572. *
  573. * @param string $path (Optional) Type of information to return
  574. * @param string|Zend_Locale $locale (Optional) Locale|Language for which this informations should be returned
  575. * @param string $value (Optional) Value for detail list
  576. * @return array Array with the wished information in the given language
  577. */
  578. public static function getTranslationList($path = null, $locale = null, $value = null)
  579. {
  580. require_once 'Zend/Locale/Data.php';
  581. $locale = self::findLocale($locale);
  582. $result = Zend_Locale_Data::getList($locale, $path, $value);
  583. if (empty($result) === true) {
  584. return false;
  585. }
  586. return $result;
  587. }
  588. /**
  589. * Returns an array with the name of all languages translated to the given language
  590. *
  591. * @param string|Zend_Locale $locale (Optional) Locale for language translation
  592. * @return array
  593. * @deprecated
  594. */
  595. public static function getLanguageTranslationList($locale = null)
  596. {
  597. trigger_error("The method getLanguageTranslationList is deprecated. Use getTranslationList('language', $locale) instead", E_USER_NOTICE);
  598. return self::getTranslationList('language', $locale);
  599. }
  600. /**
  601. * Returns an array with the name of all scripts translated to the given language
  602. *
  603. * @param string|Zend_Locale $locale (Optional) Locale for script translation
  604. * @return array
  605. * @deprecated
  606. */
  607. public static function getScriptTranslationList($locale = null)
  608. {
  609. trigger_error("The method getScriptTranslationList is deprecated. Use getTranslationList('script', $locale) instead", E_USER_NOTICE);
  610. return self::getTranslationList('script', $locale);
  611. }
  612. /**
  613. * Returns an array with the name of all countries translated to the given language
  614. *
  615. * @param string|Zend_Locale $locale (Optional) Locale for country translation
  616. * @return array
  617. * @deprecated
  618. */
  619. public static function getCountryTranslationList($locale = null)
  620. {
  621. trigger_error("The method getCountryTranslationList is deprecated. Use getTranslationList('territory', $locale, 2) instead", E_USER_NOTICE);
  622. return self::getTranslationList('territory', $locale, 2);
  623. }
  624. /**
  625. * Returns an array with the name of all territories translated to the given language
  626. * All territories contains other countries.
  627. *
  628. * @param string|Zend_Locale $locale (Optional) Locale for territory translation
  629. * @return array
  630. * @deprecated
  631. */
  632. public static function getTerritoryTranslationList($locale = null)
  633. {
  634. trigger_error("The method getTerritoryTranslationList is deprecated. Use getTranslationList('territory', $locale, 1) instead", E_USER_NOTICE);
  635. return self::getTranslationList('territory', $locale, 1);
  636. }
  637. /**
  638. * Returns a localized information string, supported are several types of informations.
  639. * For detailed information about the types look into the documentation
  640. *
  641. * @param string $value Name to get detailed information about
  642. * @param string $path (Optional) Type of information to return
  643. * @param string|Zend_Locale $locale (Optional) Locale|Language for which this informations should be returned
  644. * @return string|false The wished information in the given language
  645. */
  646. public static function getTranslation($value = null, $path = null, $locale = null)
  647. {
  648. require_once 'Zend/Locale/Data.php';
  649. $locale = self::findLocale($locale);
  650. $result = Zend_Locale_Data::getContent($locale, $path, $value);
  651. if (empty($result) === true && '0' !== $result) {
  652. return false;
  653. }
  654. return $result;
  655. }
  656. /**
  657. * Returns the localized language name
  658. *
  659. * @param string $value Name to get detailed information about
  660. * @param string $locale (Optional) Locale for language translation
  661. * @return array
  662. * @deprecated
  663. */
  664. public static function getLanguageTranslation($value, $locale = null)
  665. {
  666. trigger_error("The method getLanguageTranslation is deprecated. Use getTranslation($value, 'language', $locale) instead", E_USER_NOTICE);
  667. return self::getTranslation($value, 'language', $locale);
  668. }
  669. /**
  670. * Returns the localized script name
  671. *
  672. * @param string $value Name to get detailed information about
  673. * @param string $locale (Optional) locale for script translation
  674. * @return array
  675. * @deprecated
  676. */
  677. public static function getScriptTranslation($value, $locale = null)
  678. {
  679. trigger_error("The method getScriptTranslation is deprecated. Use getTranslation($value, 'script', $locale) instead", E_USER_NOTICE);
  680. return self::getTranslation($value, 'script', $locale);
  681. }
  682. /**
  683. * Returns the localized country name
  684. *
  685. * @param string $value Name to get detailed information about
  686. * @param string|Zend_Locale $locale (Optional) Locale for country translation
  687. * @return array
  688. * @deprecated
  689. */
  690. public static function getCountryTranslation($value, $locale = null)
  691. {
  692. trigger_error("The method getCountryTranslation is deprecated. Use getTranslation($value, 'country', $locale) instead", E_USER_NOTICE);
  693. return self::getTranslation($value, 'country', $locale);
  694. }
  695. /**
  696. * Returns the localized territory name
  697. * All territories contains other countries.
  698. *
  699. * @param string $value Name to get detailed information about
  700. * @param string|Zend_Locale $locale (Optional) Locale for territory translation
  701. * @return array
  702. * @deprecated
  703. */
  704. public static function getTerritoryTranslation($value, $locale = null)
  705. {
  706. trigger_error("The method getTerritoryTranslation is deprecated. Use getTranslation($value, 'territory', $locale) instead", E_USER_NOTICE);
  707. return self::getTranslation($value, 'territory', $locale);
  708. }
  709. /**
  710. * Returns an array with translated yes strings
  711. *
  712. * @param string|Zend_Locale $locale (Optional) Locale for language translation (defaults to $this locale)
  713. * @return array
  714. */
  715. public static function getQuestion($locale = null)
  716. {
  717. require_once 'Zend/Locale/Data.php';
  718. $locale = self::findLocale($locale);
  719. $quest = Zend_Locale_Data::getList($locale, 'question');
  720. $yes = explode(':', $quest['yes']);
  721. $no = explode(':', $quest['no']);
  722. $quest['yes'] = $yes[0];
  723. $quest['yesarray'] = $yes;
  724. $quest['no'] = $no[0];
  725. $quest['noarray'] = $no;
  726. $quest['yesexpr'] = self::_prepareQuestionString($yes);
  727. $quest['noexpr'] = self::_prepareQuestionString($no);
  728. return $quest;
  729. }
  730. /**
  731. * Internal function for preparing the returned question regex string
  732. *
  733. * @param string $input Regex to parse
  734. * @return string
  735. */
  736. private static function _prepareQuestionString($input)
  737. {
  738. $regex = '';
  739. if (is_array($input) === true) {
  740. $regex = '^';
  741. $start = true;
  742. foreach ($input as $row) {
  743. if ($start === false) {
  744. $regex .= '|';
  745. }
  746. $start = false;
  747. $regex .= '(';
  748. $one = null;
  749. if (strlen($row) > 2) {
  750. $one = true;
  751. }
  752. foreach (str_split($row, 1) as $char) {
  753. $regex .= '[' . $char;
  754. $regex .= strtoupper($char) . ']';
  755. if ($one === true) {
  756. $one = false;
  757. $regex .= '(';
  758. }
  759. }
  760. if ($one === false) {
  761. $regex .= ')';
  762. }
  763. $regex .= '?)';
  764. }
  765. }
  766. return $regex;
  767. }
  768. /**
  769. * Checks if a locale identifier is a real locale or not
  770. * Examples:
  771. * "en_XX" refers to "en", which returns true
  772. * "XX_yy" refers to "root", which returns false
  773. *
  774. * @param string|Zend_Locale $locale Locale to check for
  775. * @param boolean $strict (Optional) If true, no rerouting will be done when checking
  776. * @param boolean $compatible (DEPRECATED) Only for internal usage, brakes compatibility mode
  777. * @return boolean If the locale is known dependend on the settings
  778. */
  779. public static function isLocale($locale, $strict = false, $compatible = true)
  780. {
  781. if (($locale instanceof Zend_Locale)
  782. || (is_string($locale) && array_key_exists($locale, self::$_localeData))
  783. ) {
  784. return true;
  785. }
  786. if (($locale === null) || (!is_string($locale) and !is_array($locale))) {
  787. return false;
  788. }
  789. try {
  790. $locale = self::_prepareLocale($locale, $strict);
  791. } catch (Zend_Locale_Exception $e) {
  792. return false;
  793. }
  794. if (($compatible === true) and (self::$compatibilityMode === true)) {
  795. trigger_error('You are running Zend_Locale in compatibility mode... please migrate your scripts', E_USER_NOTICE);
  796. if (isset(self::$_localeData[$locale]) === true) {
  797. return $locale;
  798. } else if (!$strict) {
  799. $locale = explode('_', $locale);
  800. if (isset(self::$_localeData[$locale[0]]) === true) {
  801. return $locale[0];
  802. }
  803. }
  804. } else {
  805. if (isset(self::$_localeData[$locale]) === true) {
  806. return true;
  807. } else if (!$strict) {
  808. $locale = explode('_', $locale);
  809. if (isset(self::$_localeData[$locale[0]]) === true) {
  810. return true;
  811. }
  812. }
  813. }
  814. return false;
  815. }
  816. /**
  817. * Finds the proper locale based on the input
  818. * Checks if it exists, degrades it when necessary
  819. * Detects registry locale and when all fails tries to detect a automatic locale
  820. * Returns the found locale as string
  821. *
  822. * @param string $locale
  823. * @throws Zend_Locale_Exception When the given locale is no locale or the autodetection fails
  824. * @return string
  825. */
  826. public static function findLocale($locale = null)
  827. {
  828. if ($locale === null) {
  829. require_once 'Zend/Registry.php';
  830. if (Zend_Registry::isRegistered('Zend_Locale')) {
  831. $locale = Zend_Registry::get('Zend_Locale');
  832. }
  833. }
  834. if ($locale === null) {
  835. $locale = new Zend_Locale();
  836. }
  837. if (!Zend_Locale::isLocale($locale, true, false)) {
  838. if (!Zend_Locale::isLocale($locale, false, false)) {
  839. $locale = Zend_Locale::getLocaleToTerritory($locale);
  840. if (empty($locale)) {
  841. require_once 'Zend/Locale/Exception.php';
  842. throw new Zend_Locale_Exception("The locale '$locale' is no known locale");
  843. }
  844. } else {
  845. $locale = new Zend_Locale($locale);
  846. }
  847. }
  848. $locale = self::_prepareLocale($locale);
  849. return $locale;
  850. }
  851. /**
  852. * Returns the expected locale for a given territory
  853. *
  854. * @param string $territory Territory for which the locale is being searched
  855. * @return string|null Locale string or null when no locale has been found
  856. */
  857. public static function getLocaleToTerritory($territory)
  858. {
  859. $territory = strtoupper($territory);
  860. if (array_key_exists($territory, self::$_territoryData)) {
  861. return self::$_territoryData[$territory];
  862. }
  863. return null;
  864. }
  865. /**
  866. * Returns a list of all known locales where the locale is the key
  867. * Only real locales are returned, the internal locales 'root', 'auto', 'browser'
  868. * and 'environment' are suppressed
  869. *
  870. * @return array List of all Locales
  871. */
  872. public static function getLocaleList()
  873. {
  874. $list = self::$_localeData;
  875. unset($list['root']);
  876. unset($list['auto']);
  877. unset($list['browser']);
  878. unset($list['environment']);
  879. return $list;
  880. }
  881. /**
  882. * Returns the set cache
  883. *
  884. * @return Zend_Cache_Core The set cache
  885. */
  886. public static function getCache()
  887. {
  888. require_once 'Zend/Locale/Data.php';
  889. return Zend_Locale_Data::getCache();
  890. }
  891. /**
  892. * Sets a cache
  893. *
  894. * @param Zend_Cache_Core $cache Cache to set
  895. * @return void
  896. */
  897. public static function setCache(Zend_Cache_Core $cache)
  898. {
  899. require_once 'Zend/Locale/Data.php';
  900. Zend_Locale_Data::setCache($cache);
  901. }
  902. /**
  903. * Returns true when a cache is set
  904. *
  905. * @return boolean
  906. */
  907. public static function hasCache()
  908. {
  909. require_once 'Zend/Locale/Data.php';
  910. return Zend_Locale_Data::hasCache();
  911. }
  912. /**
  913. * Removes any set cache
  914. *
  915. * @return void
  916. */
  917. public static function removeCache()
  918. {
  919. require_once 'Zend/Locale/Data.php';
  920. Zend_Locale_Data::removeCache();
  921. }
  922. /**
  923. * Clears all set cache data
  924. *
  925. * @param string $tag Tag to clear when the default tag name is not used
  926. * @return void
  927. */
  928. public static function clearCache($tag = null)
  929. {
  930. require_once 'Zend/Locale/Data.php';
  931. Zend_Locale_Data::clearCache($tag);
  932. }
  933. /**
  934. * Disables the set cache
  935. *
  936. * @param boolean $flag True disables any set cache, default is false
  937. * @return void
  938. */
  939. public static function disableCache($flag)
  940. {
  941. require_once 'Zend/Locale/Data.php';
  942. Zend_Locale_Data::disableCache($flag);
  943. }
  944. /**
  945. * Internal function, returns a single locale on detection
  946. *
  947. * @param string|Zend_Locale $locale (Optional) Locale to work on
  948. * @param boolean $strict (Optional) Strict preparation
  949. * @throws Zend_Locale_Exception When no locale is set which is only possible when the class was wrong extended
  950. * @return string
  951. */
  952. private static function _prepareLocale($locale, $strict = false)
  953. {
  954. if ($locale instanceof Zend_Locale) {
  955. $locale = $locale->toString();
  956. }
  957. if (is_array($locale)) {
  958. return '';
  959. }
  960. if (empty(self::$_auto) === true) {
  961. self::$_browser = self::getBrowser();
  962. self::$_environment = self::getEnvironment();
  963. self::$_breakChain = true;
  964. self::$_auto = self::getBrowser() + self::getEnvironment() + self::getDefault();
  965. }
  966. if (!$strict) {
  967. if ($locale === 'browser') {
  968. $locale = self::$_browser;
  969. }
  970. if ($locale === 'environment') {
  971. $locale = self::$_environment;
  972. }
  973. if ($locale === 'default') {
  974. $locale = self::$_default;
  975. }
  976. if (($locale === 'auto') or ($locale === null)) {
  977. $locale = self::$_auto;
  978. }
  979. if (is_array($locale) === true) {
  980. $locale = key($locale);
  981. }
  982. }
  983. // This can only happen when someone extends Zend_Locale and erases the default
  984. if ($locale === null) {
  985. require_once 'Zend/Locale/Exception.php';
  986. throw new Zend_Locale_Exception('Autodetection of Locale has been failed!');
  987. }
  988. if (strpos($locale, '-') !== false) {
  989. $locale = strtr($locale, '-', '_');
  990. }
  991. $parts = explode('_', $locale);
  992. if (!isset(self::$_localeData[$parts[0]])) {
  993. if ((count($parts) == 1) && array_key_exists($parts[0], self::$_territoryData)) {
  994. return self::$_territoryData[$parts[0]];
  995. }
  996. return '';
  997. }
  998. foreach($parts as $key => $value) {
  999. if ((strlen($value) < 2) || (strlen($value) > 3)) {
  1000. unset($parts[$key]);
  1001. }
  1002. }
  1003. $locale = implode('_', $parts);
  1004. return (string) $locale;
  1005. }
  1006. /**
  1007. * Search the locale automatically and return all used locales
  1008. * ordered by quality
  1009. *
  1010. * Standard Searchorder is Browser, Environment, Default
  1011. *
  1012. * @param string $searchorder (Optional) Searchorder
  1013. * @return array Returns an array of all detected locales
  1014. */
  1015. public static function getOrder($order = null)
  1016. {
  1017. switch ($order) {
  1018. case self::ENVIRONMENT:
  1019. self::$_breakChain = true;
  1020. $languages = self::getEnvironment() + self::getBrowser() + self::getDefault();
  1021. break;
  1022. case self::ZFDEFAULT:
  1023. self::$_breakChain = true;
  1024. $languages = self::getDefault() + self::getEnvironment() + self::getBrowser();
  1025. break;
  1026. default:
  1027. self::$_breakChain = true;
  1028. $languages = self::getBrowser() + self::getEnvironment() + self::getDefault();
  1029. break;
  1030. }
  1031. return $languages;
  1032. }
  1033. }