Data.php 65 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384
  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. default :
  753. require_once 'Zend/Locale/Exception.php';
  754. throw new Zend_Locale_Exception("Unknown list ($path) for parsing locale data.");
  755. break;
  756. }
  757. if (isset(self::$_cache)) {
  758. self::$_cache->save( serialize($temp), $id);
  759. }
  760. return $temp;
  761. }
  762. /**
  763. * Read the LDML file, get a single path defined value
  764. *
  765. * @param string $locale
  766. * @param string $path
  767. * @param string $value
  768. * @return string
  769. * @access public
  770. */
  771. public static function getContent($locale, $path, $value = false)
  772. {
  773. $locale = self::_checkLocale($locale);
  774. if (!isset(self::$_cache) && !self::$_cacheDisabled) {
  775. require_once 'Zend/Cache.php';
  776. self::$_cache = Zend_Cache::factory(
  777. 'Core',
  778. 'File',
  779. array('automatic_serialization' => true),
  780. array());
  781. }
  782. $val = $value;
  783. if (is_array($value)) {
  784. $val = implode('_' , $value);
  785. }
  786. $val = urlencode($val);
  787. $id = strtr('Zend_LocaleC_' . $locale . '_' . $path . '_' . $val, array('-' => '_', '%' => '_', '+' => '_'));
  788. if (!self::$_cacheDisabled && ($result = self::$_cache->load($id))) {
  789. return unserialize($result);
  790. }
  791. switch(strtolower($path)) {
  792. case 'language':
  793. $temp = self::_getFile($locale, '/ldml/localeDisplayNames/languages/language[@type=\'' . $value . '\']', 'type');
  794. break;
  795. case 'script':
  796. $temp = self::_getFile($locale, '/ldml/localeDisplayNames/scripts/script[@type=\'' . $value . '\']', 'type');
  797. break;
  798. case 'country':
  799. case 'territory':
  800. $temp = self::_getFile($locale, '/ldml/localeDisplayNames/territories/territory[@type=\'' . $value . '\']', 'type');
  801. break;
  802. case 'variant':
  803. $temp = self::_getFile($locale, '/ldml/localeDisplayNames/variants/variant[@type=\'' . $value . '\']', 'type');
  804. break;
  805. case 'key':
  806. $temp = self::_getFile($locale, '/ldml/localeDisplayNames/keys/key[@type=\'' . $value . '\']', 'type');
  807. break;
  808. case 'defaultcalendar':
  809. $temp = self::_getFile($locale, '/ldml/dates/calendars/default', 'choice', 'default');
  810. break;
  811. case 'monthcontext':
  812. if (empty ($value)) {
  813. $value = "gregorian";
  814. }
  815. $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/months/default', 'choice', 'context');
  816. break;
  817. case 'defaultmonth':
  818. if (empty ($value)) {
  819. $value = "gregorian";
  820. }
  821. $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/months/monthContext[@type=\'format\']/default', 'choice', 'default');
  822. break;
  823. case 'month':
  824. if (!is_array($value)) {
  825. $temp = $value;
  826. $value = array("gregorian", "format", "wide", $temp);
  827. }
  828. $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');
  829. break;
  830. case 'daycontext':
  831. if (empty($value)) {
  832. $value = "gregorian";
  833. }
  834. $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/days/default', 'choice', 'context');
  835. break;
  836. case 'defaultday':
  837. if (empty($value)) {
  838. $value = "gregorian";
  839. }
  840. $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/days/dayContext[@type=\'format\']/default', 'choice', 'default');
  841. break;
  842. case 'day':
  843. if (!is_array($value)) {
  844. $temp = $value;
  845. $value = array("gregorian", "format", "wide", $temp);
  846. }
  847. $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');
  848. break;
  849. case 'quarter':
  850. if (!is_array($value)) {
  851. $temp = $value;
  852. $value = array("gregorian", "format", "wide", $temp);
  853. }
  854. $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');
  855. break;
  856. case 'am':
  857. if (empty($value)) {
  858. $value = "gregorian";
  859. }
  860. $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/am', '', 'am');
  861. break;
  862. case 'pm':
  863. if (empty($value)) {
  864. $value = "gregorian";
  865. }
  866. $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/pm', '', 'pm');
  867. break;
  868. case 'era':
  869. if (!is_array($value)) {
  870. $temp = $value;
  871. $value = array("gregorian", "Abbr", $temp);
  872. }
  873. $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value[0] . '\']/eras/era' . $value[1] . '/era[@type=\'' . $value[2] . '\']', 'type');
  874. break;
  875. case 'defaultdate':
  876. if (empty($value)) {
  877. $value = "gregorian";
  878. }
  879. $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/dateFormats/default', 'choice', 'default');
  880. break;
  881. case 'date':
  882. if (empty($value)) {
  883. $value = array("gregorian", "medium");
  884. }
  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] . '\']/dateFormats/dateFormatLength[@type=\'' . $value[1] . '\']/dateFormat/pattern', '', 'pattern');
  890. break;
  891. case 'defaulttime':
  892. if (empty($value)) {
  893. $value = "gregorian";
  894. }
  895. $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/timeFormats/default', 'choice', 'default');
  896. break;
  897. case 'time':
  898. if (empty($value)) {
  899. $value = array("gregorian", "medium");
  900. }
  901. if (!is_array($value)) {
  902. $temp = $value;
  903. $value = array("gregorian", $temp);
  904. }
  905. $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value[0] . '\']/timeFormats/timeFormatLength[@type=\'' . $value[1] . '\']/timeFormat/pattern', '', 'pattern');
  906. break;
  907. case 'datetime':
  908. if (empty($value)) {
  909. $value = "gregorian";
  910. }
  911. $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/dateTimeFormats/dateTimeFormatLength/dateTimeFormat/pattern', '', 'pattern');
  912. break;
  913. case 'field':
  914. if (!is_array($value)) {
  915. $temp = $value;
  916. $value = array("gregorian", $temp);
  917. }
  918. $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value[0] . '\']/fields/field[@type=\'' . $value[1] . '\']/displayName', '', $value[1]);
  919. break;
  920. case 'relative':
  921. if (!is_array($value)) {
  922. $temp = $value;
  923. $value = array("gregorian", $temp);
  924. }
  925. $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value[0] . '\']/fields/field/relative[@type=\'' . $value[1] . '\']', '', $value[1]);
  926. break;
  927. case 'decimalnumber':
  928. $temp = self::_getFile($locale, '/ldml/numbers/decimalFormats/decimalFormatLength/decimalFormat/pattern', '', 'default');
  929. break;
  930. case 'scientificnumber':
  931. $temp = self::_getFile($locale, '/ldml/numbers/scientificFormats/scientificFormatLength/scientificFormat/pattern', '', 'default');
  932. break;
  933. case 'percentnumber':
  934. $temp = self::_getFile($locale, '/ldml/numbers/percentFormats/percentFormatLength/percentFormat/pattern', '', 'default');
  935. break;
  936. case 'currencynumber':
  937. $temp = self::_getFile($locale, '/ldml/numbers/currencyFormats/currencyFormatLength/currencyFormat/pattern', '', 'default');
  938. break;
  939. case 'nametocurrency':
  940. $temp = self::_getFile($locale, '/ldml/numbers/currencies/currency[@type=\'' . $value . '\']/displayName', '', $value);
  941. break;
  942. case 'currencytoname':
  943. $temp = self::_getFile($locale, '/ldml/numbers/currencies/currency[@type=\'' . $value . '\']/displayName', '', $value);
  944. $_temp = self::_getFile($locale, '/ldml/numbers/currencies/currency', 'type');
  945. $temp = array();
  946. foreach ($_temp as $key => $keyvalue) {
  947. $val = self::_getFile($locale, '/ldml/numbers/currencies/currency[@type=\'' . $key . '\']/displayName', '', $key);
  948. if (!isset($val[$key]) or ($val[$key] != $value)) {
  949. continue;
  950. }
  951. if (!isset($temp[$val[$key]])) {
  952. $temp[$val[$key]] = $key;
  953. } else {
  954. $temp[$val[$key]] .= " " . $key;
  955. }
  956. }
  957. break;
  958. case 'currencysymbol':
  959. $temp = self::_getFile($locale, '/ldml/numbers/currencies/currency[@type=\'' . $value . '\']/symbol', '', $value);
  960. break;
  961. case 'question':
  962. $temp = self::_getFile($locale, '/ldml/posix/messages/' . $value . 'str', '', $value);
  963. break;
  964. case 'currencyfraction':
  965. if (empty($value)) {
  966. $value = "DEFAULT";
  967. }
  968. $temp = self::_getFile('supplementalData', '/supplementalData/currencyData/fractions/info[@iso4217=\'' . $value . '\']', 'digits', 'digits');
  969. break;
  970. case 'currencyrounding':
  971. if (empty($value)) {
  972. $value = "DEFAULT";
  973. }
  974. $temp = self::_getFile('supplementalData', '/supplementalData/currencyData/fractions/info[@iso4217=\'' . $value . '\']', 'rounding', 'rounding');
  975. break;
  976. case 'currencytoregion':
  977. $temp = self::_getFile('supplementalData', '/supplementalData/currencyData/region[@iso3166=\'' . $value . '\']/currency', 'iso4217', $value);
  978. break;
  979. case 'regiontocurrency':
  980. $_temp = self::_getFile('supplementalData', '/supplementalData/currencyData/region', 'iso3166');
  981. $temp = array();
  982. foreach ($_temp as $key => $keyvalue) {
  983. $val = self::_getFile('supplementalData', '/supplementalData/currencyData/region[@iso3166=\'' . $key . '\']/currency', 'iso4217', $key);
  984. if (!isset($val[$key]) or ($val[$key] != $value)) {
  985. continue;
  986. }
  987. if (!isset($temp[$val[$key]])) {
  988. $temp[$val[$key]] = $key;
  989. } else {
  990. $temp[$val[$key]] .= " " . $key;
  991. }
  992. }
  993. break;
  994. case 'regiontoterritory':
  995. $temp = self::_getFile('supplementalData', '/supplementalData/territoryContainment/group[@type=\'' . $value . '\']', 'contains', $value);
  996. break;
  997. case 'territorytoregion':
  998. $_temp2 = self::_getFile('supplementalData', '/supplementalData/territoryContainment/group', 'type');
  999. $_temp = array();
  1000. foreach ($_temp2 as $key => $found) {
  1001. $_temp += self::_getFile('supplementalData', '/supplementalData/territoryContainment/group[@type=\'' . $key . '\']', 'contains', $key);
  1002. }
  1003. $temp = array();
  1004. foreach($_temp as $key => $found) {
  1005. $_temp3 = explode(" ", $found);
  1006. foreach($_temp3 as $found3) {
  1007. if ($found3 !== $value) {
  1008. continue;
  1009. }
  1010. if (!isset($temp[$found3])) {
  1011. $temp[$found3] = (string) $key;
  1012. } else {
  1013. $temp[$found3] .= " " . $key;
  1014. }
  1015. }
  1016. }
  1017. break;
  1018. case 'scripttolanguage':
  1019. $temp = self::_getFile('supplementalData', '/supplementalData/languageData/language[@type=\'' . $value . '\']', 'scripts', $value);
  1020. break;
  1021. case 'languagetoscript':
  1022. $_temp2 = self::_getFile('supplementalData', '/supplementalData/languageData/language', 'type');
  1023. $_temp = array();
  1024. foreach ($_temp2 as $key => $found) {
  1025. $_temp += self::_getFile('supplementalData', '/supplementalData/languageData/language[@type=\'' . $key . '\']', 'scripts', $key);
  1026. }
  1027. $temp = array();
  1028. foreach($_temp as $key => $found) {
  1029. $_temp3 = explode(" ", $found);
  1030. foreach($_temp3 as $found3) {
  1031. if ($found3 !== $value) {
  1032. continue;
  1033. }
  1034. if (!isset($temp[$found3])) {
  1035. $temp[$found3] = (string) $key;
  1036. } else {
  1037. $temp[$found3] .= " " . $key;
  1038. }
  1039. }
  1040. }
  1041. break;
  1042. case 'territorytolanguage':
  1043. $temp = self::_getFile('supplementalData', '/supplementalData/languageData/language[@type=\'' . $value . '\']', 'territories', $value);
  1044. break;
  1045. case 'languagetoterritory':
  1046. $_temp2 = self::_getFile('supplementalData', '/supplementalData/languageData/language', 'type');
  1047. $_temp = array();
  1048. foreach ($_temp2 as $key => $found) {
  1049. $_temp += self::_getFile('supplementalData', '/supplementalData/languageData/language[@type=\'' . $key . '\']', 'territories', $key);
  1050. }
  1051. $temp = array();
  1052. foreach($_temp as $key => $found) {
  1053. $_temp3 = explode(" ", $found);
  1054. foreach($_temp3 as $found3) {
  1055. if ($found3 !== $value) {
  1056. continue;
  1057. }
  1058. if (!isset($temp[$found3])) {
  1059. $temp[$found3] = (string) $key;
  1060. } else {
  1061. $temp[$found3] .= " " . $key;
  1062. }
  1063. }
  1064. }
  1065. break;
  1066. case 'timezonetowindows':
  1067. $temp = self::_getFile('supplementalData', '/supplementalData/timezoneData/mapTimezones[@type=\'windows\']/mapZone[@other=\''.$value.'\']', 'type', $value);
  1068. break;
  1069. case 'windowstotimezone':
  1070. $temp = self::_getFile('supplementalData', '/supplementalData/timezoneData/mapTimezones[@type=\'windows\']/mapZone[@type=\''.$value.'\']', 'other', $value);
  1071. break;
  1072. case 'territorytotimezone':
  1073. $temp = self::_getFile('supplementalData', '/supplementalData/timezoneData/zoneFormatting/zoneItem[@type=\'' . $value . '\']', 'territory', $value);
  1074. break;
  1075. case 'timezonetoterritory':
  1076. $temp = self::_getFile('supplementalData', '/supplementalData/timezoneData/zoneFormatting/zoneItem[@territory=\'' . $value . '\']', 'type', $value);
  1077. break;
  1078. case 'citytotimezone':
  1079. $temp = self::_getFile($locale, '/ldml/dates/timeZoneNames/zone[@type=\'' . $value . '\']/exemplarCity', '', $value);
  1080. break;
  1081. case 'timezonetocity':
  1082. $_temp = self::_getFile($locale, '/ldml/dates/timeZoneNames/zone', 'type');
  1083. $temp = array();
  1084. foreach($_temp as $key => $found) {
  1085. $temp += self::_getFile($locale, '/ldml/dates/timeZoneNames/zone[@type=\'' . $key . '\']/exemplarCity', '', $key);
  1086. if (!empty($temp[$key])) {
  1087. if ($temp[$key] == $value) {
  1088. $temp[$temp[$key]] = $key;
  1089. }
  1090. }
  1091. unset($temp[$key]);
  1092. }
  1093. break;
  1094. case 'phonetoterritory':
  1095. $temp = self::_getFile('telephoneCodeData', '/supplementalData/telephoneCodeData/codesByTerritory[@territory=\'' . $value . '\']/telephoneCountryCode', 'code', $value);
  1096. break;
  1097. case 'territorytophone':
  1098. $_temp2 = self::_getFile('telephoneCodeData', '/supplementalData/telephoneCodeData/codesByTerritory', 'territory');
  1099. $_temp = array();
  1100. foreach ($_temp2 as $key => $found) {
  1101. $_temp += self::_getFile('telephoneCodeData', '/supplementalData/telephoneCodeData/codesByTerritory[@territory=\'' . $key . '\']/telephoneCountryCode', 'code', $key);
  1102. }
  1103. $temp = array();
  1104. foreach($_temp as $key => $found) {
  1105. $_temp3 = explode(" ", $found);
  1106. foreach($_temp3 as $found3) {
  1107. if ($found3 !== $value) {
  1108. continue;
  1109. }
  1110. if (!isset($temp[$found3])) {
  1111. $temp[$found3] = (string) $key;
  1112. } else {
  1113. $temp[$found3] .= " " . $key;
  1114. }
  1115. }
  1116. }
  1117. break;
  1118. case 'numerictoterritory':
  1119. $temp = self::_getFile('supplementalData', '/supplementalData/codeMappings/territoryCodes[@type=\''.$value.'\']', 'numeric', $value);
  1120. break;
  1121. case 'territorytonumeric':
  1122. $temp = self::_getFile('supplementalData', '/supplementalData/codeMappings/territoryCodes[@numeric=\''.$value.'\']', 'type', $value);
  1123. break;
  1124. case 'alpha3toterritory':
  1125. $temp = self::_getFile('supplementalData', '/supplementalData/codeMappings/territoryCodes[@type=\''.$value.'\']', 'alpha3', $value);
  1126. break;
  1127. case 'territorytoalpha3':
  1128. $temp = self::_getFile('supplementalData', '/supplementalData/codeMappings/territoryCodes[@alpha3=\''.$value.'\']', 'type', $value);
  1129. break;
  1130. case 'postaltoterritory':
  1131. $temp = self::_getFile('postalCodeData', '/supplementalData/postalCodeData/postCodeRegex[@territoryId=\'' . $value . '\']', 'territoryId');
  1132. break;
  1133. case 'numberingsystem':
  1134. $temp = self::_getFile('numberingSystems', '/supplementalData/numberingSystems/numberingSystem[@id=\'' . strtolower($value) . '\']', 'digits', $value);
  1135. break;
  1136. case 'chartofallback':
  1137. $_temp = self::_getFile('characters', '/supplementalData/characters/character-fallback/character', 'value');
  1138. foreach ($_temp as $key => $keyvalue) {
  1139. $temp2 = self::_getFile('characters', '/supplementalData/characters/character-fallback/character[@value=\'' . $key . '\']/substitute', '', $key);
  1140. if (current($temp2) == $value) {
  1141. $temp = $key;
  1142. }
  1143. }
  1144. break;
  1145. $temp = self::_getFile('characters', '/supplementalData/characters/character-fallback/character[@value=\'' . $value . '\']/substitute', '', $value);
  1146. break;
  1147. case 'fallbacktochar':
  1148. $temp = self::_getFile('characters', '/supplementalData/characters/character-fallback/character[@value=\'' . $value . '\']/substitute', '');
  1149. break;
  1150. default :
  1151. require_once 'Zend/Locale/Exception.php';
  1152. throw new Zend_Locale_Exception("Unknown detail ($path) for parsing locale data.");
  1153. break;
  1154. }
  1155. if (is_array($temp)) {
  1156. $temp = current($temp);
  1157. }
  1158. if (isset(self::$_cache)) {
  1159. self::$_cache->save( serialize($temp), $id);
  1160. }
  1161. return $temp;
  1162. }
  1163. /**
  1164. * Returns the set cache
  1165. *
  1166. * @return Zend_Cache_Core The set cache
  1167. */
  1168. public static function getCache()
  1169. {
  1170. return self::$_cache;
  1171. }
  1172. /**
  1173. * Set a cache for Zend_Locale_Data
  1174. *
  1175. * @param Zend_Cache_Core $cache A cache frontend
  1176. */
  1177. public static function setCache(Zend_Cache_Core $cache)
  1178. {
  1179. self::$_cache = $cache;
  1180. }
  1181. /**
  1182. * Returns true when a cache is set
  1183. *
  1184. * @return boolean
  1185. */
  1186. public static function hasCache()
  1187. {
  1188. if (self::$_cache !== null) {
  1189. return true;
  1190. }
  1191. return false;
  1192. }
  1193. /**
  1194. * Removes any set cache
  1195. *
  1196. * @return void
  1197. */
  1198. public static function removeCache()
  1199. {
  1200. self::$_cache = null;
  1201. }
  1202. /**
  1203. * Clears all set cache data
  1204. *
  1205. * @return void
  1206. */
  1207. public static function clearCache()
  1208. {
  1209. self::$_cache->clean();
  1210. }
  1211. /**
  1212. * Disables the cache
  1213. *
  1214. * @param unknown_type $flag
  1215. */
  1216. public static function disableCache($flag)
  1217. {
  1218. self::$_cacheDisabled = (boolean) $flag;
  1219. }
  1220. }