PageRenderTime 63ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/Zend/Locale/Data.php

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

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