PageRenderTime 66ms CodeModel.GetById 30ms RepoModel.GetById 0ms app.codeStats 0ms

/library/Zend/Locale/Data.php

https://bitbucket.org/mayorbrain/precurio-v2
PHP | 1476 lines | 1117 code | 177 blank | 182 comment | 155 complexity | 20b37957c70da8c55e114ec344aa8afa MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, LGPL-2.1, BSD-3-Clause, LGPL-2.0, CC-BY-SA-3.0, MIT

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

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