PageRenderTime 76ms CodeModel.GetById 37ms RepoModel.GetById 0ms app.codeStats 0ms

/inc/app/sitesearch/lib/Zend/Locale.php

https://github.com/lux/siteforge
PHP | 858 lines | 541 code | 93 blank | 224 comment | 76 complexity | 46846567a7901e81966ef050d99dd121 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, Apache-2.0
  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. * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
  18. * @version $Id: Locale.php,v 1.1.1.1 2007/08/12 09:24:10 lux Exp $
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. */
  21. /**
  22. * @category Zend
  23. * @package Zend_Locale
  24. * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
  25. * @license http://framework.zend.com/license/new-bsd New BSD License
  26. */
  27. class Zend_Locale {
  28. // Class wide Locale Constants
  29. private static $_localeData = array(
  30. 'root' => true, 'aa_DJ' => true, 'aa_ER' => true, 'aa_ET' => true, 'aa' => true, 'af_NA' => true, 'af_ZA' => true, 'af' => true, 'ak_GH' => true, 'ak' => true,
  31. 'am_ET' => true, 'am' => true, 'ar_AE' => true, 'ar_BH' => true, 'ar_DZ' => true, 'ar_EG' => true, 'ar_IQ' => true, 'ar_JO' => true, 'ar_KW' => true, 'ar_LB' => true,
  32. 'ar_LY' => true, 'ar_MA' => true, 'ar_OM' => true, 'ar_QA' => true, 'ar_SA' => true, 'ar_SD' => true, 'ar_SY' => true, 'ar_TN' => true, 'ar_YE' => true, 'ar' => true,
  33. 'as_IN' => true, 'as' => true, 'az_AZ' => true, 'az' => true, 'be_BY' => true, 'be' => true, 'bg_BG' => true, 'bg' => true, 'bn_BD' => true, 'bn_IN' => true,
  34. 'bn' => true, 'bs_BA' => true, 'bs' => true, 'byn_ER'=> true, 'byn' => true, 'ca_ES' => true, 'ca' => true, 'cch_NG'=> true, 'cch' => true, 'cs_CZ' => true,
  35. 'cs' => true, 'cy_GB' => true, 'cy' => true, 'da_DK' => true, 'da' => true, 'de_AT' => true, 'de_BE' => true, 'de_CH' => true, 'de_DE' => true, 'de_LI' => true,
  36. 'de_LU' => true, 'de' => true, 'dv_MV' => true, 'dv' => true, 'dz_BT' => true, 'dz' => true, 'ee_GH' => true, 'ee_TG' => true, 'ee' => true, 'el_CY' => true,
  37. 'el_GR' => true, 'el' => true, 'en_AS' => true, 'en_AU' => true, 'en_BE' => true, 'en_BW' => true, 'en_BZ' => true, 'en_CA' => true, 'en_GB' => true, 'en_GU' => true,
  38. 'en_HK' => true, 'en_IE' => true, 'en_IN' => true, 'en_JM' => true, 'en_MH' => true, 'en_MP' => true, 'en_MT' => true, 'en_NZ' => true, 'en_PH' => true, 'en_PK' => true,
  39. 'en_SG' => true, 'en_TT' => true, 'en_UM' => true, 'en_US' => true, 'en_VI' => true, 'en_ZA' => true, 'en_ZW' => true, 'en' => true, 'eo' => true, 'es_AR' => true,
  40. 'es_BO' => true, 'es_CL' => true, 'es_CO' => true, 'es_CR' => true, 'es_DO' => true, 'es_EC' => true, 'es_ES' => true, 'es_GT' => true, 'es_HN' => true, 'es_MX' => true,
  41. 'es_NI' => true, 'es_PA' => true, 'es_PE' => true, 'es_PR' => true, 'es_PY' => true, 'es_SV' => true, 'es_US' => true, 'es_UY' => true, 'es_VE' => true, 'es' => true,
  42. 'et_EE' => true, 'et' => true, 'eu_ES' => true, 'eu' => true, 'fa_AF' => true, 'fa_IR' => true, 'fa' => true, 'fi_FI' => true, 'fi' => true, 'fo_FO' => true,
  43. 'fo' => true, 'fr_BE' => true, 'fr_CA' => true, 'fr_CH' => true, 'fr_FR' => true, 'fr_LU' => true, 'fr_MC' => true, 'fr' => true, 'fur_IT'=> true, 'fur' => true,
  44. 'ga_IE' => true, 'ga' => true, 'gaa_GH'=> true, 'gaa' => true, 'gez_ER'=> true, 'gez_ET'=> true, 'gez' => true, 'gl_ES' => true, 'gl' => true, 'gu_IN' => true,
  45. 'gu' => true, 'gv_GB' => true, 'gv' => true, 'ha_GH' => true, 'ha_NE' => true, 'ha_NG' => true, 'ha' => true, 'haw_US'=> true, 'haw' => true, 'he_IL' => true,
  46. 'he' => true, 'hi_IN' => true, 'hi' => true, 'hr_HR' => true, 'hr' => true, 'hu_HU' => true, 'hu' => true, 'hy_AM' => true, 'hy' => true, 'ia' => true,
  47. 'id_ID' => true, 'id' => true, 'ig_NG' => true, 'ig' => true, 'is_IS' => true, 'is' => true, 'it_CH' => true, 'it_IT' => true, 'it' => true, 'iu' => true,
  48. 'ja_JP' => true, 'ja' => true, 'ka_GE' => true, 'ka' => true, 'kaj_NG'=> true, 'kaj' => true, 'kam_KE'=> true, 'kam' => true, 'kcg_NG'=> true, 'kcg' => true,
  49. 'kfo_NG'=> true, 'kfo' => true, 'kk_KZ' => true, 'kk' => true, 'kl_GL' => true, 'kl' => true, 'km_KH' => true, 'km' => true, 'kn_IN' => true, 'kn' => true,
  50. 'ko_KR' => true, 'ko' => true, 'kok_IN'=> true, 'kok' => true, 'ku_IQ' => true, 'ku_IR' => true, 'ku_SY' => true, 'ku_TR' => true, 'ku' => true, 'kw_GB' => true,
  51. 'kw' => true, 'ky_KG' => true, 'ky' => true, 'ln_CD' => true, 'ln_CG' => true, 'ln' => true, 'lo_LA' => true, 'lo' => true, 'lt_LT' => true, 'lt' => true,
  52. 'lv_LV' => true, 'lv' => true, 'mk_MK' => true, 'mk' => true, 'ml_IN' => true, 'ml' => true, 'mn_MN' => true, 'mn' => true, 'mr_IN' => true, 'mr' => true,
  53. 'ms_BN' => true, 'ms_MY' => true, 'ms' => true, 'mt_MT' => true, 'mt' => true, 'nb_NO' => true, 'nb' => true, 'ne_NP' => true, 'ne' => true, 'nl_BE' => true,
  54. 'nl_NL' => true, 'nl' => true, 'nn_NO' => true, 'nn' => true, 'nr_ZA' => true, 'nr' => true, 'nso_ZA'=> true, 'nso' => true, 'ny_MW' => true, 'ny' => true,
  55. 'om_ET' => true, 'om_KE' => true, 'om' => true, 'or_IN' => true, 'or' => true, 'pa_IN' => true, 'pa_PK' => true, 'pa' => true, 'pl_PL' => true, 'pl' => true,
  56. 'ps_AF' => true, 'ps' => true, 'pt_BR' => true, 'pt_PT' => true, 'pt' => true, 'ro_RO' => true, 'ro' => true, 'ru_RU' => true, 'ru_UA' => true, 'ru' => true,
  57. 'rw_RW' => true, 'rw' => true, 'sa_IN' => true, 'sa' => true, 'se_NO' => true, 'se' => true, 'sh_BA' => true, 'sh_CS' => true, 'sh_YU' => true, 'sh' => true,
  58. 'sid_ET'=> true, 'sid' => true, 'sk_SK' => true, 'sk' => true, 'sl_SI' => true, 'sl' => true, 'so_DJ' => true, 'so_ET' => true, 'so_KE' => true, 'so_SO' => true,
  59. 'so' => true, 'sq_AL' => true, 'sq' => true, 'sr_BA' => true, 'sr_CS' => true, 'sr_ME' => true, 'sr_RS' => true, 'sr_YU' => true, 'sr' => true, 'ss_ZA' => true,
  60. 'ss' => true, 'st_ZA' => true, 'st' => true, 'sv_FI' => true, 'sv_SE' => true, 'sv' => true, 'sw_KE' => true, 'sw_TZ' => true, 'sw' => true, 'syr_SY'=> true,
  61. 'syr' => true, 'ta_IN' => true, 'ta' => true, 'te_IN' => true, 'te' => true, 'tg_TJ' => true, 'tg' => true, 'th_TH' => true, 'th' => true, 'ti_ER' => true,
  62. 'ti_ET' => true, 'ti' => true, 'tig_ER'=> true, 'tig' => true, 'tn_ZA' => true, 'tn' => true, 'tr_TR' => true, 'tr' => true, 'ts_ZA' => true, 'ts' => true,
  63. 'tt_RU' => true, 'tt' => true, 'uk_UA' => true, 'uk' => true, 'ur_IN' => true, 'ur_PK' => true, 'ur' => true, 'uz_AF' => true, 'uz_UZ' => true, 'uz' => true,
  64. 've_ZA' => true, 've' => true, 'vi_VN' => true, 'vi' => true, 'wal_ET'=> true, 'wal' => true, 'xh_ZA' => true, 'xh' => true, 'yo_NG' => true, 'yo' => true,
  65. 'zh_CN' => true, 'zh_HK' => true, 'zh_MO' => true, 'zh_SG' => true, 'zh_TW' => true, 'zh' => true, 'zu_ZA' => true, 'zu' => true
  66. );
  67. /**
  68. * Autosearch constants
  69. */
  70. const BROWSER = 1;
  71. const ENVIRONMENT = 2;
  72. const FRAMEWORK = 3;
  73. /**
  74. * Actual set locale
  75. */
  76. private $_Locale;
  77. /**
  78. * Actual set Codeset
  79. */
  80. private $_Codeset;
  81. /**
  82. * Generates a locale object
  83. * If no locale is given a automatic search is done
  84. * Then the most probable locale will be automatically set
  85. * Search order is
  86. * 1. Given Locale
  87. * 2. HTTP Client
  88. * 3. Server Environment
  89. * 4. Framework Standard
  90. *
  91. * @param string $locale OPTIONAL locale for parsing input
  92. * @return object
  93. */
  94. public function __construct($locale = null)
  95. {
  96. if ($locale instanceof Zend_Locale) {
  97. $locale = $locale->toString();
  98. }
  99. $this->setLocale($locale);
  100. }
  101. /**
  102. * Serialization Interface
  103. *
  104. * @return string
  105. */
  106. public function serialize()
  107. {
  108. return serialize($this);
  109. }
  110. /**
  111. * Returns a string representation of the object
  112. *
  113. * @return string
  114. */
  115. public function toString()
  116. {
  117. return (string) $this->_Locale;
  118. }
  119. /**
  120. * Returns a string representation of the object
  121. * Alias for toString
  122. *
  123. * @return string
  124. */
  125. public function __toString()
  126. {
  127. return $this->toString();
  128. }
  129. /**
  130. * Search the locale automatically and return all used locales
  131. * ordered by quality
  132. *
  133. * Standard Searchorder is
  134. * - getBrowser
  135. * - getEnvironment
  136. * @todo - getFramework
  137. *
  138. * @param $searchorder - OPTIONAL searchorder
  139. * @param $fastsearch - OPTIONAL returnes the first found locale array when true
  140. * otherwise all found default locales will be returned
  141. * @return locale - returns an array of all the mosta locale string
  142. */
  143. public function getDefault($searchorder = null, $fastsearch = null)
  144. {
  145. $languages = array();
  146. if ($searchorder == self::ENVIRONMENT) {
  147. $languages = $this->getEnvironment();
  148. if (empty($languages) or !$fastsearch) {
  149. $languages = array_merge($languages, $this->getFramework());
  150. }
  151. if (empty($languages) or !$fastsearch) {
  152. $languages = array_merge($languages, $this->getBrowser());
  153. }
  154. } else if ($searchorder == self::FRAMEWORK) {
  155. $languages = $this->getFramework();
  156. if (empty($languages) or !$fastsearch) {
  157. $languages = array_merge($languages, $this->getEnvironment());
  158. }
  159. if (empty($languages) or !$fastsearch) {
  160. $languages = array_merge($languages, $this->getBrowser());
  161. }
  162. } else {
  163. $languages = $this->getBrowser();
  164. if (empty($languages) or !$fastsearch) {
  165. $languages = array_merge($languages, $this->getEnvironment());
  166. }
  167. if (empty($languages) or !$fastsearch) {
  168. $languages = array_merge($languages, $this->getFramework());
  169. }
  170. }
  171. return $languages;
  172. }
  173. /**
  174. * Expects the Systems standard locale
  175. *
  176. * For Windows:
  177. * f.e.: LC_COLLATE=C;LC_CTYPE=German_Austria.1252;LC_MONETARY=C
  178. * would be recognised as de_AT
  179. *
  180. * @return array
  181. */
  182. public function getEnvironment()
  183. {
  184. require_once 'Zend/Locale/Data/Translation.php';
  185. $language = setlocale(LC_ALL, 0);
  186. $languages = explode(';', $language);
  187. $languagearray = array();
  188. foreach ($languages as $locale)
  189. {
  190. $language = substr($locale, strpos($locale, '='));
  191. if ($language != '=C') {
  192. $language = substr($language, 1, strpos($language, '.') - 1);
  193. $splitted = explode('_', $language);
  194. if (array_key_exists((string) $language, self::$_localeData)) {
  195. $languagearray[$language] = 1;
  196. if (strlen($language) > 4) {
  197. $languagearray[substr($language, 0, 2)] = 1;
  198. }
  199. continue;
  200. }
  201. if (!empty(Zend_Locale_Data_Translation::$localeTranslation[$splitted[0]])) {
  202. if (!empty(Zend_Locale_Data_Translation::$localeTranslation[$splitted[1]])) {
  203. $languagearray[Zend_Locale_Data_Translation::$localeTranslation[$splitted[0]] . '_'
  204. . Zend_Locale_Data_Translation::$localeTranslation[$splitted[1]]] = 1;
  205. }
  206. $languagearray[Zend_Locale_Data_Translation::$localeTranslation[$splitted[0]]] = 1;
  207. }
  208. }
  209. }
  210. return $languagearray;
  211. }
  212. /**
  213. * Return an array of all accepted languages of the client
  214. * Expects RFC compilant Header !!
  215. *
  216. * The notation can be :
  217. * de,en-UK-US;q=0.5,fr-FR;q=0.2
  218. *
  219. * @return array - list of accepted languages including quality
  220. */
  221. public function getBrowser()
  222. {
  223. $httplanguages = getenv("HTTP_ACCEPT_LANGUAGE");
  224. $languages = array();
  225. if (empty($httplanguages)) {
  226. return $languages;
  227. }
  228. $accepted = preg_split('/,\s*/', $httplanguages);
  229. foreach ($accepted as $accept) {
  230. $result = preg_match('/^([a-z]{1,8}(?:[-_][a-z]{1,8})*)(?:;\s*q=(0(?:\.[0-9]{1,3})?|1(?:\.0{1,3})?))?$/i',
  231. $accept, $match);
  232. if (!$result) {
  233. continue;
  234. }
  235. if (isset($match[2])) {
  236. $quality = (float) $match[2];
  237. } else {
  238. $quality = 1.0;
  239. }
  240. $countrys = explode('-', $match[1]);
  241. $region = array_shift($countrys);
  242. $country2 = explode('_', $region);
  243. $region = array_shift($country2);
  244. foreach($countrys as $country) {
  245. $languages[$region . '_' . strtoupper($country)] = $quality;
  246. }
  247. foreach($country2 as $country) {
  248. $languages[$region . '_' . strtoupper($country)] = $quality;
  249. }
  250. $languages[$region] = $quality;
  251. }
  252. return $languages;
  253. }
  254. /**
  255. * Returns the locale which the framework is set to
  256. */
  257. public function getFramework()
  258. {
  259. $languages = array();
  260. return $languages;
  261. }
  262. /**
  263. * Sets a new locale
  264. *
  265. * @param mixed $locale OPTIONAL new locale to set
  266. */
  267. public function setLocale($locale = null)
  268. {
  269. if (($locale == self::BROWSER) or ($locale == self::ENVIRONMENT) or ($locale === null)) {
  270. $locale = $this->getDefault($locale, true);
  271. }
  272. if (is_array($locale)) {
  273. $locale = key($locale);
  274. }
  275. if (!array_key_exists((string) $locale, self::$_localeData)) {
  276. $region = substr($locale, 0, 3);
  277. if (isset($region[2])) {
  278. if (($region[2] == '_') or ($region[2] == '-')) {
  279. $region = substr($region, 0, 2);
  280. }
  281. }
  282. if (array_key_exists((string) $region, self::$_localeData)) {
  283. $this->_Locale = $region;
  284. } else {
  285. $this->_Locale = 'root';
  286. }
  287. } else {
  288. $this->_Locale = $locale;
  289. }
  290. }
  291. /**
  292. * Returns the language part of the locale
  293. *
  294. * @return language
  295. */
  296. public function getLanguage()
  297. {
  298. $locale = explode('_', $this->_Locale);
  299. return $locale[0];
  300. }
  301. /**
  302. * Returns the region part of the locale if avaiable
  303. *
  304. * @return region
  305. */
  306. public function getRegion()
  307. {
  308. $locale = explode('_', $this->_Locale);
  309. if (isset($locale[1])) {
  310. return $locale[1];
  311. }
  312. return false;
  313. }
  314. /**
  315. * Return the accepted charset of the client
  316. * @todo verify working
  317. */
  318. public function getHttpCharset()
  319. {
  320. $httpcharsets = getenv("HTTP_ACCEPT_CHARSET");
  321. $charsets = array();
  322. if ($httpcharsets === false) {
  323. return $charsets;
  324. }
  325. $accepted = preg_split('/,\s*/', $httpcharsets);
  326. foreach ($accepted as $accept)
  327. {
  328. if (empty($accept)) {
  329. continue;
  330. }
  331. if (strpos($accept, ';'))
  332. {
  333. $quality = (float) substr($accept, strpos($accept, '=') + 1);
  334. $charsets[substr($accept, 0, strpos($accept, ';'))] = $quality;
  335. } else {
  336. $quality = 1.0;
  337. $charsets[$accept] = $quality;
  338. }
  339. }
  340. return $charsets;
  341. }
  342. /**
  343. * Returns true if both locales are equal
  344. *
  345. * @return boolean
  346. */
  347. public function equals($object)
  348. {
  349. if ($object->toString() == $this->toString()) {
  350. return true;
  351. }
  352. return false;
  353. }
  354. /**
  355. * Returns localized informations as array, supported are several
  356. * types of informations.
  357. * Supported types are:
  358. * 'language', 'script', 'country', 'territory', 'calendar', 'month', 'month_short',
  359. * 'month_narrow', 'day', 'day_short', 'day_narrow', 'dateformat', 'timeformat',
  360. * 'timezone', 'currency', 'currency_sign', 'currency_detail', 'territory_detail'
  361. * 'language_detail', 'characters'
  362. * For detailed information about the types look into the documentation
  363. *
  364. * @param string $type OPTIONAL Type of information to return
  365. * @param string|locale $locale OPTIONAL Locale|Language for which this informations should be returned
  366. * @return array Array with the wished information in the given language
  367. */
  368. public function getTranslationList($type = null, $locale = null)
  369. {
  370. // load class within method for speed
  371. require_once 'Zend/Locale/Data.php';
  372. if ($locale === null) {
  373. $locale = $this->_Locale;
  374. }
  375. switch (strtolower($type)) {
  376. case 'language' :
  377. return Zend_Locale_Data::getContent($locale, 'languagelist');
  378. break;
  379. case 'script' :
  380. return Zend_Locale_Data::getContent($locale, 'scriptlist');
  381. break;
  382. case 'country' :
  383. $list = Zend_Locale_Data::getContent($locale, 'territorylist');
  384. foreach ($list as $key => $entry) {
  385. if (is_numeric($key) or ($key == "QO")) {
  386. unset($list[$key]);
  387. }
  388. }
  389. return $list;
  390. break;
  391. case 'territory' :
  392. $list = Zend_Locale_Data::getContent($locale, 'territorylist');
  393. foreach ($list as $key => $entry) {
  394. if (!is_numeric($key) and ($key != "QO")) {
  395. unset($list[$key]);
  396. }
  397. }
  398. return $list;
  399. break;
  400. case 'calendar' :
  401. return Zend_Locale_Data::getContent($locale, 'type', 'calendar');
  402. break;
  403. case 'month' :
  404. return Zend_Locale_Data::getContent($locale, 'monthlist', array('gregorian', 'format', 'wide'));
  405. break;
  406. case 'month_short' :
  407. return Zend_Locale_Data::getContent($locale, 'monthlist', array('gregorian', 'format', 'abbreviated'));
  408. break;
  409. case 'month_narrow' :
  410. return Zend_Locale_Data::getContent($locale, 'monthlist', array('gregorian', 'stand-alone', 'narrow'));
  411. break;
  412. case 'day' :
  413. return Zend_Locale_Data::getContent($locale, 'daylist', array('gregorian', 'format', 'wide'));
  414. break;
  415. case 'day_short' :
  416. return Zend_Locale_Data::getContent($locale, 'daylist', array('gregorian', 'format', 'abbreviated'));
  417. break;
  418. case 'day_narrow' :
  419. return Zend_Locale_Data::getContent($locale, 'daylist', array('gregorian', 'stand-alone', 'narrow'));
  420. break;
  421. case 'dateformat' :
  422. $result = Zend_Locale_Data::getContent($locale, 'defdateformat', 'gregorian');
  423. $result = Zend_Locale_Data::getContent($locale, 'dateformat', array('gregorian', $result['default'], 'narrow'));
  424. $list['default'] = $result['pattern'];
  425. $result = Zend_Locale_Data::getContent($locale, 'dateformat', array('gregorian', 'full', 'narrow'));
  426. $list['full'] = $result['pattern'];
  427. $result = Zend_Locale_Data::getContent($locale, 'dateformat', array('gregorian', 'long', 'narrow'));
  428. $list['long'] = $result['pattern'];
  429. $result = Zend_Locale_Data::getContent($locale, 'dateformat', array('gregorian', 'medium', 'narrow'));
  430. $list['medium'] = $result['pattern'];
  431. $result = Zend_Locale_Data::getContent($locale, 'dateformat', array('gregorian', 'short', 'narrow'));
  432. $list['short'] = $result['pattern'];
  433. return $list;
  434. break;
  435. case 'timeformat' :
  436. $result = Zend_Locale_Data::getContent($locale, 'deftimeformat', 'gregorian');
  437. $result = Zend_Locale_Data::getContent($locale, 'timeformat', array('gregorian', $result['default'], 'narrow'));
  438. $list['default'] = $result['pattern'];
  439. $result = Zend_Locale_Data::getContent($locale, 'timeformat', array('gregorian', 'full', 'narrow'));
  440. $list['full'] = $result['pattern'];
  441. $result = Zend_Locale_Data::getContent($locale, 'timeformat', array('gregorian', 'long', 'narrow'));
  442. $list['long'] = $result['pattern'];
  443. $result = Zend_Locale_Data::getContent($locale, 'timeformat', array('gregorian', 'medium', 'narrow'));
  444. $list['medium'] = $result['pattern'];
  445. $result = Zend_Locale_Data::getContent($locale, 'timeformat', array('gregorian', 'short', 'narrow'));
  446. $list['short'] = $result['pattern'];
  447. return $list;
  448. break;
  449. case 'timezone' :
  450. return Zend_Locale_Data::getContent($locale, 'timezones');
  451. break;
  452. case 'currency' :
  453. return Zend_Locale_Data::getContent($locale, 'currencynames');
  454. break;
  455. case 'currency_sign' :
  456. return Zend_Locale_Data::getContent($locale, 'currencysymbols');
  457. break;
  458. case 'currency_detail' :
  459. return Zend_Locale_Data::getContent($locale, 'currencyforregionlist');
  460. break;
  461. case 'territory_detail' :
  462. return Zend_Locale_Data::getContent($locale, 'regionforterritorylist');
  463. break;
  464. case 'language_detail' :
  465. return Zend_Locale_Data::getContent($locale, 'territoryforlanguagelist');
  466. break;
  467. case 'characters' :
  468. return Zend_Locale_Data::getContent($locale, 'characters');
  469. break;
  470. default :
  471. return array('language', 'script', 'country', 'territory', 'calendar', 'month', 'month_short',
  472. 'month_narrow', 'day', 'day_short', 'day_narrow', 'dateformat', 'timeformat',
  473. 'timezone', 'currency', 'currency_sign', 'currency_detail', 'territory_detail',
  474. 'language_detail', 'characters');
  475. }
  476. return false;
  477. }
  478. /**
  479. * Returns an array with the name of all languages translated to the given language
  480. *
  481. * @param string $locale OPTIONAL locale for language translation
  482. * @return array
  483. */
  484. public function getLanguageTranslationList($locale = null)
  485. {
  486. return $this->getTranslationList('language', $locale);
  487. }
  488. /**
  489. * Returns an array with the name of all scripts translated to the given language
  490. *
  491. * @param string $locale OPTIONAL locale for script translation
  492. * @return array
  493. */
  494. public function getScriptTranslationList($locale = null)
  495. {
  496. return $this->getTranslationList('script', $locale);
  497. }
  498. /**
  499. * Returns an array with the name of all countries translated to the given language
  500. *
  501. * @param string $locale OPTIONAL locale for country translation
  502. * @return array
  503. */
  504. public function getCountryTranslationList($locale = null)
  505. {
  506. return $this->getTranslationList('country', $locale);
  507. }
  508. /**
  509. * Returns an array with the name of all territories translated to the given language
  510. * All territories contains other countries.
  511. *
  512. * @param string $locale OPTIONAL locale for territory translation
  513. * @return array
  514. */
  515. public function getTerritoryTranslationList($locale = null)
  516. {
  517. return $this->getTranslationList('territory', $locale);
  518. }
  519. /**
  520. * Returns a localized information string, supported are several types of informations.
  521. *
  522. * Supported types are:
  523. * 'language', 'script', 'country', 'territory', 'calendar', 'month', 'month_short',
  524. * 'month_narrow', 'day', 'day_short', 'day_narrow', 'dateformat', 'timeformat',
  525. * 'timezone', 'currency', 'currency_sign', 'currency_detail', 'territory_detail', 'language_detail', 'characters'
  526. * For detailed information about the types look into the documentation
  527. *
  528. * @param string $what Name to get detailed information about
  529. * @param string $type OPTIONAL Type of information to return
  530. * @param string|locale $locale OPTIONAL Locale|Language for which this informations should be returned
  531. * @return string|array Array with the wished information in the given language
  532. */
  533. public function getTranslation($what, $type = null, $locale = null)
  534. {
  535. // load class within method for speed
  536. require_once 'Zend/Locale/Data.php';
  537. if ($locale === null) {
  538. $locale = $this->_Locale;
  539. }
  540. switch (strtolower($type)) {
  541. case 'language' :
  542. $list = Zend_Locale_Data::getContent($locale, 'language', $what);
  543. if (isset($list[$what])) {
  544. return $list[$what];
  545. }
  546. break;
  547. case 'script' :
  548. $list = Zend_Locale_Data::getContent($locale, 'script', $what);
  549. if (isset($list[$what])) {
  550. return $list[$what];
  551. }
  552. break;
  553. case 'country' :
  554. $list = Zend_Locale_Data::getContent($locale, 'territory', $what);
  555. if (isset($list[$what])) {
  556. return $list[$what];
  557. }
  558. break;
  559. case 'territory' :
  560. $list = Zend_Locale_Data::getContent($locale, 'territory', $what);
  561. if (isset($list[$what])) {
  562. return $list[$what];
  563. }
  564. break;
  565. case 'calendar' :
  566. $list = Zend_Locale_Data::getContent($locale, 'type', $what);
  567. if (isset($list[$what])) {
  568. return $list[$what];
  569. }
  570. break;
  571. case 'month' :
  572. $list = Zend_Locale_Data::getContent($locale, 'month', array('gregorian', 'format', 'wide', $what));
  573. if (isset($list[$what])) {
  574. return $list[$what];
  575. }
  576. break;
  577. case 'month_short' :
  578. $list = Zend_Locale_Data::getContent($locale, 'month', array('gregorian', 'format', 'abbreviated', $what));
  579. if (isset($list[$what])) {
  580. return $list[$what];
  581. }
  582. break;
  583. case 'month_narrow' :
  584. $list = Zend_Locale_Data::getContent($locale, 'month', array('gregorian', 'stand-alone', 'narrow', $what));
  585. if (isset($list[$what])) {
  586. return $list[$what];
  587. }
  588. break;
  589. case 'day' :
  590. $list = Zend_Locale_Data::getContent($locale, 'day', array('gregorian', 'format', 'wide', $what));
  591. if (isset($list[$what])) {
  592. return $list[$what];
  593. }
  594. break;
  595. case 'day_short' :
  596. $list = Zend_Locale_Data::getContent($locale, 'day', array('gregorian', 'format', 'abbreviated', $what));
  597. if (isset($list[$what])) {
  598. return $list[$what];
  599. }
  600. break;
  601. case 'day_narrow' :
  602. $list = Zend_Locale_Data::getContent($locale, 'day', array('gregorian', 'stand-alone', 'narrow', $what));
  603. if (isset($list[$what])) {
  604. return $list[$what];
  605. }
  606. break;
  607. case 'dateformat' :
  608. $list = Zend_Locale_Data::getContent($locale, 'dateformat', array('gregorian', $what, 'narrow'));
  609. if (isset($list['pattern'])) {
  610. return $list['pattern'];
  611. }
  612. break;
  613. case 'timeformat' :
  614. $list = Zend_Locale_Data::getContent($locale, 'timeformat', array('gregorian', $what, 'narrow'));
  615. if (isset($list['pattern'])) {
  616. return $list['pattern'];
  617. }
  618. break;
  619. case 'timezone' :
  620. $list = Zend_Locale_Data::getContent($locale, 'timezone', $what);
  621. if (isset($list[$what])) {
  622. return $list[$what];
  623. }
  624. break;
  625. case 'currency' :
  626. $list = Zend_Locale_Data::getContent($locale, 'currencyname', $what);
  627. if (isset($list[$what])) {
  628. return $list[$what];
  629. }
  630. break;
  631. case 'currency_sign' :
  632. $list = Zend_Locale_Data::getContent($locale, 'currencysymbol', $what);
  633. if (isset($list[$what])) {
  634. return $list[$what];
  635. }
  636. break;
  637. case 'currency_detail' :
  638. $list = Zend_Locale_Data::getContent($locale, 'currencyforregion', $what);
  639. if (!empty($list)) {
  640. return $list;
  641. }
  642. break;
  643. case 'territory_detail' :
  644. $list = Zend_Locale_Data::getContent($locale, 'regionforterritory', $what);
  645. if (isset($list[$what])) {
  646. return explode(' ', $list[$what]);
  647. }
  648. break;
  649. case 'language_detail' :
  650. $list = Zend_Locale_Data::getContent($locale, 'territoryforlanguage', $what);
  651. if (isset($list[$what])) {
  652. return explode(' ', $list[$what]);
  653. }
  654. break;
  655. case 'characters' :
  656. $list = Zend_Locale_Data::getContent($locale, 'characters');
  657. return $list[0];
  658. break;
  659. default :
  660. return array('language', 'script', 'country', 'territory', 'calendar', 'month', 'month_short',
  661. 'month_narrow', 'day', 'day_short', 'day_narrow', 'dateformat', 'timeformat',
  662. 'timezone', 'currency', 'currency_sign', 'currency_detail', 'territory_detail',
  663. 'language_detail', 'characters');
  664. }
  665. return false;
  666. }
  667. /**
  668. * Returns the localized language name
  669. *
  670. * @param string $what Name to get detailed information about
  671. * @param string $locale OPTIONAL locale for language translation
  672. * @return array
  673. */
  674. public function getLanguageTranslation($what, $locale = null)
  675. {
  676. return $this->getTranslation($what, 'language', $locale);
  677. }
  678. /**
  679. * Returns the localized script name
  680. *
  681. * @param string $what Name to get detailed information about
  682. * @param string $locale OPTIONAL locale for script translation
  683. * @return array
  684. */
  685. public function getScriptTranslation($what, $locale = null)
  686. {
  687. return $this->getTranslation($what, 'script', $locale);
  688. }
  689. /**
  690. * Returns the localized country name
  691. *
  692. * @param string $what Name to get detailed information about
  693. * @param string $locale OPTIONAL locale for country translation
  694. * @return array
  695. */
  696. public function getCountryTranslation($what, $locale = null)
  697. {
  698. return $this->getTranslation($what, 'country', $locale);
  699. }
  700. /**
  701. * Returns the localized territory name
  702. * All territories contains other countries.
  703. *
  704. * @param string $what Name to get detailed information about
  705. * @param string $locale OPTIONAL locale for territory translation
  706. * @return array
  707. */
  708. public function getTerritoryTranslation($what, $locale = null)
  709. {
  710. return $this->getTranslation($what, 'territory', $locale);
  711. }
  712. /**
  713. * Returns an array with translated yes strings
  714. *
  715. * @param string $locale OPTIONAL locale for language translation (defaults to $this locale)
  716. * @return array
  717. */
  718. public function getQuestion($locale = null)
  719. {
  720. // load class within method for speed
  721. require_once 'Zend/Locale/Data.php';
  722. if ($locale === null) {
  723. $locale = $this->_Locale;
  724. }
  725. $quest = Zend_Locale_Data::getContent($locale, 'questionstrings');
  726. $yes = explode(':', $quest['yes']);
  727. $no = explode(':', $quest['no']);
  728. $quest['yes'] = $yes[0];
  729. $quest['yesabbr'] = $yes[1];
  730. $quest['no'] = $no[0];
  731. $quest['noabbr'] = $no[1];
  732. return $quest;
  733. }
  734. /**
  735. * Checks if a locale identifier is a real locale or not
  736. * Examples:
  737. * "en_XX" refers to "en", which returns true
  738. * "XX_yy" refers to "root", which returns false
  739. *
  740. * @param string|Zend_Locale $locale Locale to check for
  741. * @param boolean $create If true, create a default locale, if $locale is empty
  742. * @return false|string false if given locale is not a locale, else the locale identifier is returned
  743. */
  744. public static function isLocale($locale, $create = false)
  745. {
  746. if (empty($locale) and ($create === true)) {
  747. $locale = new Zend_Locale();
  748. }
  749. if ($locale instanceof Zend_Locale) {
  750. return $locale->toString();
  751. }
  752. if (!is_string($locale)) {
  753. return false;
  754. }
  755. if (array_key_exists($locale, self::$_localeData)) {
  756. return $locale;
  757. } else {
  758. $locale = explode('_', $locale);
  759. if (array_key_exists($locale[0], self::$_localeData)) {
  760. return $locale[0];
  761. }
  762. }
  763. return false;
  764. }
  765. }