Public Member Functions | |
__construct ($locale=null) | |
setDefaultLocale ($locale) | |
getDefaultLocale () | |
setLocale ($locale=null) | |
getTimezone () | |
getCurrency () | |
getLocale () | |
getLocaleCode () | |
setLocaleCode ($code) | |
getOptionLocales () | |
getTranslatedOptionLocales () | |
getOptionTimezones () | |
getOptionWeekdays () | |
getOptionCountries () | |
getOptionCurrencies () | |
getOptionAllCurrencies () | |
getAllowLocales () | |
getAllowCurrencies () | |
getDateFormat ($type=null) | |
getTimeFormat ($type=null) | |
getDateTimeFormat ($type) | |
getDateStrFormat ($type) | |
getTimeStrFormat ($type) | |
date ($date=null, $part=null, $locale=null, $useTimezone=true) | |
storeDate ($store=null, $date=null, $includeTime=false) | |
storeTimeStamp ($store=null) | |
currency ($currency) | |
getNumber ($value) | |
getJsPriceFormat () | |
emulate ($storeId) | |
revert () | |
getTranslationList ($path=null, $value=null) | |
getTranslation ($value=null, $path=null) | |
getCountryTranslation ($value) | |
getCountryTranslationList () | |
IsStoreDateInInterval ($store, $dateFrom=null, $dateTo=null) | |
Public Attributes | |
const | DEFAULT_LOCALE = 'en_US' |
const | DEFAULT_TIMEZONE = 'UTC' |
const | DEFAULT_CURRENCY = 'USD' |
const | XML_PATH_DEFAULT_LOCALE = 'general/locale/code' |
const | XML_PATH_DEFAULT_TIMEZONE = 'general/locale/timezone' |
const | XML_PATH_DEFAULT_COUNTRY = 'general/country/default' |
const | XML_PATH_ALLOW_CODES = 'global/locale/allow/codes' |
const | XML_PATH_ALLOW_CURRENCIES = 'global/locale/allow/currencies' |
const | XML_PATH_ALLOW_CURRENCIES_INSTALLED = 'system/currency/installed' |
const | FORMAT_TYPE_FULL = 'full' |
const | FORMAT_TYPE_LONG = 'long' |
const | FORMAT_TYPE_MEDIUM = 'medium' |
const | FORMAT_TYPE_SHORT = 'short' |
Protected Member Functions | |
_getOptionLocales ($translatedName=false) | |
_sortOptionArray ($option) | |
Protected Attributes | |
$_defaultLocale | |
$_locale | |
$_localeCode | |
$_emulatedLocales = array() | |
Static Protected Attributes | |
static | $_currencyCache = array() |
Definition at line 32 of file Locale.php.
__construct | ( | $ | locale = null |
) |
_getOptionLocales | ( | $ | translatedName = false |
) | [protected] |
Get options array for locale dropdown
bool | $translatedName translation flag |
Definition at line 228 of file Locale.php.
00229 { 00230 $options = array(); 00231 $locales = $this->getLocale()->getLocaleList(); 00232 $languages = $this->getLocale()->getLanguageTranslationList($this->getLocale()); 00233 $countries = $this->getCountryTranslationList(); 00234 00235 $allowed = $this->getAllowLocales(); 00236 foreach ($locales as $code=>$active) { 00237 if (strstr($code, '_')) { 00238 if (!in_array($code, $allowed)) { 00239 continue; 00240 } 00241 $data = explode('_', $code); 00242 if (!isset($languages[$data[0]]) || !isset($countries[$data[1]])) { 00243 continue; 00244 } 00245 if ($translatedName) { 00246 $label = ucwords($this->getLocale()->getLanguageTranslation($data[0], $code)) 00247 . ' (' . $this->getLocale()->getCountryTranslation($data[1], $code) . ') / ' 00248 . $languages[$data[0]] . ' (' . $countries[$data[1]] . ')'; 00249 } else { 00250 $label = $languages[$data[0]] . ' (' . $countries[$data[1]] . ')'; 00251 } 00252 $options[] = array( 00253 'value' => $code, 00254 'label' => $label 00255 ); 00256 } 00257 } 00258 return $this->_sortOptionArray($options); 00259 }
_sortOptionArray | ( | $ | option | ) | [protected] |
Definition at line 360 of file Locale.php.
00361 { 00362 $data = array(); 00363 foreach ($option as $item) { 00364 $data[$item['value']] = $item['label']; 00365 } 00366 asort($data); 00367 $option = array(); 00368 foreach ($data as $key => $label) { 00369 $option[] = array( 00370 'value' => $key, 00371 'label' => $label 00372 ); 00373 } 00374 return $option; 00375 }
currency | ( | $ | currency | ) |
Create Mage_Core_Model_Locale_Currency object for current locale
string | $currency |
Definition at line 537 of file Locale.php.
00538 { 00539 Varien_Profiler::start('locale/currency'); 00540 if (!isset(self::$_currencyCache[$this->getLocaleCode()][$currency])) { 00541 try { 00542 $currencyObject = new Mage_Core_Model_Locale_Currency($currency, $this->getLocale()); 00543 } catch (Exception $e) { 00544 $currencyObject = new Mage_Core_Model_Locale_Currency($this->getCurrency(), $this->getLocale()); 00545 $options = array( 00546 'name' => $currency, 00547 'currency' => $currency, 00548 'symbol' => $currency 00549 ); 00550 $currencyObject->setFormat($options); 00551 } 00552 00553 self::$_currencyCache[$this->getLocaleCode()][$currency] = $currencyObject; 00554 } 00555 Varien_Profiler::stop('locale/currency'); 00556 return self::$_currencyCache[$this->getLocaleCode()][$currency]; 00557 }
date | ( | $ | date = null , |
|
$ | part = null , |
|||
$ | locale = null , |
|||
$ | useTimezone = true | |||
) |
Create Zend_Date object for current locale
mixed | $date | |
string | $part |
Zend_Date_Exception |
Definition at line 475 of file Locale.php.
00476 { 00477 if (is_null($locale)) { 00478 $locale = $this->getLocale(); 00479 } 00480 00481 // try-catch block was here 00482 $date = new Zend_Date($date, $part, $locale); 00483 if ($useTimezone) { 00484 if ($timezone = Mage::app()->getStore()->getConfig(self::XML_PATH_DEFAULT_TIMEZONE)) { 00485 $date->setTimezone($timezone); 00486 } 00487 } 00488 //$date->add(-(substr($date->get(Zend_Date::GMT_DIFF), 0,3)), Zend_Date::HOUR); 00489 00490 return $date; 00491 }
emulate | ( | $ | storeId | ) |
Push current locale to stack and replace with locale from specified store Event is not dispatched.
int | $storeId |
Definition at line 666 of file Locale.php.
00667 { 00668 if ($storeId) { 00669 $this->_emulatedLocales[] = clone $this->getLocale(); 00670 $this->_locale = new Zend_Locale(Mage::getStoreConfig(self::XML_PATH_DEFAULT_LOCALE, $storeId)); 00671 $this->_localeCode = $this->_locale->toString(); 00672 Mage::getSingleton('core/translate')->setLocale($this->_locale)->init('frontend', true); 00673 } 00674 else { 00675 $this->_emulatedLocales[] = false; 00676 } 00677 }
getAllowCurrencies | ( | ) |
Retrieve array of allowed currencies
Definition at line 396 of file Locale.php.
00397 { 00398 $data = array(); 00399 if (Mage::isInstalled()) { 00400 $data = Mage::app()->getStore()->getConfig(self::XML_PATH_ALLOW_CURRENCIES_INSTALLED); 00401 return explode(',', $data); 00402 } 00403 else { 00404 $data = Mage::getConfig()->getNode(self::XML_PATH_ALLOW_CURRENCIES)->asArray(); 00405 if ($data) { 00406 return array_keys($data); 00407 } 00408 } 00409 return $data; 00410 }
getAllowLocales | ( | ) |
Retrieve array of allowed locales
Definition at line 382 of file Locale.php.
00383 { 00384 $data = Mage::getConfig()->getNode(self::XML_PATH_ALLOW_CODES)->asArray(); 00385 if ($data) { 00386 return array_keys($data); 00387 } 00388 return array(); 00389 }
getCountryTranslation | ( | $ | value | ) |
Returns the localized country name
string | $value Name to get detailed information about |
Definition at line 725 of file Locale.php.
getCountryTranslationList | ( | ) |
Returns an array with the name of all countries translated to the given language
Definition at line 735 of file Locale.php.
getCurrency | ( | ) |
getDateFormat | ( | $ | type = null |
) |
Retrieve ISO date format
string | $type |
Definition at line 418 of file Locale.php.
00419 { 00420 return $this->getTranslation($type, 'date'); 00421 }
getDateStrFormat | ( | $ | type | ) |
Retrieve date format by strftime function
string | $type |
Definition at line 451 of file Locale.php.
00452 { 00453 return Varien_Date::convertZendToStrftime($this->getDateFormat($type), true, false); 00454 }
getDateTimeFormat | ( | $ | type | ) |
Retrieve ISO datetime format
string | $type |
Definition at line 440 of file Locale.php.
00441 { 00442 return $this->getDateFormat($type) . ' ' . $this->getTimeFormat($type); 00443 }
getDefaultLocale | ( | ) |
REtrieve default locale code
Definition at line 111 of file Locale.php.
00112 { 00113 if (!$this->_defaultLocale) { 00114 $locale = Mage::getStoreConfig(self::XML_PATH_DEFAULT_LOCALE); 00115 if (!$locale) { 00116 $locale = self::DEFAULT_LOCALE; 00117 } 00118 $this->_defaultLocale = $locale; 00119 } 00120 return $this->_defaultLocale; 00121 }
getJsPriceFormat | ( | ) |
Functions returns array with price formating info for js function formatCurrency in js/varien/js.js
Definition at line 616 of file Locale.php.
00617 { 00618 $format = Zend_Locale_Data::getContent($this->getLocaleCode(), 'currencynumber'); 00619 $symbols = Zend_Locale_Data::getList($this->getLocaleCode(), 'symbols'); 00620 00621 $pos = strpos($format, ';'); 00622 if ($pos !== false){ 00623 $format = substr($format, 0, $pos); 00624 } 00625 $format = preg_replace("/[^0\#\.,]/", "", $format); 00626 $totalPrecision = 0; 00627 $decimalPoint = strpos($format, '.'); 00628 if ($decimalPoint !== false) { 00629 $totalPrecision = (strlen($format) - (strrpos($format, '.')+1)); 00630 } else { 00631 $decimalPoint = strlen($format); 00632 } 00633 $requiredPrecision = $totalPrecision; 00634 $t = substr($format, $decimalPoint); 00635 $pos = strpos($t, '#'); 00636 if ($pos !== false){ 00637 $requiredPrecision = strlen($t) - $pos - $totalPrecision; 00638 } 00639 $group = 0; 00640 if (strrpos($format, ',') !== false) { 00641 $group = ($decimalPoint - strrpos($format, ',') - 1); 00642 } else { 00643 $group = strrpos($format, '.'); 00644 } 00645 $integerRequired = (strpos($format, '.') - strpos($format, '0')); 00646 00647 $result = array( 00648 'pattern' => Mage::app()->getStore()->getCurrentCurrency()->getOutputFormat(), 00649 'precision' => $totalPrecision, 00650 'requiredPrecision' => $requiredPrecision, 00651 'decimalSymbol' => $symbols['decimal'], 00652 'groupSymbol' => $symbols['group'], 00653 'groupLength' => $group, 00654 'integerRequired' => $integerRequired 00655 ); 00656 00657 return $result; 00658 }
getLocale | ( | ) |
Retrieve locale object
Definition at line 165 of file Locale.php.
00166 { 00167 if (!$this->_locale) { 00168 Zend_Locale_Data::setCache(Mage::app()->getCache()); 00169 $this->_locale = new Zend_Locale($this->getLocaleCode()); 00170 } elseif ($this->_locale->__toString() != $this->_localeCode) { 00171 $this->setLocale($this->_localeCode); 00172 } 00173 00174 return $this->_locale; 00175 }
getLocaleCode | ( | ) |
Retrieve locale code
Definition at line 182 of file Locale.php.
00183 { 00184 if ($this->_localeCode === null) { 00185 $this->setLocale(); 00186 } 00187 return $this->_localeCode; 00188 }
getNumber | ( | $ | value | ) |
Returns the first found number from an string Parsing depends on given locale (grouping and decimal)
Examples for input: ' 2345.4356,1234' = 23455456.1234 '+23,3452.123' = 233452.123 ' 12343 ' = 12343 '-9456km' = -9456 '0' = 0 '2 054,10' = 2054.1 '2'054.52' = 2054.52 '2,46 GB' = 2.46
string|int | $value |
Definition at line 576 of file Locale.php.
00577 { 00578 if (is_null($value)) { 00579 return null; 00580 } 00581 00582 if (!is_string($value)) { 00583 return floatval($value); 00584 } 00585 00586 //trim space and apos 00587 $value = str_replace('\'', '', $value); 00588 $value = str_replace(' ', '', $value); 00589 00590 $separatorComa = strpos($value, ','); 00591 $separatorDot = strpos($value, '.'); 00592 00593 if ($separatorComa !== false && $separatorDot !== false) { 00594 if ($separatorComa > $separatorDot) { 00595 $value = str_replace('.', '', $value); 00596 $value = str_replace(',', '.', $value); 00597 } 00598 else { 00599 $value = str_replace(',', '', $value); 00600 } 00601 } 00602 elseif ($separatorComa !== false) { 00603 $value = str_replace(',', '.', $value); 00604 } 00605 00606 return floatval($value); 00607 //return Zend_Locale_Format::getNumber($value, array('locale' => $this->getLocaleCode())); 00608 }
getOptionAllCurrencies | ( | ) |
Retrieve all currency option list
Definition at line 347 of file Locale.php.
00348 { 00349 $currencies = $this->getTranslationList('currencytoname'); 00350 $options = array(); 00351 foreach ($currencies as $name=>$code) { 00352 $options[] = array( 00353 'label' => $name, 00354 'value' => $code, 00355 ); 00356 } 00357 return $this->_sortOptionArray($options); 00358 }
getOptionCountries | ( | ) |
Retrieve country option list
Definition at line 304 of file Locale.php.
00305 { 00306 $options = array(); 00307 $countries = $this->getCountryTranslationList(); 00308 00309 foreach ($countries as $code=>$name) { 00310 $options[] = array( 00311 'label' => $name, 00312 'value' => $code, 00313 ); 00314 } 00315 return $this->_sortOptionArray($options); 00316 }
getOptionCurrencies | ( | ) |
Retrieve currency option list
Definition at line 323 of file Locale.php.
00324 { 00325 $currencies = $this->getTranslationList('currencytoname'); 00326 $options = array(); 00327 $allowed = $this->getAllowCurrencies(); 00328 00329 foreach ($currencies as $name=>$code) { 00330 if (!in_array($code, $allowed)) { 00331 continue; 00332 } 00333 00334 $options[] = array( 00335 'label' => $name, 00336 'value' => $code, 00337 ); 00338 } 00339 return $this->_sortOptionArray($options); 00340 }
getOptionLocales | ( | ) |
Get options array for locale dropdown in currunt locale
Definition at line 207 of file Locale.php.
00208 { 00209 return $this->_getOptionLocales(); 00210 }
getOptionTimezones | ( | ) |
Retrieve timezone option list
Definition at line 266 of file Locale.php.
00267 { 00268 $options= array(); 00269 $zones = $this->getTranslationList('windowstotimezone'); 00270 ksort($zones); 00271 foreach ($zones as $code=>$name) { 00272 $name = trim($name); 00273 $options[] = array( 00274 'label' => empty($name) ? $code : $name . ' (' . $code . ')', 00275 'value' => $code, 00276 ); 00277 } 00278 return $this->_sortOptionArray($options); 00279 }
getOptionWeekdays | ( | ) |
Retrieve days of week option list
Definition at line 286 of file Locale.php.
00287 { 00288 $options= array(); 00289 $days = $this->getTranslationList('days'); 00290 foreach (array_values($days['format']['wide']) as $code => $name) { 00291 $options[] = array( 00292 'label' => $name, 00293 'value' => $code, 00294 ); 00295 } 00296 return $options; 00297 }
getTimeFormat | ( | $ | type = null |
) |
Retrieve ISO time format
string | $type |
Definition at line 429 of file Locale.php.
00430 { 00431 return $this->getTranslation($type, 'time'); 00432 }
getTimeStrFormat | ( | $ | type | ) |
Retrieve time format by strftime function
string | $type |
Definition at line 462 of file Locale.php.
00463 { 00464 return Varien_Date::convertZendToStrftime($this->getTimeFormat($type), false, true); 00465 }
getTimezone | ( | ) |
getTranslatedOptionLocales | ( | ) |
Get translated to original locale options array for locale dropdown
Definition at line 217 of file Locale.php.
00218 { 00219 return $this->_getOptionLocales(true); 00220 }
getTranslation | ( | $ | value = null , |
|
$ | path = null | |||
) |
Returns a localized information string, supported are several types of informations. For detailed information about the types look into the documentation
string | $value Name to get detailed information about | |
string | $path (Optional) Type of information to return |
Definition at line 714 of file Locale.php.
getTranslationList | ( | $ | path = null , |
|
$ | value = null | |||
) |
Returns localized informations as array, supported are several types of informations. For detailed information about the types look into the documentation
string | $path (Optional) Type of information to return | |
string | $value (Optional) Value for detail list |
Definition at line 701 of file Locale.php.
00702 { 00703 return $this->getLocale()->getTranslationList($path, $this->getLocale(), $value); 00704 }
IsStoreDateInInterval | ( | $ | store, | |
$ | dateFrom = null , |
|||
$ | dateTo = null | |||
) |
Is Store dat in iterval
int|string|Mage_Core_Model_Store | $store | |
string|null | $dateFrom | |
string|null | $dateTo |
Definition at line 748 of file Locale.php.
00749 { 00750 if (!$store instanceof Mage_Core_Model_Store) { 00751 $store = Mage::app()->getStore($store); 00752 } 00753 00754 $storeTimeStamp = $this->storeTimeStamp($store); 00755 $fromTimeStamp = strtotime($dateFrom); 00756 $toTimeStamp = strtotime($dateTo); 00757 if ($dateTo) { 00758 // fix date YYYY-MM-DD 00:00:00 to YYYY-MM-DD 23:59:59 00759 $toTimeStamp += 86400; 00760 } 00761 00762 $result = false; 00763 if (!is_empty_date($dateFrom) && $storeTimeStamp < $fromTimeStamp) { 00764 } 00765 elseif (!is_empty_date($dateTo) && $storeTimeStamp > $toTimeStamp) { 00766 } 00767 else { 00768 $result = true; 00769 } 00770 00771 return $result; 00772 }
revert | ( | ) |
Get last locale, used before last emulation
Definition at line 683 of file Locale.php.
00684 { 00685 if ($locale = array_pop($this->_emulatedLocales)) { 00686 $this->_locale = $locale; 00687 $this->_localeCode = $this->_locale->toString(); 00688 Mage::getSingleton('core/translate')->setLocale($this->_locale)->init('adminhtml', true); 00689 } 00690 }
setDefaultLocale | ( | $ | locale | ) |
Set default locale code
string | $locale |
Definition at line 100 of file Locale.php.
setLocale | ( | $ | locale = null |
) |
Set locale
string | $locale |
Definition at line 129 of file Locale.php.
00130 { 00131 if (($locale !== null) && is_string($locale)) { 00132 $this->_localeCode = $locale; 00133 } else { 00134 $this->_localeCode = $this->getDefaultLocale(); 00135 } 00136 Mage::dispatchEvent('core_locale_set_locale', array('locale'=>$this)); 00137 return $this; 00138 }
setLocaleCode | ( | $ | code | ) |
Specify current locale code
string | $code |
Definition at line 196 of file Locale.php.
storeDate | ( | $ | store = null , |
|
$ | date = null , |
|||
$ | includeTime = false | |||
) |
Create Zend_Date object with date converted to store timezone and store Locale
mixed | $store Information about store | |
string|integer|Zend_Date|array|null | $date date in UTC | |
boolean | $includeTime flag for including time to date |
Definition at line 501 of file Locale.php.
00502 { 00503 $timezone = Mage::app()->getStore($store)->getConfig(self::XML_PATH_DEFAULT_TIMEZONE); 00504 $date = new Zend_Date($date, null, $this->getLocale()); 00505 $date->setTimezone($timezone); 00506 if (!$includeTime) { 00507 $date->setHour(0) 00508 ->setMinute(0) 00509 ->setSecond(0); 00510 } 00511 return $date; 00512 }
storeTimeStamp | ( | $ | store = null |
) |
Get store timestamp Timstamp will be builded with store timezone settings
mixed | $store |
Definition at line 521 of file Locale.php.
00522 { 00523 $timezone = Mage::app()->getStore($store)->getConfig(self::XML_PATH_DEFAULT_TIMEZONE); 00524 $currentTimezone = @date_default_timezone_get(); 00525 @date_default_timezone_set($timezone); 00526 $date = date('Y-m-d H:i:s'); 00527 @date_default_timezone_set($currentTimezone); 00528 return strtotime($date); 00529 }
$_currencyCache = array() [static, protected] |
Definition at line 87 of file Locale.php.
$_defaultLocale [protected] |
Definition at line 64 of file Locale.php.
$_emulatedLocales = array() [protected] |
Definition at line 85 of file Locale.php.
$_locale [protected] |
Definition at line 71 of file Locale.php.
$_localeCode [protected] |
Definition at line 78 of file Locale.php.
const DEFAULT_CURRENCY = 'USD' |
Definition at line 39 of file Locale.php.
const DEFAULT_LOCALE = 'en_US' |
Default locale name
Definition at line 37 of file Locale.php.
const DEFAULT_TIMEZONE = 'UTC' |
Definition at line 38 of file Locale.php.
const FORMAT_TYPE_FULL = 'full' |
Date and time format codes
Definition at line 54 of file Locale.php.
const FORMAT_TYPE_LONG = 'long' |
Definition at line 55 of file Locale.php.
const FORMAT_TYPE_MEDIUM = 'medium' |
Definition at line 56 of file Locale.php.
const FORMAT_TYPE_SHORT = 'short' |
Definition at line 57 of file Locale.php.
const XML_PATH_ALLOW_CODES = 'global/locale/allow/codes' |
Definition at line 47 of file Locale.php.
const XML_PATH_ALLOW_CURRENCIES = 'global/locale/allow/currencies' |
Definition at line 48 of file Locale.php.
const XML_PATH_ALLOW_CURRENCIES_INSTALLED = 'system/currency/installed' |
Definition at line 49 of file Locale.php.
const XML_PATH_DEFAULT_COUNTRY = 'general/country/default' |
Definition at line 46 of file Locale.php.
const XML_PATH_DEFAULT_LOCALE = 'general/locale/code' |
XML path constants
Definition at line 44 of file Locale.php.
const XML_PATH_DEFAULT_TIMEZONE = 'general/locale/timezone' |
Definition at line 45 of file Locale.php.