Data.php 66 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395
  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. * Internal option, cache disabled
  60. *
  61. * @var boolean
  62. * @access private
  63. */
  64. private static $_cacheDisabled = false;
  65. /**
  66. * Read the content from locale
  67. *
  68. * Can be called like:
  69. * <ldml>
  70. * <delimiter>test</delimiter>
  71. * <second type='myone'>content</second>
  72. * <second type='mysecond'>content2</second>
  73. * <third type='mythird' />
  74. * </ldml>
  75. *
  76. * Case 1: _readFile('ar','/ldml/delimiter') -> returns [] = test
  77. * Case 1: _readFile('ar','/ldml/second[@type=myone]') -> returns [] = content
  78. * Case 2: _readFile('ar','/ldml/second','type') -> returns [myone] = content; [mysecond] = content2
  79. * Case 3: _readFile('ar','/ldml/delimiter',,'right') -> returns [right] = test
  80. * Case 4: _readFile('ar','/ldml/third','type','myone') -> returns [myone] = mythird
  81. *
  82. * @param string $locale
  83. * @param string $path
  84. * @param string $attribute
  85. * @param string $value
  86. * @access private
  87. * @return array
  88. */
  89. private static function _readFile($locale, $path, $attribute, $value, $temp)
  90. {
  91. // without attribute - read all values
  92. // with attribute - read only this value
  93. if (!empty(self::$_ldml[(string) $locale])) {
  94. $result = self::$_ldml[(string) $locale]->xpath($path);
  95. if (!empty($result)) {
  96. foreach ($result as &$found) {
  97. if (empty($value)) {
  98. if (empty($attribute)) {
  99. // Case 1
  100. $temp[] = (string) $found;
  101. } else if (empty($temp[(string) $found[$attribute]])){
  102. // Case 2
  103. $temp[(string) $found[$attribute]] = (string) $found;
  104. }
  105. } else if (empty ($temp[$value])) {
  106. if (empty($attribute)) {
  107. // Case 3
  108. $temp[$value] = (string) $found;
  109. } else {
  110. // Case 4
  111. $temp[$value] = (string) $found[$attribute];
  112. }
  113. }
  114. }
  115. }
  116. }
  117. return $temp;
  118. }
  119. /**
  120. * Find possible routing to other path or locale
  121. *
  122. * @param string $locale
  123. * @param string $path
  124. * @param string $attribute
  125. * @param string $value
  126. * @param array $temp
  127. * @throws Zend_Locale_Exception
  128. * @access private
  129. */
  130. private static function _findRoute($locale, $path, $attribute, $value, &$temp)
  131. {
  132. // load locale file if not already in cache
  133. // needed for alias tag when referring to other locale
  134. if (empty(self::$_ldml[(string) $locale])) {
  135. $filename = dirname(__FILE__) . '/Data/' . $locale . '.xml';
  136. if (!file_exists($filename)) {
  137. require_once 'Zend/Locale/Exception.php';
  138. throw new Zend_Locale_Exception("Missing locale file '$filename' for '$locale' locale.");
  139. }
  140. self::$_ldml[(string) $locale] = simplexml_load_file($filename);
  141. }
  142. // search for 'alias' tag in the search path for redirection
  143. $search = '';
  144. $tok = strtok($path, '/');
  145. // parse the complete path
  146. if (!empty(self::$_ldml[(string) $locale])) {
  147. while ($tok !== false) {
  148. $search .= '/' . $tok;
  149. if (strpos($search, '[@') !== false) {
  150. while (strrpos($search, '[@') > strrpos($search, ']')) {
  151. $tok = strtok('/');
  152. if (empty($tok)) {
  153. $search .= '/';
  154. }
  155. $search = $search . '/' . $tok;
  156. }
  157. }
  158. $result = self::$_ldml[(string) $locale]->xpath($search . '/alias');
  159. // alias found
  160. if (!empty($result)) {
  161. $source = $result[0]['source'];
  162. $newpath = $result[0]['path'];
  163. // new path - path //ldml is to ignore
  164. if ($newpath != '//ldml') {
  165. // other path - parse to make real path
  166. while (substr($newpath,0,3) == '../') {
  167. $newpath = substr($newpath, 3);
  168. $search = substr($search, 0, strrpos($search, '/'));
  169. }
  170. // truncate ../ to realpath otherwise problems with alias
  171. $path = $search . '/' . $newpath;
  172. while (($tok = strtok('/'))!== false) {
  173. $path = $path . '/' . $tok;
  174. }
  175. }
  176. // reroute to other locale
  177. if ($source != 'locale') {
  178. $locale = $source;
  179. }
  180. $temp = self::_getFile($locale, $path, $attribute, $value, $temp);
  181. return false;
  182. }
  183. $tok = strtok('/');
  184. }
  185. }
  186. return true;
  187. }
  188. /**
  189. * Read the right LDML file
  190. *
  191. * @param string $locale
  192. * @param string $path
  193. * @param string $attribute
  194. * @param string $value
  195. * @access private
  196. */
  197. private static function _getFile($locale, $path, $attribute = false, $value = false, $temp = array())
  198. {
  199. $result = self::_findRoute($locale, $path, $attribute, $value, $temp);
  200. if ($result) {
  201. $temp = self::_readFile($locale, $path, $attribute, $value, $temp);
  202. }
  203. // parse required locales reversive
  204. // example: when given zh_Hans_CN
  205. // 1. -> zh_Hans_CN
  206. // 2. -> zh_Hans
  207. // 3. -> zh
  208. // 4. -> root
  209. if (($locale != 'root') && ($result)) {
  210. $locale = substr($locale, 0, -strlen(strrchr($locale, '_')));
  211. if (!empty($locale)) {
  212. $temp = self::_getFile($locale, $path, $attribute, $value, $temp);
  213. } else {
  214. $temp = self::_getFile('root', $path, $attribute, $value, $temp);
  215. }
  216. }
  217. return $temp;
  218. }
  219. /**
  220. * Find the details for supplemental calendar datas
  221. *
  222. * @param string $locale Locale for Detaildata
  223. * @param array $list List to search
  224. * @return string Key for Detaildata
  225. */
  226. private static function _calendarDetail($locale, $list)
  227. {
  228. $ret = "001";
  229. foreach ($list as $key => $value) {
  230. if (strpos($locale, '_') !== false) {
  231. $locale = substr($locale, strpos($locale, '_') + 1);
  232. }
  233. if (strpos($key, $locale) !== false) {
  234. $ret = $key;
  235. break;
  236. }
  237. }
  238. return $ret;
  239. }
  240. /**
  241. * Internal function for checking the locale
  242. *
  243. * @param string|Zend_Locale $locale Locale to check
  244. * @return string
  245. */
  246. private static function _checkLocale($locale)
  247. {
  248. if (empty($locale)) {
  249. $locale = new Zend_Locale();
  250. }
  251. if (!(Zend_Locale::isLocale((string) $locale, null, false))) {
  252. require_once 'Zend/Locale/Exception.php';
  253. throw new Zend_Locale_Exception("Locale (" . (string) $locale . ") is a unknown locale");
  254. }
  255. return (string) $locale;
  256. }
  257. /**
  258. * Read the LDML file, get a array of multipath defined value
  259. *
  260. * @param string $locale
  261. * @param string $path
  262. * @param string $value
  263. * @return array
  264. * @access public
  265. */
  266. public static function getList($locale, $path, $value = false)
  267. {
  268. $locale = self::_checkLocale($locale);
  269. if (!isset(self::$_cache) && !self::$_cacheDisabled) {
  270. require_once 'Zend/Cache.php';
  271. self::$_cache = Zend_Cache::factory(
  272. 'Core',
  273. 'File',
  274. array('automatic_serialization' => true),
  275. array());
  276. }
  277. $val = $value;
  278. if (is_array($value)) {
  279. $val = implode('_' , $value);
  280. }
  281. $val = urlencode($val);
  282. $id = strtr('Zend_LocaleL_' . $locale . '_' . $path . '_' . $val, array('-' => '_', '%' => '_', '+' => '_'));
  283. if (!self::$_cacheDisabled && ($result = self::$_cache->load($id))) {
  284. return unserialize($result);
  285. }
  286. $temp = array();
  287. switch(strtolower($path)) {
  288. case 'language':
  289. $temp = self::_getFile($locale, '/ldml/localeDisplayNames/languages/language', 'type');
  290. break;
  291. case 'script':
  292. $temp = self::_getFile($locale, '/ldml/localeDisplayNames/scripts/script', 'type');
  293. break;
  294. case 'territory':
  295. $temp = self::_getFile($locale, '/ldml/localeDisplayNames/territories/territory', 'type');
  296. if ($value === 1) {
  297. foreach($temp as $key => $value) {
  298. if ((is_numeric($key) === false) and ($key != 'QO') and ($key != 'QU')) {
  299. unset($temp[$key]);
  300. }
  301. }
  302. } else if ($value === 2) {
  303. foreach($temp as $key => $value) {
  304. if (is_numeric($key) or ($key == 'QO') or ($key == 'QU')) {
  305. unset($temp[$key]);
  306. }
  307. }
  308. }
  309. break;
  310. case 'variant':
  311. $temp = self::_getFile($locale, '/ldml/localeDisplayNames/variants/variant', 'type');
  312. break;
  313. case 'key':
  314. $temp = self::_getFile($locale, '/ldml/localeDisplayNames/keys/key', 'type');
  315. break;
  316. case 'type':
  317. if (empty($type)) {
  318. $temp = self::_getFile($locale, '/ldml/localeDisplayNames/types/type', 'type');
  319. } else {
  320. if (($value == 'calendar') or
  321. ($value == 'collation') or
  322. ($value == 'currency')) {
  323. $temp = self::_getFile($locale, '/ldml/localeDisplayNames/types/type[@key=\'' . $value . '\']', 'type');
  324. } else {
  325. $temp = self::_getFile($locale, '/ldml/localeDisplayNames/types/type[@type=\'' . $value . '\']', 'type');
  326. }
  327. }
  328. break;
  329. case 'layout':
  330. $temp = self::_getFile($locale, '/ldml/layout/orientation', 'lines', 'lines');
  331. $temp += self::_getFile($locale, '/ldml/layout/orientation', 'characters', 'characters');
  332. $temp += self::_getFile($locale, '/ldml/layout/inList', '', 'inList');
  333. $temp += self::_getFile($locale, '/ldml/layout/inText[@type=\'currency\']', '', 'currency');
  334. $temp += self::_getFile($locale, '/ldml/layout/inText[@type=\'dayWidth\']', '', 'dayWidth');
  335. $temp += self::_getFile($locale, '/ldml/layout/inText[@type=\'fields\']', '', 'fields');
  336. $temp += self::_getFile($locale, '/ldml/layout/inText[@type=\'keys\']', '', 'keys');
  337. $temp += self::_getFile($locale, '/ldml/layout/inText[@type=\'languages\']', '', 'languages');
  338. $temp += self::_getFile($locale, '/ldml/layout/inText[@type=\'long\']', '', 'long');
  339. $temp += self::_getFile($locale, '/ldml/layout/inText[@type=\'measurementSystemNames\']', '', 'measurementSystemNames');
  340. $temp += self::_getFile($locale, '/ldml/layout/inText[@type=\'monthWidth\']', '', 'monthWidth');
  341. $temp += self::_getFile($locale, '/ldml/layout/inText[@type=\'quarterWidth\']', '', 'quarterWidth');
  342. $temp += self::_getFile($locale, '/ldml/layout/inText[@type=\'scripts\']', '', 'scripts');
  343. $temp += self::_getFile($locale, '/ldml/layout/inText[@type=\'territories\']', '', 'territories');
  344. $temp += self::_getFile($locale, '/ldml/layout/inText[@type=\'types\']', '', 'types');
  345. $temp += self::_getFile($locale, '/ldml/layout/inText[@type=\'variants\']', '', 'variants');
  346. break;
  347. case 'characters':
  348. $temp = self::_getFile($locale, '/ldml/characters/exemplarCharacters', '', 'characters');
  349. $temp += self::_getFile($locale, '/ldml/characters/exemplarCharacters[@type=\'auxiliary\']', '', 'auxiliary');
  350. $temp += self::_getFile($locale, '/ldml/characters/exemplarCharacters[@type=\'currencySymbol\']', '', 'currencySymbol');
  351. break;
  352. case 'delimiters':
  353. $temp = self::_getFile($locale, '/ldml/delimiters/quotationStart', '', 'quoteStart');
  354. $temp += self::_getFile($locale, '/ldml/delimiters/quotationEnd', '', 'quoteEnd');
  355. $temp += self::_getFile($locale, '/ldml/delimiters/alternateQuotationStart', '', 'quoteStartAlt');
  356. $temp += self::_getFile($locale, '/ldml/delimiters/alternateQuotationEnd', '', 'quoteEndAlt');
  357. break;
  358. case 'measurement':
  359. $temp = self::_getFile('supplementalData', '/supplementalData/measurementData/measurementSystem[@type=\'metric\']', 'territories', 'metric');
  360. $temp += self::_getFile('supplementalData', '/supplementalData/measurementData/measurementSystem[@type=\'US\']', 'territories', 'US');
  361. $temp += self::_getFile('supplementalData', '/supplementalData/measurementData/paperSize[@type=\'A4\']', 'territories', 'A4');
  362. $temp += self::_getFile('supplementalData', '/supplementalData/measurementData/paperSize[@type=\'US-Letter\']', 'territories', 'US-Letter');
  363. break;
  364. case 'months':
  365. if (empty($value)) {
  366. $value = "gregorian";
  367. }
  368. $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/months/default', 'choice', 'context');
  369. $temp += self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/months/monthContext[@type=\'format\']/default', 'choice', 'default');
  370. $temp['format']['abbreviated'] = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/months/monthContext[@type=\'format\']/monthWidth[@type=\'abbreviated\']/month', 'type');
  371. $temp['format']['narrow'] = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/months/monthContext[@type=\'format\']/monthWidth[@type=\'narrow\']/month', 'type');
  372. $temp['format']['wide'] = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/months/monthContext[@type=\'format\']/monthWidth[@type=\'wide\']/month', 'type');
  373. $temp['stand-alone']['abbreviated'] = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/months/monthContext[@type=\'stand-alone\']/monthWidth[@type=\'abbreviated\']/month', 'type');
  374. $temp['stand-alone']['narrow'] = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/months/monthContext[@type=\'stand-alone\']/monthWidth[@type=\'narrow\']/month', 'type');
  375. $temp['stand-alone']['wide'] = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/months/monthContext[@type=\'stand-alone\']/monthWidth[@type=\'wide\']/month', 'type');
  376. break;
  377. case 'month':
  378. if (empty($value)) {
  379. $value = array("gregorian", "format", "wide");
  380. }
  381. $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value[0] . '\']/months/monthContext[@type=\'' . $value[1] . '\']/monthWidth[@type=\'' . $value[2] . '\']/month', 'type');
  382. break;
  383. case 'days':
  384. if (empty($value)) {
  385. $value = "gregorian";
  386. }
  387. $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/days/default', 'choice', 'context');
  388. $temp += self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/days/dayContext[@type=\'format\']/default', 'choice', 'default');
  389. $temp['format']['abbreviated'] = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/days/dayContext[@type=\'format\']/dayWidth[@type=\'abbreviated\']/day', 'type');
  390. $temp['format']['narrow'] = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/days/dayContext[@type=\'format\']/dayWidth[@type=\'narrow\']/day', 'type');
  391. $temp['format']['wide'] = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/days/dayContext[@type=\'format\']/dayWidth[@type=\'wide\']/day', 'type');
  392. $temp['stand-alone']['abbreviated'] = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/days/dayContext[@type=\'stand-alone\']/dayWidth[@type=\'abbreviated\']/day', 'type');
  393. $temp['stand-alone']['narrow'] = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/days/dayContext[@type=\'stand-alone\']/dayWidth[@type=\'narrow\']/day', 'type');
  394. $temp['stand-alone']['wide'] = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/days/dayContext[@type=\'stand-alone\']/dayWidth[@type=\'wide\']/day', 'type');
  395. break;
  396. case 'day':
  397. if (empty($value)) {
  398. $value = array("gregorian", "format", "wide");
  399. }
  400. $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value[0] . '\']/days/dayContext[@type=\'' . $value[1] . '\']/dayWidth[@type=\'' . $value[2] . '\']/day', 'type');
  401. break;
  402. case 'week':
  403. $minDays = self::_calendarDetail($locale, self::_getFile('supplementalData', '/supplementalData/weekData/minDays', 'territories'));
  404. $firstDay = self::_calendarDetail($locale, self::_getFile('supplementalData', '/supplementalData/weekData/firstDay', 'territories'));
  405. $weekStart = self::_calendarDetail($locale, self::_getFile('supplementalData', '/supplementalData/weekData/weekendStart', 'territories'));
  406. $weekEnd = self::_calendarDetail($locale, self::_getFile('supplementalData', '/supplementalData/weekData/weekendEnd', 'territories'));
  407. $temp = self::_getFile('supplementalData', "/supplementalData/weekData/minDays[@territories='" . $minDays . "']", 'count', 'minDays');
  408. $temp += self::_getFile('supplementalData', "/supplementalData/weekData/firstDay[@territories='" . $firstDay . "']", 'day', 'firstDay');
  409. $temp += self::_getFile('supplementalData', "/supplementalData/weekData/weekendStart[@territories='" . $weekStart . "']", 'day', 'weekendStart');
  410. $temp += self::_getFile('supplementalData', "/supplementalData/weekData/weekendEnd[@territories='" . $weekEnd . "']", 'day', 'weekendEnd');
  411. break;
  412. case 'quarters':
  413. if (empty($value)) {
  414. $value = "gregorian";
  415. }
  416. $temp['format']['abbreviated'] = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/quarters/quarterContext[@type=\'format\']/quarterWidth[@type=\'abbreviated\']/quarter', 'type');
  417. $temp['format']['narrow'] = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/quarters/quarterContext[@type=\'format\']/quarterWidth[@type=\'narrow\']/quarter', 'type');
  418. $temp['format']['wide'] = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/quarters/quarterContext[@type=\'format\']/quarterWidth[@type=\'wide\']/quarter', 'type');
  419. $temp['stand-alone']['abbreviated'] = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/quarters/quarterContext[@type=\'stand-alone\']/quarterWidth[@type=\'abbreviated\']/quarter', 'type');
  420. $temp['stand-alone']['narrow'] = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/quarters/quarterContext[@type=\'stand-alone\']/quarterWidth[@type=\'narrow\']/quarter', 'type');
  421. $temp['stand-alone']['wide'] = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/quarters/quarterContext[@type=\'stand-alone\']/quarterWidth[@type=\'wide\']/quarter', 'type');
  422. break;
  423. case 'quarter':
  424. if (empty($value)) {
  425. $value = array("gregorian", "format", "wide");
  426. }
  427. $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value[0] . '\']/quarters/quarterContext[@type=\'' . $value[1] . '\']/quarterWidth[@type=\'' . $value[2] . '\']/quarter', 'type');
  428. break;
  429. case 'eras':
  430. if (empty($value)) {
  431. $value = "gregorian";
  432. }
  433. $temp['names'] = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/eras/eraNames/era', 'type');
  434. $temp['abbreviated'] = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/eras/eraAbbr/era', 'type');
  435. $temp['narrow'] = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/eras/eraNarrow/era', 'type');
  436. break;
  437. case 'era':
  438. if (empty($value)) {
  439. $value = array("gregorian", "Abbr");
  440. }
  441. $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value[0] . '\']/eras/era' . $value[1] . '/era', 'type');
  442. break;
  443. case 'date':
  444. if (empty($value)) {
  445. $value = "gregorian";
  446. }
  447. $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/dateFormats/dateFormatLength[@type=\'full\']/dateFormat/pattern', '', 'full');
  448. $temp += self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/dateFormats/dateFormatLength[@type=\'long\']/dateFormat/pattern', '', 'long');
  449. $temp += self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/dateFormats/dateFormatLength[@type=\'medium\']/dateFormat/pattern', '', 'medium');
  450. $temp += self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/dateFormats/dateFormatLength[@type=\'short\']/dateFormat/pattern', '', 'short');
  451. break;
  452. case 'time':
  453. if (empty($value)) {
  454. $value = "gregorian";
  455. }
  456. $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/timeFormats/timeFormatLength[@type=\'full\']/timeFormat/pattern', '', 'full');
  457. $temp += self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/timeFormats/timeFormatLength[@type=\'long\']/timeFormat/pattern', '', 'long');
  458. $temp += self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/timeFormats/timeFormatLength[@type=\'medium\']/timeFormat/pattern', '', 'medium');
  459. $temp += self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/timeFormats/timeFormatLength[@type=\'short\']/timeFormat/pattern', '', 'short');
  460. break;
  461. case 'datetime':
  462. if (empty($value)) {
  463. $value = "gregorian";
  464. }
  465. $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/dateTimeFormats/availableFormats/dateFormatItem', 'id');
  466. break;
  467. case 'field':
  468. if (empty($value)) {
  469. $value = "gregorian";
  470. }
  471. $temp2 = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/fields/field', 'type');
  472. foreach ($temp2 as $key => $keyvalue) {
  473. $temp += self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/fields/field[@type=\'' . $key . '\']/displayName', '', $key);
  474. }
  475. break;
  476. case 'relative':
  477. if (empty($value)) {
  478. $value = "gregorian";
  479. }
  480. $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/fields/field/relative', 'type');
  481. break;
  482. case 'symbols':
  483. $temp = self::_getFile($locale, '/ldml/numbers/symbols/decimal', '', 'decimal');
  484. $temp += self::_getFile($locale, '/ldml/numbers/symbols/group', '', 'group');
  485. $temp += self::_getFile($locale, '/ldml/numbers/symbols/list', '', 'list');
  486. $temp += self::_getFile($locale, '/ldml/numbers/symbols/percentSign', '', 'percent');
  487. $temp += self::_getFile($locale, '/ldml/numbers/symbols/nativeZeroDigit', '', 'zero');
  488. $temp += self::_getFile($locale, '/ldml/numbers/symbols/patternDigit', '', 'pattern');
  489. $temp += self::_getFile($locale, '/ldml/numbers/symbols/plusSign', '', 'plus');
  490. $temp += self::_getFile($locale, '/ldml/numbers/symbols/minusSign', '', 'minus');
  491. $temp += self::_getFile($locale, '/ldml/numbers/symbols/exponential', '', 'exponent');
  492. $temp += self::_getFile($locale, '/ldml/numbers/symbols/perMille', '', 'mille');
  493. $temp += self::_getFile($locale, '/ldml/numbers/symbols/infinity', '', 'infinity');
  494. $temp += self::_getFile($locale, '/ldml/numbers/symbols/nan', '', 'nan');
  495. break;
  496. case 'nametocurrency':
  497. $_temp = self::_getFile($locale, '/ldml/numbers/currencies/currency', 'type');
  498. foreach ($_temp as $key => $found) {
  499. $temp += self::_getFile($locale, '/ldml/numbers/currencies/currency[@type=\'' . $key . '\']/displayName', '', $key);
  500. }
  501. break;
  502. case 'currencytoname':
  503. $_temp = self::_getFile($locale, '/ldml/numbers/currencies/currency', 'type');
  504. foreach ($_temp as $key => $keyvalue) {
  505. $val = self::_getFile($locale, '/ldml/numbers/currencies/currency[@type=\'' . $key . '\']/displayName', '', $key);
  506. if (!isset($val[$key])) {
  507. continue;
  508. }
  509. if (!isset($temp[$val[$key]])) {
  510. $temp[$val[$key]] = $key;
  511. } else {
  512. $temp[$val[$key]] .= " " . $key;
  513. }
  514. }
  515. break;
  516. case 'currencysymbol':
  517. $_temp = self::_getFile($locale, '/ldml/numbers/currencies/currency', 'type');
  518. foreach ($_temp as $key => $found) {
  519. $temp += self::_getFile($locale, '/ldml/numbers/currencies/currency[@type=\'' . $key . '\']/symbol', '', $key);
  520. }
  521. break;
  522. case 'question':
  523. $temp = self::_getFile($locale, '/ldml/posix/messages/yesstr', '', 'yes');
  524. $temp += self::_getFile($locale, '/ldml/posix/messages/nostr', '', 'no');
  525. break;
  526. case 'currencyfraction':
  527. $_temp = self::_getFile('supplementalData', '/supplementalData/currencyData/fractions/info', 'iso4217');
  528. foreach ($_temp as $key => $found) {
  529. $temp += self::_getFile('supplementalData', '/supplementalData/currencyData/fractions/info[@iso4217=\'' . $key . '\']', 'digits', $key);
  530. }
  531. break;
  532. case 'currencyrounding':
  533. $_temp = self::_getFile('supplementalData', '/supplementalData/currencyData/fractions/info', 'iso4217');
  534. foreach ($_temp as $key => $found) {
  535. $temp += self::_getFile('supplementalData', '/supplementalData/currencyData/fractions/info[@iso4217=\'' . $key . '\']', 'rounding', $key);
  536. }
  537. break;
  538. case 'currencytoregion':
  539. $_temp = self::_getFile('supplementalData', '/supplementalData/currencyData/region', 'iso3166');
  540. foreach ($_temp as $key => $keyvalue) {
  541. $temp += self::_getFile('supplementalData', '/supplementalData/currencyData/region[@iso3166=\'' . $key . '\']/currency', 'iso4217', $key);
  542. }
  543. break;
  544. case 'regiontocurrency':
  545. $_temp = self::_getFile('supplementalData', '/supplementalData/currencyData/region', 'iso3166');
  546. foreach ($_temp as $key => $keyvalue) {
  547. $val = self::_getFile('supplementalData', '/supplementalData/currencyData/region[@iso3166=\'' . $key . '\']/currency', 'iso4217', $key);
  548. if (!isset($val[$key])) {
  549. continue;
  550. }
  551. if (!isset($temp[$val[$key]])) {
  552. $temp[$val[$key]] = $key;
  553. } else {
  554. $temp[$val[$key]] .= " " . $key;
  555. }
  556. }
  557. break;
  558. case 'regiontoterritory':
  559. $_temp = self::_getFile('supplementalData', '/supplementalData/territoryContainment/group', 'type');
  560. foreach ($_temp as $key => $found) {
  561. $temp += self::_getFile('supplementalData', '/supplementalData/territoryContainment/group[@type=\'' . $key . '\']', 'contains', $key);
  562. }
  563. break;
  564. case 'territorytoregion':
  565. $_temp2 = self::_getFile('supplementalData', '/supplementalData/territoryContainment/group', 'type');
  566. $_temp = array();
  567. foreach ($_temp2 as $key => $found) {
  568. $_temp += self::_getFile('supplementalData', '/supplementalData/territoryContainment/group[@type=\'' . $key . '\']', 'contains', $key);
  569. }
  570. foreach($_temp as $key => $found) {
  571. $_temp3 = explode(" ", $found);
  572. foreach($_temp3 as $found3) {
  573. if (!isset($temp[$found3])) {
  574. $temp[$found3] = (string) $key;
  575. } else {
  576. $temp[$found3] .= " " . $key;
  577. }
  578. }
  579. }
  580. break;
  581. case 'scripttolanguage':
  582. $_temp = self::_getFile('supplementalData', '/supplementalData/languageData/language', 'type');
  583. foreach ($_temp as $key => $found) {
  584. $temp += self::_getFile('supplementalData', '/supplementalData/languageData/language[@type=\'' . $key . '\']', 'scripts', $key);
  585. if (empty($temp[$key])) {
  586. unset($temp[$key]);
  587. }
  588. }
  589. break;
  590. case 'languagetoscript':
  591. $_temp2 = self::_getFile('supplementalData', '/supplementalData/languageData/language', 'type');
  592. $_temp = array();
  593. foreach ($_temp2 as $key => $found) {
  594. $_temp += self::_getFile('supplementalData', '/supplementalData/languageData/language[@type=\'' . $key . '\']', 'scripts', $key);
  595. }
  596. foreach($_temp as $key => $found) {
  597. $_temp3 = explode(" ", $found);
  598. foreach($_temp3 as $found3) {
  599. if (empty($found3)) {
  600. continue;
  601. }
  602. if (!isset($temp[$found3])) {
  603. $temp[$found3] = (string) $key;
  604. } else {
  605. $temp[$found3] .= " " . $key;
  606. }
  607. }
  608. }
  609. break;
  610. case 'territorytolanguage':
  611. $_temp = self::_getFile('supplementalData', '/supplementalData/languageData/language', 'type');
  612. foreach ($_temp as $key => $found) {
  613. $temp += self::_getFile('supplementalData', '/supplementalData/languageData/language[@type=\'' . $key . '\']', 'territories', $key);
  614. if (empty($temp[$key])) {
  615. unset($temp[$key]);
  616. }
  617. }
  618. break;
  619. case 'languagetoterritory':
  620. $_temp2 = self::_getFile('supplementalData', '/supplementalData/languageData/language', 'type');
  621. $_temp = array();
  622. foreach ($_temp2 as $key => $found) {
  623. $_temp += self::_getFile('supplementalData', '/supplementalData/languageData/language[@type=\'' . $key . '\']', 'territories', $key);
  624. }
  625. foreach($_temp as $key => $found) {
  626. $_temp3 = explode(" ", $found);
  627. foreach($_temp3 as $found3) {
  628. if (empty($found3)) {
  629. continue;
  630. }
  631. if (!isset($temp[$found3])) {
  632. $temp[$found3] = (string) $key;
  633. } else {
  634. $temp[$found3] .= " " . $key;
  635. }
  636. }
  637. }
  638. break;
  639. case 'timezonetowindows':
  640. $_temp = self::_getFile('supplementalData', '/supplementalData/timezoneData/mapTimezones[@type=\'windows\']/mapZone', 'other');
  641. foreach ($_temp as $key => $found) {
  642. $temp += self::_getFile('supplementalData', '/supplementalData/timezoneData/mapTimezones[@type=\'windows\']/mapZone[@other=\'' . $key . '\']', 'type', $key);
  643. }
  644. break;
  645. case 'windowstotimezone':
  646. $_temp = self::_getFile('supplementalData', '/supplementalData/timezoneData/mapTimezones[@type=\'windows\']/mapZone', 'type');
  647. foreach ($_temp as $key => $found) {
  648. $temp += self::_getFile('supplementalData', '/supplementalData/timezoneData/mapTimezones[@type=\'windows\']/mapZone[@type=\'' .$key . '\']', 'other', $key);
  649. }
  650. break;
  651. case 'territorytotimezone':
  652. $_temp = self::_getFile('supplementalData', '/supplementalData/timezoneData/zoneFormatting/zoneItem', 'type');
  653. foreach ($_temp as $key => $found) {
  654. $temp += self::_getFile('supplementalData', '/supplementalData/timezoneData/zoneFormatting/zoneItem[@type=\'' . $key . '\']', 'territory', $key);
  655. }
  656. break;
  657. case 'timezonetoterritory':
  658. $_temp = self::_getFile('supplementalData', '/supplementalData/timezoneData/zoneFormatting/zoneItem', 'territory');
  659. foreach ($_temp as $key => $found) {
  660. $temp += self::_getFile('supplementalData', '/supplementalData/timezoneData/zoneFormatting/zoneItem[@territory=\'' . $key . '\']', 'type', $key);
  661. }
  662. break;
  663. case 'citytotimezone':
  664. $_temp = self::_getFile($locale, '/ldml/dates/timeZoneNames/zone', 'type');
  665. foreach($_temp as $key => $found) {
  666. $temp += self::_getFile($locale, '/ldml/dates/timeZoneNames/zone[@type=\'' . $key . '\']/exemplarCity', '', $key);
  667. }
  668. break;
  669. case 'timezonetocity':
  670. $_temp = self::_getFile($locale, '/ldml/dates/timeZoneNames/zone', 'type');
  671. $temp = array();
  672. foreach($_temp as $key => $found) {
  673. $temp += self::_getFile($locale, '/ldml/dates/timeZoneNames/zone[@type=\'' . $key . '\']/exemplarCity', '', $key);
  674. if (!empty($temp[$key])) {
  675. $temp[$temp[$key]] = $key;
  676. }
  677. unset($temp[$key]);
  678. }
  679. break;
  680. case 'phonetoterritory':
  681. $_temp = self::_getFile('telephoneCodeData', '/supplementalData/telephoneCodeData/codesByTerritory', 'territory');
  682. foreach ($_temp as $key => $keyvalue) {
  683. $temp += self::_getFile('telephoneCodeData', '/supplementalData/telephoneCodeData/codesByTerritory[@territory=\'' . $key . '\']/telephoneCountryCode', 'code', $key);
  684. }
  685. break;
  686. case 'territorytophone':
  687. $_temp = self::_getFile('telephoneCodeData', '/supplementalData/telephoneCodeData/codesByTerritory', 'territory');
  688. foreach ($_temp as $key => $keyvalue) {
  689. $val = self::_getFile('telephoneCodeData', '/supplementalData/telephoneCodeData/codesByTerritory[@territory=\'' . $key . '\']/telephoneCountryCode', 'code', $key);
  690. if (!isset($val[$key])) {
  691. continue;
  692. }
  693. if (!isset($temp[$val[$key]])) {
  694. $temp[$val[$key]] = $key;
  695. } else {
  696. $temp[$val[$key]] .= " " . $key;
  697. }
  698. }
  699. break;
  700. case 'numerictoterritory':
  701. $_temp = self::_getFile('supplementalData', '/supplementalData/codeMappings/territoryCodes', 'type');
  702. foreach ($_temp as $key => $keyvalue) {
  703. $temp += self::_getFile('supplementalData', '/supplementalData/codeMappings/territoryCodes[@type=\'' . $key . '\']', 'numeric', $key);
  704. }
  705. break;
  706. case 'territorytonumeric':
  707. $_temp = self::_getFile('supplementalData', '/supplementalData/codeMappings/territoryCodes', 'numeric');
  708. foreach ($_temp as $key => $keyvalue) {
  709. $temp += self::_getFile('supplementalData', '/supplementalData/codeMappings/territoryCodes[@numeric=\'' . $key . '\']', 'type', $key);
  710. }
  711. break;
  712. case 'alpha3toterritory':
  713. $_temp = self::_getFile('supplementalData', '/supplementalData/codeMappings/territoryCodes', 'type');
  714. foreach ($_temp as $key => $keyvalue) {
  715. $temp += self::_getFile('supplementalData', '/supplementalData/codeMappings/territoryCodes[@type=\'' . $key . '\']', 'alpha3', $key);
  716. }
  717. break;
  718. case 'territorytoalpha3':
  719. $_temp = self::_getFile('supplementalData', '/supplementalData/codeMappings/territoryCodes', 'alpha3');
  720. foreach ($_temp as $key => $keyvalue) {
  721. $temp += self::_getFile('supplementalData', '/supplementalData/codeMappings/territoryCodes[@alpha3=\'' . $key . '\']', 'type', $key);
  722. }
  723. break;
  724. case 'postaltoterritory':
  725. $_temp = self::_getFile('postalCodeData', '/supplementalData/postalCodeData/postCodeRegex', 'territoryId');
  726. foreach ($_temp as $key => $keyvalue) {
  727. $temp += self::_getFile('postalCodeData', '/supplementalData/postalCodeData/postCodeRegex[@territoryId=\'' . $key . '\']', 'territoryId');
  728. }
  729. break;
  730. case 'numberingsystem':
  731. $_temp = self::_getFile('numberingSystems', '/supplementalData/numberingSystems/numberingSystem', 'id');
  732. foreach ($_temp as $key => $keyvalue) {
  733. $temp += self::_getFile('numberingSystems', '/supplementalData/numberingSystems/numberingSystem[@id=\'' . $key . '\']', 'digits', $key);
  734. if (empty($temp[$key])) {
  735. unset($temp[$key]);
  736. }
  737. }
  738. break;
  739. case 'chartofallback':
  740. $_temp = self::_getFile('characters', '/supplementalData/characters/character-fallback/character', 'value');
  741. foreach ($_temp as $key => $keyvalue) {
  742. $temp2 = self::_getFile('characters', '/supplementalData/characters/character-fallback/character[@value=\'' . $key . '\']/substitute', '', $key);
  743. $temp[current($temp2)] = $key;
  744. }
  745. break;
  746. case 'fallbacktochar':
  747. $_temp = self::_getFile('characters', '/supplementalData/characters/character-fallback/character', 'value');
  748. foreach ($_temp as $key => $keyvalue) {
  749. $temp += self::_getFile('characters', '/supplementalData/characters/character-fallback/character[@value=\'' . $key . '\']/substitute', '', $key);
  750. }
  751. break;
  752. case 'localeupgrade':
  753. $_temp = self::_getFile('likelySubtags', '/supplementalData/likelySubtags/likelySubtag', 'from');
  754. foreach ($_temp as $key => $keyvalue) {
  755. $temp += self::_getFile('likelySubtags', '/supplementalData/likelySubtags/likelySubtag[@from=\'' . $key . '\']', 'to', $key);
  756. }
  757. break;
  758. default :
  759. require_once 'Zend/Locale/Exception.php';
  760. throw new Zend_Locale_Exception("Unknown list ($path) for parsing locale data.");
  761. break;
  762. }
  763. if (isset(self::$_cache)) {
  764. self::$_cache->save( serialize($temp), $id);
  765. }
  766. return $temp;
  767. }
  768. /**
  769. * Read the LDML file, get a single path defined value
  770. *
  771. * @param string $locale
  772. * @param string $path
  773. * @param string $value
  774. * @return string
  775. * @access public
  776. */
  777. public static function getContent($locale, $path, $value = false)
  778. {
  779. $locale = self::_checkLocale($locale);
  780. if (!isset(self::$_cache) && !self::$_cacheDisabled) {
  781. require_once 'Zend/Cache.php';
  782. self::$_cache = Zend_Cache::factory(
  783. 'Core',
  784. 'File',
  785. array('automatic_serialization' => true),
  786. array());
  787. }
  788. $val = $value;
  789. if (is_array($value)) {
  790. $val = implode('_' , $value);
  791. }
  792. $val = urlencode($val);
  793. $id = strtr('Zend_LocaleC_' . $locale . '_' . $path . '_' . $val, array('-' => '_', '%' => '_', '+' => '_'));
  794. if (!self::$_cacheDisabled && ($result = self::$_cache->load($id))) {
  795. return unserialize($result);
  796. }
  797. switch(strtolower($path)) {
  798. case 'language':
  799. $temp = self::_getFile($locale, '/ldml/localeDisplayNames/languages/language[@type=\'' . $value . '\']', 'type');
  800. break;
  801. case 'script':
  802. $temp = self::_getFile($locale, '/ldml/localeDisplayNames/scripts/script[@type=\'' . $value . '\']', 'type');
  803. break;
  804. case 'country':
  805. case 'territory':
  806. $temp = self::_getFile($locale, '/ldml/localeDisplayNames/territories/territory[@type=\'' . $value . '\']', 'type');
  807. break;
  808. case 'variant':
  809. $temp = self::_getFile($locale, '/ldml/localeDisplayNames/variants/variant[@type=\'' . $value . '\']', 'type');
  810. break;
  811. case 'key':
  812. $temp = self::_getFile($locale, '/ldml/localeDisplayNames/keys/key[@type=\'' . $value . '\']', 'type');
  813. break;
  814. case 'defaultcalendar':
  815. $temp = self::_getFile($locale, '/ldml/dates/calendars/default', 'choice', 'default');
  816. break;
  817. case 'monthcontext':
  818. if (empty ($value)) {
  819. $value = "gregorian";
  820. }
  821. $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/months/default', 'choice', 'context');
  822. break;
  823. case 'defaultmonth':
  824. if (empty ($value)) {
  825. $value = "gregorian";
  826. }
  827. $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/months/monthContext[@type=\'format\']/default', 'choice', 'default');
  828. break;
  829. case 'month':
  830. if (!is_array($value)) {
  831. $temp = $value;
  832. $value = array("gregorian", "format", "wide", $temp);
  833. }
  834. $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');
  835. break;
  836. case 'daycontext':
  837. if (empty($value)) {
  838. $value = "gregorian";
  839. }
  840. $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/days/default', 'choice', 'context');
  841. break;
  842. case 'defaultday':
  843. if (empty($value)) {
  844. $value = "gregorian";
  845. }
  846. $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/days/dayContext[@type=\'format\']/default', 'choice', 'default');
  847. break;
  848. case 'day':
  849. if (!is_array($value)) {
  850. $temp = $value;
  851. $value = array("gregorian", "format", "wide", $temp);
  852. }
  853. $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');
  854. break;
  855. case 'quarter':
  856. if (!is_array($value)) {
  857. $temp = $value;
  858. $value = array("gregorian", "format", "wide", $temp);
  859. }
  860. $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');
  861. break;
  862. case 'am':
  863. if (empty($value)) {
  864. $value = "gregorian";
  865. }
  866. $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/am', '', 'am');
  867. break;
  868. case 'pm':
  869. if (empty($value)) {
  870. $value = "gregorian";
  871. }
  872. $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/pm', '', 'pm');
  873. break;
  874. case 'era':
  875. if (!is_array($value)) {
  876. $temp = $value;
  877. $value = array("gregorian", "Abbr", $temp);
  878. }
  879. $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value[0] . '\']/eras/era' . $value[1] . '/era[@type=\'' . $value[2] . '\']', 'type');
  880. break;
  881. case 'defaultdate':
  882. if (empty($value)) {
  883. $value = "gregorian";
  884. }
  885. $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/dateFormats/default', 'choice', 'default');
  886. break;
  887. case 'date':
  888. if (empty($value)) {
  889. $value = array("gregorian", "medium");
  890. }
  891. if (!is_array($value)) {
  892. $temp = $value;
  893. $value = array("gregorian", $temp);
  894. }
  895. $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value[0] . '\']/dateFormats/dateFormatLength[@type=\'' . $value[1] . '\']/dateFormat/pattern', '', 'pattern');
  896. break;
  897. case 'defaulttime':
  898. if (empty($value)) {
  899. $value = "gregorian";
  900. }
  901. $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/timeFormats/default', 'choice', 'default');
  902. break;
  903. case 'time':
  904. if (empty($value)) {
  905. $value = array("gregorian", "medium");
  906. }
  907. if (!is_array($value)) {
  908. $temp = $value;
  909. $value = array("gregorian", $temp);
  910. }
  911. $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value[0] . '\']/timeFormats/timeFormatLength[@type=\'' . $value[1] . '\']/timeFormat/pattern', '', 'pattern');
  912. break;
  913. case 'datetime':
  914. if (empty($value)) {
  915. $value = "gregorian";
  916. }
  917. $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/dateTimeFormats/dateTimeFormatLength/dateTimeFormat/pattern', '', 'pattern');
  918. break;
  919. case 'field':
  920. if (!is_array($value)) {
  921. $temp = $value;
  922. $value = array("gregorian", $temp);
  923. }
  924. $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value[0] . '\']/fields/field[@type=\'' . $value[1] . '\']/displayName', '', $value[1]);
  925. break;
  926. case 'relative':
  927. if (!is_array($value)) {
  928. $temp = $value;
  929. $value = array("gregorian", $temp);
  930. }
  931. $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value[0] . '\']/fields/field/relative[@type=\'' . $value[1] . '\']', '', $value[1]);
  932. break;
  933. case 'decimalnumber':
  934. $temp = self::_getFile($locale, '/ldml/numbers/decimalFormats/decimalFormatLength/decimalFormat/pattern', '', 'default');
  935. break;
  936. case 'scientificnumber':
  937. $temp = self::_getFile($locale, '/ldml/numbers/scientificFormats/scientificFormatLength/scientificFormat/pattern', '', 'default');
  938. break;
  939. case 'percentnumber':
  940. $temp = self::_getFile($locale, '/ldml/numbers/percentFormats/percentFormatLength/percentFormat/pattern', '', 'default');
  941. break;
  942. case 'currencynumber':
  943. $temp = self::_getFile($locale, '/ldml/numbers/currencyFormats/currencyFormatLength/currencyFormat/pattern', '', 'default');
  944. break;
  945. case 'nametocurrency':
  946. $temp = self::_getFile($locale, '/ldml/numbers/currencies/currency[@type=\'' . $value . '\']/displayName', '', $value);
  947. break;
  948. case 'currencytoname':
  949. $temp = self::_getFile($locale, '/ldml/numbers/currencies/currency[@type=\'' . $value . '\']/displayName', '', $value);
  950. $_temp = self::_getFile($locale, '/ldml/numbers/currencies/currency', 'type');
  951. $temp = array();
  952. foreach ($_temp as $key => $keyvalue) {
  953. $val = self::_getFile($locale, '/ldml/numbers/currencies/currency[@type=\'' . $key . '\']/displayName', '', $key);
  954. if (!isset($val[$key]) or ($val[$key] != $value)) {
  955. continue;
  956. }
  957. if (!isset($temp[$val[$key]])) {
  958. $temp[$val[$key]] = $key;
  959. } else {
  960. $temp[$val[$key]] .= " " . $key;
  961. }
  962. }
  963. break;
  964. case 'currencysymbol':
  965. $temp = self::_getFile($locale, '/ldml/numbers/currencies/currency[@type=\'' . $value . '\']/symbol', '', $value);
  966. break;
  967. case 'question':
  968. $temp = self::_getFile($locale, '/ldml/posix/messages/' . $value . 'str', '', $value);
  969. break;
  970. case 'currencyfraction':
  971. if (empty($value)) {
  972. $value = "DEFAULT";
  973. }
  974. $temp = self::_getFile('supplementalData', '/supplementalData/currencyData/fractions/info[@iso4217=\'' . $value . '\']', 'digits', 'digits');
  975. break;
  976. case 'currencyrounding':
  977. if (empty($value)) {
  978. $value = "DEFAULT";
  979. }
  980. $temp = self::_getFile('supplementalData', '/supplementalData/currencyData/fractions/info[@iso4217=\'' . $value . '\']', 'rounding', 'rounding');
  981. break;
  982. case 'currencytoregion':
  983. $temp = self::_getFile('supplementalData', '/supplementalData/currencyData/region[@iso3166=\'' . $value . '\']/currency', 'iso4217', $value);
  984. break;
  985. case 'regiontocurrency':
  986. $_temp = self::_getFile('supplementalData', '/supplementalData/currencyData/region', 'iso3166');
  987. $temp = array();
  988. foreach ($_temp as $key => $keyvalue) {
  989. $val = self::_getFile('supplementalData', '/supplementalData/currencyData/region[@iso3166=\'' . $key . '\']/currency', 'iso4217', $key);
  990. if (!isset($val[$key]) or ($val[$key] != $value)) {
  991. continue;
  992. }
  993. if (!isset($temp[$val[$key]])) {
  994. $temp[$val[$key]] = $key;
  995. } else {
  996. $temp[$val[$key]] .= " " . $key;
  997. }
  998. }
  999. break;
  1000. case 'regiontoterritory':
  1001. $temp = self::_getFile('supplementalData', '/supplementalData/territoryContainment/group[@type=\'' . $value . '\']', 'contains', $value);
  1002. break;
  1003. case 'territorytoregion':
  1004. $_temp2 = self::_getFile('supplementalData', '/supplementalData/territoryContainment/group', 'type');
  1005. $_temp = array();
  1006. foreach ($_temp2 as $key => $found) {
  1007. $_temp += self::_getFile('supplementalData', '/supplementalData/territoryContainment/group[@type=\'' . $key . '\']', 'contains', $key);
  1008. }
  1009. $temp = array();
  1010. foreach($_temp as $key => $found) {
  1011. $_temp3 = explode(" ", $found);
  1012. foreach($_temp3 as $found3) {
  1013. if ($found3 !== $value) {
  1014. continue;
  1015. }
  1016. if (!isset($temp[$found3])) {
  1017. $temp[$found3] = (string) $key;
  1018. } else {
  1019. $temp[$found3] .= " " . $key;
  1020. }
  1021. }
  1022. }
  1023. break;
  1024. case 'scripttolanguage':
  1025. $temp = self::_getFile('supplementalData', '/supplementalData/languageData/language[@type=\'' . $value . '\']', 'scripts', $value);
  1026. break;
  1027. case 'languagetoscript':
  1028. $_temp2 = self::_getFile('supplementalData', '/supplementalData/languageData/language', 'type');
  1029. $_temp = array();
  1030. foreach ($_temp2 as $key => $found) {
  1031. $_temp += self::_getFile('supplementalData', '/supplementalData/languageData/language[@type=\'' . $key . '\']', 'scripts', $key);
  1032. }
  1033. $temp = array();
  1034. foreach($_temp as $key => $found) {
  1035. $_temp3 = explode(" ", $found);
  1036. foreach($_temp3 as $found3) {
  1037. if ($found3 !== $value) {
  1038. continue;
  1039. }
  1040. if (!isset($temp[$found3])) {
  1041. $temp[$found3] = (string) $key;
  1042. } else {
  1043. $temp[$found3] .= " " . $key;
  1044. }
  1045. }
  1046. }
  1047. break;
  1048. case 'territorytolanguage':
  1049. $temp = self::_getFile('supplementalData', '/supplementalData/languageData/language[@type=\'' . $value . '\']', 'territories', $value);
  1050. break;
  1051. case 'languagetoterritory':
  1052. $_temp2 = self::_getFile('supplementalData', '/supplementalData/languageData/language', 'type');
  1053. $_temp = array();
  1054. foreach ($_temp2 as $key => $found) {
  1055. $_temp += self::_getFile('supplementalData', '/supplementalData/languageData/language[@type=\'' . $key . '\']', 'territories', $key);
  1056. }
  1057. $temp = array();
  1058. foreach($_temp as $key => $found) {
  1059. $_temp3 = explode(" ", $found);
  1060. foreach($_temp3 as $found3) {
  1061. if ($found3 !== $value) {
  1062. continue;
  1063. }
  1064. if (!isset($temp[$found3])) {
  1065. $temp[$found3] = (string) $key;
  1066. } else {
  1067. $temp[$found3] .= " " . $key;
  1068. }
  1069. }
  1070. }
  1071. break;
  1072. case 'timezonetowindows':
  1073. $temp = self::_getFile('supplementalData', '/supplementalData/timezoneData/mapTimezones[@type=\'windows\']/mapZone[@other=\''.$value.'\']', 'type', $value);
  1074. break;
  1075. case 'windowstotimezone':
  1076. $temp = self::_getFile('supplementalData', '/supplementalData/timezoneData/mapTimezones[@type=\'windows\']/mapZone[@type=\''.$value.'\']', 'other', $value);
  1077. break;
  1078. case 'territorytotimezone':
  1079. $temp = self::_getFile('supplementalData', '/supplementalData/timezoneData/zoneFormatting/zoneItem[@type=\'' . $value . '\']', 'territory', $value);
  1080. break;
  1081. case 'timezonetoterritory':
  1082. $temp = self::_getFile('supplementalData', '/supplementalData/timezoneData/zoneFormatting/zoneItem[@territory=\'' . $value . '\']', 'type', $value);
  1083. break;
  1084. case 'citytotimezone':
  1085. $temp = self::_getFile($locale, '/ldml/dates/timeZoneNames/zone[@type=\'' . $value . '\']/exemplarCity', '', $value);
  1086. break;
  1087. case 'timezonetocity':
  1088. $_temp = self::_getFile($locale, '/ldml/dates/timeZoneNames/zone', 'type');
  1089. $temp = array();
  1090. foreach($_temp as $key => $found) {
  1091. $temp += self::_getFile($locale, '/ldml/dates/timeZoneNames/zone[@type=\'' . $key . '\']/exemplarCity', '', $key);
  1092. if (!empty($temp[$key])) {
  1093. if ($temp[$key] == $value) {
  1094. $temp[$temp[$key]] = $key;
  1095. }
  1096. }
  1097. unset($temp[$key]);
  1098. }
  1099. break;
  1100. case 'phonetoterritory':
  1101. $temp = self::_getFile('telephoneCodeData', '/supplementalData/telephoneCodeData/codesByTerritory[@territory=\'' . $value . '\']/telephoneCountryCode', 'code', $value);
  1102. break;
  1103. case 'territorytophone':
  1104. $_temp2 = self::_getFile('telephoneCodeData', '/supplementalData/telephoneCodeData/codesByTerritory', 'territory');
  1105. $_temp = array();
  1106. foreach ($_temp2 as $key => $found) {
  1107. $_temp += self::_getFile('telephoneCodeData', '/supplementalData/telephoneCodeData/codesByTerritory[@territory=\'' . $key . '\']/telephoneCountryCode', 'code', $key);
  1108. }
  1109. $temp = array();
  1110. foreach($_temp as $key => $found) {
  1111. $_temp3 = explode(" ", $found);
  1112. foreach($_temp3 as $found3) {
  1113. if ($found3 !== $value) {
  1114. continue;
  1115. }
  1116. if (!isset($temp[$found3])) {
  1117. $temp[$found3] = (string) $key;
  1118. } else {
  1119. $temp[$found3] .= " " . $key;
  1120. }
  1121. }
  1122. }
  1123. break;
  1124. case 'numerictoterritory':
  1125. $temp = self::_getFile('supplementalData', '/supplementalData/codeMappings/territoryCodes[@type=\''.$value.'\']', 'numeric', $value);
  1126. break;
  1127. case 'territorytonumeric':
  1128. $temp = self::_getFile('supplementalData', '/supplementalData/codeMappings/territoryCodes[@numeric=\''.$value.'\']', 'type', $value);
  1129. break;
  1130. case 'alpha3toterritory':
  1131. $temp = self::_getFile('supplementalData', '/supplementalData/codeMappings/territoryCodes[@type=\''.$value.'\']', 'alpha3', $value);
  1132. break;
  1133. case 'territorytoalpha3':
  1134. $temp = self::_getFile('supplementalData', '/supplementalData/codeMappings/territoryCodes[@alpha3=\''.$value.'\']', 'type', $value);
  1135. break;
  1136. case 'postaltoterritory':
  1137. $temp = self::_getFile('postalCodeData', '/supplementalData/postalCodeData/postCodeRegex[@territoryId=\'' . $value . '\']', 'territoryId');
  1138. break;
  1139. case 'numberingsystem':
  1140. $temp = self::_getFile('numberingSystems', '/supplementalData/numberingSystems/numberingSystem[@id=\'' . strtolower($value) . '\']', 'digits', $value);
  1141. break;
  1142. case 'chartofallback':
  1143. $_temp = self::_getFile('characters', '/supplementalData/characters/character-fallback/character', 'value');
  1144. foreach ($_temp as $key => $keyvalue) {
  1145. $temp2 = self::_getFile('characters', '/supplementalData/characters/character-fallback/character[@value=\'' . $key . '\']/substitute', '', $key);
  1146. if (current($temp2) == $value) {
  1147. $temp = $key;
  1148. }
  1149. }
  1150. break;
  1151. $temp = self::_getFile('characters', '/supplementalData/characters/character-fallback/character[@value=\'' . $value . '\']/substitute', '', $value);
  1152. break;
  1153. case 'fallbacktochar':
  1154. $temp = self::_getFile('characters', '/supplementalData/characters/character-fallback/character[@value=\'' . $value . '\']/substitute', '');
  1155. break;
  1156. case 'localeupgrade':
  1157. $temp = self::_getFile('likelySubtags', '/supplementalData/likelySubtags/likelySubtag[@from=\'' . $value . '\']', 'to', $value);
  1158. break;
  1159. default :
  1160. require_once 'Zend/Locale/Exception.php';
  1161. throw new Zend_Locale_Exception("Unknown detail ($path) for parsing locale data.");
  1162. break;
  1163. }
  1164. if (is_array($temp)) {
  1165. $temp = current($temp);
  1166. }
  1167. if (isset(self::$_cache)) {
  1168. self::$_cache->save( serialize($temp), $id);
  1169. }
  1170. return $temp;
  1171. }
  1172. /**
  1173. * Returns the set cache
  1174. *
  1175. * @return Zend_Cache_Core The set cache
  1176. */
  1177. public static function getCache()
  1178. {
  1179. return self::$_cache;
  1180. }
  1181. /**
  1182. * Set a cache for Zend_Locale_Data
  1183. *
  1184. * @param Zend_Cache_Core $cache A cache frontend
  1185. */
  1186. public static function setCache(Zend_Cache_Core $cache)
  1187. {
  1188. self::$_cache = $cache;
  1189. }
  1190. /**
  1191. * Returns true when a cache is set
  1192. *
  1193. * @return boolean
  1194. */
  1195. public static function hasCache()
  1196. {
  1197. if (self::$_cache !== null) {
  1198. return true;
  1199. }
  1200. return false;
  1201. }
  1202. /**
  1203. * Removes any set cache
  1204. *
  1205. * @return void
  1206. */
  1207. public static function removeCache()
  1208. {
  1209. self::$_cache = null;
  1210. }
  1211. /**
  1212. * Clears all set cache data
  1213. *
  1214. * @return void
  1215. */
  1216. public static function clearCache()
  1217. {
  1218. self::$_cache->clean();
  1219. }
  1220. /**
  1221. * Disables the cache
  1222. *
  1223. * @param unknown_type $flag
  1224. */
  1225. public static function disableCache($flag)
  1226. {
  1227. self::$_cacheDisabled = (boolean) $flag;
  1228. }
  1229. }