PageRenderTime 56ms CodeModel.GetById 3ms app.highlight 44ms RepoModel.GetById 1ms app.codeStats 1ms

/vendor/Eva/Locale/Data.php

https://github.com/zc1415926/eva-engine
PHP | 1496 lines | 1133 code | 180 blank | 183 comment | 161 complexity | 01a87f4610a1c06f4adb5f1379b5ddc3 MD5 | raw file

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

Large files files are truncated, but you can click here to view the full file