/library/Zend/Locale/Data.php
PHP | 1518 lines | 1145 code | 181 blank | 192 comment | 163 complexity | 24d463aaf9c99bbed8aa368cf5ce1930 MD5 | raw file
Possible License(s): AGPL-1.0
Large files files are truncated, but you can click here to view the full file
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 * @subpackage Data
18 * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
19 * @license http://framework.zend.com/license/new-bsd New BSD License
20 * @version $Id: Data.php 24767 2012-05-06 02:53:18Z adamlundrigan $
21 */
22
23/**
24 * include needed classes
25 */
26require_once 'Zend/Locale.php';
27
28/**
29 * Locale data reader, handles the CLDR
30 *
31 * @category Zend
32 * @package Zend_Locale
33 * @subpackage Data
34 * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
35 * @license http://framework.zend.com/license/new-bsd New BSD License
36 */
37class Zend_Locale_Data
38{
39 /**
40 * Locale files
41 *
42 * @var ressource
43 * @access private
44 */
45 private static $_ldml = array();
46
47 /**
48 * List of values which are collected
49 *
50 * @var array
51 * @access private
52 */
53 private static $_list = array();
54
55 /**
56 * Internal cache for ldml values
57 *
58 * @var Zend_Cache_Core
59 * @access private
60 */
61 private static $_cache = null;
62
63 /**
64 * Internal value to remember if cache supports tags
65 *
66 * @var boolean
67 */
68 private static $_cacheTags = false;
69
70 /**
71 * Internal option, cache disabled
72 *
73 * @var boolean
74 * @access private
75 */
76 private static $_cacheDisabled = false;
77
78 /**
79 * Read the content from locale
80 *
81 * Can be called like:
82 * <ldml>
83 * <delimiter>test</delimiter>
84 * <second type='myone'>content</second>
85 * <second type='mysecond'>content2</second>
86 * <third type='mythird' />
87 * </ldml>
88 *
89 * Case 1: _readFile('ar','/ldml/delimiter') -> returns [] = test
90 * Case 1: _readFile('ar','/ldml/second[@type=myone]') -> returns [] = content
91 * Case 2: _readFile('ar','/ldml/second','type') -> returns [myone] = content; [mysecond] = content2
92 * Case 3: _readFile('ar','/ldml/delimiter',,'right') -> returns [right] = test
93 * Case 4: _readFile('ar','/ldml/third','type','myone') -> returns [myone] = mythird
94 *
95 * @param string $locale
96 * @param string $path
97 * @param string $attribute
98 * @param string $value
99 * @access private
100 * @return array
101 */
102 private static function _readFile($locale, $path, $attribute, $value, $temp)
103 {
104 // without attribute - read all values
105 // with attribute - read only this value
106 if (!empty(self::$_ldml[(string) $locale])) {
107
108 $result = self::$_ldml[(string) $locale]->xpath($path);
109 if (!empty($result)) {
110 foreach ($result as &$found) {
111
112 if (empty($value)) {
113
114 if (empty($attribute)) {
115 // Case 1
116 $temp[] = (string) $found;
117 } else if (empty($temp[(string) $found[$attribute]])){
118 // Case 2
119 $temp[(string) $found[$attribute]] = (string) $found;
120 }
121
122 } else if (empty ($temp[$value])) {
123
124 if (empty($attribute)) {
125 // Case 3
126 $temp[$value] = (string) $found;
127 } else {
128 // Case 4
129 $temp[$value] = (string) $found[$attribute];
130 }
131
132 }
133 }
134 }
135 }
136 return $temp;
137 }
138
139 /**
140 * Find possible routing to other path or locale
141 *
142 * @param string $locale
143 * @param string $path
144 * @param string $attribute
145 * @param string $value
146 * @param array $temp
147 * @throws Zend_Locale_Exception
148 * @access private
149 */
150 private static function _findRoute($locale, $path, $attribute, $value, &$temp)
151 {
152 // load locale file if not already in cache
153 // needed for alias tag when referring to other locale
154 if (empty(self::$_ldml[(string) $locale])) {
155 $filename = dirname(__FILE__) . '/Data/' . $locale . '.xml';
156 if (!file_exists($filename)) {
157 require_once 'Zend/Locale/Exception.php';
158 throw new Zend_Locale_Exception("Missing locale file '$filename' for '$locale' locale.");
159 }
160
161 self::$_ldml[(string) $locale] = simplexml_load_file($filename);
162 }
163
164 // search for 'alias' tag in the search path for redirection
165 $search = '';
166 $tok = strtok($path, '/');
167
168 // parse the complete path
169 if (!empty(self::$_ldml[(string) $locale])) {
170 while ($tok !== false) {
171 $search .= '/' . $tok;
172 if (strpos($search, '[@') !== false) {
173 while (strrpos($search, '[@') > strrpos($search, ']')) {
174 $tok = strtok('/');
175 if (empty($tok)) {
176 $search .= '/';
177 }
178 $search = $search . '/' . $tok;
179 }
180 }
181 $result = self::$_ldml[(string) $locale]->xpath($search . '/alias');
182
183 // alias found
184 if (!empty($result)) {
185
186 $source = $result[0]['source'];
187 $newpath = $result[0]['path'];
188
189 // new path - path //ldml is to ignore
190 if ($newpath != '//ldml') {
191 // other path - parse to make real path
192
193 while (substr($newpath,0,3) == '../') {
194 $newpath = substr($newpath, 3);
195 $search = substr($search, 0, strrpos($search, '/'));
196 }
197
198 // truncate ../ to realpath otherwise problems with alias
199 $path = $search . '/' . $newpath;
200 while (($tok = strtok('/'))!== false) {
201 $path = $path . '/' . $tok;
202 }
203 }
204
205 // reroute to other locale
206 if ($source != 'locale') {
207 $locale = $source;
208 }
209
210 $temp = self::_getFile($locale, $path, $attribute, $value, $temp);
211 return false;
212 }
213
214 $tok = strtok('/');
215 }
216 }
217 return true;
218 }
219
220 /**
221 * Read the right LDML file
222 *
223 * @param string $locale
224 * @param string $path
225 * @param string $attribute
226 * @param string $value
227 * @access private
228 */
229 private static function _getFile($locale, $path, $attribute = false, $value = false, $temp = array())
230 {
231 $result = self::_findRoute($locale, $path, $attribute, $value, $temp);
232 if ($result) {
233 $temp = self::_readFile($locale, $path, $attribute, $value, $temp);
234 }
235
236 // parse required locales reversive
237 // example: when given zh_Hans_CN
238 // 1. -> zh_Hans_CN
239 // 2. -> zh_Hans
240 // 3. -> zh
241 // 4. -> root
242 if (($locale != 'root') && ($result)) {
243 $locale = substr($locale, 0, -strlen(strrchr($locale, '_')));
244 if (!empty($locale)) {
245 $temp = self::_getFile($locale, $path, $attribute, $value, $temp);
246 } else {
247 $temp = self::_getFile('root', $path, $attribute, $value, $temp);
248 }
249 }
250 return $temp;
251 }
252
253 /**
254 * Find the details for supplemental calendar datas
255 *
256 * @param string $locale Locale for Detaildata
257 * @param array $list List to search
258 * @return string Key for Detaildata
259 */
260 private static function _calendarDetail($locale, $list)
261 {
262 $ret = "001";
263 foreach ($list as $key => $value) {
264 if (strpos($locale, '_') !== false) {
265 $locale = substr($locale, strpos($locale, '_') + 1);
266 }
267 if (strpos($key, $locale) !== false) {
268 $ret = $key;
269 break;
270 }
271 }
272 return $ret;
273 }
274
275 /**
276 * Internal function for checking the locale
277 *
278 * @param string|Zend_Locale $locale Locale to check
279 * @return string
280 */
281 private static function _checkLocale($locale)
282 {
283 if (empty($locale)) {
284 $locale = new Zend_Locale();
285 }
286
287 if (!(Zend_Locale::isLocale((string) $locale, null, false))) {
288 require_once 'Zend/Locale/Exception.php';
289 throw new Zend_Locale_Exception("Locale (" . (string) $locale . ") is a unknown locale");
290 }
291
292 return (string) $locale;
293 }
294
295 /**
296 * Read the LDML file, get a array of multipath defined value
297 *
298 * @param string $locale
299 * @param string $path
300 * @param string $value
301 * @return array
302 * @access public
303 */
304 public static function getList($locale, $path, $value = false)
305 {
306 $locale = self::_checkLocale($locale);
307
308 if (!isset(self::$_cache) && !self::$_cacheDisabled) {
309 require_once 'Zend/Cache.php';
310 self::$_cache = Zend_Cache::factory(
311 'Core',
312 'File',
313 array('automatic_serialization' => true),
314 array());
315 }
316
317 $val = $value;
318 if (is_array($value)) {
319 $val = implode('_' , $value);
320 }
321
322 $val = urlencode($val);
323 $id = strtr('Zend_LocaleL_' . $locale . '_' . $path . '_' . $val, array('-' => '_', '%' => '_', '+' => '_'));
324 if (!self::$_cacheDisabled && ($result = self::$_cache->load($id))) {
325 return unserialize($result);
326 }
327
328 $temp = array();
329 switch(strtolower($path)) {
330 case 'language':
331 $temp = self::_getFile($locale, '/ldml/localeDisplayNames/languages/language', 'type');
332 break;
333
334 case 'script':
335 $temp = self::_getFile($locale, '/ldml/localeDisplayNames/scripts/script', 'type');
336 break;
337
338 case 'territory':
339 $temp = self::_getFile($locale, '/ldml/localeDisplayNames/territories/territory', 'type');
340 if ($value === 1) {
341 foreach($temp as $key => $value) {
342 if ((is_numeric($key) === false) and ($key != 'QO') and ($key != 'QU')) {
343 unset($temp[$key]);
344 }
345 }
346 } else if ($value === 2) {
347 foreach($temp as $key => $value) {
348 if (is_numeric($key) or ($key == 'QO') or ($key == 'QU')) {
349 unset($temp[$key]);
350 }
351 }
352 }
353 break;
354
355 case 'variant':
356 $temp = self::_getFile($locale, '/ldml/localeDisplayNames/variants/variant', 'type');
357 break;
358
359 case 'key':
360 $temp = self::_getFile($locale, '/ldml/localeDisplayNames/keys/key', 'type');
361 break;
362
363 case 'type':
364 if (empty($value)) {
365 $temp = self::_getFile($locale, '/ldml/localeDisplayNames/types/type', 'type');
366 } else {
367 if (($value == 'calendar') or
368 ($value == 'collation') or
369 ($value == 'currency')) {
370 $temp = self::_getFile($locale, '/ldml/localeDisplayNames/types/type[@key=\'' . $value . '\']', 'type');
371 } else {
372 $temp = self::_getFile($locale, '/ldml/localeDisplayNames/types/type[@type=\'' . $value . '\']', 'type');
373 }
374 }
375 break;
376
377 case 'layout':
378 $temp = self::_getFile($locale, '/ldml/layout/orientation', 'lines', 'lines');
379 $temp += self::_getFile($locale, '/ldml/layout/orientation', 'characters', 'characters');
380 $temp += self::_getFile($locale, '/ldml/layout/inList', '', 'inList');
381 $temp += self::_getFile($locale, '/ldml/layout/inText[@type=\'currency\']', '', 'currency');
382 $temp += self::_getFile($locale, '/ldml/layout/inText[@type=\'dayWidth\']', '', 'dayWidth');
383 $temp += self::_getFile($locale, '/ldml/layout/inText[@type=\'fields\']', '', 'fields');
384 $temp += self::_getFile($locale, '/ldml/layout/inText[@type=\'keys\']', '', 'keys');
385 $temp += self::_getFile($locale, '/ldml/layout/inText[@type=\'languages\']', '', 'languages');
386 $temp += self::_getFile($locale, '/ldml/layout/inText[@type=\'long\']', '', 'long');
387 $temp += self::_getFile($locale, '/ldml/layout/inText[@type=\'measurementSystemNames\']', '', 'measurementSystemNames');
388 $temp += self::_getFile($locale, '/ldml/layout/inText[@type=\'monthWidth\']', '', 'monthWidth');
389 $temp += self::_getFile($locale, '/ldml/layout/inText[@type=\'quarterWidth\']', '', 'quarterWidth');
390 $temp += self::_getFile($locale, '/ldml/layout/inText[@type=\'scripts\']', '', 'scripts');
391 $temp += self::_getFile($locale, '/ldml/layout/inText[@type=\'territories\']', '', 'territories');
392 $temp += self::_getFile($locale, '/ldml/layout/inText[@type=\'types\']', '', 'types');
393 $temp += self::_getFile($locale, '/ldml/layout/inText[@type=\'variants\']', '', 'variants');
394 break;
395
396 case 'characters':
397 $temp = self::_getFile($locale, '/ldml/characters/exemplarCharacters', '', 'characters');
398 $temp += self::_getFile($locale, '/ldml/characters/exemplarCharacters[@type=\'auxiliary\']', '', 'auxiliary');
399 $temp += self::_getFile($locale, '/ldml/characters/exemplarCharacters[@type=\'currencySymbol\']', '', 'currencySymbol');
400 break;
401
402 case 'delimiters':
403 $temp = self::_getFile($locale, '/ldml/delimiters/quotationStart', '', 'quoteStart');
404 $temp += self::_getFile($locale, '/ldml/delimiters/quotationEnd', '', 'quoteEnd');
405 $temp += self::_getFile($locale, '/ldml/delimiters/alternateQuotationStart', '', 'quoteStartAlt');
406 $temp += self::_getFile($locale, '/ldml/delimiters/alternateQuotationEnd', '', 'quoteEndAlt');
407 break;
408
409 case 'measurement':
410 $temp = self::_getFile('supplementalData', '/supplementalData/measurementData/measurementSystem[@type=\'metric\']', 'territories', 'metric');
411 $temp += self::_getFile('supplementalData', '/supplementalData/measurementData/measurementSystem[@type=\'US\']', 'territories', 'US');
412 $temp += self::_getFile('supplementalData', '/supplementalData/measurementData/paperSize[@type=\'A4\']', 'territories', 'A4');
413 $temp += self::_getFile('supplementalData', '/supplementalData/measurementData/paperSize[@type=\'US-Letter\']', 'territories', 'US-Letter');
414 break;
415
416 case 'months':
417 if (empty($value)) {
418 $value = "gregorian";
419 }
420 $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/months/default', 'choice', 'context');
421 $temp += self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/months/monthContext[@type=\'format\']/default', 'choice', 'default');
422 $temp['format']['abbreviated'] = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/months/monthContext[@type=\'format\']/monthWidth[@type=\'abbreviated\']/month', 'type');
423 $temp['format']['narrow'] = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/months/monthContext[@type=\'format\']/monthWidth[@type=\'narrow\']/month', 'type');
424 $temp['format']['wide'] = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/months/monthContext[@type=\'format\']/monthWidth[@type=\'wide\']/month', 'type');
425 $temp['stand-alone']['abbreviated'] = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/months/monthContext[@type=\'stand-alone\']/monthWidth[@type=\'abbreviated\']/month', 'type');
426 $temp['stand-alone']['narrow'] = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/months/monthContext[@type=\'stand-alone\']/monthWidth[@type=\'narrow\']/month', 'type');
427 $temp['stand-alone']['wide'] = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/months/monthContext[@type=\'stand-alone\']/monthWidth[@type=\'wide\']/month', 'type');
428 break;
429
430 case 'month':
431 if (empty($value)) {
432 $value = array("gregorian", "format", "wide");
433 }
434 $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value[0] . '\']/months/monthContext[@type=\'' . $value[1] . '\']/monthWidth[@type=\'' . $value[2] . '\']/month', 'type');
435 break;
436
437 case 'days':
438 if (empty($value)) {
439 $value = "gregorian";
440 }
441 $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/days/default', 'choice', 'context');
442 $temp += self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/days/dayContext[@type=\'format\']/default', 'choice', 'default');
443 $temp['format']['abbreviated'] = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/days/dayContext[@type=\'format\']/dayWidth[@type=\'abbreviated\']/day', 'type');
444 $temp['format']['narrow'] = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/days/dayContext[@type=\'format\']/dayWidth[@type=\'narrow\']/day', 'type');
445 $temp['format']['wide'] = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/days/dayContext[@type=\'format\']/dayWidth[@type=\'wide\']/day', 'type');
446 $temp['stand-alone']['abbreviated'] = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/days/dayContext[@type=\'stand-alone\']/dayWidth[@type=\'abbreviated\']/day', 'type');
447 $temp['stand-alone']['narrow'] = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/days/dayContext[@type=\'stand-alone\']/dayWidth[@type=\'narrow\']/day', 'type');
448 $temp['stand-alone']['wide'] = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/days/dayContext[@type=\'stand-alone\']/dayWidth[@type=\'wide\']/day', 'type');
449 break;
450
451 case 'day':
452 if (empty($value)) {
453 $value = array("gregorian", "format", "wide");
454 }
455 $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value[0] . '\']/days/dayContext[@type=\'' . $value[1] . '\']/dayWidth[@type=\'' . $value[2] . '\']/day', 'type');
456 break;
457
458 case 'week':
459 $minDays = self::_calendarDetail($locale, self::_getFile('supplementalData', '/supplementalData/weekData/minDays', 'territories'));
460 $firstDay = self::_calendarDetail($locale, self::_getFile('supplementalData', '/supplementalData/weekData/firstDay', 'territories'));
461 $weekStart = self::_calendarDetail($locale, self::_getFile('supplementalData', '/supplementalData/weekData/weekendStart', 'territories'));
462 $weekEnd = self::_calendarDetail($locale, self::_getFile('supplementalData', '/supplementalData/weekData/weekendEnd', 'territories'));
463
464 $temp = self::_getFile('supplementalData', "/supplementalData/weekData/minDays[@territories='" . $minDays . "']", 'count', 'minDays');
465 $temp += self::_getFile('supplementalData', "/supplementalData/weekData/firstDay[@territories='" . $firstDay . "']", 'day', 'firstDay');
466 $temp += self::_getFile('supplementalData', "/supplementalData/weekData/weekendStart[@territories='" . $weekStart . "']", 'day', 'weekendStart');
467 $temp += self::_getFile('supplementalData', "/supplementalData/weekData/weekendEnd[@territories='" . $weekEnd . "']", 'day', 'weekendEnd');
468 break;
469
470 case 'quarters':
471 if (empty($value)) {
472 $value = "gregorian";
473 }
474 $temp['format']['abbreviated'] = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/quarters/quarterContext[@type=\'format\']/quarterWidth[@type=\'abbreviated\']/quarter', 'type');
475 $temp['format']['narrow'] = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/quarters/quarterContext[@type=\'format\']/quarterWidth[@type=\'narrow\']/quarter', 'type');
476 $temp['format']['wide'] = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/quarters/quarterContext[@type=\'format\']/quarterWidth[@type=\'wide\']/quarter', 'type');
477 $temp['stand-alone']['abbreviated'] = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/quarters/quarterContext[@type=\'stand-alone\']/quarterWidth[@type=\'abbreviated\']/quarter', 'type');
478 $temp['stand-alone']['narrow'] = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/quarters/quarterContext[@type=\'stand-alone\']/quarterWidth[@type=\'narrow\']/quarter', 'type');
479 $temp['stand-alone']['wide'] = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/quarters/quarterContext[@type=\'stand-alone\']/quarterWidth[@type=\'wide\']/quarter', 'type');
480 break;
481
482 case 'quarter':
483 if (empty($value)) {
484 $value = array("gregorian", "format", "wide");
485 }
486 $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value[0] . '\']/quarters/quarterContext[@type=\'' . $value[1] . '\']/quarterWidth[@type=\'' . $value[2] . '\']/quarter', 'type');
487 break;
488
489 case 'eras':
490 if (empty($value)) {
491 $value = "gregorian";
492 }
493 $temp['names'] = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/eras/eraNames/era', 'type');
494 $temp['abbreviated'] = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/eras/eraAbbr/era', 'type');
495 $temp['narrow'] = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/eras/eraNarrow/era', 'type');
496 break;
497
498 case 'era':
499 if (empty($value)) {
500 $value = array("gregorian", "Abbr");
501 }
502 $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value[0] . '\']/eras/era' . $value[1] . '/era', 'type');
503 break;
504
505 case 'date':
506 if (empty($value)) {
507 $value = "gregorian";
508 }
509 $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/dateFormats/dateFormatLength[@type=\'full\']/dateFormat/pattern', '', 'full');
510 $temp += self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/dateFormats/dateFormatLength[@type=\'long\']/dateFormat/pattern', '', 'long');
511 $temp += self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/dateFormats/dateFormatLength[@type=\'medium\']/dateFormat/pattern', '', 'medium');
512 $temp += self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/dateFormats/dateFormatLength[@type=\'short\']/dateFormat/pattern', '', 'short');
513 break;
514
515 case 'time':
516 if (empty($value)) {
517 $value = "gregorian";
518 }
519 $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/timeFormats/timeFormatLength[@type=\'full\']/timeFormat/pattern', '', 'full');
520 $temp += self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/timeFormats/timeFormatLength[@type=\'long\']/timeFormat/pattern', '', 'long');
521 $temp += self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/timeFormats/timeFormatLength[@type=\'medium\']/timeFormat/pattern', '', 'medium');
522 $temp += self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/timeFormats/timeFormatLength[@type=\'short\']/timeFormat/pattern', '', 'short');
523 break;
524
525 case 'datetime':
526 if (empty($value)) {
527 $value = "gregorian";
528 }
529
530 $timefull = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/timeFormats/timeFormatLength[@type=\'full\']/timeFormat/pattern', '', 'full');
531 $timelong = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/timeFormats/timeFormatLength[@type=\'long\']/timeFormat/pattern', '', 'long');
532 $timemedi = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/timeFormats/timeFormatLength[@type=\'medium\']/timeFormat/pattern', '', 'medi');
533 $timeshor = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/timeFormats/timeFormatLength[@type=\'short\']/timeFormat/pattern', '', 'shor');
534
535 $datefull = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/dateFormats/dateFormatLength[@type=\'full\']/dateFormat/pattern', '', 'full');
536 $datelong = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/dateFormats/dateFormatLength[@type=\'long\']/dateFormat/pattern', '', 'long');
537 $datemedi = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/dateFormats/dateFormatLength[@type=\'medium\']/dateFormat/pattern', '', 'medi');
538 $dateshor = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/dateFormats/dateFormatLength[@type=\'short\']/dateFormat/pattern', '', 'shor');
539
540 $full = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/dateTimeFormats/dateTimeFormatLength[@type=\'full\']/dateTimeFormat/pattern', '', 'full');
541 $long = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/dateTimeFormats/dateTimeFormatLength[@type=\'long\']/dateTimeFormat/pattern', '', 'long');
542 $medi = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/dateTimeFormats/dateTimeFormatLength[@type=\'medium\']/dateTimeFormat/pattern', '', 'medi');
543 $shor = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/dateTimeFormats/dateTimeFormatLength[@type=\'short\']/dateTimeFormat/pattern', '', 'shor');
544
545 $temp['full'] = str_replace(array('{0}', '{1}'), array($timefull['full'], $datefull['full']), $full['full']);
546 $temp['long'] = str_replace(array('{0}', '{1}'), array($timelong['long'], $datelong['long']), $long['long']);
547 $temp['medium'] = str_replace(array('{0}', '{1}'), array($timemedi['medi'], $datemedi['medi']), $medi['medi']);
548 $temp['short'] = str_replace(array('{0}', '{1}'), array($timeshor['shor'], $dateshor['shor']), $shor['shor']);
549 break;
550
551 case 'dateitem':
552 if (empty($value)) {
553 $value = "gregorian";
554 }
555 $_temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/dateTimeFormats/availableFormats/dateFormatItem', 'id');
556 foreach($_temp as $key => $found) {
557 $temp += self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/dateTimeFormats/availableFormats/dateFormatItem[@id=\'' . $key . '\']', '', $key);
558 }
559 break;
560
561 case 'dateinterval':
562 if (empty($value)) {
563 $value = "gregorian";
564 }
565 $_temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/dateTimeFormats/intervalFormats/intervalFormatItem', 'id');
566 foreach($_temp as $key => $found) {
567 $temp[$key] = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/dateTimeFormats/intervalFormats/intervalFormatItem[@id=\'' . $key . '\']/greatestDifference', 'id');
568 }
569 break;
570
571 case 'field':
572 if (empty($value)) {
573 $value = "gregorian";
574 }
575 $temp2 = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/fields/field', 'type');
576 foreach ($temp2 as $key => $keyvalue) {
577 $temp += self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/fields/field[@type=\'' . $key . '\']/displayName', '', $key);
578 }
579 break;
580
581 case 'relative':
582 if (empty($value)) {
583 $value = "gregorian";
584 }
585 $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/fields/field/relative', 'type');
586 break;
587
588 case 'symbols':
589 $temp = self::_getFile($locale, '/ldml/numbers/symbols/decimal', '', 'decimal');
590 $temp += self::_getFile($locale, '/ldml/numbers/symbols/group', '', 'group');
591 $temp += self::_getFile($locale, '/ldml/numbers/symbols/list', '', 'list');
592 $temp += self::_getFile($locale, '/ldml/numbers/symbols/percentSign', '', 'percent');
593 $temp += self::_getFile($locale, '/ldml/numbers/symbols/nativeZeroDigit', '', 'zero');
594 $temp += self::_getFile($locale, '/ldml/numbers/symbols/patternDigit', '', 'pattern');
595 $temp += self::_getFile($locale, '/ldml/numbers/symbols/plusSign', '', 'plus');
596 $temp += self::_getFile($locale, '/ldml/numbers/symbols/minusSign', '', 'minus');
597 $temp += self::_getFile($locale, '/ldml/numbers/symbols/exponential', '', 'exponent');
598 $temp += self::_getFile($locale, '/ldml/numbers/symbols/perMille', '', 'mille');
599 $temp += self::_getFile($locale, '/ldml/numbers/symbols/infinity', '', 'infinity');
600 $temp += self::_getFile($locale, '/ldml/numbers/symbols/nan', '', 'nan');
601 break;
602
603 case 'nametocurrency':
604 $_temp = self::_getFile($locale, '/ldml/numbers/currencies/currency', 'type');
605 foreach ($_temp as $key => $found) {
606 $temp += self::_getFile($locale, '/ldml/numbers/currencies/currency[@type=\'' . $key . '\']/displayName', '', $key);
607 }
608 break;
609
610 case 'currencytoname':
611 $_temp = self::_getFile($locale, '/ldml/numbers/currencies/currency', 'type');
612 foreach ($_temp as $key => $keyvalue) {
613 $val = self::_getFile($locale, '/ldml/numbers/currencies/currency[@type=\'' . $key . '\']/displayName', '', $key);
614 if (!isset($val[$key])) {
615 continue;
616 }
617 if (!isset($temp[$val[$key]])) {
618 $temp[$val[$key]] = $key;
619 } else {
620 $temp[$val[$key]] .= " " . $key;
621 }
622 }
623 break;
624
625 case 'currencysymbol':
626 $_temp = self::_getFile($locale, '/ldml/numbers/currencies/currency', 'type');
627 foreach ($_temp as $key => $found) {
628 $temp += self::_getFile($locale, '/ldml/numbers/currencies/currency[@type=\'' . $key . '\']/symbol', '', $key);
629 }
630 break;
631
632 case 'question':
633 $temp = self::_getFile($locale, '/ldml/posix/messages/yesstr', '', 'yes');
634 $temp += self::_getFile($locale, '/ldml/posix/messages/nostr', '', 'no');
635 break;
636
637 case 'currencyfraction':
638 $_temp = self::_getFile('supplementalData', '/supplementalData/currencyData/fractions/info', 'iso4217');
639 foreach ($_temp as $key => $found) {
640 $temp += self::_getFile('supplementalData', '/supplementalData/currencyData/fractions/info[@iso4217=\'' . $key . '\']', 'digits', $key);
641 }
642 break;
643
644 case 'currencyrounding':
645 $_temp = self::_getFile('supplementalData', '/supplementalData/currencyData/fractions/info', 'iso4217');
646 foreach ($_temp as $key => $found) {
647 $temp += self::_getFile('supplementalData', '/supplementalData/currencyData/fractions/info[@iso4217=\'' . $key . '\']', 'rounding', $key);
648 }
649 break;
650
651 case 'currencytoregion':
652 $_temp = self::_getFile('supplementalData', '/supplementalData/currencyData/region', 'iso3166');
653 foreach ($_temp as $key => $keyvalue) {
654 $temp += self::_getFile('supplementalData', '/supplementalData/currencyData/region[@iso3166=\'' . $key . '\']/currency', 'iso4217', $key);
655 }
656 break;
657
658 case 'regiontocurrency':
659 $_temp = self::_getFile('supplementalData', '/supplementalData/currencyData/region', 'iso3166');
660 foreach ($_temp as $key => $keyvalue) {
661 $val = self::_getFile('supplementalData', '/supplementalData/currencyData/region[@iso3166=\'' . $key . '\']/currency', 'iso4217', $key);
662 if (!isset($val[$key])) {
663 continue;
664 }
665 if (!isset($temp[$val[$key]])) {
666 $temp[$val[$key]] = $key;
667 } else {
668 $temp[$val[$key]] .= " " . $key;
669 }
670 }
671 break;
672
673 case 'regiontoterritory':
674 $_temp = self::_getFile('supplementalData', '/supplementalData/territoryContainment/group', 'type');
675 foreach ($_temp as $key => $found) {
676 $temp += self::_getFile('supplementalData', '/supplementalData/territoryContainment/group[@type=\'' . $key . '\']', 'contains', $key);
677 }
678 break;
679
680 case 'territorytoregion':
681 $_temp2 = self::_getFile('supplementalData', '/supplementalData/territoryContainment/group', 'type');
682 $_temp = array();
683 foreach ($_temp2 as $key => $found) {
684 $_temp += self::_getFile('supplementalData', '/supplementalData/territoryContainment/group[@type=\'' . $key . '\']', 'contains', $key);
685 }
686 foreach($_temp as $key => $found) {
687 $_temp3 = explode(" ", $found);
688 foreach($_temp3 as $found3) {
689 if (!isset($temp[$found3])) {
690 $temp[$found3] = (string) $key;
691 } else {
692 $temp[$found3] .= " " . $key;
693 }
694 }
695 }
696 break;
697
698 case 'scripttolanguage':
699 $_temp = self::_getFile('supplementalData', '/supplementalData/languageData/language', 'type');
700 foreach ($_temp as $key => $found) {
701 $temp += self::_getFile('supplementalData', '/supplementalData/languageData/language[@type=\'' . $key . '\']', 'scripts', $key);
702 if (empty($temp[$key])) {
703 unset($temp[$key]);
704 }
705 }
706 break;
707
708 case 'languagetoscript':
709 $_temp2 = self::_getFile('supplementalData', '/supplementalData/languageData/language', 'type');
710 $_temp = array();
711 foreach ($_temp2 as $key => $found) {
712 $_temp += self::_getFile('supplementalData', '/supplementalData/languageData/language[@type=\'' . $key . '\']', 'scripts', $key);
713 }
714 foreach($_temp as $key => $found) {
715 $_temp3 = explode(" ", $found);
716 foreach($_temp3 as $found3) {
717 if (empty($found3)) {
718 continue;
719 }
720 if (!isset($temp[$found3])) {
721 $temp[$found3] = (string) $key;
722 } else {
723 $temp[$found3] .= " " . $key;
724 }
725 }
726 }
727 break;
728
729 case 'territorytolanguage':
730 $_temp = self::_getFile('supplementalData', '/supplementalData/languageData/language', 'type');
731 foreach ($_temp as $key => $found) {
732 $temp += self::_getFile('supplementalData', '/supplementalData/languageData/language[@type=\'' . $key . '\']', 'territories', $key);
733 if (empty($temp[$key])) {
734 unset($temp[$key]);
735 }
736 }
737 break;
738
739 case 'languagetoterritory':
740 $_temp2 = self::_getFile('supplementalData', '/supplementalData/languageData/language', 'type');
741 $_temp = array();
742 foreach ($_temp2 as $key => $found) {
743 $_temp += self::_getFile('supplementalData', '/supplementalData/languageData/language[@type=\'' . $key . '\']', 'territories', $key);
744 }
745 foreach($_temp as $key => $found) {
746 $_temp3 = explode(" ", $found);
747 foreach($_temp3 as $found3) {
748 if (empty($found3)) {
749 continue;
750 }
751 if (!isset($temp[$found3])) {
752 $temp[$found3] = (string) $key;
753 } else {
754 $temp[$found3] .= " " . $key;
755 }
756 }
757 }
758 break;
759
760 case 'timezonetowindows':
761 $_temp = self::_getFile('supplementalData', '/supplementalData/timezoneData/mapTimezones[@type=\'windows\']/mapZone', 'other');
762 foreach ($_temp as $key => $found) {
763 $temp += self::_getFile('supplementalData', '/supplementalData/timezoneData/mapTimezones[@type=\'windows\']/mapZone[@other=\'' . $key . '\']', 'type', $key);
764 }
765 break;
766
767 case 'windowstotimezone':
768 $_temp = self::_getFile('supplementalData', '/supplementalData/timezoneData/mapTimezones[@type=\'windows\']/mapZone', 'type');
769 foreach ($_temp as $key => $found) {
770 $temp += self::_getFile('supplementalData', '/supplementalData/timezoneData/mapTimezones[@type=\'windows\']/mapZone[@type=\'' .$key . '\']', 'other', $key);
771 }
772 break;
773
774 case 'territorytotimezone':
775 $_temp = self::_getFile('supplementalData', '/supplementalData/timezoneData/zoneFormatting/zoneItem', 'type');
776 foreach ($_temp as $key => $found) {
777 $temp += self::_getFile('supplementalData', '/supplementalData/timezoneData/zoneFormatting/zoneItem[@type=\'' . $key . '\']', 'territory', $key);
778 }
779 break;
780
781 case 'timezonetoterritory':
782 $_temp = self::_getFile('supplementalData', '/supplementalData/timezoneData/zoneFormatting/zoneItem', 'territory');
783 foreach ($_temp as $key => $found) {
784 $temp += self::_getFile('supplementalData', '/supplementalData/timezoneData/zoneFormatting/zoneItem[@territory=\'' . $key . '\']', 'type', $key);
785 }
786 break;
787
788 case 'citytotimezone':
789 $_temp = self::_getFile($locale, '/ldml/dates/timeZoneNames/zone', 'type');
790 foreach($_temp as $key => $found) {
791 $temp += self::_getFile($locale, '/ldml/dates/timeZoneNames/zone[@type=\'' . $key . '\']/exemplarCity', '', $key);
792 }
793 break;
794
795 case 'timezonetocity':
796 $_temp = self::_getFile($locale, '/ldml/dates/timeZoneNames/zone', 'type');
797 $temp = array();
798 foreach($_temp as $key => $found) {
799 $temp += self::_getFile($locale, '/ldml/dates/timeZoneNames/zone[@type=\'' . $key . '\']/exemplarCity', '', $key);
800 if (!empty($temp[$key])) {
801 $temp[$temp[$key]] = $key;
802 }
803 unset($temp[$key]);
804 }
805 break;
806
807 case 'phonetoterritory':
808 $_temp = self::_getFile('telephoneCodeData', '/supplementalData/telephoneCodeData/codesByTerritory', 'territory');
809 foreach ($_temp as $key => $keyvalue) {
810 $temp += self::_getFile('telephoneCodeData', '/supplementalData/telephoneCodeData/codesByTerritory[@territory=\'' . $key . '\']/telephoneCountryCode', 'code', $key);
811 }
812 break;
813
814 case 'territorytophone':
815 $_temp = self::_getFile('telephoneCodeData', '/supplementalData/telephoneCodeData/codesByTerritory', 'territory');
816 foreach ($_temp as $key => $keyvalue) {
817 $val = self::_getFile('telephoneCodeData', '/supplementalData/telephoneCodeData/codesByTerritory[@territory=\'' . $key . '\']/telephoneCountryCode', 'code', $key);
818 if (!isset($val[$key])) {
819 continue;
820 }
821 if (!isset($temp[$val[$key]])) {
822 $temp[$val[$key]] = $key;
823 } else {
824 $temp[$val[$key]] .= " " . $key;
825 }
826 }
827 break;
828
829 case 'numerictoterritory':
830 $_temp = self::_getFile('supplementalData', '/supplementalData/codeMappings/territoryCodes', 'type');
831 foreach ($_temp as $key => $keyvalue) {
832 $temp += self::_getFile('supplementalData', '/supplementalData/codeMappings/territoryCodes[@type=\'' . $key . '\']', 'numeric', $key);
833 }
834 break;
835
836 case 'territorytonumeric':
837 $_temp = self::_getFile('supplementalData', '/supplementalData/codeMappings/territoryCodes', 'numeric');
838 foreach ($_temp as $key => $keyvalue) {
839 $temp += self::_getFile('supplementalData', '/supplementalData/codeMappings/territoryCodes[@numeric=\'' . $key . '\']', 'type', $key);
840 }
841 break;
842
843 case 'alpha3toterritory':
844 $_temp = self::_getFile('supplementalData', '/supplementalData/codeMappings/territoryCodes', 'type');
845 foreach ($_temp as $key => $keyvalue) {
846 $temp += self::_getFile('supplementalData', '/supplementalData/codeMappings/territoryCodes[@type=\'' . $key . '\']', 'alpha3', $key);
847 }
848 break;
849
850 case 'territorytoalpha3':
851 $_temp = self::_getFile('supplementalData', '/supplementalData/codeMappings/territoryCodes', 'alpha3');
852 foreach ($_temp as $key => $keyvalue) {
853 $temp += self::_getFile('supplementalData', '/supplementalData/codeMappings/territoryCodes[@alpha3=\'' . $key . '\']', 'type', $key);
854 }
855 break;
856
857 case 'postaltoterritory':
858 $_temp = self::_getFile('postalCodeData', '/supplementalData/postalCodeData/postCodeRegex', 'territoryId');
859 foreach ($_temp as $key => $keyvalue) {
860 $temp += self::_getFile('postalCodeData', '/supplementalData/postalCodeData/postCodeRegex[@territoryId=\'' . $key . '\']', 'territoryId');
861 }
862 break;
863
864 case 'numberingsystem':
865 $_temp = self::_getFile('numberingSystems', '/supplementalData/numberingSystems/numberingSystem', 'id');
866 foreach ($_temp as $key => $keyvalue) {
867 $temp += self::_getFile('numberingSystems', '/supplementalData/numberingSystems/numberingSystem[@id=\'' . $key . '\']', 'digits', $key);
868 if (empty($temp[$key])) {
869 unset($temp[$key]);
870 }
871 }
872 break;
873
874 case 'chartofallback':
875 $_temp = self::_getFile('characters', '/supplementalData/characters/character-fallback/character', 'value');
876 foreach ($_temp as $key => $keyvalue) {
877 $temp2 = self::_getFile('characters', '/supplementalData/characters/character-fallback/character[@value=\'' . $key . '\']/substitute', '', $key);
878 $temp[current($temp2)] = $key;
879 }
880 break;
881
882 case 'fallbacktochar':
883 $_temp = self::_getFile('characters', '/supplementalData/characters/character-fallback/character', 'value');
884 foreach ($_temp as $key => $keyvalue) {
885 $temp += self::_getFile('characters', '/supplementalData/characters/character-fallback/character[@value=\'' . $key . '\']/substitute', '', $key);
886 }
887 break;
888
889 case 'localeupgrade':
890 $_temp = self::_getFile('likelySubtags', '/supplementalData/likelySubtags/likelySubtag', 'from');
891 foreach ($_temp as $key => $keyvalue) {
892 $temp += self::_getFile('likelySubtags', '/supplementalData/likelySubtags/likelySubtag[@from=\'' . $key . '\']', 'to', $key);
893 }
894 break;
895
896 case 'unit':
897 $_temp = self::_getFile($locale, '/ldml/units/unit', 'type');
898 foreach($_temp as $key => $keyvalue) {
899 $_temp2 = self::_getFile($locale, '/ldml/units/unit[@type=\'' . $key . '\']/unitPattern', 'count');
900 $temp[$key] = $_temp2;
901 }
902 break;
903
904 default :
905 require_once 'Zend/Locale/Exception.php';
906 throw new Zend_Locale_Exception("Unknown list ($path) for parsing locale data.");
907 break;
908 }
909
910 if (isset(self::$_cache)) {
911 if (self::$_cacheTags) {
912 self::$_cache->save( serialize($temp), $id, array('Zend_Locale'));
913 } else {
914 self::$_cache->save( serialize($temp), $id);
915 }
916 }
917
918 return $temp;
919 }
920
921 /**
922 * Read the LDML file, get a single path defined value
923 *
924 * @param string $locale
925 * @param string $path
926 * @param string $value
927 * @return string
928 * @access public
929 */
930 public static function getContent($locale, $path, $value = false)
931 {
932 $locale = self::_checkLocale($locale);
933
934 if (!isset(self::$_cache) && !self::$_cacheDisabled) {
935 require_once 'Zend/Cache.php';
936 self::$_cache = Zend_Cache::factory(
937 'Core',
938 'File',
939 array('automatic_serialization' => true),
940 array());
941 }
942
943 $val = $value;
944 if (is_array($value)) {
945 $val = implode('_' , $value);
946 }
947 $val = urlencode($val);
948 $id = strtr('Zend_LocaleC_' . $locale . '_' . $path . '_' . $val, array('-' => '_', '%' => '_', '+' => '_'));
949 if (!self::$_cacheDisabled && ($result = self::$_cache->load($id))) {
950 return unserialize($…
Large files files are truncated, but you can click here to view the full file