統計
| ブランチ: | リビジョン:

pictcode_admin / lib / Cake / I18n / L10n.php @ 5ad38a95

履歴 | 表示 | アノテート | ダウンロード (28.59 KB)

1
<?php
2
/**
3
 * Localization
4
 *
5
 * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
6
 * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
7
 *
8
 * Licensed under The MIT License
9
 * For full copyright and license information, please see the LICENSE.txt
10
 * Redistributions of files must retain the above copyright notice.
11
 *
12
 * @copyright     Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
13
 * @link          http://cakephp.org CakePHP(tm) Project
14
 * @package       Cake.I18n
15
 * @since         CakePHP(tm) v 1.2.0.4116
16
 * @license       http://www.opensource.org/licenses/mit-license.php MIT License
17
 */
18

    
19
App::uses('CakeRequest', 'Network');
20

    
21
/**
22
 * Localization
23
 *
24
 * @package       Cake.I18n
25
 */
26
class L10n {
27

    
28
/**
29
 * The language for current locale
30
 *
31
 * @var string
32
 */
33
        public $language = 'English (United States)';
34

    
35
/**
36
 * Locale search paths
37
 *
38
 * @var array
39
 */
40
        public $languagePath = array('en_us', 'eng');
41

    
42
/**
43
 * ISO 639-3 for current locale
44
 *
45
 * @var string
46
 */
47
        public $lang = 'eng';
48

    
49
/**
50
 * Locale
51
 *
52
 * @var string
53
 */
54
        public $locale = 'en_us';
55

    
56
/**
57
 * Default language.
58
 *
59
 * If config value 'Config.language' is set in an application this will be set
60
 * as a fall back else if DEFAULT_LANGUAGE it defined it will be used.
61
 * Constant DEFAULT_LANGUAGE has been deprecated in 2.4
62
 *
63
 * @var string
64
 */
65
        public $default = null;
66

    
67
/**
68
 * Encoding used for current locale
69
 *
70
 * @var string
71
 */
72
        public $charset = 'utf-8';
73

    
74
/**
75
 * Text direction for current locale
76
 *
77
 * @var string
78
 */
79
        public $direction = 'ltr';
80

    
81
/**
82
 * Maps ISO 639-3 to I10n::_l10nCatalog
83
 * The terminological codes (first one per language) should be used if possible.
84
 * They are the ones building the path in `/APP/Locale/[code]/`
85
 * The bibliographic codes are aliases.
86
 *
87
 * @var array
88
 */
89
        protected $_l10nMap = array(
90
                /* Afrikaans */ 'afr' => 'af',
91
                /* Albanian */ 'sqi' => 'sq',
92
                /* Albanian - bibliographic */ 'alb' => 'sq',
93
                /* Arabic */ 'ara' => 'ar',
94
                /* Armenian/Armenia */ 'hye' => 'hy',
95
                /* Basque */ 'eus' => 'eu',
96
                /* Basque */ 'baq' => 'eu',
97
                /* Tibetan */ 'bod' => 'bo',
98
                /* Tibetan - bibliographic */ 'tib' => 'bo',
99
                /* Bosnian */ 'bos' => 'bs',
100
                /* Bulgarian */ 'bul' => 'bg',
101
                /* Byelorussian */ 'bel' => 'be',
102
                /* Catalan */ 'cat' => 'ca',
103
                /* Chinese */ 'zho' => 'zh',
104
                /* Chinese - bibliographic */ 'chi' => 'zh',
105
                /* Croatian */ 'hrv' => 'hr',
106
                /* Czech */ 'ces' => 'cs',
107
                /* Czech - bibliographic */ 'cze' => 'cs',
108
                /* Danish */ 'dan' => 'da',
109
                /* Dutch (Standard) */ 'nld' => 'nl',
110
                /* Dutch (Standard) - bibliographic */ 'dut' => 'nl',
111
                /* English */ 'eng' => 'en',
112
                /* Estonian */ 'est' => 'et',
113
                /* Faeroese */ 'fao' => 'fo',
114
                /* Farsi/Persian */ 'fas' => 'fa',
115
                /* Farsi/Persian - bibliographic */ 'per' => 'fa',
116
                /* Finnish */ 'fin' => 'fi',
117
                /* French (Standard) */ 'fra' => 'fr',
118
                /* French (Standard)  - bibliographic */ 'fre' => 'fr',
119
                /* Gaelic (Scots) */ 'gla' => 'gd',
120
                /* Galician */ 'glg' => 'gl',
121
                /* German (Standard) */ 'deu' => 'de',
122
                /* German (Standard) - bibliographic */ 'ger' => 'de',
123
                /* Greek */ 'gre' => 'el',
124
                /* Greek */ 'ell' => 'el',
125
                /* Hebrew */ 'heb' => 'he',
126
                /* Hindi */ 'hin' => 'hi',
127
                /* Hungarian */ 'hun' => 'hu',
128
                /* Icelandic */ 'isl' => 'is',
129
                /* Icelandic - bibliographic */ 'ice' => 'is',
130
                /* Indonesian */ 'ind' => 'id',
131
                /* Irish */ 'gle' => 'ga',
132
                /* Italian */ 'ita' => 'it',
133
                /* Japanese */ 'jpn' => 'ja',
134
                /* Kazakh */ 'kaz' => 'kk',
135
                /* Kalaallisut (Greenlandic) */ 'kal' => 'kl',
136
                /* Korean */ 'kor' => 'ko',
137
                /* Latvian */ 'lav' => 'lv',
138
                /* Limburgish */ 'lim' => 'li',
139
                /* Lithuanian */ 'lit' => 'lt',
140
                /* Macedonian */ 'mkd' => 'mk',
141
                /* Macedonian - bibliographic */ 'mac' => 'mk',
142
                /* Malaysian */ 'msa' => 'ms',
143
                /* Malaysian - bibliographic */ 'may' => 'ms',
144
                /* Maltese */ 'mlt' => 'mt',
145
                /* Norwegian */ 'nor' => 'no',
146
                /* Norwegian Bokmal */ 'nob' => 'nb',
147
                /* Norwegian Nynorsk */ 'nno' => 'nn',
148
                /* Polish */ 'pol' => 'pl',
149
                /* Portuguese (Portugal) */ 'por' => 'pt',
150
                /* Rhaeto-Romanic */ 'roh' => 'rm',
151
                /* Romanian */ 'ron' => 'ro',
152
                /* Romanian - bibliographic */ 'rum' => 'ro',
153
                /* Russian */ 'rus' => 'ru',
154
                /* Sami */ 'sme' => 'se',
155
                /* Serbian */ 'srp' => 'sr',
156
                /* Slovak */ 'slk' => 'sk',
157
                /* Slovak - bibliographic */ 'slo' => 'sk',
158
                /* Slovenian */ 'slv' => 'sl',
159
                /* Sorbian */ 'wen' => 'sb',
160
                /* Spanish (Spain - Traditional) */ 'spa' => 'es',
161
                /* Swedish */ 'swe' => 'sv',
162
                /* Thai */ 'tha' => 'th',
163
                /* Tsonga */ 'tso' => 'ts',
164
                /* Tswana */ 'tsn' => 'tn',
165
                /* Turkish */ 'tur' => 'tr',
166
                /* Ukrainian */ 'ukr' => 'uk',
167
                /* Urdu */ 'urd' => 'ur',
168
                /* Venda */ 'ven' => 've',
169
                /* Vietnamese */ 'vie' => 'vi',
170
                /* Welsh */ 'cym' => 'cy',
171
                /* Welsh - bibliographic */ 'wel' => 'cy',
172
                /* Xhosa */ 'xho' => 'xh',
173
                /* Yiddish */ 'yid' => 'yi',
174
                /* Zulu */ 'zul' => 'zu'
175
        );
176

    
177
/**
178
 * HTTP_ACCEPT_LANGUAGE catalog
179
 *
180
 * holds all information related to a language
181
 *
182
 * @var array
183
 */
184
        protected $_l10nCatalog = array(
185
                'af' => array('language' => 'Afrikaans', 'locale' => 'afr', 'localeFallback' => 'afr', 'charset' => 'utf-8', 'direction' => 'ltr'),
186
                'ar' => array('language' => 'Arabic', 'locale' => 'ara', 'localeFallback' => 'ara', 'charset' => 'utf-8', 'direction' => 'rtl'),
187
                'ar-ae' => array('language' => 'Arabic (U.A.E.)', 'locale' => 'ar_ae', 'localeFallback' => 'ara', 'charset' => 'utf-8', 'direction' => 'rtl'),
188
                'ar-bh' => array('language' => 'Arabic (Bahrain)', 'locale' => 'ar_bh', 'localeFallback' => 'ara', 'charset' => 'utf-8', 'direction' => 'rtl'),
189
                'ar-dz' => array('language' => 'Arabic (Algeria)', 'locale' => 'ar_dz', 'localeFallback' => 'ara', 'charset' => 'utf-8', 'direction' => 'rtl'),
190
                'ar-eg' => array('language' => 'Arabic (Egypt)', 'locale' => 'ar_eg', 'localeFallback' => 'ara', 'charset' => 'utf-8', 'direction' => 'rtl'),
191
                'ar-iq' => array('language' => 'Arabic (Iraq)', 'locale' => 'ar_iq', 'localeFallback' => 'ara', 'charset' => 'utf-8', 'direction' => 'rtl'),
192
                'ar-jo' => array('language' => 'Arabic (Jordan)', 'locale' => 'ar_jo', 'localeFallback' => 'ara', 'charset' => 'utf-8', 'direction' => 'rtl'),
193
                'ar-kw' => array('language' => 'Arabic (Kuwait)', 'locale' => 'ar_kw', 'localeFallback' => 'ara', 'charset' => 'utf-8', 'direction' => 'rtl'),
194
                'ar-lb' => array('language' => 'Arabic (Lebanon)', 'locale' => 'ar_lb', 'localeFallback' => 'ara', 'charset' => 'utf-8', 'direction' => 'rtl'),
195
                'ar-ly' => array('language' => 'Arabic (Libya)', 'locale' => 'ar_ly', 'localeFallback' => 'ara', 'charset' => 'utf-8', 'direction' => 'rtl'),
196
                'ar-ma' => array('language' => 'Arabic (Morocco)', 'locale' => 'ar_ma', 'localeFallback' => 'ara', 'charset' => 'utf-8', 'direction' => 'rtl'),
197
                'ar-om' => array('language' => 'Arabic (Oman)', 'locale' => 'ar_om', 'localeFallback' => 'ara', 'charset' => 'utf-8', 'direction' => 'rtl'),
198
                'ar-qa' => array('language' => 'Arabic (Qatar)', 'locale' => 'ar_qa', 'localeFallback' => 'ara', 'charset' => 'utf-8', 'direction' => 'rtl'),
199
                'ar-sa' => array('language' => 'Arabic (Saudi Arabia)', 'locale' => 'ar_sa', 'localeFallback' => 'ara', 'charset' => 'utf-8', 'direction' => 'rtl'),
200
                'ar-sy' => array('language' => 'Arabic (Syria)', 'locale' => 'ar_sy', 'localeFallback' => 'ara', 'charset' => 'utf-8', 'direction' => 'rtl'),
201
                'ar-tn' => array('language' => 'Arabic (Tunisia)', 'locale' => 'ar_tn', 'localeFallback' => 'ara', 'charset' => 'utf-8', 'direction' => 'rtl'),
202
                'ar-ye' => array('language' => 'Arabic (Yemen)', 'locale' => 'ar_ye', 'localeFallback' => 'ara', 'charset' => 'utf-8', 'direction' => 'rtl'),
203
                'be' => array('language' => 'Byelorussian', 'locale' => 'bel', 'localeFallback' => 'bel', 'charset' => 'utf-8', 'direction' => 'ltr'),
204
                'bg' => array('language' => 'Bulgarian', 'locale' => 'bul', 'localeFallback' => 'bul', 'charset' => 'utf-8', 'direction' => 'ltr'),
205
                'bo' => array('language' => 'Tibetan', 'locale' => 'bod', 'localeFallback' => 'bod', 'charset' => 'utf-8', 'direction' => 'ltr'),
206
                'bo-cn' => array('language' => 'Tibetan (China)', 'locale' => 'bo_cn', 'localeFallback' => 'bod', 'charset' => 'utf-8', 'direction' => 'ltr'),
207
                'bo-in' => array('language' => 'Tibetan (India)', 'locale' => 'bo_in', 'localeFallback' => 'bod', 'charset' => 'utf-8', 'direction' => 'ltr'),
208
                'bs' => array('language' => 'Bosnian', 'locale' => 'bos', 'localeFallback' => 'bos', 'charset' => 'utf-8', 'direction' => 'ltr'),
209
                'ca' => array('language' => 'Catalan', 'locale' => 'cat', 'localeFallback' => 'cat', 'charset' => 'utf-8', 'direction' => 'ltr'),
210
                'cs' => array('language' => 'Czech', 'locale' => 'ces', 'localeFallback' => 'ces', 'charset' => 'utf-8', 'direction' => 'ltr'),
211
                'da' => array('language' => 'Danish', 'locale' => 'dan', 'localeFallback' => 'dan', 'charset' => 'utf-8', 'direction' => 'ltr'),
212
                'de' => array('language' => 'German (Standard)', 'locale' => 'deu', 'localeFallback' => 'deu', 'charset' => 'utf-8', 'direction' => 'ltr'),
213
                'de-at' => array('language' => 'German (Austria)', 'locale' => 'de_at', 'localeFallback' => 'deu', 'charset' => 'utf-8', 'direction' => 'ltr'),
214
                'de-ch' => array('language' => 'German (Swiss)', 'locale' => 'de_ch', 'localeFallback' => 'deu', 'charset' => 'utf-8', 'direction' => 'ltr'),
215
                'de-de' => array('language' => 'German (Germany)', 'locale' => 'de_de', 'localeFallback' => 'deu', 'charset' => 'utf-8', 'direction' => 'ltr'),
216
                'de-li' => array('language' => 'German (Liechtenstein)', 'locale' => 'de_li', 'localeFallback' => 'deu', 'charset' => 'utf-8', 'direction' => 'ltr'),
217
                'de-lu' => array('language' => 'German (Luxembourg)', 'locale' => 'de_lu', 'localeFallback' => 'deu', 'charset' => 'utf-8', 'direction' => 'ltr'),
218
                'el' => array('language' => 'Greek', 'locale' => 'ell', 'localeFallback' => 'ell', 'charset' => 'utf-8', 'direction' => 'ltr'),
219
                'en' => array('language' => 'English', 'locale' => 'eng', 'localeFallback' => 'eng', 'charset' => 'utf-8', 'direction' => 'ltr'),
220
                'en-au' => array('language' => 'English (Australian)', 'locale' => 'en_au', 'localeFallback' => 'eng', 'charset' => 'utf-8', 'direction' => 'ltr'),
221
                'en-bz' => array('language' => 'English (Belize)', 'locale' => 'en_bz', 'localeFallback' => 'eng', 'charset' => 'utf-8', 'direction' => 'ltr'),
222
                'en-ca' => array('language' => 'English (Canadian)', 'locale' => 'en_ca', 'localeFallback' => 'eng', 'charset' => 'utf-8', 'direction' => 'ltr'),
223
                'en-gb' => array('language' => 'English (British)', 'locale' => 'en_gb', 'localeFallback' => 'eng', 'charset' => 'utf-8', 'direction' => 'ltr'),
224
                'en-ie' => array('language' => 'English (Ireland)', 'locale' => 'en_ie', 'localeFallback' => 'eng', 'charset' => 'utf-8', 'direction' => 'ltr'),
225
                'en-jm' => array('language' => 'English (Jamaica)', 'locale' => 'en_jm', 'localeFallback' => 'eng', 'charset' => 'utf-8', 'direction' => 'ltr'),
226
                'en-nz' => array('language' => 'English (New Zealand)', 'locale' => 'en_nz', 'localeFallback' => 'eng', 'charset' => 'utf-8', 'direction' => 'ltr'),
227
                'en-tt' => array('language' => 'English (Trinidad)', 'locale' => 'en_tt', 'localeFallback' => 'eng', 'charset' => 'utf-8', 'direction' => 'ltr'),
228
                'en-us' => array('language' => 'English (United States)', 'locale' => 'en_us', 'localeFallback' => 'eng', 'charset' => 'utf-8', 'direction' => 'ltr'),
229
                'en-za' => array('language' => 'English (South Africa)', 'locale' => 'en_za', 'localeFallback' => 'eng', 'charset' => 'utf-8', 'direction' => 'ltr'),
230
                'es' => array('language' => 'Spanish (Spain - Traditional)', 'locale' => 'spa', 'localeFallback' => 'spa', 'charset' => 'utf-8', 'direction' => 'ltr'),
231
                'es-ar' => array('language' => 'Spanish (Argentina)', 'locale' => 'es_ar', 'localeFallback' => 'spa', 'charset' => 'utf-8', 'direction' => 'ltr'),
232
                'es-bo' => array('language' => 'Spanish (Bolivia)', 'locale' => 'es_bo', 'localeFallback' => 'spa', 'charset' => 'utf-8', 'direction' => 'ltr'),
233
                'es-cl' => array('language' => 'Spanish (Chile)', 'locale' => 'es_cl', 'localeFallback' => 'spa', 'charset' => 'utf-8', 'direction' => 'ltr'),
234
                'es-co' => array('language' => 'Spanish (Colombia)', 'locale' => 'es_co', 'localeFallback' => 'spa', 'charset' => 'utf-8', 'direction' => 'ltr'),
235
                'es-cr' => array('language' => 'Spanish (Costa Rica)', 'locale' => 'es_cr', 'localeFallback' => 'spa', 'charset' => 'utf-8', 'direction' => 'ltr'),
236
                'es-do' => array('language' => 'Spanish (Dominican Republic)', 'locale' => 'es_do', 'localeFallback' => 'spa', 'charset' => 'utf-8', 'direction' => 'ltr'),
237
                'es-ec' => array('language' => 'Spanish (Ecuador)', 'locale' => 'es_ec', 'localeFallback' => 'spa', 'charset' => 'utf-8', 'direction' => 'ltr'),
238
                'es-es' => array('language' => 'Spanish (Spain)', 'locale' => 'es_es', 'localeFallback' => 'spa', 'charset' => 'utf-8', 'direction' => 'ltr'),
239
                'es-gt' => array('language' => 'Spanish (Guatemala)', 'locale' => 'es_gt', 'localeFallback' => 'spa', 'charset' => 'utf-8', 'direction' => 'ltr'),
240
                'es-hn' => array('language' => 'Spanish (Honduras)', 'locale' => 'es_hn', 'localeFallback' => 'spa', 'charset' => 'utf-8', 'direction' => 'ltr'),
241
                'es-mx' => array('language' => 'Spanish (Mexican)', 'locale' => 'es_mx', 'localeFallback' => 'spa', 'charset' => 'utf-8', 'direction' => 'ltr'),
242
                'es-ni' => array('language' => 'Spanish (Nicaragua)', 'locale' => 'es_ni', 'localeFallback' => 'spa', 'charset' => 'utf-8', 'direction' => 'ltr'),
243
                'es-pa' => array('language' => 'Spanish (Panama)', 'locale' => 'es_pa', 'localeFallback' => 'spa', 'charset' => 'utf-8', 'direction' => 'ltr'),
244
                'es-pe' => array('language' => 'Spanish (Peru)', 'locale' => 'es_pe', 'localeFallback' => 'spa', 'charset' => 'utf-8', 'direction' => 'ltr'),
245
                'es-pr' => array('language' => 'Spanish (Puerto Rico)', 'locale' => 'es_pr', 'localeFallback' => 'spa', 'charset' => 'utf-8', 'direction' => 'ltr'),
246
                'es-py' => array('language' => 'Spanish (Paraguay)', 'locale' => 'es_py', 'localeFallback' => 'spa', 'charset' => 'utf-8', 'direction' => 'ltr'),
247
                'es-sv' => array('language' => 'Spanish (El Salvador)', 'locale' => 'es_sv', 'localeFallback' => 'spa', 'charset' => 'utf-8', 'direction' => 'ltr'),
248
                'es-uy' => array('language' => 'Spanish (Uruguay)', 'locale' => 'es_uy', 'localeFallback' => 'spa', 'charset' => 'utf-8', 'direction' => 'ltr'),
249
                'es-ve' => array('language' => 'Spanish (Venezuela)', 'locale' => 'es_ve', 'localeFallback' => 'spa', 'charset' => 'utf-8', 'direction' => 'ltr'),
250
                'et' => array('language' => 'Estonian', 'locale' => 'est', 'localeFallback' => 'est', 'charset' => 'utf-8', 'direction' => 'ltr'),
251
                'eu' => array('language' => 'Basque', 'locale' => 'eus', 'localeFallback' => 'eus', 'charset' => 'utf-8', 'direction' => 'ltr'),
252
                'fa' => array('language' => 'Farsi', 'locale' => 'fas', 'localeFallback' => 'fas', 'charset' => 'utf-8', 'direction' => 'rtl'),
253
                'fi' => array('language' => 'Finnish', 'locale' => 'fin', 'localeFallback' => 'fin', 'charset' => 'utf-8', 'direction' => 'ltr'),
254
                'fo' => array('language' => 'Faeroese', 'locale' => 'fao', 'localeFallback' => 'fao', 'charset' => 'utf-8', 'direction' => 'ltr'),
255
                'fr' => array('language' => 'French (Standard)', 'locale' => 'fra', 'localeFallback' => 'fra', 'charset' => 'utf-8', 'direction' => 'ltr'),
256
                'fr-be' => array('language' => 'French (Belgium)', 'locale' => 'fr_be', 'localeFallback' => 'fra', 'charset' => 'utf-8', 'direction' => 'ltr'),
257
                'fr-ca' => array('language' => 'French (Canadian)', 'locale' => 'fr_ca', 'localeFallback' => 'fra', 'charset' => 'utf-8', 'direction' => 'ltr'),
258
                'fr-ch' => array('language' => 'French (Swiss)', 'locale' => 'fr_ch', 'localeFallback' => 'fra', 'charset' => 'utf-8', 'direction' => 'ltr'),
259
                'fr-fr' => array('language' => 'French (France)', 'locale' => 'fr_fr', 'localeFallback' => 'fra', 'charset' => 'utf-8', 'direction' => 'ltr'),
260
                'fr-lu' => array('language' => 'French (Luxembourg)', 'locale' => 'fr_lu', 'localeFallback' => 'fra', 'charset' => 'utf-8', 'direction' => 'ltr'),
261
                'ga' => array('language' => 'Irish', 'locale' => 'gle', 'localeFallback' => 'gle', 'charset' => 'utf-8', 'direction' => 'ltr'),
262
                'gd' => array('language' => 'Gaelic (Scots)', 'locale' => 'gla', 'localeFallback' => 'gla', 'charset' => 'utf-8', 'direction' => 'ltr'),
263
                'gd-ie' => array('language' => 'Gaelic (Irish)', 'locale' => 'gd_ie', 'localeFallback' => 'gla', 'charset' => 'utf-8', 'direction' => 'ltr'),
264
                'gl' => array('language' => 'Galician', 'locale' => 'glg', 'localeFallback' => 'glg', 'charset' => 'utf-8', 'direction' => 'ltr'),
265
                'he' => array('language' => 'Hebrew', 'locale' => 'heb', 'localeFallback' => 'heb', 'charset' => 'utf-8', 'direction' => 'rtl'),
266
                'hi' => array('language' => 'Hindi', 'locale' => 'hin', 'localeFallback' => 'hin', 'charset' => 'utf-8', 'direction' => 'ltr'),
267
                'hr' => array('language' => 'Croatian', 'locale' => 'hrv', 'localeFallback' => 'hrv', 'charset' => 'utf-8', 'direction' => 'ltr'),
268
                'hu' => array('language' => 'Hungarian', 'locale' => 'hun', 'localeFallback' => 'hun', 'charset' => 'utf-8', 'direction' => 'ltr'),
269
                'hy' => array('language' => 'Armenian - Armenia', 'locale' => 'hye', 'localeFallback' => 'hye', 'charset' => 'utf-8', 'direction' => 'ltr'),
270
                'id' => array('language' => 'Indonesian', 'locale' => 'ind', 'localeFallback' => 'ind', 'charset' => 'utf-8', 'direction' => 'ltr'),
271
                'is' => array('language' => 'Icelandic', 'locale' => 'isl', 'localeFallback' => 'isl', 'charset' => 'utf-8', 'direction' => 'ltr'),
272
                'it' => array('language' => 'Italian', 'locale' => 'ita', 'localeFallback' => 'ita', 'charset' => 'utf-8', 'direction' => 'ltr'),
273
                'it-ch' => array('language' => 'Italian (Swiss) ', 'locale' => 'it_ch', 'localeFallback' => 'ita', 'charset' => 'utf-8', 'direction' => 'ltr'),
274
                'ja' => array('language' => 'Japanese', 'locale' => 'jpn', 'localeFallback' => 'jpn', 'charset' => 'utf-8', 'direction' => 'ltr'),
275
                'kk' => array('language' => 'Kazakh', 'locale' => 'kaz', 'localeFallback' => 'kaz', 'charset' => 'utf-8', 'direction' => 'ltr'),
276
                'kl' => array('language' => 'Kalaallisut (Greenlandic)', 'locale' => 'kal', 'localeFallback' => 'kal', 'charset' => 'kl', 'direction' => 'ltr'),
277
                'ko' => array('language' => 'Korean', 'locale' => 'kor', 'localeFallback' => 'kor', 'charset' => 'kr', 'direction' => 'ltr'),
278
                'ko-kp' => array('language' => 'Korea (North)', 'locale' => 'ko_kp', 'localeFallback' => 'kor', 'charset' => 'kr', 'direction' => 'ltr'),
279
                'ko-kr' => array('language' => 'Korea (South)', 'locale' => 'ko_kr', 'localeFallback' => 'kor', 'charset' => 'kr', 'direction' => 'ltr'),
280
                'koi8-r' => array('language' => 'Russian', 'locale' => 'koi8_r', 'localeFallback' => 'rus', 'charset' => 'koi8-r', 'direction' => 'ltr'),
281
                'li' => array('language' => 'Limburgish', 'locale' => 'lim', 'localeFallback' => 'nld', 'charset' => 'utf-8', 'direction' => 'ltr'),
282
                'lt' => array('language' => 'Lithuanian', 'locale' => 'lit', 'localeFallback' => 'lit', 'charset' => 'utf-8', 'direction' => 'ltr'),
283
                'lv' => array('language' => 'Latvian', 'locale' => 'lav', 'localeFallback' => 'lav', 'charset' => 'utf-8', 'direction' => 'ltr'),
284
                'mk' => array('language' => 'FYRO Macedonian', 'locale' => 'mkd', 'localeFallback' => 'mkd', 'charset' => 'utf-8', 'direction' => 'ltr'),
285
                'mk-mk' => array('language' => 'Macedonian', 'locale' => 'mk_mk', 'localeFallback' => 'mkd', 'charset' => 'utf-8', 'direction' => 'ltr'),
286
                'ms' => array('language' => 'Malaysian', 'locale' => 'msa', 'localeFallback' => 'msa', 'charset' => 'utf-8', 'direction' => 'ltr'),
287
                'mt' => array('language' => 'Maltese', 'locale' => 'mlt', 'localeFallback' => 'mlt', 'charset' => 'utf-8', 'direction' => 'ltr'),
288
                'nb' => array('language' => 'Norwegian Bokmal', 'locale' => 'nob', 'localeFallback' => 'nor', 'charset' => 'utf-8', 'direction' => 'ltr'),
289
                'nl' => array('language' => 'Dutch (Standard)', 'locale' => 'nld', 'localeFallback' => 'nld', 'charset' => 'utf-8', 'direction' => 'ltr'),
290
                'nl-be' => array('language' => 'Dutch (Belgium)', 'locale' => 'nl_be', 'localeFallback' => 'nld', 'charset' => 'utf-8', 'direction' => 'ltr'),
291
                'nn' => array('language' => 'Norwegian Nynorsk', 'locale' => 'nno', 'localeFallback' => 'nor', 'charset' => 'utf-8', 'direction' => 'ltr'),
292
                'no' => array('language' => 'Norwegian', 'locale' => 'nor', 'localeFallback' => 'nor', 'charset' => 'utf-8', 'direction' => 'ltr'),
293
                'pl' => array('language' => 'Polish', 'locale' => 'pol', 'localeFallback' => 'pol', 'charset' => 'utf-8', 'direction' => 'ltr'),
294
                'pt' => array('language' => 'Portuguese (Portugal)', 'locale' => 'por', 'localeFallback' => 'por', 'charset' => 'utf-8', 'direction' => 'ltr'),
295
                'pt-br' => array('language' => 'Portuguese (Brazil)', 'locale' => 'pt_br', 'localeFallback' => 'por', 'charset' => 'utf-8', 'direction' => 'ltr'),
296
                'rm' => array('language' => 'Rhaeto-Romanic', 'locale' => 'roh', 'localeFallback' => 'roh', 'charset' => 'utf-8', 'direction' => 'ltr'),
297
                'ro' => array('language' => 'Romanian', 'locale' => 'ron', 'localeFallback' => 'ron', 'charset' => 'utf-8', 'direction' => 'ltr'),
298
                'ro-mo' => array('language' => 'Romanian (Moldavia)', 'locale' => 'ro_mo', 'localeFallback' => 'ron', 'charset' => 'utf-8', 'direction' => 'ltr'),
299
                'ru' => array('language' => 'Russian', 'locale' => 'rus', 'localeFallback' => 'rus', 'charset' => 'utf-8', 'direction' => 'ltr'),
300
                'ru-mo' => array('language' => 'Russian (Moldavia)', 'locale' => 'ru_mo', 'localeFallback' => 'rus', 'charset' => 'utf-8', 'direction' => 'ltr'),
301
                'sb' => array('language' => 'Sorbian', 'locale' => 'wen', 'localeFallback' => 'wen', 'charset' => 'utf-8', 'direction' => 'ltr'),
302
                'sk' => array('language' => 'Slovak', 'locale' => 'slk', 'localeFallback' => 'slk', 'charset' => 'utf-8', 'direction' => 'ltr'),
303
                'sl' => array('language' => 'Slovenian', 'locale' => 'slv', 'localeFallback' => 'slv', 'charset' => 'utf-8', 'direction' => 'ltr'),
304
                'sq' => array('language' => 'Albanian', 'locale' => 'sqi', 'localeFallback' => 'sqi', 'charset' => 'utf-8', 'direction' => 'ltr'),
305
                'sr' => array('language' => 'Serbian', 'locale' => 'srp', 'localeFallback' => 'srp', 'charset' => 'utf-8', 'direction' => 'ltr'),
306
                'sv' => array('language' => 'Swedish', 'locale' => 'swe', 'localeFallback' => 'swe', 'charset' => 'utf-8', 'direction' => 'ltr'),
307
                'sv-fi' => array('language' => 'Swedish (Finland)', 'locale' => 'sv_fi', 'localeFallback' => 'swe', 'charset' => 'utf-8', 'direction' => 'ltr'),
308
                'se' => array('language' => 'Sami', 'locale' => 'sme', 'localeFallback' => 'sme', 'charset' => 'utf-8', 'direction' => 'ltr'),
309
                'th' => array('language' => 'Thai', 'locale' => 'tha', 'localeFallback' => 'tha', 'charset' => 'utf-8', 'direction' => 'ltr'),
310
                'tn' => array('language' => 'Tswana', 'locale' => 'tsn', 'localeFallback' => 'tsn', 'charset' => 'utf-8', 'direction' => 'ltr'),
311
                'tr' => array('language' => 'Turkish', 'locale' => 'tur', 'localeFallback' => 'tur', 'charset' => 'utf-8', 'direction' => 'ltr'),
312
                'ts' => array('language' => 'Tsonga', 'locale' => 'tso', 'localeFallback' => 'tso', 'charset' => 'utf-8', 'direction' => 'ltr'),
313
                'uk' => array('language' => 'Ukrainian', 'locale' => 'ukr', 'localeFallback' => 'ukr', 'charset' => 'utf-8', 'direction' => 'ltr'),
314
                'ur' => array('language' => 'Urdu', 'locale' => 'urd', 'localeFallback' => 'urd', 'charset' => 'utf-8', 'direction' => 'rtl'),
315
                've' => array('language' => 'Venda', 'locale' => 'ven', 'localeFallback' => 'ven', 'charset' => 'utf-8', 'direction' => 'ltr'),
316
                'vi' => array('language' => 'Vietnamese', 'locale' => 'vie', 'localeFallback' => 'vie', 'charset' => 'utf-8', 'direction' => 'ltr'),
317
                'cy' => array('language' => 'Welsh', 'locale' => 'cym', 'localeFallback' => 'cym', 'charset' => 'utf-8', 'direction' => 'ltr'),
318
                'xh' => array('language' => 'Xhosa', 'locale' => 'xho', 'localeFallback' => 'xho', 'charset' => 'utf-8', 'direction' => 'ltr'),
319
                'yi' => array('language' => 'Yiddish', 'locale' => 'yid', 'localeFallback' => 'yid', 'charset' => 'utf-8', 'direction' => 'ltr'),
320
                'zh' => array('language' => 'Chinese', 'locale' => 'zho', 'localeFallback' => 'zho', 'charset' => 'utf-8', 'direction' => 'ltr'),
321
                'zh-cn' => array('language' => 'Chinese (PRC)', 'locale' => 'zh_cn', 'localeFallback' => 'zho', 'charset' => 'GB2312', 'direction' => 'ltr'),
322
                'zh-hk' => array('language' => 'Chinese (Hong Kong)', 'locale' => 'zh_hk', 'localeFallback' => 'zho', 'charset' => 'utf-8', 'direction' => 'ltr'),
323
                'zh-sg' => array('language' => 'Chinese (Singapore)', 'locale' => 'zh_sg', 'localeFallback' => 'zho', 'charset' => 'utf-8', 'direction' => 'ltr'),
324
                'zh-tw' => array('language' => 'Chinese (Taiwan)', 'locale' => 'zh_tw', 'localeFallback' => 'zho', 'charset' => 'utf-8', 'direction' => 'ltr'),
325
                'zu' => array('language' => 'Zulu', 'locale' => 'zul', 'localeFallback' => 'zul', 'charset' => 'utf-8', 'direction' => 'ltr')
326
        );
327

    
328
/**
329
 * Class constructor
330
 */
331
        public function __construct() {
332
                if (defined('DEFAULT_LANGUAGE')) {
333
                        $this->default = DEFAULT_LANGUAGE;
334
                }
335
                $default = Configure::read('Config.language');
336
                if ($default) {
337
                        $this->default = $default;
338
                }
339
        }
340

    
341
/**
342
 * Gets the settings for $language.
343
 * If $language is null it attempt to get settings from L10n::_autoLanguage(); if this fails
344
 * the method will get the settings from L10n::_setLanguage();
345
 *
346
 * @param string $language Language (if null will use DEFAULT_LANGUAGE if defined)
347
 * @return mixed
348
 */
349
        public function get($language = null) {
350
                if ($language !== null) {
351
                        return $this->_setLanguage($language);
352
                }
353

    
354
                if (!$this->_autoLanguage()) {
355
                        $this->_setLanguage();
356
                }
357
                return $this->lang;
358
        }
359

    
360
/**
361
 * Sets the class vars to correct values for $language.
362
 * If $language is null it will use the L10n::$default if defined
363
 *
364
 * @param string $language Language (if null will use L10n::$default if defined)
365
 * @return mixed
366
 */
367
        protected function _setLanguage($language = null) {
368
                $catalog = false;
369
                if ($language !== null) {
370
                        $catalog = $this->catalog($language);
371
                }
372

    
373
                if (!$catalog && $this->default) {
374
                        $language = $this->default;
375
                        $catalog = $this->catalog($language);
376
                }
377

    
378
                if ($catalog) {
379
                        $this->language = $catalog['language'];
380
                        $this->languagePath = array_unique(array(
381
                                $catalog['locale'],
382
                                $catalog['localeFallback']
383
                        ));
384
                        $this->lang = $language;
385
                        $this->locale = $catalog['locale'];
386
                        $this->charset = $catalog['charset'];
387
                        $this->direction = $catalog['direction'];
388
                } elseif ($language) {
389
                        $this->lang = $language;
390
                        $this->languagePath = array($language);
391
                }
392

    
393
                if ($this->default && $language !== $this->default) {
394
                        $catalog = $this->catalog($this->default);
395
                        $fallback = $catalog['localeFallback'];
396
                        if (!in_array($fallback, $this->languagePath)) {
397
                                $this->languagePath[] = $fallback;
398
                        }
399
                }
400

    
401
                if (Configure::read('Config.language') === null) {
402
                        Configure::write('Config.language', $this->lang);
403
                }
404

    
405
                if ($language) {
406
                        return $language;
407
                }
408
        }
409

    
410
/**
411
 * Attempts to find the locale settings based on the HTTP_ACCEPT_LANGUAGE variable
412
 *
413
 * @return bool Success
414
 */
415
        protected function _autoLanguage() {
416
                $_detectableLanguages = CakeRequest::acceptLanguage();
417
                foreach ($_detectableLanguages as $langKey) {
418
                        if (isset($this->_l10nCatalog[$langKey])) {
419
                                $this->_setLanguage($langKey);
420
                                return true;
421
                        }
422
                        if (strpos($langKey, '-') !== false) {
423
                                $langKey = substr($langKey, 0, 2);
424
                                if (isset($this->_l10nCatalog[$langKey])) {
425
                                        $this->_setLanguage($langKey);
426
                                        return true;
427
                                }
428
                        }
429
                }
430
                return false;
431
        }
432

    
433
/**
434
 * Attempts to find locale for language, or language for locale
435
 *
436
 * @param string|array $mixed 2/3 char string (language/locale), array of those strings, or null
437
 * @return string|array|bool string language/locale, array of those values, whole map as an array,
438
 *    or false when language/locale doesn't exist
439
 */
440
        public function map($mixed = null) {
441
                if (is_array($mixed)) {
442
                        $result = array();
443
                        foreach ($mixed as $_mixed) {
444
                                if ($_result = $this->map($_mixed)) {
445
                                        $result[$_mixed] = $_result;
446
                                }
447
                        }
448
                        return $result;
449
                }
450
                if (is_string($mixed)) {
451
                        if (strlen($mixed) === 2 && in_array($mixed, $this->_l10nMap)) {
452
                                return array_search($mixed, $this->_l10nMap);
453
                        }
454
                        if (isset($this->_l10nMap[$mixed])) {
455
                                return $this->_l10nMap[$mixed];
456
                        }
457
                        return false;
458
                }
459
                return $this->_l10nMap;
460
        }
461

    
462
/**
463
 * Attempts to find catalog record for requested language
464
 *
465
 * @param string|array $language string requested language, array of requested languages, or null for whole catalog
466
 * @return array|bool array catalog record for requested language, array of catalog records, whole catalog,
467
 *    or false when language doesn't exist
468
 */
469
        public function catalog($language = null) {
470
                if (is_array($language)) {
471
                        $result = array();
472
                        foreach ($language as $_language) {
473
                                if ($_result = $this->catalog($_language)) {
474
                                        $result[$_language] = $_result;
475
                                }
476
                        }
477
                        return $result;
478
                }
479
                if (is_string($language)) {
480
                        if (isset($this->_l10nCatalog[$language])) {
481
                                return $this->_l10nCatalog[$language];
482
                        }
483
                        if (isset($this->_l10nMap[$language]) && isset($this->_l10nCatalog[$this->_l10nMap[$language]])) {
484
                                return $this->_l10nCatalog[$this->_l10nMap[$language]];
485
                        }
486
                        return false;
487
                }
488
                return $this->_l10nCatalog;
489
        }
490

    
491
}