本文整理汇总了PHP中Zend_Locale::setDefault方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Locale::setDefault方法的具体用法?PHP Zend_Locale::setDefault怎么用?PHP Zend_Locale::setDefault使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend_Locale
的用法示例。
在下文中一共展示了Zend_Locale::setDefault方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: init
public function init()
{
if (null === $this->_locale) {
$sessionLocale = new Zend_Session_Namespace('locale');
//Zend_Session::destroy();
//var_dump($session->localename);
//Zend_Debug::dump($_SESSION);exit;
//Zend_Debug::dump(Zend_Session::getOptions());exit;
if (isset($sessionLocale->localename)) {
$this->_locale = new Zend_Locale($sessionLocale->localename);
} else {
$options = $this->getOptions();
if (!isset($options['default'])) {
$this->_locale = new Zend_Locale();
} elseif (!isset($options['force']) || (bool) $options['force'] == false) {
// Don't force any locale, just go for auto detection
Zend_Locale::setDefault($options['default']);
$this->_locale = new Zend_Locale();
} else {
//强制区域为...
$this->_locale = new Zend_Locale($options['default']);
}
$sessionLocale->localename = $this->_locale->getLanguage() . '_' . $this->_locale->getRegion();
}
$key = isset($options['registry_key']) && !is_numeric($options['registry_key']) ? $options['registry_key'] : self::DEFAULT_REGISTRY_KEY;
Zend_Registry::set($key, $this->_locale);
Zend_Registry::set('sessionLocale', $sessionLocale);
}
return $this->_locale;
}
示例2: init
public function init()
{
$controller = $this->getActionController();
if (!($requestedLocale = $controller->getRequest()->getParam('language', false))) {
$local = new Zend_Locale();
$requestedLocale = $local->getLanguage();
}
if (is_array($requestedLocale)) {
$requestedLocale = current($requestedLocale);
}
$requestedLocale = strtolower($requestedLocale);
try {
Centurion_Db::getSingleton('translation/language')->get(array('locale' => $requestedLocale));
} catch (Centurion_Db_Table_Row_Exception_DoesNotExist $e) {
$requestedLocale = Translation_Traits_Common::getDefaultLanguage();
$requestedLocale = $requestedLocale->locale;
}
Zend_Registry::get('Zend_Translate')->setLocale($requestedLocale);
Zend_Locale::setDefault($requestedLocale);
Zend_Registry::set('Zend_Locale', $requestedLocale);
$options = Centurion_Db_Table_Abstract::getDefaultFrontendOptions();
if (!isset($options['cache_id_prefix'])) {
$options['cache_id_prefix'] = '';
}
$options['cache_id_prefix'] = $requestedLocale . '_' . $options['cache_id_prefix'];
Centurion_Db_Table_Abstract::setDefaultFrontendOptions($options);
//TODO: fix this when in test unit environment
if (!APPLICATION_ENV === 'testing') {
$this->getActionController()->getFrontController()->getParam('bootstrap')->getResource('cachemanager')->addIdPrefix($requestedLocale . '_');
}
if (Centurion_Config_Manager::get('translation.global_param')) {
$this->getFrontController()->getRouter()->setGlobalParam('language', $requestedLocale);
}
}
示例3: setUp
/**
* Setup environment
*/
public function setUp()
{
date_default_timezone_set('America/Chicago');
Zend_Locale::setDefault('en_US');
Zend_Amf_Parse_TypeLoader::resetMap();
$this->_response = new Zend_Amf_Response();
}
示例4: setUp
/**
* Setup environment
*/
public function setUp()
{
date_default_timezone_set("America/Chicago");
Zend_Locale::setDefault('en');
Zend_Amf_Parse_TypeLoader::resetMap();
$this->_request = new Zend_Amf_Request();
}
示例5: preDispatch
public function preDispatch($request)
{
try {
$locale = new Zend_Locale();
$locale->setDefault('en');
$locale->setLocale(Zend_Locale::BROWSER);
$requestedLanguage = key($locale->getBrowser());
$formatter = new Zend_Log_Formatter_Simple('%message%' . PHP_EOL);
$writer = new Zend_Log_Writer_Stream(APPLICATION_LOG_PATH . 'translations.log');
$writer->setFormatter($formatter);
$logger = new Zend_Log($writer);
$frontendOptions = array('cache_id_prefix' => 'translation', 'lifetime' => 86400, 'automatic_serialization' => true);
$backendOptions = array('cache_dir' => APPLICATION_CACHE_PATH);
$cache = Zend_Cache::factory('Core', 'File', $frontendOptions, $backendOptions);
$options = array('adapter' => 'gettext', 'scan' => Zend_Translate::LOCALE_FILENAME, 'content' => APPLICATION_PATH . '/languages/en/en.mo', 'locale' => 'auto', 'disableNotices' => true);
$translate = new Zend_Translate($options);
if (!$translate->isAvailable($locale->getLanguage())) {
$locale->setLocale('en');
} else {
$translate->setLocale($locale);
}
$translate->setCache($cache);
Zend_Registry::set('locale', $locale->getLanguage());
Zend_Registry::set('Zend_Translate', $translate);
} catch (Exception $e) {
try {
$writer = new Zend_Log_Writer_Stream(APPLICATION_LOG_PATH . 'plugin-locale.log');
$logger = new Zend_Log($writer);
$logger->log($e->getMessage(), Zend_Log::ERR);
} catch (Exception $e) {
}
}
}
示例6: __invoke
/**
* @param \HumusMvc\MvcEvent $e
* @return void
*/
public function __invoke(MvcEvent $e)
{
$serviceManager = $e->getApplication()->getServiceManager();
$config = $serviceManager->get('Config');
if (!isset($config['locale'])) {
// no locale config found, return
return;
}
// set cache in locale to speed up application
if ($serviceManager->has('CacheManager')) {
$cacheManager = $serviceManager->get('CacheManager');
Locale::setCache($cacheManager->getCache('default'));
}
$options = $config['locale'];
if (!isset($options['default'])) {
$locale = new Locale();
} elseif (!isset($options['force']) || (bool) $options['force'] == false) {
// Don't force any locale, just go for auto detection
Locale::setDefault($options['default']);
$locale = new Locale();
} else {
$locale = new Locale($options['default']);
}
$key = isset($options['registry_key']) && !is_numeric($options['registry_key']) ? $options['registry_key'] : self::DEFAULT_REGISTRY_KEY;
Registry::set($key, $locale);
}
示例7: _initLanguage
protected function _initLanguage()
{
$locale = new Zend_Locale('de_AT');
$translator = new Zend_Translate('array', APPLICATION_PATH . '/../resources/languages', 'de', array('scan' => Zend_Translate::LOCALE_DIRECTORY));
Zend_Validate_Abstract::setDefaultTranslator($translator);
Zend_Locale::setDefault($locale);
}
示例8: startLocale
protected function startLocale()
{
require_once "Zend/Translate.php";
// silenciando strict até arrumar zend_locale
date_default_timezone_set("America/Sao_Paulo");
$i18n = new Zend_Translate('gettext', $this->config->system->path->base . '/lang/pt_BR.mo', 'pt_BR');
Zend_Registry::set('i18n', $i18n);
$translation_files = $this->config->system->path->base . "/lang/";
foreach (scandir($translation_files) as $filename) {
// Todos os arquivos .php devem ser classes de descrição de modulos
if (preg_match("/.*\\.mo\$/", $filename)) {
$translation_id = basename($filename, '.mo');
if ($translation_id != "pt_BR") {
$i18n->addTranslation($translation_files . "/{$filename}", $translation_id);
}
}
}
require_once "Zend/Locale.php";
if (Zend_Locale::isLocale($this->config->system->locale)) {
$locale = $this->config->system->locale;
} else {
$locale = "pt_BR";
}
Zend_Registry::set('Zend_Locale', new Zend_Locale($locale));
Zend_Locale::setDefault($locale);
Zend_Locale_Format::setOptions(array("locale" => $locale));
$i18n->setLocale($locale);
Zend_Registry::set("Zend_Translate", $i18n);
$zend_validate_translator = new Zend_Translate_Adapter_Array($this->config->system->path->base . "/lang/Zend_Validate/{$locale}/Zend_Validate.php", $locale);
Zend_Validate_Abstract::setDefaultTranslator($zend_validate_translator);
}
示例9: getLocale
/**
* Retrieve locale object
*
* @return Zend_Locale
*/
public function getLocale()
{
if (null === $this->_locale) {
$options = $this->getOptions();
if (!isset($options['default'])) {
$this->_locale = new Zend_Locale();
} elseif(!isset($options['force']) ||
(bool) $options['force'] == false)
{
// Don't force any locale, just go for auto detection
Zend_Locale::setDefault($options['default']);
$this->_locale = new Zend_Locale();
} else {
$this->_locale = new Zend_Locale($options['default']);
}
$key = (isset($options['registry_key']) && !is_numeric($options['registry_key']))
? $options['registry_key']
: self::DEFAULT_REGISTRY_KEY;
Zend_Registry::set($key, $this->_locale);
}
return $this->_locale;
}
示例10: preDispatch
/**
* Detect the locale
*
* @param Zend_Controller_Request_Abstract $request
*/
public function preDispatch(Zend_Controller_Request_Abstract $request)
{
$language = $request->getParam('language_code');
$locale = new Zend_Locale($language);
Zend_Locale::setDefault($language);
Zend_Registry::set('Zend_Locale', $locale);
}
示例11: _initDate
protected function _initDate()
{
$config = $this->getOption('configuration');
date_default_timezone_set($config['date']['timezone']);
setlocale(LC_ALL, $config['date']['locale']);
\Zend_Locale::setDefault($config['date']['locale']);
$date = new \Zend_Date();
return $date;
}
示例12: getLocaleInstance
public function getLocaleInstance()
{
if ($this->_locale === null) {
require_once 'Zend/Locale.php';
Zend_Locale::setDefault(self::LANGUAGE_EN);
$this->_locale = new Zend_Locale();
}
return $this->_locale;
}
示例13: _initLocale
/**
* Bootstrap the locale
*
* @return void
*/
protected function _initLocale()
{
date_default_timezone_set('America/Sao_Paulo');
$locale = new Zend_Locale('pt_BR');
Zend_Registry::set('Zend_Locale', $locale);
Zend_Locale::setDefault($locale);
Zend_Controller_Front::getInstance()->getRouter()->setGlobalParam('language', strtolower($locale->getRegion()));
$translate = new Zend_Translate(array('adapter' => 'csv', 'content' => APPLICATION_PATH . '/languages/default/' . $locale->toString() . '.csv'));
Zend_Registry::set('Zend_Translate', $translate);
}
示例14: _initTranslator
protected function _initTranslator()
{
$session = Zend_Registry::get('session');
Zend_Locale::setDefault('en');
$locale = isset($session->locale) ? $session->locale : new Zend_Locale(Zend_Locale::ZFDEFAULT);
Zend_Registry::set('Zend_Locale', $locale);
$session->locale = $locale;
$translator = new Zend_Translate(array('adapter' => 'array', 'content' => INSTALL_PATH . DIRECTORY_SEPARATOR . 'system/languages/', 'scan' => Zend_Translate::LOCALE_FILENAME, 'locale' => $locale->getLanguage(), 'ignore' => array('.'), 'route' => array('fr' => 'en', 'it' => 'en', 'de' => 'en')));
Zend_Form::setDefaultTranslator($translator);
Zend_Registry::set('Zend_Translate', $translator);
Zend_Registry::set('session', $session);
}
示例15: _initLocale
protected function _initLocale()
{
Zend_Loader::loadClass('Zend_Locale');
Zend_Locale::setDefault('fr');
$session = new Zend_Session_Namespace();
$session->locale = !empty($session->locale) ? $session->locale : DEFAULT_LOCALE;
$translator = new Zend_Translate(array('adapter' => 'array', 'content' => APPLICATION_PATH . '/languages/' . $session->locale . '.php', 'locale' => $session->locale));
Zend_Validate_Abstract::setDefaultTranslator($translator);
Zend_Form::setDefaultTranslator($translator);
Zend_Validate::setDefaultTranslator($translator);
Zend_Registry::set("Zend_Translate", $translator);
}