本文整理汇总了PHP中Zend_Translate::setLocale方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Translate::setLocale方法的具体用法?PHP Zend_Translate::setLocale怎么用?PHP Zend_Translate::setLocale使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend_Translate
的用法示例。
在下文中一共展示了Zend_Translate::setLocale方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _initTranslate
public function _initTranslate()
{
$locale = new Zend_Locale(Zend_Locale::BROWSER);
$translate = new Zend_Translate(array('adapter' => 'csv', 'content' => APPLICATION_PATH . '/configs/languages/lang.en', 'locale' => 'en'));
$translate->addTranslation(array('content' => APPLICATION_PATH . '/configs/languages/lang.hi', 'locale' => 'hi'));
if ($translate->isAvailable($locale->getLanguage())) {
$translate->setLocale($locale);
} else {
$translate->setLocale('en');
}
Zend_Registry::set('Translate', $translate);
}
示例2: _initSetTranslations
protected function _initSetTranslations()
{
$translate = new Zend_Translate(array('adapter' => 'gettext', 'content' => APPLICATION_PATH . '/../library/Rdine/Translate/Language', 'locale' => null, 'scan' => Zend_Translate::LOCALE_FILENAME));
$namespace = new Zend_Session_Namespace();
$language = 'en';
if ($namespace->lang) {
if ($namespace->lang == 'en_US') {
$language = 'en';
$namespace->lang = 'en_US';
}
if ($namespace->lang == 'es_SP') {
$language = 'es_SP';
}
} else {
$language = 'en';
$namespace->lang = 'en_US';
}
$translate->setLocale($language);
$view = $this->getResource('view');
$view->translate = $translate;
if ($namespace->lang) {
$view->lang = $namespace->lang;
} else {
$view->lang = 'en_US';
$namespace->lang = 'en_US';
}
}
示例3: _initLanguages
protected function _initLanguages()
{
$languageDir = APPLICATION_PATH . DIRECTORY_SEPARATOR . 'languages';
Zend_Registry::set('languageDir', $languageDir);
$translate = new Zend_Translate(
'gettext', $languageDir
);
$translate->addTranslation($languageDir . DIRECTORY_SEPARATOR . 'en_GB.mo', 'en');
$translate->addTranslation($languageDir . DIRECTORY_SEPARATOR . 'fr_FR.mo', 'fr');
$translate->addTranslation($languageDir . DIRECTORY_SEPARATOR . 'it_IT.mo', 'it');
$translate->addTranslation($languageDir . DIRECTORY_SEPARATOR . 'ru_RU.mo', 'ru');
$locale = new Zend_Session_Namespace('locale');
if ($locale->value === null) {
$config_model = new Default_Model_Configuration();
$locale_config = $config_model->getKey('locale');
isset($locale_config) ? $locale->value = $locale_config : $locale->value = 'en';
}
$translate->setLocale($locale->value);
Zend_Registry::set('tr', $translate);
Zend_Registry::set('Zend_Translate', $translate);
Zend_Registry::set('Zend_Locale', $locale);
}
示例4: 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) {
}
}
}
示例5: translate
/**
* Retturn translation string
* example $l->translate('Field %1 is incorrect', 'FieldName');
*
* @param string $msg Message to transalte.
*/
public function translate($msg)
{
$translated = $msg;
if ($this->translate->isTranslated($msg, true, $this->locale)) {
$translated = $this->translate->translate($msg);
} else {
foreach ($this->translationsPaths as $name => $value) {
if (!$this->translate->isAvailable($name)) {
try {
$this->translate->addTranslation($this->translationsPaths[$name], $name);
$this->translate->setLocale($this->getLocale());
} catch (Zend_Translate_Exception $e) {
continue;
}
}
if ($this->translate->isTranslated($msg, $name)) {
$translated = $this->translate->translate($msg, $name);
break;
}
}
}
if (func_num_args() > 1) {
$params = func_get_args();
$params[0] = $translated;
$translated = @call_user_func_array("sprintf", $params);
//add shield for incorrect translations(warning about incorrect number of arguments)
}
return $translated;
}
示例6: _initTranslation
protected function _initTranslation()
{
$translate = new Zend_Translate('Array', APPLICATION_PATH . '/configs/languages/pt_BR.php', 'pt_BR');
$translate->setLocale('pt_BR');
Zend_Registry::set('Zend_Translate', $translate);
$locale = new Zend_Locale('pt_BR');
Zend_Registry::set('Zend_Locale', $locale);
}
示例7: _initTranslate
protected function _initTranslate()
{
$translate = new Zend_Translate('gettext', APPLICATION_PATH . '/data/languages/zh.mo', 'zh');
$translate->addTranslation(APPLICATION_PATH . '/data/languages/en.mo', 'en');
//$translate->setLocale('zh');
$translate->setLocale('en');
Zend_Registry::set('translate', $translate);
}
示例8: testSetLocale
public function testSetLocale()
{
$lang = new Zend_Translate(Zend_Translate::AN_ARRAY, array('msg1' => 'Message 1'), 'en');
$lang->addTranslation('ru', array('msg1' => 'Message 1 (ru)'));
$this->assertEquals($lang->getLocale(), new Zend_Locale('en'));
$lang->setLocale('ru');
$this->assertEquals($lang->getLocale(), new Zend_Locale('ru'));
}
示例9: setIniFilenameScanTranslator
public function setIniFilenameScanTranslator($path, $defaultLanguage, $language = null)
{
require_once 'Zend/Translate.php';
$translate = new Zend_Translate(Zend_Translate::AN_INI, $path, $defaultLanguage, array('scan' => Zend_Translate::LOCALE_FILENAME));
if ($translate->isAvailable($language)) {
$translate->setLocale($language);
}
$this->setTranslator($translate->getAdapter());
}
示例10: getCurrentlanguage
public static function getCurrentlanguage($lang = 1, $layout = false)
{
// set up translation adapter
$session_lang = new Zend_Session_Namespace('lang');
$session_lang->lang_id = 1;
if ($lang == 1) {
$str = "km";
} else {
$str = "en";
}
$tr = new Zend_Translate('ini', PUBLIC_PATH . '/lang/' . $str, null, array('scan' => Zend_Translate::LOCALE_FILENAME));
// set locale
$tr->setLocale('en');
$session_language = new Zend_Session_Namespace('language');
if (!empty($session_language->language)) {
$tr->setLocale(strtolower($session_language->language));
}
return $tr;
}
示例11: getTranslate
/**
* Retrieve translate object
*
* @return Zend_Translate
* @throws Streamwide_Exception When provided locales invalid, throw Streamwide_Exception
*/
public function getTranslate()
{
if (null === $this->_translate) {
$options = $this->getOptions();
if (!isset($options['locales']) || !is_array($options['locales'])) {
throw new Streamwide_Exception('No translation source data provided.');
}
$log = $this->getBootstrap()->getResource('Logger');
$adapter = isset($options['adapter']) ? $options['adapter'] : Zend_Translate::AN_CSV;
$locale = isset($options['locales']['default']) ? $options['locales']['default'] : null;
$translateOptions = array('scan' => Zend_Translate::LOCALE_DIRECTORY, 'log' => $log, 'logUntranslated' => true, 'disableNotices' => $options['disableNotices']);
$this->_translate = new Zend_Translate($adapter, $options['locales']['path'], $locale, $translateOptions);
$this->_translate->setLocale($this->_locale);
$view = $this->getBootstrap()->getResource('View');
$view->doctype('XHTML1_STRICT');
$view->translate()->setTranslator($this->_translate);
}
return $this->_translate;
}
示例12: setUp
/**
* Setup test
*
* @return void
*/
public function setUp()
{
// Backup server array
$this->_server = $_SERVER;
// Clean host env
unset($_SERVER['HTTP_HOST'], $_SERVER['HTTPS'], $_SERVER['SERVER_NAME'], $_SERVER['SERVER_PORT']);
// Set translator
$translator = new Zend_Translate('array', array('foo' => 'en_foo', 'bar' => 'en_bar'), 'en');
$translator->addTranslation(array('foo' => 'de_foo', 'bar' => 'de_bar'), 'de');
$translator->setLocale('en');
Zend_Registry::set('Zend_Translate', $translator);
}
示例13: preDispatch
public function preDispatch(Zend_Controller_Request_Abstract $request)
{
// Die CSV-Dateien laden
$translate = new Zend_Translate('csv', '../application/config/lang.de.csv', 'de');
$translate->addTranslation('../application/config/lang.en.csv', 'en');
// sprache einstellen
$translate->setLocale('de');
// translateobjekt in der registry speichern
$registry = Zend_Registry::getInstance();
$registry->set('translate', $translate);
// für alle Formular der Klasse Zend_Form das standard translate objekt setzen
Zend_Form::setDefaultTranslator($translate);
}
示例14: preDispatch
public function preDispatch(Zend_Controller_Request_Abstract $request)
{
$locale = new Zend_Locale();
Zend_Registry::set('Zend_Locale', $locale);
// default language when requested language is not available
$defaultlanguage = 'vi';
// somewhere in your application
$adapter = new Zend_Translate(array('adapter' => 'ini', 'content' => APPLICATION_PATH . '/languages', 'scan' => Zend_Translate::LOCALE_DIRECTORY, 'locale' => $locale->getLanguage()));
//if (! $adapter->isAvailable($locale->getLanguage())) {
// not available languages are rerouted to another language
$adapter->setLocale($defaultlanguage);
Zend_Registry::set('Zend_Translate', $adapter);
//}
}
示例15: setLocale
/** Changes the currently active locale
* @param string $locale The locale to activate (for example: 'en_US')
* @param bool $coreOnly = false Set to true to load only the core translation files, set to false (default) to load also packages and site locale translations
*/
public function setLocale($locale, $coreOnly = false)
{
$localeNeededLoading = false;
if ($locale == 'en_US' && !ENABLE_TRANSLATE_LOCALE_EN_US) {
if (isset($this->translate)) {
unset($this->translate);
}
return;
}
if (is_dir(DIR_LANGUAGES . '/' . $locale)) {
$languageDir = DIR_LANGUAGES . '/' . $locale;
} elseif (is_dir(DIR_LANGUAGES_CORE . '/' . $locale)) {
$languageDir = DIR_LANGUAGES_CORE . '/' . $locale;
} else {
return;
}
$options = array('adapter' => 'gettext', 'content' => $languageDir, 'locale' => $locale, 'disableNotices' => true, 'ignore' => array('.', 'messages.po'));
if (defined('TRANSLATE_OPTIONS')) {
$_options = unserialize(TRANSLATE_OPTIONS);
if (is_array($_options)) {
$options = array_merge($options, $_options);
}
}
if (!isset($this->translate)) {
$this->translate = new Zend_Translate($options);
$localeNeededLoading = true;
} else {
if (!in_array($locale, $this->translate->getList())) {
$this->translate->addTranslation($options);
$localeNeededLoading = true;
}
$this->translate->setLocale($locale);
}
if (!$coreOnly) {
$this->addSiteInterfaceLanguage($locale);
global $config_check_failed;
if (!(isset($config_check_failed) && $config_check_failed)) {
foreach (PackageList::get(1)->getPackages() as $p) {
$pkg = Loader::package($p->getPackageHandle());
if (is_object($pkg)) {
$pkg->setupPackageLocalization($locale, null, $this->translate);
}
}
}
}
if ($localeNeededLoading) {
Events::fire('on_locale_load', $locale);
}
}