Locale.php 41 KB

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