PageRenderTime 48ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/library/Zend/Locale/Data.php

https://bitbucket.org/fabiancarlos/feature_seguimentos
PHP | 1518 lines | 1145 code | 181 blank | 192 comment | 163 complexity | 478881321c39023100877b586b5c40ed MD5 | raw file

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

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

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