本文整理汇总了PHP中Zend_Translate::setCache方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Translate::setCache方法的具体用法?PHP Zend_Translate::setCache怎么用?PHP Zend_Translate::setCache使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend_Translate
的用法示例。
在下文中一共展示了Zend_Translate::setCache方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: array
/**
* Retrieve service object instance
*
* @param Zend_Config $config
* @return Zend_Translate
*/
public function &getService($config)
{
if (!$this->service) {
Zend_Translate::setCache(Zoo::getService('cache')->getCache('translate'));
/*
* @todo Re-enable this with configuration options instead of hardcoding
$writer = new Zend_Log_Writer_Firebug();
$logger = new Zend_Log($writer);
$this->service = new Zend_Translate('gettext',
ZfApplication::$_base_path."/app/Zoo/Language",
null,
array(
'scan' => Zend_Translate::LOCALE_FILENAME,
'disableNotices' => true,
'log' => $logger,
'logUntranslated' => true)
);
*/
if ($config->language->default) {
$locale = new Zend_Locale($config->language->default);
Zend_Registry::set("Zend_Locale", $locale);
} else {
$locale = new Zend_Locale("en");
}
$this->service = new Zend_Translate('gettext', ZfApplication::$_base_path . "/app/Zoo/Language", $locale, array('scan' => Zend_Translate::LOCALE_FILENAME, 'disableNotices' => true));
}
return $this->service;
}
示例2: init
public function init()
{
if (null === $this->_cache) {
$options = $this->getOptions();
if (!isset($options[0]) && $options) {
if (!isset($options['frontend']['adapter'])) {
$options['frontend']['adapter'] = 'Core';
}
if (!isset($options['backend']['adapter'])) {
$options['backend']['adapter'] = 'Memcached';
}
if (!isset($options['frontend']['params'])) {
$options['frontend']['params'] = array();
}
if (!isset($options['backend']['params'])) {
$options['backend']['params'] = array();
}
$this->_cache = Zend_Cache::factory($options['frontend']['adapter'], $options['backend']['adapter'], $options['frontend']['params'], $options['backend']['params']);
if (isset($options['metadata']) && true === (bool) $options['metadata']) {
Zend_Db_Table_Abstract::setDefaultMetadataCache($this->_cache);
}
if (isset($options['translate']) && true === (bool) $options['translate']) {
Zend_Translate::setCache($this->_cache);
}
if (isset($options['locale']) && true === (bool) $options['locale']) {
Zend_Locale::setCache($this->_cache);
}
} else {
$this->_cache = false;
}
$key = isset($options['registry']) && !is_numeric($options['registry']) ? $options['registry'] : self::DEFAULT_REGISTRY_KEY;
Zend_Registry::set($key, $this->_cache);
}
return $this->_cache;
}
示例3: initializeLocale
function initializeLocale($g_ui_locale)
{
global $_, $_locale;
if (!file_exists($vs_locale_path = __CA_APP_DIR__ . '/locale/user/' . $g_ui_locale . '/messages.mo')) {
$vs_locale_path = __CA_APP_DIR__ . '/locale/' . $g_ui_locale . '/messages.mo';
}
if (file_exists($vs_locale_path)) {
// If the locale is valid, locale is set
$_locale = new Zend_Locale($g_ui_locale);
Zend_Registry::set('Zend_Locale', $_locale);
if (!caIsRunFromCLI() && ($o_cache = caGetCacheObject('ca_translation', 3600 * 24))) {
Zend_Translate::setCache($o_cache);
}
$_ = new Zend_Translate(array('adapter' => 'gettext', 'content' => $vs_locale_path, 'locale' => $_locale, 'tag' => 'CA'));
$cookiepath = __CA_URL_ROOT__ == "" ? "/" : __CA_URL_ROOT__;
if (!headers_sent()) {
setcookie('CA_' . __CA_APP_NAME__ . '_ui_locale', $g_ui_locale, time() + 36000, $cookiepath);
}
return true;
} else {
// cookie invalid, deleting
if (!headers_sent()) {
setcookie('CA_' . __CA_APP_NAME__ . '_ui_locale', NULL, -1);
}
return false;
}
}
示例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: init
/**
* To init the view
*
* @return Zend_View $view
*/
public function init()
{
$frontendOptions = array('automatic_serialization' => true, 'lifetime' => 86400);
$backendOptions = array('cache_dir' => PROJECT_ROOT . '/repository/cache/');
if ('development' == APPLICATION_ENV) {
$frontendOptions['caching'] = false;
//关闭缓存
} else {
$classFileIncCache = $backendOptions['cache_dir'] . 'pluginLoaderCache.php';
if (file_exists($classFileIncCache)) {
include_once $classFileIncCache;
}
Zend_Loader_PluginLoader::setIncludeFileCache($classFileIncCache);
}
$this->_cache = Zend_Cache::factory('Core', 'File', $frontendOptions, $backendOptions);
Zend_Db_Table_Abstract::setDefaultMetadataCache($this->_cache);
//缓存Zend_Db_Table元数据
Zend_Date::setOptions(array('cache' => $this->_cache));
//缓存Zend_Date
Zend_Translate::setCache($this->_cache);
//缓存Zend_Translate
Zend_Registry::set('cache', $this->_cache);
// Return it, so that it can be stored by the bootstrap
return $this->_cache;
}
示例6: _initTranslation
protected function _initTranslation()
{
$cache = $this->_getCache('core');
Zend_Translate::setCache($cache);
Zend_Date::setOptions(array('cache' => $cache));
Zend_Paginator::setCache($cache);
}
示例7: _initTranslateCache
protected function _initTranslateCache()
{
//$this->_bootstrap('cache');
if (Zend_Registry::getInstance()->isRegistered(self::TRANSLATE_CACHE_REGISTRY_KEY)) {
$translateCache = Zend_Registry::getInstance()->get(self::TRANSLATE_CACHE_REGISTRY_KEY);
Zend_Translate::setCache($translateCache);
}
}
示例8: routeStartup
public function routeStartup(Zend_Controller_Request_Abstract $request)
{
$backendOptions = array('cache_dir' => APPLICATION_PATH . '/../cache');
$frontendOptions = array('caching' => Zend_Registry::getInstance()->get('Zend_Config')->get('cache', false) == false ? false : Zend_Registry::getInstance()->get('Zend_Config')->get('cache')->get('enabled', false), 'automatic_serialization' => true, 'lifetime' => null, 'automatic_serialization' => true);
$translateCache = Zend_Cache::factory('Core', 'File', $frontendOptions, $backendOptions);
Zend_Translate::setCache($translateCache);
$translate = new Zend_Translate(Zend_Translate::AN_ARRAY, APPLICATION_PATH . '/languages', null, array('scan' => Zend_Translate::LOCALE_DIRECTORY));
Zend_Registry::getInstance()->set('Zend_Translate', $translate);
}
示例9: _initCache
/**
* Démarrage du gestionnaire de caches, on récupère chaque configuration.
* Par défaut on met en cache les métadata de la bdd
*
* @return void.
*/
protected function _initCache()
{
if ((bool) APP_CACHE) {
// Récupération des ressources du gestionnaire du cache
$this->bootstrap('cachemanager');
// Activation du cache du Zend_Translate
Zend_Translate::setCache($this->getResource('cachemanager')->getCache('translate'));
// Activation du cache de la base de données
Zend_Db_Table_Abstract::setDefaultMetadataCache($this->getResource('cachemanager')->getCache('default'));
}
}
示例10: _initTranslate
protected function _initTranslate()
{
$frontendOptions = array('lifetime' => 60 * 60 * 24, 'automatic_serialization' => true);
// время жизни кэша - 24 часа
$cfg = $this->getOptions();
$backendOptions = array('cache_dir' => $cfg['temp']['path']);
// директория, в которой размещаются файлы кэша
$cache = Zend_Cache::factory('Page', 'File', $frontendOptions, $backendOptions);
Zend_Translate::setCache($cache);
$translate = new Zend_Translate(Zend_Translate::AN_GETTEXT, APPLICATION_PATH . 'locales', 'auto', array('scan' => Zend_Translate::LOCALE_DIRECTORY, 'disableNotices' => true));
Zend_Registry::set('Zend_Translate', $translate);
}
示例11: addSiteInterfaceLanguage
public function addSiteInterfaceLanguage($language) {
if (is_object($this->translate)) {
$this->translate->addTranslation(DIR_LANGUAGES_SITE_INTERFACE . '/' . $language . '.mo', $language);
} else {
Loader::library('3rdparty/Zend/Translate');
$cache = Cache::getLibrary();
if (is_object($cache)) {
Zend_Translate::setCache($cache);
}
$this->translate = new Zend_Translate(array('adapter' => 'gettext', 'content' => DIR_LANGUAGES_SITE_INTERFACE . '/' . $language . '.mo', 'locale' => $language, 'disableNotices' => true));
}
}
示例12: _initZendCache
/**
* Setup zend cache directory.
*
* @return void
*/
protected function _initZendCache()
{
$this->bootstrap('Configuration');
$config = $this->getResource('Configuration');
$frontendOptions = array('lifetime' => 600, 'automatic_serialization' => true);
$backendOptions = array('cache_dir' => $config->workspacePath . '/cache/');
$cache = Zend_Cache::factory('Core', 'File', $frontendOptions, $backendOptions);
Zend_Translate::setCache($cache);
Zend_Locale::setCache($cache);
Zend_Locale_Data::setCache($cache);
Zend_Db_Table_Abstract::setDefaultMetadataCache($cache);
return $cache;
}
示例13: __construct
public function __construct()
{
Loader::library('3rdparty/Zend/Date');
Loader::library('3rdparty/Zend/Translate');
Loader::library('3rdparty/Zend/Locale');
Loader::library('3rdparty/Zend/Locale/Data');
$cache = Cache::getLibrary();
if (is_object($cache)) {
Zend_Translate::setCache($cache);
Zend_Date::setOptions(array('cache' => $cache));
}
$locale = defined('ACTIVE_LOCALE') ? ACTIVE_LOCALE : 'en_US';
$this->setLocale($locale);
Zend_Date::setOptions(array('format_type' => 'php'));
}
示例14: _initCache
/**
* Set caching
*
* @return void
*/
public function _initCache()
{
if (!Zend_Registry::isRegistered('cachemanager')) {
return false;
}
$cache = HCMS_Cache::getInstance()->getCoreCache();
//set cache for table metadata
Zend_Db_Table_Abstract::setDefaultMetadataCache($cache);
//set cache for locale
Zend_Locale::setCache($cache);
//set cache for translate
Zend_Translate::setCache($cache);
//plugin loader cache
$classFileIncCache = APPLICATION_PATH . '/../cache/file/pluginLoaderCache.php';
if (file_exists($classFileIncCache)) {
include_once $classFileIncCache;
}
Zend_Loader_PluginLoader::setIncludeFileCache($classFileIncCache);
}
示例15: _setCache
/**
* Sets the translation cache
*
* @return void
*/
protected function _setCache()
{
$options = $this->getOptions();
// Disable cache? If not defined, cache will be active
if (isset($options['cache']['active']) && !$options['cache']['active']) {
// Explicitly remove cache, in case it was set before
Zend_Translate::removeCache();
return;
}
// Get the cache using the config settings as input
$this->_bootstrap->bootstrap('CacheManager');
$manager = $this->_bootstrap->getResource('CacheManager');
$cache = $manager->getCache('translate');
// Write caching errors to log file (if activated in the config)
$this->_bootstrap->bootstrap('Log');
$logger = $this->_bootstrap->getResource('Log');
$cache->setOption('logger', $logger);
Zend_Translate::setCache($cache);
}