Data.php 63 KB

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