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

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