Locale.php 56 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881
  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-2014 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-2014 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,
  38. 'aa' => true,
  39. 'aa_DJ' => true,
  40. 'aa_ER' => true,
  41. 'aa_ET' => true,
  42. 'af' => true,
  43. 'af_NA' => true,
  44. 'af_ZA' => true,
  45. 'agq' => true,
  46. 'agq_CM' => true,
  47. 'ak' => true,
  48. 'ak_GH' => true,
  49. 'am' => true,
  50. 'am_ET' => true,
  51. 'ar' => true,
  52. 'ar_001' => true,
  53. 'ar_AE' => true,
  54. 'ar_BH' => true,
  55. 'ar_DJ' => true,
  56. 'ar_DZ' => true,
  57. 'ar_EG' => true,
  58. 'ar_EH' => true,
  59. 'ar_ER' => true,
  60. 'ar_IL' => true,
  61. 'ar_IQ' => true,
  62. 'ar_JO' => true,
  63. 'ar_KM' => true,
  64. 'ar_KW' => true,
  65. 'ar_LB' => true,
  66. 'ar_LY' => true,
  67. 'ar_MA' => true,
  68. 'ar_MR' => true,
  69. 'ar_OM' => true,
  70. 'ar_PS' => true,
  71. 'ar_QA' => true,
  72. 'ar_SA' => true,
  73. 'ar_SD' => true,
  74. 'ar_SO' => true,
  75. 'ar_SY' => true,
  76. 'ar_TD' => true,
  77. 'ar_TN' => true,
  78. 'ar_YE' => true,
  79. 'as' => true,
  80. 'as_IN' => true,
  81. 'asa' => true,
  82. 'asa_TZ' => true,
  83. 'ast' => true,
  84. 'ast_ES' => true,
  85. 'az' => true,
  86. 'az_Cyrl' => true,
  87. 'az_Cyrl_AZ' => true,
  88. 'az_Latn' => true,
  89. 'az_Latn_AZ' => true,
  90. 'bas' => true,
  91. 'bas_CM' => true,
  92. 'be' => true,
  93. 'be_BY' => true,
  94. 'bem' => true,
  95. 'bem_ZM' => true,
  96. 'bez' => true,
  97. 'bez_TZ' => true,
  98. 'bg' => true,
  99. 'bg_BG' => true,
  100. 'bm' => true,
  101. 'bm_ML' => true,
  102. 'bn' => true,
  103. 'bn_BD' => true,
  104. 'bn_IN' => true,
  105. 'bo' => true,
  106. 'bo_CN' => true,
  107. 'bo_IN' => true,
  108. 'br' => true,
  109. 'br_FR' => true,
  110. 'brx' => true,
  111. 'brx_IN' => true,
  112. 'bs' => true,
  113. 'bs_Cyrl' => true,
  114. 'bs_Cyrl_BA' => true,
  115. 'bs_Latn' => true,
  116. 'bs_Latn_BA' => true,
  117. 'byn' => true,
  118. 'byn_ER' => true,
  119. 'ca' => true,
  120. 'ca_AD' => true,
  121. 'ca_ES' => true,
  122. 'cgg' => true,
  123. 'cgg_UG' => true,
  124. 'chr' => true,
  125. 'chr_US' => true,
  126. 'cs' => true,
  127. 'cs_CZ' => true,
  128. 'cy' => true,
  129. 'cy_GB' => true,
  130. 'da' => true,
  131. 'da_DK' => true,
  132. 'dav' => true,
  133. 'dav_KE' => true,
  134. 'de' => true,
  135. 'de_AT' => true,
  136. 'de_BE' => true,
  137. 'de_CH' => true,
  138. 'de_DE' => true,
  139. 'de_LI' => true,
  140. 'de_LU' => true,
  141. 'dje' => true,
  142. 'dje_NE' => true,
  143. 'dua' => true,
  144. 'dua_CM' => true,
  145. 'dyo' => true,
  146. 'dyo_SN' => true,
  147. 'dz' => true,
  148. 'dz_BT' => true,
  149. 'ebu' => true,
  150. 'ebu_KE' => true,
  151. 'ee' => true,
  152. 'ee_GH' => true,
  153. 'ee_TG' => true,
  154. 'el' => true,
  155. 'el_CY' => true,
  156. 'el_GR' => true,
  157. 'en' => true,
  158. 'en_150' => true,
  159. 'en_AG' => true,
  160. 'en_AS' => true,
  161. 'en_AU' => true,
  162. 'en_BB' => true,
  163. 'en_BE' => true,
  164. 'en_BM' => true,
  165. 'en_BS' => true,
  166. 'en_BW' => true,
  167. 'en_BZ' => true,
  168. 'en_CA' => true,
  169. 'en_CM' => true,
  170. 'en_DM' => true,
  171. 'en_Dsrt' => true,
  172. 'en_Dsrt_US' => true,
  173. 'en_FJ' => true,
  174. 'en_FM' => true,
  175. 'en_GB' => true,
  176. 'en_GD' => true,
  177. 'en_GG' => true,
  178. 'en_GH' => true,
  179. 'en_GI' => true,
  180. 'en_GM' => true,
  181. 'en_GU' => true,
  182. 'en_GY' => true,
  183. 'en_HK' => true,
  184. 'en_IE' => true,
  185. 'en_IM' => true,
  186. 'en_IN' => true,
  187. 'en_JE' => true,
  188. 'en_JM' => true,
  189. 'en_KE' => true,
  190. 'en_KI' => true,
  191. 'en_KN' => true,
  192. 'en_KY' => true,
  193. 'en_LC' => true,
  194. 'en_LR' => true,
  195. 'en_LS' => true,
  196. 'en_MG' => true,
  197. 'en_MH' => true,
  198. 'en_MP' => true,
  199. 'en_MT' => true,
  200. 'en_MU' => true,
  201. 'en_MW' => true,
  202. 'en_NA' => true,
  203. 'en_NG' => true,
  204. 'en_NZ' => true,
  205. 'en_PG' => true,
  206. 'en_PH' => true,
  207. 'en_PK' => true,
  208. 'en_PR' => true,
  209. 'en_PW' => true,
  210. 'en_SB' => true,
  211. 'en_SC' => true,
  212. 'en_SG' => true,
  213. 'en_SL' => true,
  214. 'en_SS' => true,
  215. 'en_SZ' => true,
  216. 'en_TC' => true,
  217. 'en_TO' => true,
  218. 'en_TT' => true,
  219. 'en_TZ' => true,
  220. 'en_UG' => true,
  221. 'en_UM' => true,
  222. 'en_US' => true,
  223. 'en_US_POSIX' => true,
  224. 'en_VC' => true,
  225. 'en_VG' => true,
  226. 'en_VI' => true,
  227. 'en_VU' => true,
  228. 'en_WS' => true,
  229. 'en_ZA' => true,
  230. 'en_ZM' => true,
  231. 'en_ZW' => true,
  232. 'eo' => true,
  233. 'es' => true,
  234. 'es_419' => true,
  235. 'es_AR' => true,
  236. 'es_BO' => true,
  237. 'es_CL' => true,
  238. 'es_CO' => true,
  239. 'es_CR' => true,
  240. 'es_CU' => true,
  241. 'es_DO' => true,
  242. 'es_EA' => true,
  243. 'es_EC' => true,
  244. 'es_ES' => true,
  245. 'es_GQ' => true,
  246. 'es_GT' => true,
  247. 'es_HN' => true,
  248. 'es_IC' => true,
  249. 'es_MX' => true,
  250. 'es_NI' => true,
  251. 'es_PA' => true,
  252. 'es_PE' => true,
  253. 'es_PH' => true,
  254. 'es_PR' => true,
  255. 'es_PY' => true,
  256. 'es_SV' => true,
  257. 'es_US' => true,
  258. 'es_UY' => true,
  259. 'es_VE' => true,
  260. 'et' => true,
  261. 'et_EE' => true,
  262. 'eu' => true,
  263. 'eu_ES' => true,
  264. 'ewo' => true,
  265. 'ewo_CM' => true,
  266. 'fa' => true,
  267. 'fa_AF' => true,
  268. 'fa_IR' => true,
  269. 'ff' => true,
  270. 'ff_SN' => true,
  271. 'fi' => true,
  272. 'fi_FI' => true,
  273. 'fil' => true,
  274. 'fil_PH' => true,
  275. 'fo' => true,
  276. 'fo_FO' => true,
  277. 'fr' => true,
  278. 'fr_BE' => true,
  279. 'fr_BF' => true,
  280. 'fr_BI' => true,
  281. 'fr_BJ' => true,
  282. 'fr_BL' => true,
  283. 'fr_CA' => true,
  284. 'fr_CD' => true,
  285. 'fr_CF' => true,
  286. 'fr_CG' => true,
  287. 'fr_CH' => true,
  288. 'fr_CI' => true,
  289. 'fr_CM' => true,
  290. 'fr_DJ' => true,
  291. 'fr_DZ' => true,
  292. 'fr_FR' => true,
  293. 'fr_GA' => true,
  294. 'fr_GF' => true,
  295. 'fr_GN' => true,
  296. 'fr_GP' => true,
  297. 'fr_GQ' => true,
  298. 'fr_HT' => true,
  299. 'fr_KM' => true,
  300. 'fr_LU' => true,
  301. 'fr_MA' => true,
  302. 'fr_MC' => true,
  303. 'fr_MF' => true,
  304. 'fr_MG' => true,
  305. 'fr_ML' => true,
  306. 'fr_MQ' => true,
  307. 'fr_MR' => true,
  308. 'fr_MU' => true,
  309. 'fr_NC' => true,
  310. 'fr_NE' => true,
  311. 'fr_PF' => true,
  312. 'fr_RE' => true,
  313. 'fr_RW' => true,
  314. 'fr_SC' => true,
  315. 'fr_SN' => true,
  316. 'fr_SY' => true,
  317. 'fr_TD' => true,
  318. 'fr_TG' => true,
  319. 'fr_TN' => true,
  320. 'fr_VU' => true,
  321. 'fr_YT' => true,
  322. 'fur' => true,
  323. 'fur_IT' => true,
  324. 'ga' => true,
  325. 'ga_IE' => true,
  326. 'gd' => true,
  327. 'gd_GB' => true,
  328. 'gl' => true,
  329. 'gl_ES' => true,
  330. 'gsw' => true,
  331. 'gsw_CH' => true,
  332. 'gu' => true,
  333. 'gu_IN' => true,
  334. 'guz' => true,
  335. 'guz_KE' => true,
  336. 'gv' => true,
  337. 'ha' => true,
  338. 'ha_Latn' => true,
  339. 'ha_Latn_GH' => true,
  340. 'ha_Latn_NE' => true,
  341. 'ha_Latn_NG' => true,
  342. 'haw' => true,
  343. 'haw_US' => true,
  344. 'he' => true,
  345. 'he_IL' => true,
  346. 'hi' => true,
  347. 'hi_IN' => true,
  348. 'hr' => true,
  349. 'hr_BA' => true,
  350. 'hr_HR' => true,
  351. 'hu' => true,
  352. 'hu_HU' => true,
  353. 'hy' => true,
  354. 'hy_AM' => true,
  355. 'ia' => true,
  356. 'ia_FR' => true,
  357. 'id' => true,
  358. 'id_ID' => true,
  359. 'ig' => true,
  360. 'ig_NG' => true,
  361. 'ii' => true,
  362. 'ii_CN' => true,
  363. 'is' => true,
  364. 'is_IS' => true,
  365. 'it' => true,
  366. 'it_CH' => true,
  367. 'it_IT' => true,
  368. 'it_SM' => true,
  369. 'ja' => true,
  370. 'ja_JP' => true,
  371. 'jgo' => true,
  372. 'jgo_CM' => true,
  373. 'jmc' => true,
  374. 'jmc_TZ' => true,
  375. 'ka' => true,
  376. 'ka_GE' => true,
  377. 'kab' => true,
  378. 'kab_DZ' => true,
  379. 'kam' => true,
  380. 'kam_KE' => true,
  381. 'kde' => true,
  382. 'kde_TZ' => true,
  383. 'kea' => true,
  384. 'kea_CV' => true,
  385. 'khq' => true,
  386. 'khq_ML' => true,
  387. 'ki' => true,
  388. 'ki_KE' => true,
  389. 'kk' => true,
  390. 'kk_Cyrl' => true,
  391. 'kk_Cyrl_KZ' => true,
  392. 'kkj' => true,
  393. 'kkj_CM' => true,
  394. 'kl' => true,
  395. 'kl_GL' => true,
  396. 'kln' => true,
  397. 'kln_KE' => true,
  398. 'km' => true,
  399. 'km_KH' => true,
  400. 'kn' => true,
  401. 'kn_IN' => true,
  402. 'ko' => true,
  403. 'ko_KP' => true,
  404. 'ko_KR' => true,
  405. 'kok' => true,
  406. 'kok_IN' => true,
  407. 'ks' => true,
  408. 'ks_Arab' => true,
  409. 'ks_Arab_IN' => true,
  410. 'ksb' => true,
  411. 'ksb_TZ' => true,
  412. 'ksf' => true,
  413. 'ksf_CM' => true,
  414. 'ksh' => true,
  415. 'ksh_DE' => true,
  416. 'kw' => true,
  417. 'kw_GB' => true,
  418. 'ky' => true,
  419. 'lag' => true,
  420. 'lag_TZ' => true,
  421. 'lg' => true,
  422. 'lg_UG' => true,
  423. 'ln' => true,
  424. 'ln_AO' => true,
  425. 'ln_CD' => true,
  426. 'ln_CF' => true,
  427. 'ln_CG' => true,
  428. 'lo' => true,
  429. 'lo_LA' => true,
  430. 'lt' => true,
  431. 'lt_LT' => true,
  432. 'lu' => true,
  433. 'lu_CD' => true,
  434. 'luo' => true,
  435. 'luo_KE' => true,
  436. 'luy' => true,
  437. 'luy_KE' => true,
  438. 'lv' => true,
  439. 'lv_LV' => true,
  440. 'mas' => true,
  441. 'mas_KE' => true,
  442. 'mas_TZ' => true,
  443. 'mer' => true,
  444. 'mer_KE' => true,
  445. 'mfe' => true,
  446. 'mfe_MU' => true,
  447. 'mg' => true,
  448. 'mg_MG' => true,
  449. 'mgh' => true,
  450. 'mgh_MZ' => true,
  451. 'mgo' => true,
  452. 'mgo_CM' => true,
  453. 'mk' => true,
  454. 'mk_MK' => true,
  455. 'ml' => true,
  456. 'ml_IN' => true,
  457. 'mn' => true,
  458. 'mn_Cyrl' => true,
  459. 'mn_Cyrl_MN' => true,
  460. 'mr' => true,
  461. 'mr_IN' => true,
  462. 'ms' => true,
  463. 'ms_Latn' => true,
  464. 'ms_Latn_BN' => true,
  465. 'ms_Latn_MY' => true,
  466. 'ms_Latn_SG' => true,
  467. 'mt' => true,
  468. 'mt_MT' => true,
  469. 'mua' => true,
  470. 'mua_CM' => true,
  471. 'my' => true,
  472. 'my_MM' => true,
  473. 'naq' => true,
  474. 'naq_NA' => true,
  475. 'nb' => true,
  476. 'nb_NO' => true,
  477. 'nd' => true,
  478. 'nd_ZW' => true,
  479. 'ne' => true,
  480. 'ne_IN' => true,
  481. 'ne_NP' => true,
  482. 'nl' => true,
  483. 'nl_AW' => true,
  484. 'nl_BE' => true,
  485. 'nl_CW' => true,
  486. 'nl_NL' => true,
  487. 'nl_SR' => true,
  488. 'nl_SX' => true,
  489. 'nmg' => true,
  490. 'nmg_CM' => true,
  491. 'nn' => true,
  492. 'nn_NO' => true,
  493. 'nnh' => true,
  494. 'nnh_CM' => true,
  495. 'nr' => true,
  496. 'nr_ZA' => true,
  497. 'nso' => true,
  498. 'nso_ZA' => true,
  499. 'nus' => true,
  500. 'nus_SD' => true,
  501. 'nyn' => true,
  502. 'nyn_UG' => true,
  503. 'om' => true,
  504. 'om_ET' => true,
  505. 'om_KE' => true,
  506. 'or' => true,
  507. 'or_IN' => true,
  508. 'ordinals' => true,
  509. 'os' => true,
  510. 'os_GE' => true,
  511. 'os_RU' => true,
  512. 'pa' => true,
  513. 'pa_Arab' => true,
  514. 'pa_Arab_PK' => true,
  515. 'pa_Guru' => true,
  516. 'pa_Guru_IN' => true,
  517. 'pl' => true,
  518. 'pl_PL' => true,
  519. 'plurals' => true,
  520. 'ps' => true,
  521. 'ps_AF' => true,
  522. 'pt' => true,
  523. 'pt_AO' => true,
  524. 'pt_BR' => true,
  525. 'pt_CV' => true,
  526. 'pt_GW' => true,
  527. 'pt_MO' => true,
  528. 'pt_MZ' => true,
  529. 'pt_PT' => true,
  530. 'pt_ST' => true,
  531. 'pt_TL' => true,
  532. 'rm' => true,
  533. 'rm_CH' => true,
  534. 'rn' => true,
  535. 'rn_BI' => true,
  536. 'ro' => true,
  537. 'ro_MD' => true,
  538. 'ro_RO' => true,
  539. 'rof' => true,
  540. 'rof_TZ' => true,
  541. 'ru' => true,
  542. 'ru_BY' => true,
  543. 'ru_KG' => true,
  544. 'ru_KZ' => true,
  545. 'ru_MD' => true,
  546. 'ru_RU' => true,
  547. 'ru_UA' => true,
  548. 'rw' => true,
  549. 'rw_RW' => true,
  550. 'rwk' => true,
  551. 'rwk_TZ' => true,
  552. 'sah' => true,
  553. 'sah_RU' => true,
  554. 'saq' => true,
  555. 'saq_KE' => true,
  556. 'sbp' => true,
  557. 'sbp_TZ' => true,
  558. 'se' => true,
  559. 'se_FI' => true,
  560. 'se_NO' => true,
  561. 'seh' => true,
  562. 'seh_MZ' => true,
  563. 'ses' => true,
  564. 'ses_ML' => true,
  565. 'sg' => true,
  566. 'sg_CF' => true,
  567. 'shi' => true,
  568. 'shi_Latn' => true,
  569. 'shi_Latn_MA' => true,
  570. 'shi_Tfng' => true,
  571. 'shi_Tfng_MA' => true,
  572. 'si' => true,
  573. 'si_LK' => true,
  574. 'sk' => true,
  575. 'sk_SK' => true,
  576. 'sl' => true,
  577. 'sl_SI' => true,
  578. 'sn' => true,
  579. 'sn_ZW' => true,
  580. 'so' => true,
  581. 'so_DJ' => true,
  582. 'so_ET' => true,
  583. 'so_KE' => true,
  584. 'so_SO' => true,
  585. 'sq' => true,
  586. 'sq_AL' => true,
  587. 'sq_MK' => true,
  588. 'sq_XK' => true,
  589. 'sr' => true,
  590. 'sr_Cyrl' => true,
  591. 'sr_Cyrl_BA' => true,
  592. 'sr_Cyrl_ME' => true,
  593. 'sr_Cyrl_RS' => true,
  594. 'sr_Cyrl_XK' => true,
  595. 'sr_Latn' => true,
  596. 'sr_Latn_BA' => true,
  597. 'sr_Latn_ME' => true,
  598. 'sr_Latn_RS' => true,
  599. 'sr_Latn_XK' => true,
  600. 'ss' => true,
  601. 'ss_SZ' => true,
  602. 'ss_ZA' => true,
  603. 'ssy' => true,
  604. 'ssy_ER' => true,
  605. 'st' => true,
  606. 'st_LS' => true,
  607. 'st_ZA' => true,
  608. 'sv' => true,
  609. 'sv_AX' => true,
  610. 'sv_FI' => true,
  611. 'sv_SE' => true,
  612. 'sw' => true,
  613. 'sw_KE' => true,
  614. 'sw_TZ' => true,
  615. 'sw_UG' => true,
  616. 'swc' => true,
  617. 'swc_CD' => true,
  618. 'ta' => true,
  619. 'ta_IN' => true,
  620. 'ta_LK' => true,
  621. 'ta_MY' => true,
  622. 'ta_SG' => true,
  623. 'te' => true,
  624. 'te_IN' => true,
  625. 'teo' => true,
  626. 'teo_KE' => true,
  627. 'teo_UG' => true,
  628. 'tg' => true,
  629. 'tg_Cyrl' => true,
  630. 'tg_Cyrl_TJ' => true,
  631. 'th' => true,
  632. 'th_TH' => true,
  633. 'ti' => true,
  634. 'ti_ER' => true,
  635. 'ti_ET' => true,
  636. 'tig' => true,
  637. 'tig_ER' => true,
  638. 'tn' => true,
  639. 'tn_BW' => true,
  640. 'tn_ZA' => true,
  641. 'to' => true,
  642. 'to_TO' => true,
  643. 'tr' => true,
  644. 'tr_CY' => true,
  645. 'tr_TR' => true,
  646. 'ts' => true,
  647. 'ts_ZA' => true,
  648. 'twq' => true,
  649. 'twq_NE' => true,
  650. 'tzm' => true,
  651. 'tzm_Latn' => true,
  652. 'tzm_Latn_MA' => true,
  653. 'uk' => true,
  654. 'uk_UA' => true,
  655. 'ur' => true,
  656. 'ur_IN' => true,
  657. 'ur_PK' => true,
  658. 'uz' => true,
  659. 'uz_Arab' => true,
  660. 'uz_Arab_AF' => true,
  661. 'uz_Cyrl' => true,
  662. 'uz_Cyrl_UZ' => true,
  663. 'uz_Latn' => true,
  664. 'uz_Latn_UZ' => true,
  665. 'vai' => true,
  666. 'vai_Latn' => true,
  667. 'vai_Latn_LR' => true,
  668. 'vai_Vaii' => true,
  669. 'vai_Vaii_LR' => true,
  670. 've' => true,
  671. 've_ZA' => true,
  672. 'vi' => true,
  673. 'vi_VN' => true,
  674. 'vo' => true,
  675. 'vun' => true,
  676. 'vun_TZ' => true,
  677. 'wae' => true,
  678. 'wae_CH' => true,
  679. 'wal' => true,
  680. 'wal_ET' => true,
  681. 'xh' => true,
  682. 'xh_ZA' => true,
  683. 'xog' => true,
  684. 'xog_UG' => true,
  685. 'yav' => true,
  686. 'yav_CM' => true,
  687. 'yo' => true,
  688. 'yo_NG' => true,
  689. 'zh' => true,
  690. 'zh_Hans' => true,
  691. 'zh_Hans_CN' => true,
  692. 'zh_Hans_HK' => true,
  693. 'zh_Hans_MO' => true,
  694. 'zh_Hans_SG' => true,
  695. 'zh_Hant' => true,
  696. 'zh_Hant_HK' => true,
  697. 'zh_Hant_MO' => true,
  698. 'zh_Hant_TW' => true,
  699. 'zu' => true,
  700. 'zu_ZA' => true,
  701. );
  702. /**
  703. * Class wide Locale Constants
  704. *
  705. * @var array $_territoryData
  706. */
  707. private static $_territoryData = array(
  708. 'AD' => 'ca_AD',
  709. 'AE' => 'ar_AE',
  710. 'AF' => 'fa_AF',
  711. 'AG' => 'en_AG',
  712. 'AI' => 'en_AI',
  713. 'AL' => 'sq_AL',
  714. 'AM' => 'hy_AM',
  715. 'AN' => 'pap_AN',
  716. 'AO' => 'pt_AO',
  717. 'AQ' => 'und_AQ',
  718. 'AR' => 'es_AR',
  719. 'AS' => 'sm_AS',
  720. 'AT' => 'de_AT',
  721. 'AU' => 'en_AU',
  722. 'AW' => 'nl_AW',
  723. 'AX' => 'sv_AX',
  724. 'AZ' => 'az_Latn_AZ',
  725. 'BA' => 'bs_BA',
  726. 'BB' => 'en_BB',
  727. 'BD' => 'bn_BD',
  728. 'BE' => 'nl_BE',
  729. 'BF' => 'mos_BF',
  730. 'BG' => 'bg_BG',
  731. 'BH' => 'ar_BH',
  732. 'BI' => 'rn_BI',
  733. 'BJ' => 'fr_BJ',
  734. 'BL' => 'fr_BL',
  735. 'BM' => 'en_BM',
  736. 'BN' => 'ms_BN',
  737. 'BO' => 'es_BO',
  738. 'BR' => 'pt_BR',
  739. 'BS' => 'en_BS',
  740. 'BT' => 'dz_BT',
  741. 'BV' => 'und_BV',
  742. 'BW' => 'en_BW',
  743. 'BY' => 'be_BY',
  744. 'BZ' => 'en_BZ',
  745. 'CA' => 'en_CA',
  746. 'CC' => 'ms_CC',
  747. 'CD' => 'sw_CD',
  748. 'CF' => 'fr_CF',
  749. 'CG' => 'fr_CG',
  750. 'CH' => 'de_CH',
  751. 'CI' => 'fr_CI',
  752. 'CK' => 'en_CK',
  753. 'CL' => 'es_CL',
  754. 'CM' => 'fr_CM',
  755. 'CN' => 'zh_Hans_CN',
  756. 'CO' => 'es_CO',
  757. 'CR' => 'es_CR',
  758. 'CU' => 'es_CU',
  759. 'CV' => 'kea_CV',
  760. 'CX' => 'en_CX',
  761. 'CY' => 'el_CY',
  762. 'CZ' => 'cs_CZ',
  763. 'DE' => 'de_DE',
  764. 'DJ' => 'aa_DJ',
  765. 'DK' => 'da_DK',
  766. 'DM' => 'en_DM',
  767. 'DO' => 'es_DO',
  768. 'DZ' => 'ar_DZ',
  769. 'EC' => 'es_EC',
  770. 'EE' => 'et_EE',
  771. 'EG' => 'ar_EG',
  772. 'EH' => 'ar_EH',
  773. 'ER' => 'ti_ER',
  774. 'ES' => 'es_ES',
  775. 'ET' => 'en_ET',
  776. 'FI' => 'fi_FI',
  777. 'FJ' => 'hi_FJ',
  778. 'FK' => 'en_FK',
  779. 'FM' => 'chk_FM',
  780. 'FO' => 'fo_FO',
  781. 'FR' => 'fr_FR',
  782. 'GA' => 'fr_GA',
  783. 'GB' => 'en_GB',
  784. 'GD' => 'en_GD',
  785. 'GE' => 'ka_GE',
  786. 'GF' => 'fr_GF',
  787. 'GG' => 'en_GG',
  788. 'GH' => 'ak_GH',
  789. 'GI' => 'en_GI',
  790. 'GL' => 'iu_GL',
  791. 'GM' => 'en_GM',
  792. 'GN' => 'fr_GN',
  793. 'GP' => 'fr_GP',
  794. 'GQ' => 'fan_GQ',
  795. 'GR' => 'el_GR',
  796. 'GS' => 'und_GS',
  797. 'GT' => 'es_GT',
  798. 'GU' => 'en_GU',
  799. 'GW' => 'pt_GW',
  800. 'GY' => 'en_GY',
  801. 'HK' => 'zh_Hant_HK',
  802. 'HM' => 'und_HM',
  803. 'HN' => 'es_HN',
  804. 'HR' => 'hr_HR',
  805. 'HT' => 'ht_HT',
  806. 'HU' => 'hu_HU',
  807. 'ID' => 'id_ID',
  808. 'IE' => 'en_IE',
  809. 'IL' => 'he_IL',
  810. 'IM' => 'en_IM',
  811. 'IN' => 'hi_IN',
  812. 'IO' => 'und_IO',
  813. 'IQ' => 'ar_IQ',
  814. 'IR' => 'fa_IR',
  815. 'IS' => 'is_IS',
  816. 'IT' => 'it_IT',
  817. 'JE' => 'en_JE',
  818. 'JM' => 'en_JM',
  819. 'JO' => 'ar_JO',
  820. 'JP' => 'ja_JP',
  821. 'KE' => 'en_KE',
  822. 'KG' => 'ky_Cyrl_KG',
  823. 'KH' => 'km_KH',
  824. 'KI' => 'en_KI',
  825. 'KM' => 'ar_KM',
  826. 'KN' => 'en_KN',
  827. 'KP' => 'ko_KP',
  828. 'KR' => 'ko_KR',
  829. 'KW' => 'ar_KW',
  830. 'KY' => 'en_KY',
  831. 'KZ' => 'ru_KZ',
  832. 'LA' => 'lo_LA',
  833. 'LB' => 'ar_LB',
  834. 'LC' => 'en_LC',
  835. 'LI' => 'de_LI',
  836. 'LK' => 'si_LK',
  837. 'LR' => 'en_LR',
  838. 'LS' => 'st_LS',
  839. 'LT' => 'lt_LT',
  840. 'LU' => 'fr_LU',
  841. 'LV' => 'lv_LV',
  842. 'LY' => 'ar_LY',
  843. 'MA' => 'ar_MA',
  844. 'MC' => 'fr_MC',
  845. 'MD' => 'ro_MD',
  846. 'ME' => 'sr_Latn_ME',
  847. 'MF' => 'fr_MF',
  848. 'MG' => 'mg_MG',
  849. 'MH' => 'mh_MH',
  850. 'MK' => 'mk_MK',
  851. 'ML' => 'bm_ML',
  852. 'MM' => 'my_MM',
  853. 'MN' => 'mn_Cyrl_MN',
  854. 'MO' => 'zh_Hant_MO',
  855. 'MP' => 'en_MP',
  856. 'MQ' => 'fr_MQ',
  857. 'MR' => 'ar_MR',
  858. 'MS' => 'en_MS',
  859. 'MT' => 'mt_MT',
  860. 'MU' => 'mfe_MU',
  861. 'MV' => 'dv_MV',
  862. 'MW' => 'ny_MW',
  863. 'MX' => 'es_MX',
  864. 'MY' => 'ms_MY',
  865. 'MZ' => 'pt_MZ',
  866. 'NA' => 'kj_NA',
  867. 'NC' => 'fr_NC',
  868. 'NE' => 'ha_Latn_NE',
  869. 'NF' => 'en_NF',
  870. 'NG' => 'en_NG',
  871. 'NI' => 'es_NI',
  872. 'NL' => 'nl_NL',
  873. 'NO' => 'nb_NO',
  874. 'NP' => 'ne_NP',
  875. 'NR' => 'en_NR',
  876. 'NU' => 'niu_NU',
  877. 'NZ' => 'en_NZ',
  878. 'OM' => 'ar_OM',
  879. 'PA' => 'es_PA',
  880. 'PE' => 'es_PE',
  881. 'PF' => 'fr_PF',
  882. 'PG' => 'tpi_PG',
  883. 'PH' => 'fil_PH',
  884. 'PK' => 'ur_PK',
  885. 'PL' => 'pl_PL',
  886. 'PM' => 'fr_PM',
  887. 'PN' => 'en_PN',
  888. 'PR' => 'es_PR',
  889. 'PS' => 'ar_PS',
  890. 'PT' => 'pt_PT',
  891. 'PW' => 'pau_PW',
  892. 'PY' => 'gn_PY',
  893. 'QA' => 'ar_QA',
  894. 'RE' => 'fr_RE',
  895. 'RO' => 'ro_RO',
  896. 'RS' => 'sr_Cyrl_RS',
  897. 'RU' => 'ru_RU',
  898. 'RW' => 'rw_RW',
  899. 'SA' => 'ar_SA',
  900. 'SB' => 'en_SB',
  901. 'SC' => 'crs_SC',
  902. 'SD' => 'ar_SD',
  903. 'SE' => 'sv_SE',
  904. 'SG' => 'en_SG',
  905. 'SH' => 'en_SH',
  906. 'SI' => 'sl_SI',
  907. 'SJ' => 'nb_SJ',
  908. 'SK' => 'sk_SK',
  909. 'SL' => 'kri_SL',
  910. 'SM' => 'it_SM',
  911. 'SN' => 'fr_SN',
  912. 'SO' => 'sw_SO',
  913. 'SR' => 'srn_SR',
  914. 'ST' => 'pt_ST',
  915. 'SV' => 'es_SV',
  916. 'SY' => 'ar_SY',
  917. 'SZ' => 'en_SZ',
  918. 'TC' => 'en_TC',
  919. 'TD' => 'fr_TD',
  920. 'TF' => 'und_TF',
  921. 'TG' => 'fr_TG',
  922. 'TH' => 'th_TH',
  923. 'TJ' => 'tg_Cyrl_TJ',
  924. 'TK' => 'tkl_TK',
  925. 'TL' => 'pt_TL',
  926. 'TM' => 'tk_TM',
  927. 'TN' => 'ar_TN',
  928. 'TO' => 'to_TO',
  929. 'TR' => 'tr_TR',
  930. 'TT' => 'en_TT',
  931. 'TV' => 'tvl_TV',
  932. 'TW' => 'zh_Hant_TW',
  933. 'TZ' => 'sw_TZ',
  934. 'UA' => 'uk_UA',
  935. 'UG' => 'sw_UG',
  936. 'UM' => 'en_UM',
  937. 'US' => 'en_US',
  938. 'UY' => 'es_UY',
  939. 'UZ' => 'uz_Cyrl_UZ',
  940. 'VA' => 'it_VA',
  941. 'VC' => 'en_VC',
  942. 'VE' => 'es_VE',
  943. 'VG' => 'en_VG',
  944. 'VI' => 'en_VI',
  945. 'VN' => 'vi_VN',
  946. 'VU' => 'bi_VU',
  947. 'WF' => 'wls_WF',
  948. 'WS' => 'sm_WS',
  949. 'YE' => 'ar_YE',
  950. 'YT' => 'swb_YT',
  951. 'ZA' => 'en_ZA',
  952. 'ZM' => 'en_ZM',
  953. 'ZW' => 'sn_ZW'
  954. );
  955. /**
  956. * Autosearch constants
  957. */
  958. const BROWSER = 'browser';
  959. const ENVIRONMENT = 'environment';
  960. const ZFDEFAULT = 'default';
  961. /**
  962. * Defines if old behaviour should be supported
  963. * Old behaviour throws notices and will be deleted in future releases
  964. *
  965. * @var boolean
  966. */
  967. public static $compatibilityMode = false;
  968. /**
  969. * Internal variable
  970. *
  971. * @var boolean
  972. */
  973. private static $_breakChain = false;
  974. /**
  975. * Actual set locale
  976. *
  977. * @var string Locale
  978. */
  979. protected $_locale;
  980. /**
  981. * Automatic detected locale
  982. *
  983. * @var string Locales
  984. */
  985. protected static $_auto;
  986. /**
  987. * Browser detected locale
  988. *
  989. * @var string Locales
  990. */
  991. protected static $_browser;
  992. /**
  993. * Environment detected locale
  994. *
  995. * @var string Locales
  996. */
  997. protected static $_environment;
  998. /**
  999. * Default locale
  1000. *
  1001. * @var string Locales
  1002. */
  1003. protected static $_default = array('en' => true);
  1004. /**
  1005. * Generates a locale object
  1006. * If no locale is given a automatic search is done
  1007. * Then the most probable locale will be automatically set
  1008. * Search order is
  1009. * 1. Given Locale
  1010. * 2. HTTP Client
  1011. * 3. Server Environment
  1012. * 4. Framework Standard
  1013. *
  1014. * @param string|Zend_Locale $locale (Optional) Locale for parsing input
  1015. * @throws Zend_Locale_Exception When autodetection has been failed
  1016. */
  1017. public function __construct($locale = null)
  1018. {
  1019. $this->setLocale($locale);
  1020. }
  1021. /**
  1022. * Serialization Interface
  1023. *
  1024. * @return string
  1025. */
  1026. public function serialize()
  1027. {
  1028. return serialize($this);
  1029. }
  1030. /**
  1031. * Returns a string representation of the object
  1032. *
  1033. * @return string
  1034. */
  1035. public function toString()
  1036. {
  1037. return (string) $this->_locale;
  1038. }
  1039. /**
  1040. * Returns a string representation of the object
  1041. * Alias for toString
  1042. *
  1043. * @return string
  1044. */
  1045. public function __toString()
  1046. {
  1047. return $this->toString();
  1048. }
  1049. /**
  1050. * Return the default locale
  1051. *
  1052. * @return array Returns an array of all locale string
  1053. */
  1054. public static function getDefault()
  1055. {
  1056. if ((self::$compatibilityMode === true) or (func_num_args() > 0)) {
  1057. if (!self::$_breakChain) {
  1058. self::$_breakChain = true;
  1059. trigger_error('You are running Zend_Locale in compatibility mode... please migrate your scripts', E_USER_NOTICE);
  1060. $params = func_get_args();
  1061. $param = null;
  1062. if (isset($params[0])) {
  1063. $param = $params[0];
  1064. }
  1065. return self::getOrder($param);
  1066. }
  1067. self::$_breakChain = false;
  1068. }
  1069. return self::$_default;
  1070. }
  1071. /**
  1072. * Sets a new default locale which will be used when no locale can be detected
  1073. * If provided you can set a quality between 0 and 1 (or 2 and 100)
  1074. * which represents the percent of quality the browser
  1075. * requested within HTTP
  1076. *
  1077. * @param string|Zend_Locale $locale Locale to set
  1078. * @param float $quality The quality to set from 0 to 1
  1079. * @throws Zend_Locale_Exception When a autolocale was given
  1080. * @throws Zend_Locale_Exception When a unknown locale was given
  1081. * @return void
  1082. */
  1083. public static function setDefault($locale, $quality = 1)
  1084. {
  1085. if (($locale === 'auto') or ($locale === 'root') or ($locale === 'default') or
  1086. ($locale === 'environment') or ($locale === 'browser')) {
  1087. require_once 'Zend/Locale/Exception.php';
  1088. throw new Zend_Locale_Exception('Only full qualified locales can be used as default!');
  1089. }
  1090. if (($quality < 0.1) or ($quality > 100)) {
  1091. require_once 'Zend/Locale/Exception.php';
  1092. throw new Zend_Locale_Exception("Quality must be between 0.1 and 100");
  1093. }
  1094. if ($quality > 1) {
  1095. $quality /= 100;
  1096. }
  1097. $locale = self::_prepareLocale($locale);
  1098. if (isset(self::$_localeData[(string) $locale]) === true) {
  1099. self::$_default = array((string) $locale => $quality);
  1100. } else {
  1101. $elocale = explode('_', (string) $locale);
  1102. if (isset(self::$_localeData[$elocale[0]]) === true) {
  1103. self::$_default = array($elocale[0] => $quality);
  1104. } else {
  1105. require_once 'Zend/Locale/Exception.php';
  1106. throw new Zend_Locale_Exception("Unknown locale '" . (string) $locale . "' can not be set as default!");
  1107. }
  1108. }
  1109. self::$_auto = self::getBrowser() + self::getEnvironment() + self::getDefault();
  1110. }
  1111. /**
  1112. * Expects the Systems standard locale
  1113. *
  1114. * For Windows:
  1115. * f.e.: LC_COLLATE=C;LC_CTYPE=German_Austria.1252;LC_MONETARY=C
  1116. * would be recognised as de_AT
  1117. *
  1118. * @return array
  1119. */
  1120. public static function getEnvironment()
  1121. {
  1122. if (self::$_environment !== null) {
  1123. return self::$_environment;
  1124. }
  1125. require_once 'Zend/Locale/Data/Translation.php';
  1126. $language = setlocale(LC_ALL, 0);
  1127. $languages = explode(';', $language);
  1128. $languagearray = array();
  1129. foreach ($languages as $locale) {
  1130. if (strpos($locale, '=') !== false) {
  1131. $language = substr($locale, strpos($locale, '='));
  1132. $language = substr($language, 1);
  1133. }
  1134. if ($language !== 'C') {
  1135. if (strpos($language, '.') !== false) {
  1136. $language = substr($language, 0, strpos($language, '.'));
  1137. } else if (strpos($language, '@') !== false) {
  1138. $language = substr($language, 0, strpos($language, '@'));
  1139. }
  1140. $language = str_ireplace(
  1141. array_keys(Zend_Locale_Data_Translation::$languageTranslation),
  1142. array_values(Zend_Locale_Data_Translation::$languageTranslation),
  1143. (string) $language
  1144. );
  1145. $language = str_ireplace(
  1146. array_keys(Zend_Locale_Data_Translation::$regionTranslation),
  1147. array_values(Zend_Locale_Data_Translation::$regionTranslation),
  1148. $language
  1149. );
  1150. if (isset(self::$_localeData[$language]) === true) {
  1151. $languagearray[$language] = 1;
  1152. if (strpos($language, '_') !== false) {
  1153. $languagearray[substr($language, 0, strpos($language, '_'))] = 1;
  1154. }
  1155. }
  1156. }
  1157. }
  1158. self::$_environment = $languagearray;
  1159. return $languagearray;
  1160. }
  1161. /**
  1162. * Return an array of all accepted languages of the client
  1163. * Expects RFC compilant Header !!
  1164. *
  1165. * The notation can be :
  1166. * de,en-UK-US;q=0.5,fr-FR;q=0.2
  1167. *
  1168. * @return array - list of accepted languages including quality
  1169. */
  1170. public static function getBrowser()
  1171. {
  1172. if (self::$_browser !== null) {
  1173. return self::$_browser;
  1174. }
  1175. $httplanguages = getenv('HTTP_ACCEPT_LANGUAGE');
  1176. if (empty($httplanguages) && array_key_exists('HTTP_ACCEPT_LANGUAGE', $_SERVER)) {
  1177. $httplanguages = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
  1178. }
  1179. $languages = array();
  1180. if (empty($httplanguages)) {
  1181. return $languages;
  1182. }
  1183. $accepted = preg_split('/,\s*/', $httplanguages);
  1184. foreach ($accepted as $accept) {
  1185. $match = null;
  1186. $result = preg_match('/^([a-z]{1,8}(?:[-_][a-z]{1,8})*)(?:;\s*q=(0(?:\.[0-9]{1,3})?|1(?:\.0{1,3})?))?$/i',
  1187. $accept, $match);
  1188. if ($result < 1) {
  1189. continue;
  1190. }
  1191. if (isset($match[2]) === true) {
  1192. $quality = (float) $match[2];
  1193. } else {
  1194. $quality = 1.0;
  1195. }
  1196. $countrys = explode('-', $match[1]);
  1197. $region = array_shift($countrys);
  1198. $country2 = explode('_', $region);
  1199. $region = array_shift($country2);
  1200. foreach ($countrys as $country) {
  1201. $languages[$region . '_' . strtoupper($country)] = $quality;
  1202. }
  1203. foreach ($country2 as $country) {
  1204. $languages[$region . '_' . strtoupper($country)] = $quality;
  1205. }
  1206. if ((isset($languages[$region]) === false) || ($languages[$region] < $quality)) {
  1207. $languages[$region] = $quality;
  1208. }
  1209. }
  1210. self::$_browser = $languages;
  1211. return $languages;
  1212. }
  1213. /**
  1214. * Sets a new locale
  1215. *
  1216. * @param string|Zend_Locale $locale (Optional) New locale to set
  1217. * @return void
  1218. */
  1219. public function setLocale($locale = null)
  1220. {
  1221. $locale = self::_prepareLocale($locale);
  1222. if (isset(self::$_localeData[(string) $locale]) === false) {
  1223. $region = substr((string) $locale, 0, 3);
  1224. if (isset($region[2]) === true) {
  1225. if (($region[2] === '_') or ($region[2] === '-')) {
  1226. $region = substr($region, 0, 2);
  1227. }
  1228. }
  1229. if (isset(self::$_localeData[(string) $region]) === true) {
  1230. $this->_locale = $region;
  1231. } else {
  1232. $this->_locale = 'root';
  1233. }
  1234. } else {
  1235. $this->_locale = $locale;
  1236. }
  1237. }
  1238. /**
  1239. * Returns the language part of the locale
  1240. *
  1241. * @return string
  1242. */
  1243. public function getLanguage()
  1244. {
  1245. $locale = explode('_', $this->_locale);
  1246. return $locale[0];
  1247. }
  1248. /**
  1249. * Returns the region part of the locale if available
  1250. *
  1251. * @return string|false - Regionstring
  1252. */
  1253. public function getRegion()
  1254. {
  1255. $locale = explode('_', $this->_locale);
  1256. if (isset($locale[1]) === true) {
  1257. return $locale[1];
  1258. }
  1259. return false;
  1260. }
  1261. /**
  1262. * Return the accepted charset of the client
  1263. *
  1264. * @return string
  1265. */
  1266. public static function getHttpCharset()
  1267. {
  1268. $httpcharsets = getenv('HTTP_ACCEPT_CHARSET');
  1269. $charsets = array();
  1270. if ($httpcharsets === false) {
  1271. return $charsets;
  1272. }
  1273. $accepted = preg_split('/,\s*/', $httpcharsets);
  1274. foreach ($accepted as $accept) {
  1275. if (empty($accept) === true) {
  1276. continue;
  1277. }
  1278. if (strpos($accept, ';') !== false) {
  1279. $quality = (float) substr($accept, (strpos($accept, '=') + 1));
  1280. $pos = substr($accept, 0, strpos($accept, ';'));
  1281. $charsets[$pos] = $quality;
  1282. } else {
  1283. $quality = 1.0;
  1284. $charsets[$accept] = $quality;
  1285. }
  1286. }
  1287. return $charsets;
  1288. }
  1289. /**
  1290. * Returns true if both locales are equal
  1291. *
  1292. * @param Zend_Locale $object Locale to check for equality
  1293. * @return boolean
  1294. */
  1295. public function equals(Zend_Locale $object)
  1296. {
  1297. if ($object->toString() === $this->toString()) {
  1298. return true;
  1299. }
  1300. return false;
  1301. }
  1302. /**
  1303. * Returns localized informations as array, supported are several
  1304. * types of informations.
  1305. * For detailed information about the types look into the documentation
  1306. *
  1307. * @param string $path (Optional) Type of information to return
  1308. * @param string|Zend_Locale $locale (Optional) Locale|Language for which this informations should be returned
  1309. * @param string $value (Optional) Value for detail list
  1310. * @return array Array with the wished information in the given language
  1311. */
  1312. public static function getTranslationList($path = null, $locale = null, $value = null)
  1313. {
  1314. require_once 'Zend/Locale/Data.php';
  1315. $locale = self::findLocale($locale);
  1316. $result = Zend_Locale_Data::getList($locale, $path, $value);
  1317. if (empty($result) === true) {
  1318. return false;
  1319. }
  1320. return $result;
  1321. }
  1322. /**
  1323. * Returns an array with the name of all languages translated to the given language
  1324. *
  1325. * @param string|Zend_Locale $locale (Optional) Locale for language translation
  1326. * @return array
  1327. * @deprecated
  1328. */
  1329. public static function getLanguageTranslationList($locale = null)
  1330. {
  1331. trigger_error("The method getLanguageTranslationList is deprecated. Use getTranslationList('language', $locale) instead", E_USER_NOTICE);
  1332. return self::getTranslationList('language', $locale);
  1333. }
  1334. /**
  1335. * Returns an array with the name of all scripts translated to the given language
  1336. *
  1337. * @param string|Zend_Locale $locale (Optional) Locale for script translation
  1338. * @return array
  1339. * @deprecated
  1340. */
  1341. public static function getScriptTranslationList($locale = null)
  1342. {
  1343. trigger_error("The method getScriptTranslationList is deprecated. Use getTranslationList('script', $locale) instead", E_USER_NOTICE);
  1344. return self::getTranslationList('script', $locale);
  1345. }
  1346. /**
  1347. * Returns an array with the name of all countries translated to the given language
  1348. *
  1349. * @param string|Zend_Locale $locale (Optional) Locale for country translation
  1350. * @return array
  1351. * @deprecated
  1352. */
  1353. public static function getCountryTranslationList($locale = null)
  1354. {
  1355. trigger_error("The method getCountryTranslationList is deprecated. Use getTranslationList('territory', $locale, 2) instead", E_USER_NOTICE);
  1356. return self::getTranslationList('territory', $locale, 2);
  1357. }
  1358. /**
  1359. * Returns an array with the name of all territories translated to the given language
  1360. * All territories contains other countries.
  1361. *
  1362. * @param string|Zend_Locale $locale (Optional) Locale for territory translation
  1363. * @return array
  1364. * @deprecated
  1365. */
  1366. public static function getTerritoryTranslationList($locale = null)
  1367. {
  1368. trigger_error("The method getTerritoryTranslationList is deprecated. Use getTranslationList('territory', $locale, 1) instead", E_USER_NOTICE);
  1369. return self::getTranslationList('territory', $locale, 1);
  1370. }
  1371. /**
  1372. * Returns a localized information string, supported are several types of informations.
  1373. * For detailed information about the types look into the documentation
  1374. *
  1375. * @param string $value Name to get detailed information about
  1376. * @param string $path (Optional) Type of information to return
  1377. * @param string|Zend_Locale $locale (Optional) Locale|Language for which this informations should be returned
  1378. * @return string|false The wished information in the given language
  1379. */
  1380. public static function getTranslation($value = null, $path = null, $locale = null)
  1381. {
  1382. require_once 'Zend/Locale/Data.php';
  1383. $locale = self::findLocale($locale);
  1384. $result = Zend_Locale_Data::getContent($locale, $path, $value);
  1385. if (empty($result) === true && '0' !== $result) {
  1386. return false;
  1387. }
  1388. return $result;
  1389. }
  1390. /**
  1391. * Returns the localized language name
  1392. *
  1393. * @param string $value Name to get detailed information about
  1394. * @param string $locale (Optional) Locale for language translation
  1395. * @return array
  1396. * @deprecated
  1397. */
  1398. public static function getLanguageTranslation($value, $locale = null)
  1399. {
  1400. trigger_error("The method getLanguageTranslation is deprecated. Use getTranslation($value, 'language', $locale) instead", E_USER_NOTICE);
  1401. return self::getTranslation($value, 'language', $locale);
  1402. }
  1403. /**
  1404. * Returns the localized script name
  1405. *
  1406. * @param string $value Name to get detailed information about
  1407. * @param string $locale (Optional) locale for script translation
  1408. * @return array
  1409. * @deprecated
  1410. */
  1411. public static function getScriptTranslation($value, $locale = null)
  1412. {
  1413. trigger_error("The method getScriptTranslation is deprecated. Use getTranslation($value, 'script', $locale) instead", E_USER_NOTICE);
  1414. return self::getTranslation($value, 'script', $locale);
  1415. }
  1416. /**
  1417. * Returns the localized country name
  1418. *
  1419. * @param string $value Name to get detailed information about
  1420. * @param string|Zend_Locale $locale (Optional) Locale for country translation
  1421. * @return array
  1422. * @deprecated
  1423. */
  1424. public static function getCountryTranslation($value, $locale = null)
  1425. {
  1426. trigger_error("The method getCountryTranslation is deprecated. Use getTranslation($value, 'country', $locale) instead", E_USER_NOTICE);
  1427. return self::getTranslation($value, 'country', $locale);
  1428. }
  1429. /**
  1430. * Returns the localized territory name
  1431. * All territories contains other countries.
  1432. *
  1433. * @param string $value Name to get detailed information about
  1434. * @param string|Zend_Locale $locale (Optional) Locale for territory translation
  1435. * @return array
  1436. * @deprecated
  1437. */
  1438. public static function getTerritoryTranslation($value, $locale = null)
  1439. {
  1440. trigger_error("The method getTerritoryTranslation is deprecated. Use getTranslation($value, 'territory', $locale) instead", E_USER_NOTICE);
  1441. return self::getTranslation($value, 'territory', $locale);
  1442. }
  1443. /**
  1444. * Returns an array with translated yes strings
  1445. *
  1446. * @param string|Zend_Locale $locale (Optional) Locale for language translation (defaults to $this locale)
  1447. * @return array
  1448. */
  1449. public static function getQuestion($locale = null)
  1450. {
  1451. require_once 'Zend/Locale/Data.php';
  1452. $locale = self::findLocale($locale);
  1453. $quest = Zend_Locale_Data::getList($locale, 'question');
  1454. $yes = explode(':', $quest['yes']);
  1455. $no = explode(':', $quest['no']);
  1456. $quest['yes'] = $yes[0];
  1457. $quest['yesarray'] = $yes;
  1458. $quest['no'] = $no[0];
  1459. $quest['noarray'] = $no;
  1460. $quest['yesexpr'] = self::_prepareQuestionString($yes);
  1461. $quest['noexpr'] = self::_prepareQuestionString($no);
  1462. return $quest;
  1463. }
  1464. /**
  1465. * Internal function for preparing the returned question regex string
  1466. *
  1467. * @param string $input Regex to parse
  1468. * @return string
  1469. */
  1470. private static function _prepareQuestionString($input)
  1471. {
  1472. $regex = '';
  1473. if (is_array($input) === true) {
  1474. $regex = '^';
  1475. $start = true;
  1476. foreach ($input as $row) {
  1477. if ($start === false) {
  1478. $regex .= '|';
  1479. }
  1480. $start = false;
  1481. $regex .= '(';
  1482. $one = null;
  1483. if (strlen($row) > 2) {
  1484. $one = true;
  1485. }
  1486. foreach (str_split($row, 1) as $char) {
  1487. $regex .= '[' . $char;
  1488. $regex .= strtoupper($char) . ']';
  1489. if ($one === true) {
  1490. $one = false;
  1491. $regex .= '(';
  1492. }
  1493. }
  1494. if ($one === false) {
  1495. $regex .= ')';
  1496. }
  1497. $regex .= '?)';
  1498. }
  1499. }
  1500. return $regex;
  1501. }
  1502. /**
  1503. * Checks if a locale identifier is a real locale or not
  1504. * Examples:
  1505. * "en_XX" refers to "en", which returns true
  1506. * "XX_yy" refers to "root", which returns false
  1507. *
  1508. * @param string|Zend_Locale $locale Locale to check for
  1509. * @param boolean $strict (Optional) If true, no rerouting will be done when checking
  1510. * @param boolean $compatible (DEPRECATED) Only for internal usage, brakes compatibility mode
  1511. * @return boolean If the locale is known dependend on the settings
  1512. */
  1513. public static function isLocale($locale, $strict = false, $compatible = true)
  1514. {
  1515. if (($locale instanceof Zend_Locale)
  1516. || (is_string($locale) && array_key_exists($locale, self::$_localeData))
  1517. ) {
  1518. return true;
  1519. }
  1520. if (($locale === null) || (!is_string($locale) and !is_array($locale))) {
  1521. return false;
  1522. }
  1523. try {
  1524. $locale = self::_prepareLocale($locale, $strict);
  1525. } catch (Zend_Locale_Exception $e) {
  1526. return false;
  1527. }
  1528. if (($compatible === true) and (self::$compatibilityMode === true)) {
  1529. trigger_error('You are running Zend_Locale in compatibility mode... please migrate your scripts', E_USER_NOTICE);
  1530. if (isset(self::$_localeData[$locale]) === true) {
  1531. return $locale;
  1532. } else if (!$strict) {
  1533. $locale = explode('_', $locale);
  1534. if (isset(self::$_localeData[$locale[0]]) === true) {
  1535. return $locale[0];
  1536. }
  1537. }
  1538. } else {
  1539. if (isset(self::$_localeData[$locale]) === true) {
  1540. return true;
  1541. } else if (!$strict) {
  1542. $locale = explode('_', $locale);
  1543. if (isset(self::$_localeData[$locale[0]]) === true) {
  1544. return true;
  1545. }
  1546. }
  1547. }
  1548. return false;
  1549. }
  1550. /**
  1551. * Finds the proper locale based on the input
  1552. * Checks if it exists, degrades it when necessary
  1553. * Detects registry locale and when all fails tries to detect a automatic locale
  1554. * Returns the found locale as string
  1555. *
  1556. * @param string $locale
  1557. * @throws Zend_Locale_Exception When the given locale is no locale or the autodetection fails
  1558. * @return string
  1559. */
  1560. public static function findLocale($locale = null)
  1561. {
  1562. if ($locale === null) {
  1563. require_once 'Zend/Registry.php';
  1564. if (Zend_Registry::isRegistered('Zend_Locale')) {
  1565. $locale = Zend_Registry::get('Zend_Locale');
  1566. }
  1567. }
  1568. if ($locale === null) {
  1569. $locale = new Zend_Locale();
  1570. }
  1571. if (!Zend_Locale::isLocale($locale, true, false)) {
  1572. if (!Zend_Locale::isLocale($locale, false, false)) {
  1573. $locale = Zend_Locale::getLocaleToTerritory($locale);
  1574. if (empty($locale)) {
  1575. require_once 'Zend/Locale/Exception.php';
  1576. throw new Zend_Locale_Exception("The locale '$locale' is no known locale");
  1577. }
  1578. } else {
  1579. $locale = new Zend_Locale($locale);
  1580. }
  1581. }
  1582. $locale = self::_prepareLocale($locale);
  1583. return $locale;
  1584. }
  1585. /**
  1586. * Returns the expected locale for a given territory
  1587. *
  1588. * @param string $territory Territory for which the locale is being searched
  1589. * @return string|null Locale string or null when no locale has been found
  1590. */
  1591. public static function getLocaleToTerritory($territory)
  1592. {
  1593. $territory = strtoupper($territory);
  1594. if (array_key_exists($territory, self::$_territoryData)) {
  1595. return self::$_territoryData[$territory];
  1596. }
  1597. return null;
  1598. }
  1599. /**
  1600. * Returns a list of all known locales where the locale is the key
  1601. * Only real locales are returned, the internal locales 'root', 'auto', 'browser'
  1602. * and 'environment' are suppressed
  1603. *
  1604. * @return array List of all Locales
  1605. */
  1606. public static function getLocaleList()
  1607. {
  1608. $list = self::$_localeData;
  1609. unset($list['root']);
  1610. unset($list['auto']);
  1611. unset($list['browser']);
  1612. unset($list['environment']);
  1613. return $list;
  1614. }
  1615. /**
  1616. * Returns the set cache
  1617. *
  1618. * @return Zend_Cache_Core The set cache
  1619. */
  1620. public static function getCache()
  1621. {
  1622. require_once 'Zend/Locale/Data.php';
  1623. return Zend_Locale_Data::getCache();
  1624. }
  1625. /**
  1626. * Sets a cache
  1627. *
  1628. * @param Zend_Cache_Core $cache Cache to set
  1629. * @return void
  1630. */
  1631. public static function setCache(Zend_Cache_Core $cache)
  1632. {
  1633. require_once 'Zend/Locale/Data.php';
  1634. Zend_Locale_Data::setCache($cache);
  1635. }
  1636. /**
  1637. * Returns true when a cache is set
  1638. *
  1639. * @return boolean
  1640. */
  1641. public static function hasCache()
  1642. {
  1643. require_once 'Zend/Locale/Data.php';
  1644. return Zend_Locale_Data::hasCache();
  1645. }
  1646. /**
  1647. * Removes any set cache
  1648. *
  1649. * @return void
  1650. */
  1651. public static function removeCache()
  1652. {
  1653. require_once 'Zend/Locale/Data.php';
  1654. Zend_Locale_Data::removeCache();
  1655. }
  1656. /**
  1657. * Clears all set cache data
  1658. *
  1659. * @param string $tag Tag to clear when the default tag name is not used
  1660. * @return void
  1661. */
  1662. public static function clearCache($tag = null)
  1663. {
  1664. require_once 'Zend/Locale/Data.php';
  1665. Zend_Locale_Data::clearCache($tag);
  1666. }
  1667. /**
  1668. * Disables the set cache
  1669. *
  1670. * @param boolean $flag True disables any set cache, default is false
  1671. * @return void
  1672. */
  1673. public static function disableCache($flag)
  1674. {
  1675. require_once 'Zend/Locale/Data.php';
  1676. Zend_Locale_Data::disableCache($flag);
  1677. }
  1678. /**
  1679. * Internal function, returns a single locale on detection
  1680. *
  1681. * @param string|Zend_Locale $locale (Optional) Locale to work on
  1682. * @param boolean $strict (Optional) Strict preparation
  1683. * @throws Zend_Locale_Exception When no locale is set which is only possible when the class was wrong extended
  1684. * @return string
  1685. */
  1686. private static function _prepareLocale($locale, $strict = false)
  1687. {
  1688. if ($locale instanceof Zend_Locale) {
  1689. $locale = $locale->toString();
  1690. }
  1691. if (is_array($locale)) {
  1692. return '';
  1693. }
  1694. if (empty(self::$_auto) === true) {
  1695. self::$_browser = self::getBrowser();
  1696. self::$_environment = self::getEnvironment();
  1697. self::$_breakChain = true;
  1698. self::$_auto = self::getBrowser() + self::getEnvironment() + self::getDefault();
  1699. }
  1700. if (!$strict) {
  1701. if ($locale === 'browser') {
  1702. $locale = self::$_browser;
  1703. }
  1704. if ($locale === 'environment') {
  1705. $locale = self::$_environment;
  1706. }
  1707. if ($locale === 'default') {
  1708. $locale = self::$_default;
  1709. }
  1710. if (($locale === 'auto') or ($locale === null)) {
  1711. $locale = self::$_auto;
  1712. }
  1713. if (is_array($locale) === true) {
  1714. $locale = key($locale);
  1715. }
  1716. }
  1717. // This can only happen when someone extends Zend_Locale and erases the default
  1718. if ($locale === null) {
  1719. require_once 'Zend/Locale/Exception.php';
  1720. throw new Zend_Locale_Exception('Autodetection of Locale has been failed!');
  1721. }
  1722. if (strpos($locale, '-') !== false) {
  1723. $locale = strtr($locale, '-', '_');
  1724. }
  1725. $parts = explode('_', $locale);
  1726. if (!isset(self::$_localeData[$parts[0]])) {
  1727. if ((count($parts) == 1) && array_key_exists($parts[0], self::$_territoryData)) {
  1728. return self::$_territoryData[$parts[0]];
  1729. }
  1730. return '';
  1731. }
  1732. foreach($parts as $key => $value) {
  1733. if ((strlen($value) < 2) || (strlen($value) > 3)) {
  1734. unset($parts[$key]);
  1735. }
  1736. }
  1737. $locale = implode('_', $parts);
  1738. return (string) $locale;
  1739. }
  1740. /**
  1741. * Search the locale automatically and return all used locales
  1742. * ordered by quality
  1743. *
  1744. * Standard Searchorder is Browser, Environment, Default
  1745. *
  1746. * @param string $searchorder (Optional) Searchorder
  1747. * @return array Returns an array of all detected locales
  1748. */
  1749. public static function getOrder($order = null)
  1750. {
  1751. switch ($order) {
  1752. case self::ENVIRONMENT:
  1753. self::$_breakChain = true;
  1754. $languages = self::getEnvironment() + self::getBrowser() + self::getDefault();
  1755. break;
  1756. case self::ZFDEFAULT:
  1757. self::$_breakChain = true;
  1758. $languages = self::getDefault() + self::getEnvironment() + self::getBrowser();
  1759. break;
  1760. default:
  1761. self::$_breakChain = true;
  1762. $languages = self::getBrowser() + self::getEnvironment() + self::getDefault();
  1763. break;
  1764. }
  1765. return $languages;
  1766. }
  1767. }