/** * test getDefault * expected true */ public function testgetDefault() { $value = new Zend_Locale(); $default = $value->getDefault(); $this->assertTrue(is_array($default), 'No Default Locale found'); $default = $value->getDefault(Zend_Locale::BROWSER); $this->assertTrue(is_array($default), 'No Default Locale found'); $default = $value->getDefault(Zend_Locale::ENVIRONMENT); $this->assertTrue(is_array($default), 'No Default Locale found'); $default = $value->getDefault(Zend_Locale::FRAMEWORK); $this->assertTrue(is_array($default), 'No Default Locale found'); }
public function __construct($locale = null) { if ($locale === null) { $locale = key(Zend_Locale::getDefault()); } elseif (empty($locale)) { $locale = 'en_US'; } $this->locale = $locale; }
public function localeShort() { $translator = $this->view->getHelper('translate')->getTranslator(); $locale = $translator->getLocale(); if (!$translator->isAvailable($locale)) { $defaults = Zend_Locale::getDefault(); arsort($defaults); $locale = key($defaults); } $locale = new Zend_Locale($locale); return $locale->getLanguage(); }
/** * Retrieve router object * * @return Zend_Controller_Router_Rewrite */ public function getRouter() { $routesIni = $this->_getRoutesConfig(); $this->setOptions($routesIni->toArray()); $options = $this->getOptions(); if ($this->_localeIsEnabled()) { $bootstrap = $this->getBootstrap(); if (!$this->_locale) { $bootstrap->bootstrap('Locale'); $this->_locale = $bootstrap->getContainer()->locale; } $defaultLocale = array_keys($this->_locale->getDefault()); $defaultLocale = $defaultLocale[0]; $locales = $this->_getPossibleLocales(); $routes = $options['routes']; $localizedRoutes = Garp_I18n::getLocalizedRoutes($routes, $locales); $options['routes'] = array_merge($routes, $localizedRoutes); $this->setOptions($options); } $router = parent::getRouter(); $router->addDefaultRoutes(); return $router; }
public function Translate($text) { $translated = $text; try { $locale = new Zend_Locale(Zend_Locale::BROWSER); $translate = Zend_Registry::get('translate'); if (!$translate->isAvailable($locale)) { $translate->setLocale(Zend_Locale::getDefault()); } $translated = $translate->_($text); } catch (Exception $e) { Zend_Registry::get('logger')->err($e->getMessage()); } return $translated; }
/** * Retrieve translate object * * @return Zend_Translate */ public function getTranslate() { $options = $this->getOptions(); if (!isset($options['data'])) { throw new Zend_Application_Resource_Exception('No translation source data provided in the ini file for: ' . get_class($this->getBootstrap()) . '.'); } foreach (Zend_Locale::getDefault() as $default => $value) { break; } $adapter = isset($options['adapter']) ? $options['adapter'] : Zend_Translate::AN_ARRAY; $locale = isset($options['locale']) ? $options['locale'] : $default; $translateOptions = isset($options['options']) ? $options['options'] : array(); $key = isset($options['registry_key']) && !is_numeric($options['registry_key']) ? $options['registry_key'] : self::DEFAULT_REGISTRY_KEY; // If no translate object was set in the registry we create it. if (!Zend_Registry::isRegistered($key)) { $this->_createTranslation($adapter, $options['data'], $locale, $translateOptions); // if there is, we should add a translation source to the existing translate object } elseif (Zend_Registry::isRegistered($key)) { $this->_translate = Zend_Registry::get($key); $this->_addTranslation($options['data'], $locale, $translateOptions); } Zend_Registry::set($key, $this->_translate); return $this->_translate; }
/** * test getDefault * expected true */ public function testgetDefault() { Zend_Locale::setDefault('de'); $value = new Zend_Locale(); $default = $value->getDefault(); $this->assertTrue(array_key_exists('de', $default)); $default = $value->getDefault(); $this->assertTrue(is_array($default)); $default = $value->getDefault(Zend_Locale::BROWSER); $this->assertTrue(is_array($default)); $default = $value->getDefault(Zend_Locale::ENVIRONMENT); $this->assertTrue(is_array($default)); $default = $value->getDefault(Zend_Locale::FRAMEWORK); $this->assertTrue(is_array($default)); }
/** * 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 (empty(self::$_auto)) { $temp = new Zend_Locale($locale); self::$_auto = $temp->getDefault(null, false); self::$_browser = $temp->getDefault(self::BROWSER, false); self::$_environment = $temp->getDefault(self::ENVIRONMENT, false); } if ($locale == 'auto') { $locale = self::$_auto; } if ($locale == 'browser') { $locale = self::$_browser; } if ($locale == 'environment') { $locale = self::$_environment; } if (is_array($locale)) { $locale = key($locale); } 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; }
function getDefaultLocale($addRegion = false) { @(list($found, ) = array_keys(Zend_Locale::getDefault())); if (!$found) { return 'en_US'; } if (!$addRegion) { return $found; } return strlen($found) <= 4 ? ___('_default_locale') : $found; }
public function getLanguage() { return Zend_Locale::getDefault(); }
/** * test getDefaultFramework * expected true */ public function testDefaultFramework() { $value = new Zend_Locale(); $default = $value->getDefault(Zend_Locale::FRAMEWORK); $this->assertTrue(is_array($default), 'No Default Locale found'); }
public function getLanguage() { $_list = $this->getLangaugeList(); $_locale = key(Zend_Locale::getDefault()); if (!array_key_exists($_locale, $_list)) { list($_locale) = explode('_', $_locale); } return $_locale; }
/** * Return Zend_Date object with browser sent|german locale. * * @param Zend_Date $timestamp * @return Zend_Locale */ protected function _getLocaleDate(Zend_Date $date) { // TODO Get currently used locale in a better/easier way. if (!self::$_locale) { $currentLocales = Zend_Locale::getDefault(); self::$_locale = key($currentLocales); } $date = $date->setLocale(self::$_locale); return $date; }
function get_locale() { $locale = new Zend_Locale(); return $locale->getDefault(); }