/inc/app/sitesearch/lib/Zend/Locale.php
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
- <?php
- /**
- * Zend Framework
- *
- * LICENSE
- *
- * This source file is subject to the new BSD license that is bundled
- * with this package in the file LICENSE.txt.
- * It is also available through the world-wide-web at this URL:
- * http://framework.zend.com/license/new-bsd
- * If you did not receive a copy of the license and are unable to
- * obtain it through the world-wide-web, please send an email
- * to license@zend.com so we can send you a copy immediately.
- *
- * @category Zend
- * @package Zend_Locale
- * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
- * @version $Id: Locale.php,v 1.1.1.1 2007/08/12 09:24:10 lux Exp $
- * @license http://framework.zend.com/license/new-bsd New BSD License
- */
- /**
- * @category Zend
- * @package Zend_Locale
- * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
- * @license http://framework.zend.com/license/new-bsd New BSD License
- */
- class Zend_Locale {
- // Class wide Locale Constants
- private static $_localeData = array(
- '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,
- '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,
- '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,
- '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,
- '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,
- '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,
- '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,
- '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,
- '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,
- '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,
- '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,
- '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,
- '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,
- '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,
- '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,
- '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,
- 'he' => true, 'hi_IN' => true, 'hi' => true, 'hr_HR' => true, 'hr' => true, 'hu_HU' => true, 'hu' => true, 'hy_AM' => true, 'hy' => true, 'ia' => true,
- '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,
- '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,
- '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,
- '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,
- '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,
- '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,
- '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,
- '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,
- '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,
- '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,
- '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,
- '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,
- '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,
- '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,
- '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,
- '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,
- '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,
- '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,
- 'zh_CN' => true, 'zh_HK' => true, 'zh_MO' => true, 'zh_SG' => true, 'zh_TW' => true, 'zh' => true, 'zu_ZA' => true, 'zu' => true
- );
- /**
- * Autosearch constants
- */
- const BROWSER = 1;
- const ENVIRONMENT = 2;
- const FRAMEWORK = 3;
- /**
- * Actual set locale
- */
- private $_Locale;
- /**
- * Actual set Codeset
- */
- private $_Codeset;
- /**
- * Generates a locale object
- * If no locale is given a automatic search is done
- * Then the most probable locale will be automatically set
- * Search order is
- * 1. Given Locale
- * 2. HTTP Client
- * 3. Server Environment
- * 4. Framework Standard
- *
- * @param string $locale OPTIONAL locale for parsing input
- * @return object
- */
- public function __construct($locale = null)
- {
- if ($locale instanceof Zend_Locale) {
- $locale = $locale->toString();
- }
- $this->setLocale($locale);
- }
- /**
- * Serialization Interface
- *
- * @return string
- */
- public function serialize()
- {
- return serialize($this);
- }
- /**
- * Returns a string representation of the object
- *
- * @return string
- */
- public function toString()
- {
- return (string) $this->_Locale;
- }
- /**
- * Returns a string representation of the object
- * Alias for toString
- *
- * @return string
- */
- public function __toString()
- {
- return $this->toString();
- }
- /**
- * Search the locale automatically and return all used locales
- * ordered by quality
- *
- * Standard Searchorder is
- * - getBrowser
- * - getEnvironment
- * @todo - getFramework
- *
- * @param $searchorder - OPTIONAL searchorder
- * @param $fastsearch - OPTIONAL returnes the first found locale array when true
- * otherwise all found default locales will be returned
- * @return locale - returns an array of all the mosta locale string
- */
- public function getDefault($searchorder = null, $fastsearch = null)
- {
- $languages = array();
- if ($searchorder == self::ENVIRONMENT) {
- $languages = $this->getEnvironment();
- if (empty($languages) or !$fastsearch) {
- $languages = array_merge($languages, $this->getFramework());
- }
- if (empty($languages) or !$fastsearch) {
- $languages = array_merge($languages, $this->getBrowser());
- }
- } else if ($searchorder == self::FRAMEWORK) {
- $languages = $this->getFramework();
- if (empty($languages) or !$fastsearch) {
- $languages = array_merge($languages, $this->getEnvironment());
- }
- if (empty($languages) or !$fastsearch) {
- $languages = array_merge($languages, $this->getBrowser());
- }
- } else {
- $languages = $this->getBrowser();
- if (empty($languages) or !$fastsearch) {
- $languages = array_merge($languages, $this->getEnvironment());
- }
- if (empty($languages) or !$fastsearch) {
- $languages = array_merge($languages, $this->getFramework());
- }
- }
- return $languages;
- }
- /**
- * Expects the Systems standard locale
- *
- * For Windows:
- * f.e.: LC_COLLATE=C;LC_CTYPE=German_Austria.1252;LC_MONETARY=C
- * would be recognised as de_AT
- *
- * @return array
- */
- public function getEnvironment()
- {
- require_once 'Zend/Locale/Data/Translation.php';
- $language = setlocale(LC_ALL, 0);
- $languages = explode(';', $language);
- $languagearray = array();
- foreach ($languages as $locale)
- {
- $language = substr($locale, strpos($locale, '='));
- if ($language != '=C') {
- $language = substr($language, 1, strpos($language, '.') - 1);
- $splitted = explode('_', $language);
- if (array_key_exists((string) $language, self::$_localeData)) {
- $languagearray[$language] = 1;
- if (strlen($language) > 4) {
- $languagearray[substr($language, 0, 2)] = 1;
- }
- continue;
- }
- if (!empty(Zend_Locale_Data_Translation::$localeTranslation[$splitted[0]])) {
- if (!empty(Zend_Locale_Data_Translation::$localeTranslation[$splitted[1]])) {
- $languagearray[Zend_Locale_Data_Translation::$localeTranslation[$splitted[0]] . '_'
- . Zend_Locale_Data_Translation::$localeTranslation[$splitted[1]]] = 1;
- }
- $languagearray[Zend_Locale_Data_Translation::$localeTranslation[$splitted[0]]] = 1;
- }
- }
- }
- return $languagearray;
- }
- /**
- * Return an array of all accepted languages of the client
- * Expects RFC compilant Header !!
- *
- * The notation can be :
- * de,en-UK-US;q=0.5,fr-FR;q=0.2
- *
- * @return array - list of accepted languages including quality
- */
- public function getBrowser()
- {
- $httplanguages = getenv("HTTP_ACCEPT_LANGUAGE");
- $languages = array();
- if (empty($httplanguages)) {
- return $languages;
- }
- $accepted = preg_split('/,\s*/', $httplanguages);
- foreach ($accepted as $accept) {
- $result = preg_match('/^([a-z]{1,8}(?:[-_][a-z]{1,8})*)(?:;\s*q=(0(?:\.[0-9]{1,3})?|1(?:\.0{1,3})?))?$/i',
- $accept, $match);
- if (!$result) {
- continue;
- }
- if (isset($match[2])) {
- $quality = (float) $match[2];
- } else {
- $quality = 1.0;
- }
- $countrys = explode('-', $match[1]);
- $region = array_shift($countrys);
- $country2 = explode('_', $region);
- $region = array_shift($country2);
- foreach($countrys as $country) {
- $languages[$region . '_' . strtoupper($country)] = $quality;
- }
- foreach($country2 as $country) {
- $languages[$region . '_' . strtoupper($country)] = $quality;
- }
- $languages[$region] = $quality;
- }
- return $languages;
- }
- /**
- * Returns the locale which the framework is set to
- */
- public function getFramework()
- {
- $languages = array();
- return $languages;
- }
- /**
- * Sets a new locale
- *
- * @param mixed $locale OPTIONAL new locale to set
- */
- public function setLocale($locale = null)
- {
- if (($locale == self::BROWSER) or ($locale == self::ENVIRONMENT) or ($locale === null)) {
- $locale = $this->getDefault($locale, true);
- }
- if (is_array($locale)) {
- $locale = key($locale);
- }
- if (!array_key_exists((string) $locale, self::$_localeData)) {
- $region = substr($locale, 0, 3);
- if (isset($region[2])) {
- if (($region[2] == '_') or ($region[2] == '-')) {
- $region = substr($region, 0, 2);
- }
- }
- if (array_key_exists((string) $region, self::$_localeData)) {
- $this->_Locale = $region;
- } else {
- $this->_Locale = 'root';
- }
- } else {
- $this->_Locale = $locale;
- }
- }
- /**
- * Returns the language part of the locale
- *
- * @return language
- */
- public function getLanguage()
- {
- $locale = explode('_', $this->_Locale);
- return $locale[0];
- }
- /**
- * Returns the region part of the locale if avaiable
- *
- * @return region
- */
- public function getRegion()
- {
- $locale = explode('_', $this->_Locale);
- if (isset($locale[1])) {
- return $locale[1];
- }
- return false;
- }
- /**
- * Return the accepted charset of the client
- * @todo verify working
- */
- public function getHttpCharset()
- {
- $httpcharsets = getenv("HTTP_ACCEPT_CHARSET");
- $charsets = array();
- if ($httpcharsets === false) {
- return $charsets;
- }
- $accepted = preg_split('/,\s*/', $httpcharsets);
- foreach ($accepted as $accept)
- {
- if (empty($accept)) {
- continue;
- }
- if (strpos($accept, ';'))
- {
- $quality = (float) substr($accept, strpos($accept, '=') + 1);
- $charsets[substr($accept, 0, strpos($accept, ';'))] = $quality;
- } else {
- $quality = 1.0;
- $charsets[$accept] = $quality;
- }
- }
- return $charsets;
- }
- /**
- * Returns true if both locales are equal
- *
- * @return boolean
- */
- public function equals($object)
- {
- if ($object->toString() == $this->toString()) {
- return true;
- }
- return false;
- }
- /**
- * Returns localized informations as array, supported are several
- * types of informations.
- * Supported types are:
- * 'language', 'script', 'country', 'territory', 'calendar', 'month', 'month_short',
- * 'month_narrow', 'day', 'day_short', 'day_narrow', 'dateformat', 'timeformat',
- * 'timezone', 'currency', 'currency_sign', 'currency_detail', 'territory_detail'
- * 'language_detail', 'characters'
- * For detailed information about the types look into the documentation
- *
- * @param string $type OPTIONAL Type of information to return
- * @param string|locale $locale OPTIONAL Locale|Language for which this informations should be returned
- * @return array Array with the wished information in the given language
- */
- public function getTranslationList($type = null, $locale = null)
- {
- // load class within method for speed
- require_once 'Zend/Locale/Data.php';
- if ($locale === null) {
- $locale = $this->_Locale;
- }
- switch (strtolower($type)) {
- case 'language' :
- return Zend_Locale_Data::getContent($locale, 'languagelist');
- break;
- case 'script' :
- return Zend_Locale_Data::getContent($locale, 'scriptlist');
- break;
- case 'country' :
- $list = Zend_Locale_Data::getContent($locale, 'territorylist');
- foreach ($list as $key => $entry) {
- if (is_numeric($key) or ($key == "QO")) {
- unset($list[$key]);
- }
- }
- return $list;
- break;
- case 'territory' :
- $list = Zend_Locale_Data::getContent($locale, 'territorylist');
- foreach ($list as $key => $entry) {
- if (!is_numeric($key) and ($key != "QO")) {
- unset($list[$key]);
- }
- }
- return $list;
- break;
- case 'calendar' :
- return Zend_Locale_Data::getContent($locale, 'type', 'calendar');
- break;
- case 'month' :
- return Zend_Locale_Data::getContent($locale, 'monthlist', array('gregorian', 'format', 'wide'));
- break;
- case 'month_short' :
- return Zend_Locale_Data::getContent($locale, 'monthlist', array('gregorian', 'format', 'abbreviated'));
- break;
- case 'month_narrow' :
- return Zend_Locale_Data::getContent($locale, 'monthlist', array('gregorian', 'stand-alone', 'narrow'));
- break;
- case 'day' :
- return Zend_Locale_Data::getContent($locale, 'daylist', array('gregorian', 'format', 'wide'));
- break;
- case 'day_short' :
- return Zend_Locale_Data::getContent($locale, 'daylist', array('gregorian', 'format', 'abbreviated'));
- break;
- case 'day_narrow' :
- return Zend_Locale_Data::getContent($locale, 'daylist', array('gregorian', 'stand-alone', 'narrow'));
- break;
- case 'dateformat' :
- $result = Zend_Locale_Data::getContent($locale, 'defdateformat', 'gregorian');
- $result = Zend_Locale_Data::getContent($locale, 'dateformat', array('gregorian', $result['default'], 'narrow'));
- $list['default'] = $result['pattern'];
- $result = Zend_Locale_Data::getContent($locale, 'dateformat', array('gregorian', 'full', 'narrow'));
- $list['full'] = $result['pattern'];
- $result = Zend_Locale_Data::getContent($locale, 'dateformat', array('gregorian', 'long', 'narrow'));
- $list['long'] = $result['pattern'];
- $result = Zend_Locale_Data::getContent($locale, 'dateformat', array('gregorian', 'medium', 'narrow'));
- $list['medium'] = $result['pattern'];
- $result = Zend_Locale_Data::getContent($locale, 'dateformat', array('gregorian', 'short', 'narrow'));
- $list['short'] = $result['pattern'];
- return $list;
- break;
- case 'timeformat' :
- $result = Zend_Locale_Data::getContent($locale, 'deftimeformat', 'gregorian');
- $result = Zend_Locale_Data::getContent($locale, 'timeformat', array('gregorian', $result['default'], 'narrow'));
- $list['default'] = $result['pattern'];
- $result = Zend_Locale_Data::getContent($locale, 'timeformat', array('gregorian', 'full', 'narrow'));
- $list['full'] = $result['pattern'];
- $result = Zend_Locale_Data::getContent($locale, 'timeformat', array('gregorian', 'long', 'narrow'));
- $list['long'] = $result['pattern'];
- $result = Zend_Locale_Data::getContent($locale, 'timeformat', array('gregorian', 'medium', 'narrow'));
- $list['medium'] = $result['pattern'];
- $result = Zend_Locale_Data::getContent($locale, 'timeformat', array('gregorian', 'short', 'narrow'));
- $list['short'] = $result['pattern'];
- return $list;
- break;
- case 'timezone' :
- return Zend_Locale_Data::getContent($locale, 'timezones');
- break;
- case 'currency' :
- return Zend_Locale_Data::getContent($locale, 'currencynames');
- break;
- case 'currency_sign' :
- return Zend_Locale_Data::getContent($locale, 'currencysymbols');
- break;
- case 'currency_detail' :
- return Zend_Locale_Data::getContent($locale, 'currencyforregionlist');
- break;
- case 'territory_detail' :
- return Zend_Locale_Data::getContent($locale, 'regionforterritorylist');
- break;
- case 'language_detail' :
- return Zend_Locale_Data::getContent($locale, 'territoryforlanguagelist');
- break;
- case 'characters' :
- return Zend_Locale_Data::getContent($locale, 'characters');
- break;
- default :
- return array('language', 'script', 'country', 'territory', 'calendar', 'month', 'month_short',
- 'month_narrow', 'day', 'day_short', 'day_narrow', 'dateformat', 'timeformat',
- 'timezone', 'currency', 'currency_sign', 'currency_detail', 'territory_detail',
- 'language_detail', 'characters');
- }
- return false;
- }
- /**
- * Returns an array with the name of all languages translated to the given language
- *
- * @param string $locale OPTIONAL locale for language translation
- * @return array
- */
- public function getLanguageTranslationList($locale = null)
- {
- return $this->getTranslationList('language', $locale);
- }
- /**
- * Returns an array with the name of all scripts translated to the given language
- *
- * @param string $locale OPTIONAL locale for script translation
- * @return array
- */
- public function getScriptTranslationList($locale = null)
- {
- return $this->getTranslationList('script', $locale);
- }
- /**
- * Returns an array with the name of all countries translated to the given language
- *
- * @param string $locale OPTIONAL locale for country translation
- * @return array
- */
- public function getCountryTranslationList($locale = null)
- {
- return $this->getTranslationList('country', $locale);
- }
- /**
- * Returns an array with the name of all territories translated to the given language
- * All territories contains other countries.
- *
- * @param string $locale OPTIONAL locale for territory translation
- * @return array
- */
- public function getTerritoryTranslationList($locale = null)
- {
- return $this->getTranslationList('territory', $locale);
- }
- /**
- * Returns a localized information string, supported are several types of informations.
- *
- * Supported types are:
- * 'language', 'script', 'country', 'territory', 'calendar', 'month', 'month_short',
- * 'month_narrow', 'day', 'day_short', 'day_narrow', 'dateformat', 'timeformat',
- * 'timezone', 'currency', 'currency_sign', 'currency_detail', 'territory_detail', 'language_detail', 'characters'
- * For detailed information about the types look into the documentation
- *
- * @param string $what Name to get detailed information about
- * @param string $type OPTIONAL Type of information to return
- * @param string|locale $locale OPTIONAL Locale|Language for which this informations should be returned
- * @return string|array Array with the wished information in the given language
- */
- public function getTranslation($what, $type = null, $locale = null)
- {
- // load class within method for speed
- require_once 'Zend/Locale/Data.php';
- if ($locale === null) {
- $locale = $this->_Locale;
- }
- switch (strtolower($type)) {
- case 'language' :
- $list = Zend_Locale_Data::getContent($locale, 'language', $what);
- if (isset($list[$what])) {
- return $list[$what];
- }
- break;
- case 'script' :
- $list = Zend_Locale_Data::getContent($locale, 'script', $what);
- if (isset($list[$what])) {
- return $list[$what];
- }
- break;
- case 'country' :
- $list = Zend_Locale_Data::getContent($locale, 'territory', $what);
- if (isset($list[$what])) {
- return $list[$what];
- }
- break;
- case 'territory' :
- $list = Zend_Locale_Data::getContent($locale, 'territory', $what);
- if (isset($list[$what])) {
- return $list[$what];
- }
- break;
- case 'calendar' :
- $list = Zend_Locale_Data::getContent($locale, 'type', $what);
- if (isset($list[$what])) {
- return $list[$what];
- }
- break;
- case 'month' :
- $list = Zend_Locale_Data::getContent($locale, 'month', array('gregorian', 'format', 'wide', $what));
- if (isset($list[$what])) {
- return $list[$what];
- }
- break;
- case 'month_short' :
- $list = Zend_Locale_Data::getContent($locale, 'month', array('gregorian', 'format', 'abbreviated', $what));
- if (isset($list[$what])) {
- return $list[$what];
- }
- break;
- case 'month_narrow' :
- $list = Zend_Locale_Data::getContent($locale, 'month', array('gregorian', 'stand-alone', 'narrow', $what));
- if (isset($list[$what])) {
- return $list[$what];
- }
- break;
- case 'day' :
- $list = Zend_Locale_Data::getContent($locale, 'day', array('gregorian', 'format', 'wide', $what));
- if (isset($list[$what])) {
- return $list[$what];
- }
- break;
- case 'day_short' :
- $list = Zend_Locale_Data::getContent($locale, 'day', array('gregorian', 'format', 'abbreviated', $what));
- if (isset($list[$what])) {
- return $list[$what];
- }
- break;
- case 'day_narrow' :
- $list = Zend_Locale_Data::getContent($locale, 'day', array('gregorian', 'stand-alone', 'narrow', $what));
- if (isset($list[$what])) {
- return $list[$what];
- }
- break;
- case 'dateformat' :
- $list = Zend_Locale_Data::getContent($locale, 'dateformat', array('gregorian', $what, 'narrow'));
- if (isset($list['pattern'])) {
- return $list['pattern'];
- }
- break;
- case 'timeformat' :
- $list = Zend_Locale_Data::getContent($locale, 'timeformat', array('gregorian', $what, 'narrow'));
- if (isset($list['pattern'])) {
- return $list['pattern'];
- }
- break;
- case 'timezone' :
- $list = Zend_Locale_Data::getContent($locale, 'timezone', $what);
- if (isset($list[$what])) {
- return $list[$what];
- }
- break;
- case 'currency' :
- $list = Zend_Locale_Data::getContent($locale, 'currencyname', $what);
- if (isset($list[$what])) {
- return $list[$what];
- }
- break;
- case 'currency_sign' :
- $list = Zend_Locale_Data::getContent($locale, 'currencysymbol', $what);
- if (isset($list[$what])) {
- return $list[$what];
- }
- break;
- case 'currency_detail' :
- $list = Zend_Locale_Data::getContent($locale, 'currencyforregion', $what);
- if (!empty($list)) {
- return $list;
- }
- break;
- case 'territory_detail' :
- $list = Zend_Locale_Data::getContent($locale, 'regionforterritory', $what);
- if (isset($list[$what])) {
- return explode(' ', $list[$what]);
- }
- break;
- case 'language_detail' :
- $list = Zend_Locale_Data::getContent($locale, 'territoryforlanguage', $what);
- if (isset($list[$what])) {
- return explode(' ', $list[$what]);
- }
- break;
- case 'characters' :
- $list = Zend_Locale_Data::getContent($locale, 'characters');
- return $list[0];
- break;
- default :
- return array('language', 'script', 'country', 'territory', 'calendar', 'month', 'month_short',
- 'month_narrow', 'day', 'day_short', 'day_narrow', 'dateformat', 'timeformat',
- 'timezone', 'currency', 'currency_sign', 'currency_detail', 'territory_detail',
- 'language_detail', 'characters');
- }
- return false;
- }
- /**
- * Returns the localized language name
- *
- * @param string $what Name to get detailed information about
- * @param string $locale OPTIONAL locale for language translation
- * @return array
- */
- public function getLanguageTranslation($what, $locale = null)
- {
- return $this->getTranslation($what, 'language', $locale);
- }
- /**
- * Returns the localized script name
- *
- * @param string $what Name to get detailed information about
- * @param string $locale OPTIONAL locale for script translation
- * @return array
- */
- public function getScriptTranslation($what, $locale = null)
- {
- return $this->getTranslation($what, 'script', $locale);
- }
- /**
- * Returns the localized country name
- *
- * @param string $what Name to get detailed information about
- * @param string $locale OPTIONAL locale for country translation
- * @return array
- */
- public function getCountryTranslation($what, $locale = null)
- {
- return $this->getTranslation($what, 'country', $locale);
- }
- /**
- * Returns the localized territory name
- * All territories contains other countries.
- *
- * @param string $what Name to get detailed information about
- * @param string $locale OPTIONAL locale for territory translation
- * @return array
- */
- public function getTerritoryTranslation($what, $locale = null)
- {
- return $this->getTranslation($what, 'territory', $locale);
- }
- /**
- * Returns an array with translated yes strings
- *
- * @param string $locale OPTIONAL locale for language translation (defaults to $this locale)
- * @return array
- */
- public function getQuestion($locale = null)
- {
- // load class within method for speed
- require_once 'Zend/Locale/Data.php';
- if ($locale === null) {
- $locale = $this->_Locale;
- }
- $quest = Zend_Locale_Data::getContent($locale, 'questionstrings');
- $yes = explode(':', $quest['yes']);
- $no = explode(':', $quest['no']);
- $quest['yes'] = $yes[0];
- $quest['yesabbr'] = $yes[1];
- $quest['no'] = $no[0];
- $quest['noabbr'] = $no[1];
- return $quest;
- }
- /**
- * Checks if a locale identifier is a real locale or not
- * Examples:
- * "en_XX" refers to "en", which returns true
- * "XX_yy" refers to "root", which returns false
- *
- * @param string|Zend_Locale $locale Locale to check for
- * @param boolean $create If true, create a default locale, if $locale is empty
- * @return false|string false if given locale is not a locale, else the locale identifier is returned
- */
- public static function isLocale($locale, $create = false)
- {
- if (empty($locale) and ($create === true)) {
- $locale = new Zend_Locale();
- }
- if ($locale instanceof Zend_Locale) {
- return $locale->toString();
- }
- if (!is_string($locale)) {
- return false;
- }
- if (array_key_exists($locale, self::$_localeData)) {
- return $locale;
- } else {
- $locale = explode('_', $locale);
- if (array_key_exists($locale[0], self::$_localeData)) {
- return $locale[0];
- }
- }
- return false;
- }
- }