Locale.php 58 KB

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