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.
16
* @package Zend_Locale
17
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
18
* @license http://framework.zend.com/license/new-bsd New BSD License
19
* @version $Id: Locale.php 15765 2009-05-25 19:59:45Z thomas $
23
* Base class for localization
26
* @package Zend_Locale
27
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
28
* @license http://framework.zend.com/license/new-bsd New BSD License
33
* Class wide Locale Constants
35
* @var array $_localeData
37
private static $_localeData = array(
38
'root' => true, 'aa_DJ' => true, 'aa_ER' => true, 'aa_ET' => true, 'aa' => true,
39
'af_NA' => true, 'af_ZA' => true, 'af' => true, 'ak_GH' => true, 'ak' => true,
40
'am_ET' => true, 'am' => true, 'ar_AE' => true, 'ar_BH' => true, 'ar_DZ' => true,
41
'ar_EG' => true, 'ar_IQ' => true, 'ar_JO' => true, 'ar_KW' => true, 'ar_LB' => true,
42
'ar_LY' => true, 'ar_MA' => true, 'ar_OM' => true, 'ar_QA' => true, 'ar_SA' => true,
43
'ar_SD' => true, 'ar_SY' => true, 'ar_TN' => true, 'ar_YE' => true, 'ar' => true,
44
'as_IN' => true, 'as' => true, 'az_AZ' => true, 'az' => true, 'be_BY' => true,
45
'be' => true, 'bg_BG' => true, 'bg' => true, 'bn_BD' => true, 'bn_IN' => true,
46
'bn' => true, 'bo_CN' => true, 'bo_IN' => true, 'bo' => true, 'bs_BA' => true,
47
'bs' => true, 'byn_ER'=> true, 'byn' => true, 'ca_ES' => true, 'ca' => true,
48
'cch_NG'=> true, 'cch' => true, 'cop_EG'=> true, 'cop_US'=> true, 'cop' => true,
49
'cs_CZ' => true, 'cs' => true, 'cy_GB' => true, 'cy' => true, 'da_DK' => true,
50
'da' => true, 'de_AT' => true, 'de_BE' => true, 'de_CH' => true, 'de_DE' => true,
51
'de_LI' => true, 'de_LU' => true, 'de' => true, 'dv_MV' => true, 'dv' => true,
52
'dz_BT' => true, 'dz' => true, 'ee_GH' => true, 'ee_TG' => true, 'ee' => true,
53
'el_CY' => true, 'el_GR' => true, 'el' => true, 'en_AS' => true, 'en_AU' => true,
54
'en_BE' => true, 'en_BW' => true, 'en_BZ' => true, 'en_CA' => true, 'en_GB' => true,
55
'en_GU' => true, 'en_HK' => true, 'en_IE' => true, 'en_IN' => true, 'en_JM' => true,
56
'en_MH' => true, 'en_MP' => true, 'en_MT' => true, 'en_NZ' => true, 'en_PH' => true,
57
'en_PK' => true, 'en_SG' => true, 'en_TT' => true, 'en_UM' => true, 'en_US' => true,
58
'en_VI' => true, 'en_ZA' => true, 'en_ZW' => true, 'en' => true, 'eo' => true,
59
'es_AR' => true, 'es_BO' => true, 'es_CL' => true, 'es_CO' => true, 'es_CR' => true,
60
'es_DO' => true, 'es_EC' => true, 'es_ES' => true, 'es_GT' => true, 'es_HN' => true,
61
'es_MX' => true, 'es_NI' => true, 'es_PA' => true, 'es_PE' => true, 'es_PR' => true,
62
'es_PY' => true, 'es_SV' => true, 'es_US' => true, 'es_UY' => true, 'es_VE' => true,
63
'es' => true, 'et_EE' => true, 'et' => true, 'eu_ES' => true, 'eu' => true,
64
'fa_AF' => true, 'fa_IR' => true, 'fa' => true, 'fi_FI' => true, 'fi' => true,
65
'fil' => true, 'fo_FO' => true, 'fo' => true, 'fr_BE' => true, 'fr_CA' => true,
66
'fr_CH' => true, 'fr_FR' => true, 'fr_LU' => true, 'fr_MC' => true, 'fr' => true,
67
'fur_IT'=> true, 'fur' => true, 'ga_IE' => true, 'ga' => true, 'gaa_GH'=> true,
68
'gaa' => true, 'gez_ER'=> true, 'gez_ET'=> true, 'gez' => true, 'gl_ES' => true,
69
'gl' => true, 'gu_IN' => true, 'gu' => true, 'gv_GB' => true, 'gv' => true,
70
'ha_GH' => true, 'ha_NE' => true, 'ha_NG' => true, 'ha' => true, 'haw_US'=> true,
71
'haw' => true, 'he_IL' => true, 'he' => true, 'hi_IN' => true, 'hi' => true,
72
'hr_HR' => true, 'hr' => true, 'hu_HU' => true, 'hu' => true, 'hy_AM' => true,
73
'hy' => true, 'ia' => true, 'id_ID' => true, 'id' => true, 'ig_NG' => true,
74
'ig' => true, 'ii_CN' => true, 'ii' => true, 'is_IS' => true, 'is' => true,
75
'it_CH' => true, 'it_IT' => true, 'it' => true, 'iu' => true, 'ja_JP' => true,
76
'ja' => true, 'ka_GE' => true, 'ka' => true, 'kaj_NG'=> true, 'kaj' => true,
77
'kam_KE'=> true, 'kam' => true, 'kcg_NG'=> true, 'kcg' => true, 'kfo_NG'=> true,
78
'kfo' => true, 'kk_KZ' => true, 'kk' => true, 'kl_GL' => true, 'kl' => true,
79
'km_KH' => true, 'km' => true, 'kn_IN' => true, 'kn' => true, 'ko_KR' => true,
80
'ko' => true, 'kok_IN'=> true, 'kok' => true, 'kpe_GN'=> true, 'kpe_LR'=> true,
81
'kpe' => true, 'ku_IQ' => true, 'ku_IR' => true, 'ku_SY' => true, 'ku_TR' => true,
82
'ku' => true, 'kw_GB' => true, 'kw' => true, 'ky_KG' => true, 'ky' => true,
83
'ln_CD' => true, 'ln_CG' => true, 'ln' => true, 'lo_LA' => true, 'lo' => true,
84
'lt_LT' => true, 'lt' => true, 'lv_LV' => true, 'lv' => true, 'mk_MK' => true,
85
'mk' => true, 'ml_IN' => true, 'ml' => true, 'mn_MN' => true, 'mn' => true,
86
'mr_IN' => true, 'mr' => true, 'ms_BN' => true, 'ms_MY' => true, 'ms' => true,
87
'mt_MT' => true, 'mt' => true, 'my_MM' => true, 'my' => true, 'nb_NO' => true,
88
'nb' => true, 'ne_NP' => true, 'ne' => true, 'nl_BE' => true, 'nl_NL' => true,
89
'nl' => true, 'nn_NO' => true, 'nn' => true, 'nr_ZA' => true, 'nr' => true,
90
'nso_ZA'=> true, 'nso' => true, 'ny_MW' => true, 'ny' => true, 'om_ET' => true,
91
'om_KE' => true, 'om' => true, 'or_IN' => true, 'or' => true, 'pa_IN' => true,
92
'pa_PK' => true, 'pa' => true, 'pl_PL' => true, 'pl' => true, 'ps_AF' => true,
93
'ps' => true, 'pt_BR' => true, 'pt_PT' => true, 'pt' => true, 'ro_RO' => true,
94
'ro' => true, 'ru_RU' => true, 'ru_UA' => true, 'ru' => true, 'rw_RW' => true,
95
'rw' => true, 'sa_IN' => true, 'sa' => true, 'se_FI' => true, 'se_NO' => true,
96
'se' => true, 'sh_BA' => true, 'sh_CS' => true, 'sh_YU' => true, 'sh' => true,
97
'sid_ET'=> true, 'sid' => true, 'sk_SK' => true, 'sk' => true, 'sl_SI' => true,
98
'sl' => true, 'so_DJ' => true, 'so_ET' => true, 'so_KE' => true, 'so_SO' => true,
99
'so' => true, 'sq_AL' => true, 'sq' => true, 'sr_BA' => true, 'sr_CS' => true,
100
'sr_ME' => true, 'sr_RS' => true, 'sr_YU' => true, 'sr' => true, 'ss_ZA' => true,
101
'ss' => true, 'ssy' => true, 'st_ZA' => true, 'st' => true, 'sv_FI' => true,
102
'sv_SE' => true, 'sv' => true, 'sw_KE' => true, 'sw_TZ' => true, 'sw' => true,
103
'syr_SY'=> true, 'syr' => true, 'ta_IN' => true, 'ta' => true, 'te_IN' => true,
104
'te' => true, 'tg_TJ' => true, 'tg' => true, 'th_TH' => true, 'th' => true,
105
'ti_ER' => true, 'ti_ET' => true, 'ti' => true, 'tig_ER'=> true, 'tig' => true,
106
'tn_ZA' => true, 'tn' => true, 'to_TO' => true, 'to' => true, 'tr_TR' => true,
107
'tr' => true, 'ts_ZA' => true, 'ts' => true, 'tt_RU' => true, 'tt' => true,
108
'ug' => true, 'uk_UA' => true, 'uk' => true, 'und_ZZ'=> true, 'und' => true,
109
'ur_IN' => true, 'ur_PK' => true, 'ur' => true, 'uz_AF' => true, 'uz_UZ' => true,
110
'uz' => true, 've_ZA' => true, 've' => true, 'vi_VN' => true, 'vi' => true,
111
'wal_ET'=> true, 'wal' => true, 'wo_SN' => true, 'wo' => true, 'xh_ZA' => true,
112
'xh' => true, 'yo_NG' => true, 'yo' => true, 'zh_CN' => true, 'zh_HK' => true,
113
'zh_MO' => true, 'zh_SG' => true, 'zh_TW' => true, 'zh' => true, 'zu_ZA' => true,
118
* Autosearch constants
120
const BROWSER = 'browser';
121
const ENVIRONMENT = 'environment';
122
const ZFDEFAULT = 'default';
125
* Defines if old behaviour should be supported
126
* Old behaviour throws notices and will be deleted in future releases
130
public static $compatibilityMode = false;
137
private static $_breakChain = false;
147
* Automatic detected locale
149
* @var string Locales
151
protected static $_auto;
154
* Browser detected locale
156
* @var string Locales
158
protected static $_browser;
161
* Environment detected locale
163
* @var string Locales
165
protected static $_environment;
170
* @var string Locales
172
protected static $_default = array('en' => true);
175
* Generates a locale object
176
* If no locale is given a automatic search is done
177
* Then the most probable locale will be automatically set
181
* 3. Server Environment
182
* 4. Framework Standard
184
* @param string|Zend_Locale $locale (Optional) Locale for parsing input
185
* @throws Zend_Locale_Exception When autodetection has been failed
187
public function __construct($locale = null)
189
$locale = self::_prepareLocale($locale);
190
$this->setLocale((string) $locale);
194
* Serialization Interface
198
public function serialize()
200
return serialize($this);
204
* Returns a string representation of the object
208
public function toString()
210
return (string) $this->_locale;
214
* Returns a string representation of the object
219
public function __toString()
221
return $this->toString();
225
* Return the default locale
227
* @return array Returns an array of all locale string
229
public static function getDefault()
231
if ((self::$compatibilityMode === true) or (func_num_args() > 0)) {
232
if (!self::$_breakChain) {
233
self::$_breakChain = true;
234
trigger_error('You are running Zend_Locale in compatibility mode... please migrate your scripts', E_USER_NOTICE);
235
$params = func_get_args();
237
if (isset($params[0])) {
240
return self::getOrder($param);
243
self::$_breakChain = false;
246
return self::$_default;
250
* Sets a new default locale
251
* If provided you can set a quality between 0 and 1 (or 2 and 100)
252
* which represents the percent of quality the browser
253
* requested within HTTP
255
* @param string|Zend_Locale $locale Locale to set
256
* @param float $quality The quality to set from 0 to 1
257
* @throws Zend_Locale_Exception When a autolocale was given
258
* @throws Zend_Locale_Exception When a unknown locale was given
261
public static function setDefault($locale, $quality = 1)
263
if (($locale === 'auto') or ($locale === 'root') or ($locale === 'default') or
264
($locale === 'environment') or ($locale === 'browser')) {
265
require_once 'Zend/Locale/Exception.php';
266
throw new Zend_Locale_Exception('Only full qualified locales can be used as default!');
269
if (($quality < 0.1) or ($quality > 100)) {
270
require_once 'Zend/Locale/Exception.php';
271
throw new Zend_Locale_Exception("Quality must be between 0.1 and 100");
278
if (isset(self::$_localeData[(string) $locale]) === true) {
279
self::$_default = array((string) $locale => $quality);
281
$locale = explode('_', (string) $locale);
282
if (isset(self::$_localeData[$locale[0]]) === true) {
283
self::$_default = array($locale[0] => $quality);
285
require_once 'Zend/Locale/Exception.php';
286
throw new Zend_Locale_Exception("Unknown locale '" . (string) $locale . "' can not be set as default!");
292
* Expects the Systems standard locale
295
* f.e.: LC_COLLATE=C;LC_CTYPE=German_Austria.1252;LC_MONETARY=C
296
* would be recognised as de_AT
300
public static function getEnvironment()
302
if (self::$_environment !== null) {
303
return self::$_environment;
306
require_once 'Zend/Locale/Data/Translation.php';
308
$language = setlocale(LC_ALL, 0);
309
$languages = explode(';', $language);
310
$languagearray = array();
312
foreach ($languages as $locale) {
313
if (strpos($locale, '=') !== false) {
314
$language = substr($locale, strpos($locale, '='));
315
$language = substr($language, 1);
318
if ($language !== 'C') {
319
if (strpos($language, '.') !== false) {
320
$language = substr($language, 0, (strpos($language, '.') - 1));
321
} else if (strpos($language, '@') !== false) {
322
$language = substr($language, 0, (strpos($language, '@') - 1));
325
$splitted = explode('_', $language);
326
$language = (string) $language;
327
if (isset(self::$_localeData[$language]) === true) {
328
$languagearray[$language] = 1;
329
if (strlen($language) > 4) {
330
$languagearray[substr($language, 0, 2)] = 1;
336
if (empty(Zend_Locale_Data_Translation::$localeTranslation[$splitted[0]]) === false) {
337
if (empty(Zend_Locale_Data_Translation::$localeTranslation[$splitted[1]]) === false) {
338
$languagearray[Zend_Locale_Data_Translation::$localeTranslation[$splitted[0]] . '_' .
339
Zend_Locale_Data_Translation::$localeTranslation[$splitted[1]]] = 1;
342
$languagearray[Zend_Locale_Data_Translation::$localeTranslation[$splitted[0]]] = 1;
347
self::$_environment = $languagearray;
348
return $languagearray;
352
* Return an array of all accepted languages of the client
353
* Expects RFC compilant Header !!
355
* The notation can be :
356
* de,en-UK-US;q=0.5,fr-FR;q=0.2
358
* @return array - list of accepted languages including quality
360
public static function getBrowser()
362
if (self::$_browser !== null) {
363
return self::$_browser;
366
$httplanguages = getenv('HTTP_ACCEPT_LANGUAGE');
367
$languages = array();
368
if (empty($httplanguages) === true) {
372
$accepted = preg_split('/,\s*/', $httplanguages);
374
foreach ($accepted as $accept) {
376
$result = preg_match('/^([a-z]{1,8}(?:[-_][a-z]{1,8})*)(?:;\s*q=(0(?:\.[0-9]{1,3})?|1(?:\.0{1,3})?))?$/i',
383
if (isset($match[2]) === true) {
384
$quality = (float) $match[2];
389
$countrys = explode('-', $match[1]);
390
$region = array_shift($countrys);
392
$country2 = explode('_', $region);
393
$region = array_shift($country2);
395
foreach ($countrys as $country) {
396
$languages[$region . '_' . strtoupper($country)] = $quality;
399
foreach ($country2 as $country) {
400
$languages[$region . '_' . strtoupper($country)] = $quality;
403
if ((isset($languages[$region]) === false) || ($languages[$region] < $quality)) {
404
$languages[$region] = $quality;
408
self::$_browser = $languages;
415
* @param string|Zend_Locale $locale (Optional) New locale to set
418
public function setLocale($locale = null)
420
$locale = self::_prepareLocale($locale);
422
if (isset(self::$_localeData[(string) $locale]) === false) {
423
$region = substr((string) $locale, 0, 3);
424
if (isset($region[2]) === true) {
425
if (($region[2] === '_') or ($region[2] === '-')) {
426
$region = substr($region, 0, 2);
430
if (isset(self::$_localeData[(string) $region]) === true) {
431
$this->_locale = $region;
433
$this->_locale = 'root';
436
$this->_locale = $locale;
441
* Returns the language part of the locale
443
* @return string Language
445
public function getLanguage()
447
$locale = explode('_', $this->_locale);
452
* Returns the region part of the locale if available
454
* @return string|false - Regionstring
456
public function getRegion()
458
$locale = explode('_', $this->_locale);
459
if (isset($locale[1]) === true) {
467
* Return the accepted charset of the client
471
public static function getHttpCharset()
473
$httpcharsets = getenv('HTTP_ACCEPT_CHARSET');
476
if ($httpcharsets === false) {
480
$accepted = preg_split('/,\s*/', $httpcharsets);
481
foreach ($accepted as $accept) {
482
if (empty($accept) === true) {
486
if (strpos($accept, ';') !== false) {
487
$quality = (float) substr($accept, (strpos($accept, '=') + 1));
488
$pos = substr($accept, 0, strpos($accept, ';'));
489
$charsets[$pos] = $quality;
492
$charsets[$accept] = $quality;
500
* Returns true if both locales are equal
502
* @param Zend_Locale $object Locale to check for equality
505
public function equals(Zend_Locale $object)
507
if ($object->toString() === $this->toString()) {
515
* Returns localized informations as array, supported are several
516
* types of informations.
517
* For detailed information about the types look into the documentation
519
* @param string $path (Optional) Type of information to return
520
* @param string|Zend_Locale $locale (Optional) Locale|Language for which this informations should be returned
521
* @param string $value (Optional) Value for detail list
522
* @return array Array with the wished information in the given language
524
public static function getTranslationList($path = null, $locale = null, $value = null)
526
require_once 'Zend/Locale/Data.php';
527
$locale = self::_prepareLocale($locale);
528
$result = Zend_Locale_Data::getList($locale, $path, $value);
529
if (empty($result) === true) {
537
* Returns an array with the name of all languages translated to the given language
539
* @param string|Zend_Locale $locale (Optional) Locale for language translation
542
public static function getLanguageTranslationList($locale = null)
544
return self::getTranslationList('language', $locale);
548
* Returns an array with the name of all scripts translated to the given language
550
* @param string|Zend_Locale $locale (Optional) Locale for script translation
553
public static function getScriptTranslationList($locale = null)
555
return self::getTranslationList('script', $locale);
559
* Returns an array with the name of all countries translated to the given language
561
* @param string|Zend_Locale $locale (Optional) Locale for country translation
564
public static function getCountryTranslationList($locale = null)
566
return self::getTranslationList('territory', $locale, 2);
570
* Returns an array with the name of all territories translated to the given language
571
* All territories contains other countries.
573
* @param string|Zend_Locale $locale (Optional) Locale for territory translation
576
public static function getTerritoryTranslationList($locale = null)
578
return self::getTranslationList('territory', $locale, 1);
582
* Returns a localized information string, supported are several types of informations.
583
* For detailed information about the types look into the documentation
585
* @param string $value Name to get detailed information about
586
* @param string $path (Optional) Type of information to return
587
* @param string|Zend_Locale $locale (Optional) Locale|Language for which this informations should be returned
588
* @return string|false The wished information in the given language
590
public static function getTranslation($value = null, $path = null, $locale = null)
592
require_once 'Zend/Locale/Data.php';
593
$locale = self::_prepareLocale($locale);
594
$result = Zend_Locale_Data::getContent($locale, $path, $value);
595
if (empty($result) === true) {
603
* Returns the localized language name
605
* @param string $value Name to get detailed information about
606
* @param string $locale (Optional) Locale for language translation
609
public static function getLanguageTranslation($value, $locale = null)
611
return self::getTranslation($value, 'language', $locale);
615
* Returns the localized script name
617
* @param string $value Name to get detailed information about
618
* @param string $locale (Optional) locale for script translation
621
public static function getScriptTranslation($value, $locale = null)
623
return self::getTranslation($value, 'script', $locale);
627
* Returns the localized country name
629
* @param string $value Name to get detailed information about
630
* @param string|Zend_Locale $locale (Optional) Locale for country translation
633
public static function getCountryTranslation($value, $locale = null)
635
return self::getTranslation($value, 'country', $locale);
639
* Returns the localized territory name
640
* All territories contains other countries.
642
* @param string $value Name to get detailed information about
643
* @param string|Zend_Locale $locale (Optional) Locale for territory translation
646
public static function getTerritoryTranslation($value, $locale = null)
648
return self::getTranslation($value, 'territory', $locale);
652
* Returns an array with translated yes strings
654
* @param string|Zend_Locale $locale (Optional) Locale for language translation (defaults to $this locale)
657
public static function getQuestion($locale = null)
659
require_once 'Zend/Locale/Data.php';
660
$locale = self::_prepareLocale($locale);
661
$quest = Zend_Locale_Data::getList($locale, 'question');
662
$yes = explode(':', $quest['yes']);
663
$no = explode(':', $quest['no']);
664
$quest['yes'] = $yes[0];
665
$quest['yesarray'] = $yes;
666
$quest['no'] = $no[0];
667
$quest['noarray'] = $no;
668
$quest['yesexpr'] = self::_prepareQuestionString($yes);
669
$quest['noexpr'] = self::_prepareQuestionString($no);
675
* Internal function for preparing the returned question regex string
677
* @param string $input Regex to parse
680
private static function _prepareQuestionString($input)
683
if (is_array($input) === true) {
686
foreach ($input as $row) {
687
if ($start === false) {
694
if (strlen($row) > 2) {
698
foreach (str_split($row, 1) as $char) {
699
$regex .= '[' . $char;
700
$regex .= strtoupper($char) . ']';
707
if ($one === false) {
719
* Checks if a locale identifier is a real locale or not
721
* "en_XX" refers to "en", which returns true
722
* "XX_yy" refers to "root", which returns false
724
* @param string|Zend_Locale $locale Locale to check for
725
* @param boolean $strict (Optional) If true, no rerouting will be done when checking
726
* @param boolean $compatible (DEPRECIATED) Only for internal usage, brakes compatibility mode
727
* @return boolean If the locale is known dependend on the settings
729
public static function isLocale($locale, $strict = false, $compatible = true)
732
$locale = self::_prepareLocale($locale, $strict);
733
} catch (Zend_Locale_Exception $e) {
737
if (($compatible === true) and (self::$compatibilityMode === true)) {
738
trigger_error('You are running Zend_Locale in compatibility mode... please migrate your scripts', E_USER_NOTICE);
739
if (isset(self::$_localeData[$locale]) === true) {
741
} else if (!$strict) {
742
$locale = explode('_', $locale);
743
if (isset(self::$_localeData[$locale[0]]) === true) {
748
if (isset(self::$_localeData[$locale]) === true) {
750
} else if (!$strict) {
751
$locale = explode('_', $locale);
752
if (isset(self::$_localeData[$locale[0]]) === true) {
762
* Finds the proper locale based on the input
763
* Checks if it exists, degrades it when necessary
764
* Detects registry locale and when all fails tries to detect a automatic locale
765
* Returns the found locale as string
767
* @param string $locale
768
* @throws Zend_Locale_Exception When the given locale is no locale or the autodetection fails
771
public static function findLocale($locale = null)
773
if ($locale === null) {
774
require_once 'Zend/Registry.php';
775
if (Zend_Registry::isRegistered('Zend_Locale')) {
776
$locale = Zend_Registry::get('Zend_Locale');
780
require_once 'Zend/Locale.php';
781
if ($locale === null) {
782
$locale = new Zend_Locale();
785
if (!Zend_Locale::isLocale($locale, true, false)) {
786
if (!Zend_Locale::isLocale($locale, false, false)) {
787
require_once 'Zend/Locale/Exception.php';
788
throw new Zend_Locale_Exception("The locale '$locale' is no known locale");
791
$locale = new Zend_Locale($locale);
794
if ($locale instanceof Zend_Locale) {
795
$locale = $locale->toString();
802
* Returns a list of all known locales where the locale is the key
803
* Only real locales are returned, the internal locales 'root', 'auto', 'browser'
804
* and 'environment' are suppressed
806
* @return array List of all Locales
808
public static function getLocaleList()
810
$list = self::$_localeData;
811
unset($list['root']);
812
unset($list['auto']);
813
unset($list['browser']);
814
unset($list['environment']);
819
* Returns the set cache
821
* @return Zend_Cache_Core The set cache
823
public static function getCache()
825
require_once 'Zend/Locale/Data.php';
826
$cache = Zend_Locale_Data::getCache();
834
* @param Zend_Cache_Core $cache Cache to set
837
public static function setCache(Zend_Cache_Core $cache)
839
require_once 'Zend/Locale/Data.php';
840
Zend_Locale_Data::setCache($cache);
844
* Returns true when a cache is set
848
public static function hasCache()
850
require_once 'Zend/Locale/Data.php';
851
return Zend_Locale_Data::hasCache();
855
* Removes any set cache
859
public static function removeCache()
861
require_once 'Zend/Locale/Data.php';
862
Zend_Locale_Data::removeCache();
866
* Clears all set cache data
870
public static function clearCache()
872
require_once 'Zend/Locale/Data.php';
873
Zend_Locale_Data::clearCache();
877
* Disables the set cache
879
* @param boolean $flag True disables any set cache, default is false
882
public static function disableCache($flag)
884
require_once 'Zend/Locale/Data.php';
885
Zend_Locale_Data::disableCache($flag);
889
* Internal function, returns a single locale on detection
891
* @param string|Zend_Locale $locale (Optional) Locale to work on
892
* @param boolean $strict (Optional) Strict preparation
893
* @throws Zend_Locale_Exception When no locale is set which is only possible when the class was wrong extended
896
private static function _prepareLocale($locale, $strict = false)
898
if ($locale instanceof Zend_Locale) {
899
$locale = $locale->toString();
902
if (is_array($locale)) {
906
if (empty(self::$_auto) === true) {
907
self::$_browser = self::getBrowser();
908
self::$_environment = self::getEnvironment();
909
self::$_breakChain = true;
910
self::$_auto = self::getBrowser() + self::getEnvironment() + self::getDefault();
914
if ($locale === 'browser') {
915
$locale = self::$_browser;
918
if ($locale === 'environment') {
919
$locale = self::$_environment;
922
if ($locale === 'default') {
923
$locale = self::$_default;
926
if (($locale === 'auto') or ($locale === null)) {
927
$locale = self::$_auto;
930
if (is_array($locale) === true) {
931
$locale = key($locale);
935
// This can only happen when someone extends Zend_Locale and erases the default
936
if ($locale === null) {
937
require_once 'Zend/Locale/Exception.php';
938
throw new Zend_Locale_Exception('Autodetection of Locale has been failed!');
941
if (strpos($locale, '-') !== false) {
942
$locale = strtr($locale, '-', '_');
945
return (string) $locale;
949
* Search the locale automatically and return all used locales
952
* Standard Searchorder is Browser, Environment, Default
954
* @param string $searchorder (Optional) Searchorder
955
* @return array Returns an array of all detected locales
957
public static function getOrder($order = null)
960
case self::ENVIRONMENT:
961
self::$_breakChain = true;
962
$languages = self::getEnvironment() + self::getBrowser() + self::getDefault();
965
case self::ZFDEFAULT:
966
self::$_breakChain = true;
967
$languages = self::getDefault() + self::getEnvironment() + self::getBrowser();
971
self::$_breakChain = true;
972
$languages = self::getBrowser() + self::getEnvironment() + self::getDefault();