Locale.php 41 KB

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