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