Data.php 62 KB

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