Data.php 62 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320
  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$
  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. require_once 'Zend/Cache.php';
  264. self::$_cache = Zend_Cache::factory(
  265. 'Core',
  266. 'File',
  267. array('automatic_serialization' => true),
  268. array());
  269. }
  270. $val = $value;
  271. if (is_array($value)) {
  272. $val = implode('_' , $value);
  273. }
  274. $val = urlencode($val);
  275. $id = strtr('Zend_LocaleL_' . $locale . '_' . $path . '_' . $val, array('-' => '_', '%' => '_', '+' => '_'));
  276. if ($result = self::$_cache->load($id)) {
  277. return unserialize($result);
  278. }
  279. $temp = array();
  280. switch(strtolower($path)) {
  281. case 'language':
  282. $temp = self::_getFile($locale, '/ldml/localeDisplayNames/languages/language', 'type');
  283. break;
  284. case 'script':
  285. $temp = self::_getFile($locale, '/ldml/localeDisplayNames/scripts/script', 'type');
  286. break;
  287. case 'territory':
  288. $temp = self::_getFile($locale, '/ldml/localeDisplayNames/territories/territory', 'type');
  289. if ($value === 1) {
  290. foreach($temp as $key => $value) {
  291. if ((is_numeric($key) === false) and ($key != 'QO') and ($key != 'QU')) {
  292. unset($temp[$key]);
  293. }
  294. }
  295. } else if ($value === 2) {
  296. foreach($temp as $key => $value) {
  297. if (is_numeric($key) or ($key == 'QO') or ($key == 'QU')) {
  298. unset($temp[$key]);
  299. }
  300. }
  301. }
  302. break;
  303. case 'variant':
  304. $temp = self::_getFile($locale, '/ldml/localeDisplayNames/variants/variant', 'type');
  305. break;
  306. case 'key':
  307. $temp = self::_getFile($locale, '/ldml/localeDisplayNames/keys/key', 'type');
  308. break;
  309. case 'type':
  310. if (empty($type)) {
  311. $temp = self::_getFile($locale, '/ldml/localeDisplayNames/types/type', 'type');
  312. } else {
  313. if (($value == 'calendar') or
  314. ($value == 'collation') or
  315. ($value == 'currency')) {
  316. $temp = self::_getFile($locale, '/ldml/localeDisplayNames/types/type[@key=\'' . $value . '\']', 'type');
  317. } else {
  318. $temp = self::_getFile($locale, '/ldml/localeDisplayNames/types/type[@type=\'' . $value . '\']', 'type');
  319. }
  320. }
  321. break;
  322. case 'layout':
  323. $temp = self::_getFile($locale, '/ldml/layout/orientation', 'lines', 'lines');
  324. $temp += self::_getFile($locale, '/ldml/layout/orientation', 'characters', 'characters');
  325. $temp += self::_getFile($locale, '/ldml/layout/inList', '', 'inList');
  326. $temp += self::_getFile($locale, '/ldml/layout/inText[@type=\'currency\']', '', 'currency');
  327. $temp += self::_getFile($locale, '/ldml/layout/inText[@type=\'dayWidth\']', '', 'dayWidth');
  328. $temp += self::_getFile($locale, '/ldml/layout/inText[@type=\'fields\']', '', 'fields');
  329. $temp += self::_getFile($locale, '/ldml/layout/inText[@type=\'keys\']', '', 'keys');
  330. $temp += self::_getFile($locale, '/ldml/layout/inText[@type=\'languages\']', '', 'languages');
  331. $temp += self::_getFile($locale, '/ldml/layout/inText[@type=\'long\']', '', 'long');
  332. $temp += self::_getFile($locale, '/ldml/layout/inText[@type=\'measurementSystemNames\']', '', 'measurementSystemNames');
  333. $temp += self::_getFile($locale, '/ldml/layout/inText[@type=\'monthWidth\']', '', 'monthWidth');
  334. $temp += self::_getFile($locale, '/ldml/layout/inText[@type=\'quarterWidth\']', '', 'quarterWidth');
  335. $temp += self::_getFile($locale, '/ldml/layout/inText[@type=\'scripts\']', '', 'scripts');
  336. $temp += self::_getFile($locale, '/ldml/layout/inText[@type=\'territories\']', '', 'territories');
  337. $temp += self::_getFile($locale, '/ldml/layout/inText[@type=\'types\']', '', 'types');
  338. $temp += self::_getFile($locale, '/ldml/layout/inText[@type=\'variants\']', '', 'variants');
  339. break;
  340. case 'characters':
  341. $temp = self::_getFile($locale, '/ldml/characters/exemplarCharacters', '', 'characters');
  342. $temp += self::_getFile($locale, '/ldml/characters/exemplarCharacters[@type=\'auxiliary\']', '', 'auxiliary');
  343. $temp += self::_getFile($locale, '/ldml/characters/exemplarCharacters[@type=\'currencySymbol\']', '', 'currencySymbol');
  344. break;
  345. case 'delimiters':
  346. $temp = self::_getFile($locale, '/ldml/delimiters/quotationStart', '', 'quoteStart');
  347. $temp += self::_getFile($locale, '/ldml/delimiters/quotationEnd', '', 'quoteEnd');
  348. $temp += self::_getFile($locale, '/ldml/delimiters/alternateQuotationStart', '', 'quoteStartAlt');
  349. $temp += self::_getFile($locale, '/ldml/delimiters/alternateQuotationEnd', '', 'quoteEndAlt');
  350. break;
  351. case 'measurement':
  352. $temp = self::_getFile('supplementalData', '/supplementalData/measurementData/measurementSystem[@type=\'metric\']', 'territories', 'metric');
  353. $temp += self::_getFile('supplementalData', '/supplementalData/measurementData/measurementSystem[@type=\'US\']', 'territories', 'US');
  354. $temp += self::_getFile('supplementalData', '/supplementalData/measurementData/paperSize[@type=\'A4\']', 'territories', 'A4');
  355. $temp += self::_getFile('supplementalData', '/supplementalData/measurementData/paperSize[@type=\'US-Letter\']', 'territories', 'US-Letter');
  356. break;
  357. case 'months':
  358. if (empty($value)) {
  359. $value = "gregorian";
  360. }
  361. $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/months/default', 'choice', 'context');
  362. $temp += self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/months/monthContext[@type=\'format\']/default', 'choice', 'default');
  363. $temp['format']['abbreviated'] = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/months/monthContext[@type=\'format\']/monthWidth[@type=\'abbreviated\']/month', 'type');
  364. $temp['format']['narrow'] = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/months/monthContext[@type=\'format\']/monthWidth[@type=\'narrow\']/month', 'type');
  365. $temp['format']['wide'] = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/months/monthContext[@type=\'format\']/monthWidth[@type=\'wide\']/month', 'type');
  366. $temp['stand-alone']['abbreviated'] = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/months/monthContext[@type=\'stand-alone\']/monthWidth[@type=\'abbreviated\']/month', 'type');
  367. $temp['stand-alone']['narrow'] = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/months/monthContext[@type=\'stand-alone\']/monthWidth[@type=\'narrow\']/month', 'type');
  368. $temp['stand-alone']['wide'] = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/months/monthContext[@type=\'stand-alone\']/monthWidth[@type=\'wide\']/month', 'type');
  369. break;
  370. case 'month':
  371. if (empty($value)) {
  372. $value = array("gregorian", "format", "wide");
  373. }
  374. $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value[0] . '\']/months/monthContext[@type=\'' . $value[1] . '\']/monthWidth[@type=\'' . $value[2] . '\']/month', 'type');
  375. break;
  376. case 'days':
  377. if (empty($value)) {
  378. $value = "gregorian";
  379. }
  380. $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/days/default', 'choice', 'context');
  381. $temp += self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/days/dayContext[@type=\'format\']/default', 'choice', 'default');
  382. $temp['format']['abbreviated'] = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/days/dayContext[@type=\'format\']/dayWidth[@type=\'abbreviated\']/day', 'type');
  383. $temp['format']['narrow'] = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/days/dayContext[@type=\'format\']/dayWidth[@type=\'narrow\']/day', 'type');
  384. $temp['format']['wide'] = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/days/dayContext[@type=\'format\']/dayWidth[@type=\'wide\']/day', 'type');
  385. $temp['stand-alone']['abbreviated'] = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/days/dayContext[@type=\'stand-alone\']/dayWidth[@type=\'abbreviated\']/day', 'type');
  386. $temp['stand-alone']['narrow'] = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/days/dayContext[@type=\'stand-alone\']/dayWidth[@type=\'narrow\']/day', 'type');
  387. $temp['stand-alone']['wide'] = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/days/dayContext[@type=\'stand-alone\']/dayWidth[@type=\'wide\']/day', 'type');
  388. break;
  389. case 'day':
  390. if (empty($value)) {
  391. $value = array("gregorian", "format", "wide");
  392. }
  393. $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value[0] . '\']/days/dayContext[@type=\'' . $value[1] . '\']/dayWidth[@type=\'' . $value[2] . '\']/day', 'type');
  394. break;
  395. case 'week':
  396. $minDays = self::_calendarDetail($locale, self::_getFile('supplementalData', '/supplementalData/weekData/minDays', 'territories'));
  397. $firstDay = self::_calendarDetail($locale, self::_getFile('supplementalData', '/supplementalData/weekData/firstDay', 'territories'));
  398. $weekStart = self::_calendarDetail($locale, self::_getFile('supplementalData', '/supplementalData/weekData/weekendStart', 'territories'));
  399. $weekEnd = self::_calendarDetail($locale, self::_getFile('supplementalData', '/supplementalData/weekData/weekendEnd', 'territories'));
  400. $temp = self::_getFile('supplementalData', "/supplementalData/weekData/minDays[@territories='" . $minDays . "']", 'count', 'minDays');
  401. $temp += self::_getFile('supplementalData', "/supplementalData/weekData/firstDay[@territories='" . $firstDay . "']", 'day', 'firstDay');
  402. $temp += self::_getFile('supplementalData', "/supplementalData/weekData/weekendStart[@territories='" . $weekStart . "']", 'day', 'weekendStart');
  403. $temp += self::_getFile('supplementalData', "/supplementalData/weekData/weekendEnd[@territories='" . $weekEnd . "']", 'day', 'weekendEnd');
  404. break;
  405. case 'quarters':
  406. if (empty($value)) {
  407. $value = "gregorian";
  408. }
  409. $temp['format']['abbreviated'] = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/quarters/quarterContext[@type=\'format\']/quarterWidth[@type=\'abbreviated\']/quarter', 'type');
  410. $temp['format']['narrow'] = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/quarters/quarterContext[@type=\'format\']/quarterWidth[@type=\'narrow\']/quarter', 'type');
  411. $temp['format']['wide'] = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/quarters/quarterContext[@type=\'format\']/quarterWidth[@type=\'wide\']/quarter', 'type');
  412. $temp['stand-alone']['abbreviated'] = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/quarters/quarterContext[@type=\'stand-alone\']/quarterWidth[@type=\'abbreviated\']/quarter', 'type');
  413. $temp['stand-alone']['narrow'] = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/quarters/quarterContext[@type=\'stand-alone\']/quarterWidth[@type=\'narrow\']/quarter', 'type');
  414. $temp['stand-alone']['wide'] = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/quarters/quarterContext[@type=\'stand-alone\']/quarterWidth[@type=\'wide\']/quarter', 'type');
  415. break;
  416. case 'quarter':
  417. if (empty($value)) {
  418. $value = array("gregorian", "format", "wide");
  419. }
  420. $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value[0] . '\']/quarters/quarterContext[@type=\'' . $value[1] . '\']/quarterWidth[@type=\'' . $value[2] . '\']/quarter', 'type');
  421. break;
  422. case 'eras':
  423. if (empty($value)) {
  424. $value = "gregorian";
  425. }
  426. $temp['names'] = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/eras/eraNames/era', 'type');
  427. $temp['abbreviated'] = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/eras/eraAbbr/era', 'type');
  428. $temp['narrow'] = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/eras/eraNarrow/era', 'type');
  429. break;
  430. case 'era':
  431. if (empty($value)) {
  432. $value = array("gregorian", "Abbr");
  433. }
  434. $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value[0] . '\']/eras/era' . $value[1] . '/era', 'type');
  435. break;
  436. case 'date':
  437. if (empty($value)) {
  438. $value = "gregorian";
  439. }
  440. $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/dateFormats/dateFormatLength[@type=\'full\']/dateFormat/pattern', '', 'full');
  441. $temp += self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/dateFormats/dateFormatLength[@type=\'long\']/dateFormat/pattern', '', 'long');
  442. $temp += self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/dateFormats/dateFormatLength[@type=\'medium\']/dateFormat/pattern', '', 'medium');
  443. $temp += self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/dateFormats/dateFormatLength[@type=\'short\']/dateFormat/pattern', '', 'short');
  444. break;
  445. case 'time':
  446. if (empty($value)) {
  447. $value = "gregorian";
  448. }
  449. $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/timeFormats/timeFormatLength[@type=\'full\']/timeFormat/pattern', '', 'full');
  450. $temp += self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/timeFormats/timeFormatLength[@type=\'long\']/timeFormat/pattern', '', 'long');
  451. $temp += self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/timeFormats/timeFormatLength[@type=\'medium\']/timeFormat/pattern', '', 'medium');
  452. $temp += self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/timeFormats/timeFormatLength[@type=\'short\']/timeFormat/pattern', '', 'short');
  453. break;
  454. case 'datetime':
  455. if (empty($value)) {
  456. $value = "gregorian";
  457. }
  458. $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/dateTimeFormats/availableFormats/dateFormatItem', 'id');
  459. break;
  460. case 'field':
  461. if (empty($value)) {
  462. $value = "gregorian";
  463. }
  464. $temp2 = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/fields/field', 'type');
  465. foreach ($temp2 as $key => $keyvalue) {
  466. $temp += self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/fields/field[@type=\'' . $key . '\']/displayName', '', $key);
  467. }
  468. break;
  469. case 'relative':
  470. if (empty($value)) {
  471. $value = "gregorian";
  472. }
  473. $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/fields/field/relative', 'type');
  474. break;
  475. case 'symbols':
  476. $temp = self::_getFile($locale, '/ldml/numbers/symbols/decimal', '', 'decimal');
  477. $temp += self::_getFile($locale, '/ldml/numbers/symbols/group', '', 'group');
  478. $temp += self::_getFile($locale, '/ldml/numbers/symbols/list', '', 'list');
  479. $temp += self::_getFile($locale, '/ldml/numbers/symbols/percentSign', '', 'percent');
  480. $temp += self::_getFile($locale, '/ldml/numbers/symbols/nativeZeroDigit', '', 'zero');
  481. $temp += self::_getFile($locale, '/ldml/numbers/symbols/patternDigit', '', 'pattern');
  482. $temp += self::_getFile($locale, '/ldml/numbers/symbols/plusSign', '', 'plus');
  483. $temp += self::_getFile($locale, '/ldml/numbers/symbols/minusSign', '', 'minus');
  484. $temp += self::_getFile($locale, '/ldml/numbers/symbols/exponential', '', 'exponent');
  485. $temp += self::_getFile($locale, '/ldml/numbers/symbols/perMille', '', 'mille');
  486. $temp += self::_getFile($locale, '/ldml/numbers/symbols/infinity', '', 'infinity');
  487. $temp += self::_getFile($locale, '/ldml/numbers/symbols/nan', '', 'nan');
  488. break;
  489. case 'nametocurrency':
  490. $_temp = self::_getFile($locale, '/ldml/numbers/currencies/currency', 'type');
  491. foreach ($_temp as $key => $found) {
  492. $temp += self::_getFile($locale, '/ldml/numbers/currencies/currency[@type=\'' . $key . '\']/displayName', '', $key);
  493. }
  494. break;
  495. case 'currencytoname':
  496. $_temp = self::_getFile($locale, '/ldml/numbers/currencies/currency', 'type');
  497. foreach ($_temp as $key => $keyvalue) {
  498. $val = self::_getFile($locale, '/ldml/numbers/currencies/currency[@type=\'' . $key . '\']/displayName', '', $key);
  499. if (!isset($val[$key])) {
  500. continue;
  501. }
  502. if (!isset($temp[$val[$key]])) {
  503. $temp[$val[$key]] = $key;
  504. } else {
  505. $temp[$val[$key]] .= " " . $key;
  506. }
  507. }
  508. break;
  509. case 'currencysymbol':
  510. $_temp = self::_getFile($locale, '/ldml/numbers/currencies/currency', 'type');
  511. foreach ($_temp as $key => $found) {
  512. $temp += self::_getFile($locale, '/ldml/numbers/currencies/currency[@type=\'' . $key . '\']/symbol', '', $key);
  513. }
  514. break;
  515. case 'question':
  516. $temp = self::_getFile($locale, '/ldml/posix/messages/yesstr', '', 'yes');
  517. $temp += self::_getFile($locale, '/ldml/posix/messages/nostr', '', 'no');
  518. break;
  519. case 'currencyfraction':
  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 . '\']', 'digits', $key);
  523. }
  524. break;
  525. case 'currencyrounding':
  526. $_temp = self::_getFile('supplementalData', '/supplementalData/currencyData/fractions/info', 'iso4217');
  527. foreach ($_temp as $key => $found) {
  528. $temp += self::_getFile('supplementalData', '/supplementalData/currencyData/fractions/info[@iso4217=\'' . $key . '\']', 'rounding', $key);
  529. }
  530. break;
  531. case 'currencytoregion':
  532. $_temp = self::_getFile('supplementalData', '/supplementalData/currencyData/region', 'iso3166');
  533. foreach ($_temp as $key => $keyvalue) {
  534. $temp += self::_getFile('supplementalData', '/supplementalData/currencyData/region[@iso3166=\'' . $key . '\']/currency', 'iso4217', $key);
  535. }
  536. break;
  537. case 'regiontocurrency':
  538. $_temp = self::_getFile('supplementalData', '/supplementalData/currencyData/region', 'iso3166');
  539. foreach ($_temp as $key => $keyvalue) {
  540. $val = self::_getFile('supplementalData', '/supplementalData/currencyData/region[@iso3166=\'' . $key . '\']/currency', 'iso4217', $key);
  541. if (!isset($val[$key])) {
  542. continue;
  543. }
  544. if (!isset($temp[$val[$key]])) {
  545. $temp[$val[$key]] = $key;
  546. } else {
  547. $temp[$val[$key]] .= " " . $key;
  548. }
  549. }
  550. break;
  551. case 'regiontoterritory':
  552. $_temp = self::_getFile('supplementalData', '/supplementalData/territoryContainment/group', 'type');
  553. foreach ($_temp as $key => $found) {
  554. $temp += self::_getFile('supplementalData', '/supplementalData/territoryContainment/group[@type=\'' . $key . '\']', 'contains', $key);
  555. }
  556. break;
  557. case 'territorytoregion':
  558. $_temp2 = self::_getFile('supplementalData', '/supplementalData/territoryContainment/group', 'type');
  559. $_temp = array();
  560. foreach ($_temp2 as $key => $found) {
  561. $_temp += self::_getFile('supplementalData', '/supplementalData/territoryContainment/group[@type=\'' . $key . '\']', 'contains', $key);
  562. }
  563. foreach($_temp as $key => $found) {
  564. $_temp3 = explode(" ", $found);
  565. foreach($_temp3 as $found3) {
  566. if (!isset($temp[$found3])) {
  567. $temp[$found3] = (string) $key;
  568. } else {
  569. $temp[$found3] .= " " . $key;
  570. }
  571. }
  572. }
  573. break;
  574. case 'scripttolanguage':
  575. $_temp = self::_getFile('supplementalData', '/supplementalData/languageData/language', 'type');
  576. foreach ($_temp as $key => $found) {
  577. $temp += self::_getFile('supplementalData', '/supplementalData/languageData/language[@type=\'' . $key . '\']', 'scripts', $key);
  578. if (empty($temp[$key])) {
  579. unset($temp[$key]);
  580. }
  581. }
  582. break;
  583. case 'languagetoscript':
  584. $_temp2 = self::_getFile('supplementalData', '/supplementalData/languageData/language', 'type');
  585. $_temp = array();
  586. foreach ($_temp2 as $key => $found) {
  587. $_temp += self::_getFile('supplementalData', '/supplementalData/languageData/language[@type=\'' . $key . '\']', 'scripts', $key);
  588. }
  589. foreach($_temp as $key => $found) {
  590. $_temp3 = explode(" ", $found);
  591. foreach($_temp3 as $found3) {
  592. if (empty($found3)) {
  593. continue;
  594. }
  595. if (!isset($temp[$found3])) {
  596. $temp[$found3] = (string) $key;
  597. } else {
  598. $temp[$found3] .= " " . $key;
  599. }
  600. }
  601. }
  602. break;
  603. case 'territorytolanguage':
  604. $_temp = self::_getFile('supplementalData', '/supplementalData/languageData/language', 'type');
  605. foreach ($_temp as $key => $found) {
  606. $temp += self::_getFile('supplementalData', '/supplementalData/languageData/language[@type=\'' . $key . '\']', 'territories', $key);
  607. if (empty($temp[$key])) {
  608. unset($temp[$key]);
  609. }
  610. }
  611. break;
  612. case 'languagetoterritory':
  613. $_temp2 = self::_getFile('supplementalData', '/supplementalData/languageData/language', 'type');
  614. $_temp = array();
  615. foreach ($_temp2 as $key => $found) {
  616. $_temp += self::_getFile('supplementalData', '/supplementalData/languageData/language[@type=\'' . $key . '\']', 'territories', $key);
  617. }
  618. foreach($_temp as $key => $found) {
  619. $_temp3 = explode(" ", $found);
  620. foreach($_temp3 as $found3) {
  621. if (empty($found3)) {
  622. continue;
  623. }
  624. if (!isset($temp[$found3])) {
  625. $temp[$found3] = (string) $key;
  626. } else {
  627. $temp[$found3] .= " " . $key;
  628. }
  629. }
  630. }
  631. break;
  632. case 'timezonetowindows':
  633. $_temp = self::_getFile('supplementalData', '/supplementalData/timezoneData/mapTimezones[@type=\'windows\']/mapZone', 'other');
  634. foreach ($_temp as $key => $found) {
  635. $temp += self::_getFile('supplementalData', '/supplementalData/timezoneData/mapTimezones[@type=\'windows\']/mapZone[@other=\'' . $key . '\']', 'type', $key);
  636. }
  637. break;
  638. case 'windowstotimezone':
  639. $_temp = self::_getFile('supplementalData', '/supplementalData/timezoneData/mapTimezones[@type=\'windows\']/mapZone', 'type');
  640. foreach ($_temp as $key => $found) {
  641. $temp += self::_getFile('supplementalData', '/supplementalData/timezoneData/mapTimezones[@type=\'windows\']/mapZone[@type=\'' .$key . '\']', 'other', $key);
  642. }
  643. break;
  644. case 'territorytotimezone':
  645. $_temp = self::_getFile('supplementalData', '/supplementalData/timezoneData/zoneFormatting/zoneItem', 'type');
  646. foreach ($_temp as $key => $found) {
  647. $temp += self::_getFile('supplementalData', '/supplementalData/timezoneData/zoneFormatting/zoneItem[@type=\'' . $key . '\']', 'territory', $key);
  648. }
  649. break;
  650. case 'timezonetoterritory':
  651. $_temp = self::_getFile('supplementalData', '/supplementalData/timezoneData/zoneFormatting/zoneItem', 'territory');
  652. foreach ($_temp as $key => $found) {
  653. $temp += self::_getFile('supplementalData', '/supplementalData/timezoneData/zoneFormatting/zoneItem[@territory=\'' . $key . '\']', 'type', $key);
  654. }
  655. break;
  656. case 'citytotimezone':
  657. $_temp = self::_getFile($locale, '/ldml/dates/timeZoneNames/zone', 'type');
  658. foreach($_temp as $key => $found) {
  659. $temp += self::_getFile($locale, '/ldml/dates/timeZoneNames/zone[@type=\'' . $key . '\']/exemplarCity', '', $key);
  660. }
  661. break;
  662. case 'timezonetocity':
  663. $_temp = self::_getFile($locale, '/ldml/dates/timeZoneNames/zone', 'type');
  664. $temp = array();
  665. foreach($_temp as $key => $found) {
  666. $temp += self::_getFile($locale, '/ldml/dates/timeZoneNames/zone[@type=\'' . $key . '\']/exemplarCity', '', $key);
  667. if (!empty($temp[$key])) {
  668. $temp[$temp[$key]] = $key;
  669. }
  670. unset($temp[$key]);
  671. }
  672. break;
  673. case 'phonetoterritory':
  674. $_temp = self::_getFile('telephoneCodeData', '/supplementalData/telephoneCodeData/codesByTerritory', 'territory');
  675. foreach ($_temp as $key => $keyvalue) {
  676. $temp += self::_getFile('telephoneCodeData', '/supplementalData/telephoneCodeData/codesByTerritory[@territory=\'' . $key . '\']/telephoneCountryCode', 'code', $key);
  677. }
  678. break;
  679. case 'territorytophone':
  680. $_temp = self::_getFile('telephoneCodeData', '/supplementalData/telephoneCodeData/codesByTerritory', 'territory');
  681. foreach ($_temp as $key => $keyvalue) {
  682. $val = self::_getFile('telephoneCodeData', '/supplementalData/telephoneCodeData/codesByTerritory[@territory=\'' . $key . '\']/telephoneCountryCode', 'code', $key);
  683. if (!isset($val[$key])) {
  684. continue;
  685. }
  686. if (!isset($temp[$val[$key]])) {
  687. $temp[$val[$key]] = $key;
  688. } else {
  689. $temp[$val[$key]] .= " " . $key;
  690. }
  691. }
  692. break;
  693. case 'numerictoterritory':
  694. $_temp = self::_getFile('supplementalData', '/supplementalData/codeMappings/territoryCodes', 'type');
  695. foreach ($_temp as $key => $keyvalue) {
  696. $temp += self::_getFile('supplementalData', '/supplementalData/codeMappings/territoryCodes[@type=\'' . $key . '\']', 'numeric', $key);
  697. }
  698. break;
  699. case 'territorytonumeric':
  700. $_temp = self::_getFile('supplementalData', '/supplementalData/codeMappings/territoryCodes', 'numeric');
  701. foreach ($_temp as $key => $keyvalue) {
  702. $temp += self::_getFile('supplementalData', '/supplementalData/codeMappings/territoryCodes[@numeric=\'' . $key . '\']', 'type', $key);
  703. }
  704. break;
  705. case 'alpha3toterritory':
  706. $_temp = self::_getFile('supplementalData', '/supplementalData/codeMappings/territoryCodes', 'type');
  707. foreach ($_temp as $key => $keyvalue) {
  708. $temp += self::_getFile('supplementalData', '/supplementalData/codeMappings/territoryCodes[@type=\'' . $key . '\']', 'alpha3', $key);
  709. }
  710. break;
  711. case 'territorytoalpha3':
  712. $_temp = self::_getFile('supplementalData', '/supplementalData/codeMappings/territoryCodes', 'alpha3');
  713. foreach ($_temp as $key => $keyvalue) {
  714. $temp += self::_getFile('supplementalData', '/supplementalData/codeMappings/territoryCodes[@alpha3=\'' . $key . '\']', 'type', $key);
  715. }
  716. break;
  717. case 'postaltoterritory':
  718. $_temp = self::_getFile('postalCodeData', '/supplementalData/postalCodeData/postCodeRegex', 'territoryId');
  719. foreach ($_temp as $key => $keyvalue) {
  720. $temp += self::_getFile('postalCodeData', '/supplementalData/postalCodeData/postCodeRegex[@territoryId=\'' . $key . '\']', 'territoryId');
  721. }
  722. break;
  723. default :
  724. require_once 'Zend/Locale/Exception.php';
  725. throw new Zend_Locale_Exception("Unknown list ($path) for parsing locale data.");
  726. break;
  727. }
  728. if (isset(self::$_cache)) {
  729. self::$_cache->save( serialize($temp), $id);
  730. }
  731. return $temp;
  732. }
  733. /**
  734. * Read the LDML file, get a single path defined value
  735. *
  736. * @param string $locale
  737. * @param string $path
  738. * @param string $value
  739. * @return string
  740. * @access public
  741. */
  742. public static function getContent($locale, $path, $value = false)
  743. {
  744. $locale = self::_checkLocale($locale);
  745. if (!isset(self::$_cache)) {
  746. require_once 'Zend/Cache.php';
  747. self::$_cache = Zend_Cache::factory(
  748. 'Core',
  749. 'File',
  750. array('automatic_serialization' => true),
  751. array());
  752. }
  753. $val = $value;
  754. if (is_array($value)) {
  755. $val = implode('_' , $value);
  756. }
  757. $val = urlencode($val);
  758. $id = strtr('Zend_LocaleC_' . $locale . '_' . $path . '_' . $val, array('-' => '_', '%' => '_', '+' => '_'));
  759. if ($result = self::$_cache->load($id)) {
  760. return unserialize($result);
  761. }
  762. switch(strtolower($path)) {
  763. case 'language':
  764. $temp = self::_getFile($locale, '/ldml/localeDisplayNames/languages/language[@type=\'' . $value . '\']', 'type');
  765. break;
  766. case 'script':
  767. $temp = self::_getFile($locale, '/ldml/localeDisplayNames/scripts/script[@type=\'' . $value . '\']', 'type');
  768. break;
  769. case 'country':
  770. case 'territory':
  771. $temp = self::_getFile($locale, '/ldml/localeDisplayNames/territories/territory[@type=\'' . $value . '\']', 'type');
  772. break;
  773. case 'variant':
  774. $temp = self::_getFile($locale, '/ldml/localeDisplayNames/variants/variant[@type=\'' . $value . '\']', 'type');
  775. break;
  776. case 'key':
  777. $temp = self::_getFile($locale, '/ldml/localeDisplayNames/keys/key[@type=\'' . $value . '\']', 'type');
  778. break;
  779. case 'defaultcalendar':
  780. $temp = self::_getFile($locale, '/ldml/dates/calendars/default', 'choice', 'default');
  781. break;
  782. case 'monthcontext':
  783. if (empty ($value)) {
  784. $value = "gregorian";
  785. }
  786. $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/months/default', 'choice', 'context');
  787. break;
  788. case 'defaultmonth':
  789. if (empty ($value)) {
  790. $value = "gregorian";
  791. }
  792. $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/months/monthContext[@type=\'format\']/default', 'choice', 'default');
  793. break;
  794. case 'month':
  795. if (!is_array($value)) {
  796. $temp = $value;
  797. $value = array("gregorian", "format", "wide", $temp);
  798. }
  799. $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');
  800. break;
  801. case 'daycontext':
  802. if (empty($value)) {
  803. $value = "gregorian";
  804. }
  805. $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/days/default', 'choice', 'context');
  806. break;
  807. case 'defaultday':
  808. if (empty($value)) {
  809. $value = "gregorian";
  810. }
  811. $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/days/dayContext[@type=\'format\']/default', 'choice', 'default');
  812. break;
  813. case 'day':
  814. if (!is_array($value)) {
  815. $temp = $value;
  816. $value = array("gregorian", "format", "wide", $temp);
  817. }
  818. $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');
  819. break;
  820. case 'quarter':
  821. if (!is_array($value)) {
  822. $temp = $value;
  823. $value = array("gregorian", "format", "wide", $temp);
  824. }
  825. $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');
  826. break;
  827. case 'am':
  828. if (empty($value)) {
  829. $value = "gregorian";
  830. }
  831. $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/am', '', 'am');
  832. break;
  833. case 'pm':
  834. if (empty($value)) {
  835. $value = "gregorian";
  836. }
  837. $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/pm', '', 'pm');
  838. break;
  839. case 'era':
  840. if (!is_array($value)) {
  841. $temp = $value;
  842. $value = array("gregorian", "Abbr", $temp);
  843. }
  844. $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value[0] . '\']/eras/era' . $value[1] . '/era[@type=\'' . $value[2] . '\']', 'type');
  845. break;
  846. case 'defaultdate':
  847. if (empty($value)) {
  848. $value = "gregorian";
  849. }
  850. $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/dateFormats/default', 'choice', 'default');
  851. break;
  852. case 'date':
  853. if (empty($value)) {
  854. $value = array("gregorian", "medium");
  855. }
  856. if (!is_array($value)) {
  857. $temp = $value;
  858. $value = array("gregorian", $temp);
  859. }
  860. $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value[0] . '\']/dateFormats/dateFormatLength[@type=\'' . $value[1] . '\']/dateFormat/pattern', '', 'pattern');
  861. break;
  862. case 'defaulttime':
  863. if (empty($value)) {
  864. $value = "gregorian";
  865. }
  866. $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/timeFormats/default', 'choice', 'default');
  867. break;
  868. case 'time':
  869. if (empty($value)) {
  870. $value = array("gregorian", "medium");
  871. }
  872. if (!is_array($value)) {
  873. $temp = $value;
  874. $value = array("gregorian", $temp);
  875. }
  876. $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value[0] . '\']/timeFormats/timeFormatLength[@type=\'' . $value[1] . '\']/timeFormat/pattern', '', 'pattern');
  877. break;
  878. case 'datetime':
  879. if (empty($value)) {
  880. $value = "gregorian";
  881. }
  882. $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/dateTimeFormats/dateTimeFormatLength/dateTimeFormat/pattern', '', 'pattern');
  883. break;
  884. case 'field':
  885. if (!is_array($value)) {
  886. $temp = $value;
  887. $value = array("gregorian", $temp);
  888. }
  889. $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value[0] . '\']/fields/field[@type=\'' . $value[1] . '\']/displayName', '', $value[1]);
  890. break;
  891. case 'relative':
  892. if (!is_array($value)) {
  893. $temp = $value;
  894. $value = array("gregorian", $temp);
  895. }
  896. $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value[0] . '\']/fields/field/relative[@type=\'' . $value[1] . '\']', '', $value[1]);
  897. break;
  898. case 'decimalnumber':
  899. $temp = self::_getFile($locale, '/ldml/numbers/decimalFormats/decimalFormatLength/decimalFormat/pattern', '', 'default');
  900. break;
  901. case 'scientificnumber':
  902. $temp = self::_getFile($locale, '/ldml/numbers/scientificFormats/scientificFormatLength/scientificFormat/pattern', '', 'default');
  903. break;
  904. case 'percentnumber':
  905. $temp = self::_getFile($locale, '/ldml/numbers/percentFormats/percentFormatLength/percentFormat/pattern', '', 'default');
  906. break;
  907. case 'currencynumber':
  908. $temp = self::_getFile($locale, '/ldml/numbers/currencyFormats/currencyFormatLength/currencyFormat/pattern', '', 'default');
  909. break;
  910. case 'nametocurrency':
  911. $temp = self::_getFile($locale, '/ldml/numbers/currencies/currency[@type=\'' . $value . '\']/displayName', '', $value);
  912. break;
  913. case 'currencytoname':
  914. $temp = self::_getFile($locale, '/ldml/numbers/currencies/currency[@type=\'' . $value . '\']/displayName', '', $value);
  915. $_temp = self::_getFile($locale, '/ldml/numbers/currencies/currency', 'type');
  916. $temp = array();
  917. foreach ($_temp as $key => $keyvalue) {
  918. $val = self::_getFile($locale, '/ldml/numbers/currencies/currency[@type=\'' . $key . '\']/displayName', '', $key);
  919. if (!isset($val[$key]) or ($val[$key] != $value)) {
  920. continue;
  921. }
  922. if (!isset($temp[$val[$key]])) {
  923. $temp[$val[$key]] = $key;
  924. } else {
  925. $temp[$val[$key]] .= " " . $key;
  926. }
  927. }
  928. break;
  929. case 'currencysymbol':
  930. $temp = self::_getFile($locale, '/ldml/numbers/currencies/currency[@type=\'' . $value . '\']/symbol', '', $value);
  931. break;
  932. case 'question':
  933. $temp = self::_getFile($locale, '/ldml/posix/messages/' . $value . 'str', '', $value);
  934. break;
  935. case 'currencyfraction':
  936. if (empty($value)) {
  937. $value = "DEFAULT";
  938. }
  939. $temp = self::_getFile('supplementalData', '/supplementalData/currencyData/fractions/info[@iso4217=\'' . $value . '\']', 'digits', 'digits');
  940. break;
  941. case 'currencyrounding':
  942. if (empty($value)) {
  943. $value = "DEFAULT";
  944. }
  945. $temp = self::_getFile('supplementalData', '/supplementalData/currencyData/fractions/info[@iso4217=\'' . $value . '\']', 'rounding', 'rounding');
  946. break;
  947. case 'currencytoregion':
  948. $temp = self::_getFile('supplementalData', '/supplementalData/currencyData/region[@iso3166=\'' . $value . '\']/currency', 'iso4217', $value);
  949. break;
  950. case 'regiontocurrency':
  951. $_temp = self::_getFile('supplementalData', '/supplementalData/currencyData/region', 'iso3166');
  952. $temp = array();
  953. foreach ($_temp as $key => $keyvalue) {
  954. $val = self::_getFile('supplementalData', '/supplementalData/currencyData/region[@iso3166=\'' . $key . '\']/currency', 'iso4217', $key);
  955. if (!isset($val[$key]) or ($val[$key] != $value)) {
  956. continue;
  957. }
  958. if (!isset($temp[$val[$key]])) {
  959. $temp[$val[$key]] = $key;
  960. } else {
  961. $temp[$val[$key]] .= " " . $key;
  962. }
  963. }
  964. break;
  965. case 'regiontoterritory':
  966. $temp = self::_getFile('supplementalData', '/supplementalData/territoryContainment/group[@type=\'' . $value . '\']', 'contains', $value);
  967. break;
  968. case 'territorytoregion':
  969. $_temp2 = self::_getFile('supplementalData', '/supplementalData/territoryContainment/group', 'type');
  970. $_temp = array();
  971. foreach ($_temp2 as $key => $found) {
  972. $_temp += self::_getFile('supplementalData', '/supplementalData/territoryContainment/group[@type=\'' . $key . '\']', 'contains', $key);
  973. }
  974. $temp = array();
  975. foreach($_temp as $key => $found) {
  976. $_temp3 = explode(" ", $found);
  977. foreach($_temp3 as $found3) {
  978. if ($found3 !== $value) {
  979. continue;
  980. }
  981. if (!isset($temp[$found3])) {
  982. $temp[$found3] = (string) $key;
  983. } else {
  984. $temp[$found3] .= " " . $key;
  985. }
  986. }
  987. }
  988. break;
  989. case 'scripttolanguage':
  990. $temp = self::_getFile('supplementalData', '/supplementalData/languageData/language[@type=\'' . $value . '\']', 'scripts', $value);
  991. break;
  992. case 'languagetoscript':
  993. $_temp2 = self::_getFile('supplementalData', '/supplementalData/languageData/language', 'type');
  994. $_temp = array();
  995. foreach ($_temp2 as $key => $found) {
  996. $_temp += self::_getFile('supplementalData', '/supplementalData/languageData/language[@type=\'' . $key . '\']', 'scripts', $key);
  997. }
  998. $temp = array();
  999. foreach($_temp as $key => $found) {
  1000. $_temp3 = explode(" ", $found);
  1001. foreach($_temp3 as $found3) {
  1002. if ($found3 !== $value) {
  1003. continue;
  1004. }
  1005. if (!isset($temp[$found3])) {
  1006. $temp[$found3] = (string) $key;
  1007. } else {
  1008. $temp[$found3] .= " " . $key;
  1009. }
  1010. }
  1011. }
  1012. break;
  1013. case 'territorytolanguage':
  1014. $temp = self::_getFile('supplementalData', '/supplementalData/languageData/language[@type=\'' . $value . '\']', 'territories', $value);
  1015. break;
  1016. case 'languagetoterritory':
  1017. $_temp2 = self::_getFile('supplementalData', '/supplementalData/languageData/language', 'type');
  1018. $_temp = array();
  1019. foreach ($_temp2 as $key => $found) {
  1020. $_temp += self::_getFile('supplementalData', '/supplementalData/languageData/language[@type=\'' . $key . '\']', 'territories', $key);
  1021. }
  1022. $temp = array();
  1023. foreach($_temp as $key => $found) {
  1024. $_temp3 = explode(" ", $found);
  1025. foreach($_temp3 as $found3) {
  1026. if ($found3 !== $value) {
  1027. continue;
  1028. }
  1029. if (!isset($temp[$found3])) {
  1030. $temp[$found3] = (string) $key;
  1031. } else {
  1032. $temp[$found3] .= " " . $key;
  1033. }
  1034. }
  1035. }
  1036. break;
  1037. case 'timezonetowindows':
  1038. $temp = self::_getFile('supplementalData', '/supplementalData/timezoneData/mapTimezones[@type=\'windows\']/mapZone[@other=\''.$value.'\']', 'type', $value);
  1039. break;
  1040. case 'windowstotimezone':
  1041. $temp = self::_getFile('supplementalData', '/supplementalData/timezoneData/mapTimezones[@type=\'windows\']/mapZone[@type=\''.$value.'\']', 'other', $value);
  1042. break;
  1043. case 'territorytotimezone':
  1044. $temp = self::_getFile('supplementalData', '/supplementalData/timezoneData/zoneFormatting/zoneItem[@type=\'' . $value . '\']', 'territory', $value);
  1045. break;
  1046. case 'timezonetoterritory':
  1047. $temp = self::_getFile('supplementalData', '/supplementalData/timezoneData/zoneFormatting/zoneItem[@territory=\'' . $value . '\']', 'type', $value);
  1048. break;
  1049. case 'citytotimezone':
  1050. $temp = self::_getFile($locale, '/ldml/dates/timeZoneNames/zone[@type=\'' . $value . '\']/exemplarCity', '', $value);
  1051. break;
  1052. case 'timezonetocity':
  1053. $_temp = self::_getFile($locale, '/ldml/dates/timeZoneNames/zone', 'type');
  1054. $temp = array();
  1055. foreach($_temp as $key => $found) {
  1056. $temp += self::_getFile($locale, '/ldml/dates/timeZoneNames/zone[@type=\'' . $key . '\']/exemplarCity', '', $key);
  1057. if (!empty($temp[$key])) {
  1058. if ($temp[$key] == $value) {
  1059. $temp[$temp[$key]] = $key;
  1060. }
  1061. }
  1062. unset($temp[$key]);
  1063. }
  1064. break;
  1065. case 'phonetoterritory':
  1066. $temp = self::_getFile('telephoneCodeData', '/supplementalData/telephoneCodeData/codesByTerritory[@territory=\'' . $value . '\']/telephoneCountryCode', 'code', $value);
  1067. break;
  1068. case 'territorytophone':
  1069. $_temp2 = self::_getFile('telephoneCodeData', '/supplementalData/telephoneCodeData/codesByTerritory', 'territory');
  1070. $_temp = array();
  1071. foreach ($_temp2 as $key => $found) {
  1072. $_temp += self::_getFile('telephoneCodeData', '/supplementalData/telephoneCodeData/codesByTerritory[@territory=\'' . $key . '\']/telephoneCountryCode', 'code', $key);
  1073. }
  1074. $temp = array();
  1075. foreach($_temp as $key => $found) {
  1076. $_temp3 = explode(" ", $found);
  1077. foreach($_temp3 as $found3) {
  1078. if ($found3 !== $value) {
  1079. continue;
  1080. }
  1081. if (!isset($temp[$found3])) {
  1082. $temp[$found3] = (string) $key;
  1083. } else {
  1084. $temp[$found3] .= " " . $key;
  1085. }
  1086. }
  1087. }
  1088. break;
  1089. case 'numerictoterritory':
  1090. $temp = self::_getFile('supplementalData', '/supplementalData/codeMappings/territoryCodes[@type=\''.$value.'\']', 'numeric', $value);
  1091. break;
  1092. case 'territorytonumeric':
  1093. $temp = self::_getFile('supplementalData', '/supplementalData/codeMappings/territoryCodes[@numeric=\''.$value.'\']', 'type', $value);
  1094. break;
  1095. case 'alpha3toterritory':
  1096. $temp = self::_getFile('supplementalData', '/supplementalData/codeMappings/territoryCodes[@type=\''.$value.'\']', 'alpha3', $value);
  1097. break;
  1098. case 'territorytoalpha3':
  1099. $temp = self::_getFile('supplementalData', '/supplementalData/codeMappings/territoryCodes[@alpha3=\''.$value.'\']', 'type', $value);
  1100. break;
  1101. case 'postaltoterritory':
  1102. $temp = self::_getFile('postalCodeData', '/supplementalData/postalCodeData/postCodeRegex[@territoryId=\'' . $value . '\']', 'territoryId');
  1103. break;
  1104. default :
  1105. require_once 'Zend/Locale/Exception.php';
  1106. throw new Zend_Locale_Exception("Unknown detail ($path) for parsing locale data.");
  1107. break;
  1108. }
  1109. if (is_array($temp)) {
  1110. $temp = current($temp);
  1111. }
  1112. if (isset(self::$_cache)) {
  1113. self::$_cache->save( serialize($temp), $id);
  1114. }
  1115. return $temp;
  1116. }
  1117. /**
  1118. * Returns the set cache
  1119. *
  1120. * @return Zend_Cache_Core The set cache
  1121. */
  1122. public static function getCache()
  1123. {
  1124. return self::$_cache;
  1125. }
  1126. /**
  1127. * Set a cache for Zend_Locale_Data
  1128. *
  1129. * @param Zend_Cache_Core $cache A cache frontend
  1130. */
  1131. public static function setCache(Zend_Cache_Core $cache)
  1132. {
  1133. self::$_cache = $cache;
  1134. }
  1135. /**
  1136. * Returns true when a cache is set
  1137. *
  1138. * @return boolean
  1139. */
  1140. public static function hasCache()
  1141. {
  1142. if (self::$_cache !== null) {
  1143. return true;
  1144. }
  1145. return false;
  1146. }
  1147. /**
  1148. * Removes any set cache
  1149. *
  1150. * @return void
  1151. */
  1152. public static function removeCache()
  1153. {
  1154. self::$_cache = null;
  1155. }
  1156. /**
  1157. * Clears all set cache data
  1158. *
  1159. * @return void
  1160. */
  1161. public static function clearCache()
  1162. {
  1163. self::$_cache->clean();
  1164. }
  1165. }