Example #1
0
 /**
  * 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;
 }
Example #2
0
 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;
 }
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;
    }
}
Example #4
0
 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) {
         }
     }
 }
Example #5
0
 /**
  * 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;
 }
Example #6
0
 protected function _initTranslation()
 {
     $cache = $this->_getCache('core');
     Zend_Translate::setCache($cache);
     Zend_Date::setOptions(array('cache' => $cache));
     Zend_Paginator::setCache($cache);
 }
 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);
     }
 }
 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);
 }
Example #9
0
 /**
  * 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'));
     }
 }
Example #10
0
 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);
 }
Example #11
0
		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));
			}
		}
Example #12
0
 /**
  * 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;
 }
Example #13
0
 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'));
 }
Example #14
0
 /**
  * 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);
 }
Example #15
0
 /**
  * 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);
 }
Example #16
0
 /**
  * Nastavuje funkcionalitu prekladani
  *
  * @return void
  * @todo nastavit cache pro Zend_Locale + otestovat vykon
  * @todo nastaveni Zend_Locale podle nastaveni v db
  * @todo pouziti $locale->getLanguage nebo neco podobneho - mohlo by to zkratit switch, pripadne by se nove jazyky mohly pridavat pres admin rozhrani
  */
 public function setLanguage()
 {
     $options = $this->getOptions();
     $locale = new Zend_Locale();
     switch ($locale) {
         case 'cs_CZ':
             $this->_lang->code = 'cs';
             $this->_lang->locale = $locale;
             $this->_lang->name = 'Czech';
             break;
         case 'de_AT':
         case 'de_BE':
         case 'de_CH':
         case 'de_DE':
         case 'de_LI':
         case 'de_LU':
         case 'de':
             $this->_lang->code = 'de';
             $this->_lang->locale = 'de';
             $this->_lang->name = 'German';
             break;
         default:
             $this->_lang->code = 'en';
             $this->_lang->locale = 'en_US';
             $this->_lang->name = 'English';
             break;
     }
     $locale->setLocale($this->_lang->locale);
     // Nastaveni locale - nejspis se to nastavi nekde v pluginu podle preferenci uzivatele a ulozi do registru nebo session
     Zend_Registry::set('Zend_Locale', $locale);
     $manager = $this->getBootstrap()->getResource('CacheManager');
     $cache = $manager->getCache('translate');
     Zend_Translate::setCache($cache);
     if (isset($options['logUntranslated']) and $options['logUntranslated'] == true) {
         $writer = new Unodor_Log_Writer_Translate(LANGUAGES_PATH . '/source/stringtable.php');
         $log = new Zend_Log();
         $log->addWriter($writer);
         $options = array('log' => $log, 'logUntranslated' => true, 'logMessage' => 'gettext(%message%);');
     }
     $translate = new Zend_Translate('Unodor_Translate_Adapter_Gettext', LANGUAGES_PATH . '/' . $this->_lang->name . '.mo', $this->_lang->code, $options);
     Zend_Registry::set('Zend_Translate', $translate);
 }
Example #17
0
 /**
  * this function routes all requests that come in to the default module to the index controller / index action
  *
  * @param zend_controller_request $request
  */
 public function preDispatch(Zend_Controller_Request_Abstract $request)
 {
     if (!$request->isXmlHttpRequest()) {
         //load the module, controller, and action for reference
         $this->module = $request->getModuleName();
         $this->controller = $request->getControllerName();
         $this->action = $request->getActionName();
         //load the section
         if (isset($this->sections[$this->controller])) {
             $this->section = $this->sections[$this->controller];
         } else {
             $this->section = $this->defaultSection;
         }
         if ($this->_isAdminPage($request)) {
             $this->view->isAdminPage = true;
             //load config
             $config = Zend_Registry::get('config');
             //setup layout
             $options = array('layout' => $config->design->adminLayout, 'layoutPath' => $config->design->adminLayoutFolder, 'contentKey' => 'form');
             $this->layout = Zend_Layout::startMvc($options);
             $this->view = $this->layout->getView();
             //load the common helpers
             Digitalus_View_RegisterHelpers::register($this->view);
             $this->view->setScriptPath($config->filepath->adminViews);
             //load language files
             $translate = null;
             foreach ($config->language->translations as $locale => $translation) {
                 if (is_object($translate)) {
                     $translate->addTranslation($config->language->path . '/' . $translation . '.csv', $locale);
                 } else {
                     $translate = new Zend_Translate('csv', $config->language->path . '/' . $translation . '.csv', $locale);
                 }
             }
             $locale = $config->language->defaultLocale;
             #                $translate->setLocale($locale);
             $translate->setCache(Zend_Registry::get('cache'));
             $this->view->translate = $translate;
             //page links
             $this->view->toolbarLinks = array();
         }
     }
 }
Example #18
0
 public function routeShutdown(Zend_Controller_Request_Abstract $request)
 {
     $config = Zend_Registry::get('config');
     //this is the only place where i want to have another cache instance - for zend_db metadata we should use file cache
     Zend_Db_Table_Abstract::setDefaultMetadataCache(Zend_Registry::get('cache_files'));
     $db = Zend_Db::factory($config->setup->database->adapter, $config->setup->database->config->toArray());
     #TODO did they implement that in 1.7 or still we have to wait :/
     switch ($config->setup->database) {
         case 'PDO_PGSQL':
             $db->query("SET NAMES 'UNICODE'");
             break;
         case 'PDO_MYSQL':
             $db->query("SET NAMES 'utf8'");
             break;
         default:
             break;
     }
     #start up the profiler if needed
     if ($config->setup->database->profiler == true) {
         $db->getProfiler()->setEnabled($config->setup->database->profiler);
     }
     Zend_Db_Table::setDefaultAdapter($db);
     #TODO database driven sessions - maybe we want to change that in future ? for better scaling ?
     Zend_Session::setSaveHandler(new Zend_Session_SaveHandler_DbTable(array('name' => 'session', 'primary' => 'id', 'modifiedColumn' => 'modified', 'dataColumn' => 'data', 'lifetimeColumn' => 'lifetime')));
     //set up the view
     $viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer');
     $viewRenderer->init();
     $view = $viewRenderer->view;
     $view->addHelperPath('Reactor/View/Helper', 'Reactor_View_Helper');
     Zend_Dojo::enableView($view);
     $view->doctype('XHTML1_STRICT');
     $view->setEncoding('UTF-8');
     $view->request = $this->getRequest();
     $view->baseUrl = $this->getRequest()->getBaseUrl();
     $this->locale = new Zend_Locale($config->setup->defaultLocale);
     Zend_Registry::set('Zend_Locale', $this->locale);
     Zend_Translate::setCache(Zend_Registry::get('cache'));
     #TODO currently hardcoded
     Zend_Registry::set('Zend_Translate', new Zend_Translate('gettext', '../data/locales/en_GB/LC_MESSAGES/default.mo', 'en'));
     Zend_Registry::set('Users', new Users());
 }
Example #19
0
 public function routeShutdown(Zend_Controller_Request_Abstract $request)
 {
     $locale = new Zend_Locale();
     $options = array('scan' => Zend_Translate::LOCALE_FILENAME, 'clear' => false, 'disableNotices' => true);
     Zend_Translate::setCache(Zend_Registry::get('cache'));
     if (isset($_COOKIE['language_select'])) {
         $language = $_COOKIE['language_select'];
     } else {
         $language = 'en';
     }
     $translate = new Zend_Translate('csv', APPLICATION_PATH . '/languages', 'auto', $options);
     $translate->addTranslation(APPLICATION_PATH . '/languages/ot');
     $translate->addTranslation(APPLICATION_PATH . '/../overrides/languages');
     if (!$translate->isAvailable($language)) {
         throw new Exception('Language ' . $language . ' is not available');
     }
     $locale->setLocale($language);
     $translate->setLocale($locale);
     Zend_Registry::set('Zend_Locale', $locale);
     Zend_Registry::set('Zend_Translate', $translate);
 }
Example #20
0
		public function getTranslate() {
			if (LOCALE != 'en_US') {
				static $translate;
				if (!isset($translate)) {
					Loader::library('3rdparty/Zend/Translate');
					$cache = Cache::getLibrary();
					if (is_object($cache)) {
						Zend_Translate::setCache($cache);
					}
					if (LOCALE != 'en_US') {
						if (is_dir(DIR_BASE . '/languages/' . LOCALE)) {
							$translate = new Zend_Translate('gettext', DIR_BASE . '/languages/' . LOCALE, LOCALE);
						}
					}
					
					if (!isset($translate)) {
						$translate = false;
					}
				}
				return $translate;
			}
		}
Example #21
0
 public function preDispatch(Zend_Controller_Request_Abstract $request)
 {
     //$config = Zend_Registry::get('config');
     // Get languages
     $locale = new Zend_Locale();
     $options = array('scan' => Zend_Translate::LOCALE_FILENAME, 'disableNotices' => true);
     $cache = Zend_Registry::get('cache');
     Zend_Translate::setCache($cache);
     $translate = @new Zend_Translate('tmx', APPLICATION_PATH . '/languages/', 'auto', $options);
     $params = $this->getRequest()->getParams();
     $language = 'en';
     /*
     if(isset($params['language']))
     {
     	$language = $params['language'];
     }
     
     if($language == false)
     {
     	$language = $translate->isAvailable($locale->getLanguage) ? $locale->getLanguage() : $config->language->default;
     }
     
     if(!$translate->isAvailable($language))
     {
     	$language = 'en';
     	//throw new Zend_Controller_Action_Exception('This page does not exist', 404);
     }
     */
     //else
     //{
     $locale->setLocale($language);
     $translate->setLocale($locale);
     Zend_Form::setDefaultTranslator($translate);
     //setcookie('lang', $locale->getLanguage(), null, '/');
     Zend_Registry::set('Zend_Locale', $locale);
     Zend_Registry::set('Zend_Translate', $translate);
     Zend_Registry::set('Available_Translations', $translate->getList());
     //}
 }
Example #22
0
 /**
  * Setup
  *
  * @return void
  */
 public function setup(Zend_Config $config)
 {
     // Setup Cache
     if ($config->get('cache')) {
         $cache = Zym_Cache::factory('Core');
         Zend_Translate::setCache($cache);
     }
     $adapter = $config->get('adapter');
     $data = $this->_parseDataPath($config->get('data'));
     $locale = $config->get('locale');
     $options = $this->_parseOptions($config->get('options')->toArray());
     $translate = new Zend_Translate($adapter, $data, null, $options);
     // Weird Zend_Translate issues
     // We cannot set a locale in the constructor
     $translate->getAdapter()->setLocale($locale);
     if ((bool) $config->get('registry')->get('enabled')) {
         /**
          * @see Zend_Registry
          */
         require_once 'Zend/Registry.php';
         Zend_Registry::set($config->get('registry')->get('key'), $translate);
     }
 }
Example #23
0
 /**
  * Init translation services and locale.
  *
  * @return void
  */
 protected function _initTranslationService()
 {
     // Build the path for the languages folder in the current module
     $languagesPath = APPLICATION_PATH . '/languages';
     // Setup a cache
     $frontendOptions = array();
     $backendOptions = array();
     $frontendOptions['automatic_serialization'] = true;
     $frontendOptions['lifetime'] = '604800';
     $frontendOptions['write_control'] = false;
     $frontendOptions['master_files'] = array($languagesPath . '/en/messages.mo');
     $backendOptions['cache_dir'] = APPLICATION_PATH . '/../zendCache';
     $backendOptions['hashed_directory_level'] = 1;
     $cache = Zend_Cache::factory('File', 'File', $frontendOptions, $backendOptions);
     Zend_Translate::setCache($cache);
     Zend_Locale::setCache($cache);
     // Register the locale for system-wide use
     Zend_Registry::set('Zend_Locale', new Zend_Locale('en'));
     // Create a translator
     $translator = new Zend_Translate(array('adapter' => 'gettext', 'content' => $languagesPath . '/en/messages.mo', 'locale' => 'en'));
     // Register the translator for system-wide use
     Zend_Registry::set('Zend_Translate', $translator);
 }
Example #24
0
 /**
  * Setup
  *
  * @return void
  */
 public function setup(Zend_Config $config)
 {
     // Setup Cache
     if ($config->get('cache')) {
         $cache = Zym_Cache::factory('Core');
         Zend_Translate::setCache($cache);
     }
     $adapter = $config->get('adapter');
     $data = $this->_parseDataPath($config->get('data'));
     $options = $this->_parseOptions($config->get('options')->toArray());
     if (!($locale = $config->get('locale'))) {
         if (Zend_Registry::isRegistered('Zend_Locale')) {
             $locale = Zend_Registry::get('Zend_Locale');
         }
     }
     $translate = new Zend_Translate($adapter, $data, $locale, $options);
     if ((bool) $config->get('registry')->get('enabled')) {
         /**
          * @see Zend_Registry
          */
         require_once 'Zend/Registry.php';
         Zend_Registry::set($config->get('registry')->get('key'), $translate);
     }
 }
 /**
  * @return array Array of priority keys to instances of Zend_Translate, mapped by name.
  */
 public static function get_translators()
 {
     if (!Zend_Translate::getCache()) {
         Zend_Translate::setCache(self::get_cache());
     }
     if (!self::$translators) {
         $defaultPriority = 10;
         self::$translators[$defaultPriority] = array('core' => new Zend_Translate(array('adapter' => 'i18nRailsYamlAdapter', 'locale' => self::$default_locale, 'disableNotices' => true)));
         i18n::include_by_locale('en');
         i18n::include_by_locale('en_US');
     }
     return self::$translators;
 }
 /**
  * Tests if cached options are read from the cache for a new instance
  */
 public function testGetOptionsFromCache()
 {
     require_once 'Zend/Cache.php';
     $cache = Zend_Cache::factory('Core', 'File', array('lifetime' => 120, 'automatic_serialization' => true), array('cache_dir' => dirname(__FILE__) . '/_files/'));
     Zend_Translate::setCache($cache);
     $lang = new Zend_Translate(Zend_Translate::AN_CSV, dirname(__FILE__) . '/Translate/Adapter/_files', 'en', array('delimiter' => ','));
     $lang->setOptions(array('logMessage' => 'test'));
     $this->assertEquals('test', $lang->getOptions('logMessage'));
     unset($lang);
     $lang2 = new Zend_Translate(Zend_Translate::AN_CSV, dirname(__FILE__) . '/Translate/Adapter/_files', 'en', array('delimiter' => ','));
     $this->assertEquals('test', $lang2->getOptions('logMessage'));
 }
Example #27
0
$CLASS['knowledgeroot']->start($CLASS);
// addslashes on GET/POST/COOKIE/REQUEST/SERVER
$CLASS['knowledgeroot']->addSlashesOnArray($_GET);
$CLASS['knowledgeroot']->addSlashesOnArray($_POST);
$CLASS['knowledgeroot']->addSlashesOnArray($_COOKIE);
$CLASS['knowledgeroot']->addSlashesOnArray($_REQUEST);
$CLASS['knowledgeroot']->addSlashesOnArray($_SERVER);
// init session
$CLASS['session'] = new session();
$CLASS['session']->start($CLASS);
$CLASS['session']->startSession(md5($CLASS['config']->base->base_url));
if (!$CLASS['session']->checkSession()) {
    die("Wrong session!");
}
// init gettext
Zend_Translate::setCache($CLASS['cache']);
if (isset($_SESSION['language']) && $_SESSION['language'] != '' && (is_file($base_path . 'system/language/' . $_SESSION['language'] . '.UTF8/LC_MESSAGES/knowledgeroot.mo') || is_file($base_path . 'system/language/' . $_SESSION['language'] . '/LC_MESSAGES/knowledgeroot.mo'))) {
    $language = str_replace(".UTF8", "", $_SESSION['language']);
    $CLASS['translate'] = new Zend_Translate('gettext', $base_path . 'system/language/' . $language . '.UTF8/LC_MESSAGES/knowledgeroot.mo', $language);
    if ($language != $CLASS['config']->base->locale) {
        $CLASS['translate']->addTranslation($base_path . 'system/language/' . $CLASS['config']->base->locale . '.UTF8/LC_MESSAGES/knowledgeroot.mo', $CLASS['config']->base->locale);
        $CLASS['translate']->setLocale($language);
    }
} elseif (is_file($base_path . 'system/language/' . $CLASS['config']->base->locale . '.UTF8/LC_MESSAGES/knowledgeroot.mo')) {
    $CLASS['translate'] = new Zend_Translate('gettext', $base_path . 'system/language/' . $CLASS['config']->base->locale . '.UTF8/LC_MESSAGES/knowledgeroot.mo', $CLASS['config']->base->locale);
} else {
    $CLASS['translate'] = new Zend_Translate('gettext', $base_path . 'system/language/en_US.UTF8/LC_MESSAGES/knowledgeroot.mo', 'en_US');
}
// init language
$CLASS['language'] = new language();
$CLASS['language']->start($CLASS, $CLASS['config']->base->locale);
Example #28
0
 /**
  * @return array Array of priority keys to instances of Zend_Translate, mapped by name.
  */
 public static function get_translators()
 {
     if (!Zend_Translate::getCache()) {
         Zend_Translate::setCache(SS_Cache::factory('i18n', 'Output', array('lifetime' => null, 'automatic_serialization' => true)));
     }
     if (!self::$translators) {
         $defaultPriority = 10;
         self::$translators[$defaultPriority] = array('core' => new Zend_Translate(array('adapter' => 'i18nRailsYamlAdapter', 'locale' => self::$default_locale, 'disableNotices' => true)));
         i18n::include_by_locale('en', isset($_GET['flush']));
         i18n::include_by_locale('en_US', isset($_GET['flush']));
     }
     return self::$translators;
 }
 /**
  * setup the cache and add it to zend registry
  *
  * @param bool $_enabled disabled cache regardless what's configured in config.inc.php
  * 
  * @todo use the same config keys as Zend_Cache (backend + frontend) to simplify this
  */
 public static function setupCache($_enabled = true)
 {
     if (self::$cacheStatus !== NULL && self::$cacheStatus === $_enabled) {
         return;
     }
     $config = self::getConfig();
     if ($config->caching && $config->caching->active) {
         if (isset($config->caching->shared) && $config->caching->shared === true) {
             self::set(self::SHAREDCACHE, true);
         } else {
             self::set(self::SHAREDCACHE, false);
         }
     }
     // create zend cache
     if ($_enabled === true && $config->caching && $config->caching->active) {
         $logging = $config->caching->logging ? $config->caching->logging : false;
         $logger = self::getLogger();
         $frontendOptions = array('lifetime' => $config->caching->lifetime ? $config->caching->lifetime : 7200, 'automatic_serialization' => true, 'caching' => true, 'automatic_cleaning_factor' => 0, 'write_control' => false, 'logging' => $logging, 'logger' => $logger);
         $backendType = $config->caching->backend ? ucfirst($config->caching->backend) : 'File';
         $backendOptions = $config->caching->backendOptions ? $config->caching->backendOptions->toArray() : false;
         if (!$backendOptions) {
             switch ($backendType) {
                 case 'File':
                     $backendOptions = array('cache_dir' => $config->caching->path ? $config->caching->path : Tinebase_Core::getTempDir(), 'hashed_directory_level' => $config->caching->dirlevel ? $config->caching->dirlevel : 4, 'logging' => $logging, 'logger' => $logger);
                     break;
                 case 'Memcached':
                     $host = $config->caching->host ? $config->caching->host : (isset($config->caching->memcached->host) ? $config->caching->memcached->host : 'localhost');
                     $port = $config->caching->port ? $config->caching->port : (isset($config->caching->memcached->port) ? $config->caching->memcached->port : 11211);
                     $backendOptions = array('servers' => array('host' => $host, 'port' => $port, 'persistent' => TRUE));
                     break;
                 case 'Redis':
                     $host = $config->caching->host ? $config->caching->host : ($config->caching->redis->host ? $config->caching->redis->host : 'localhost');
                     $port = $config->caching->port ? $config->caching->port : ($config->caching->redis->port ? $config->caching->redis->port : 6379);
                     if ($config->caching && $config->caching->prefix) {
                         $prefix = $config->caching->prefix;
                     } else {
                         if ($config->caching && $config->caching->redis && $config->caching->redis->prefix) {
                             $prefix = $config->caching->redis->prefix;
                         } else {
                             $prefix = $config->database && $config->database->tableprefix ? $config->database->tableprefix : 'tine20';
                         }
                     }
                     $prefix .= '_CACHE_';
                     $backendOptions = array('servers' => array('host' => $host, 'port' => $port, 'prefix' => $prefix));
                     break;
                 default:
                     $backendOptions = array();
                     break;
             }
         }
         Tinebase_Core::getLogger()->INFO(__METHOD__ . '::' . __LINE__ . " cache of backend type '{$backendType}' enabled");
         if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) {
             // logger is an object, that makes ugly traces :)
             $backendOptionsWithoutLogger = $backendOptions;
             if (isset($backendOptionsWithoutLogger['logger'])) {
                 unset($backendOptionsWithoutLogger['logger']);
             }
             Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . " backend options: " . print_r($backendOptionsWithoutLogger, TRUE));
         }
     } else {
         Tinebase_Core::getLogger()->INFO(__METHOD__ . '::' . __LINE__ . ' Cache disabled');
         $backendType = 'Test';
         $frontendOptions = array('caching' => false);
         $backendOptions = array();
     }
     // getting a Zend_Cache_Core object
     try {
         $cache = Zend_Cache::factory('Core', $backendType, $frontendOptions, $backendOptions);
     } catch (Exception $e) {
         Tinebase_Exception::log($e);
         $enabled = false;
         if ('File' === $backendType && !is_dir($backendOptions['cache_dir'])) {
             Tinebase_Core::getLogger()->INFO(__METHOD__ . '::' . __LINE__ . ' Create cache directory and re-try');
             if (mkdir($backendOptions['cache_dir'], 0770, true)) {
                 $enabled = $_enabled;
             }
         }
         self::setupCache($enabled);
         return;
     }
     // some important caches
     Zend_Locale::setCache($cache);
     Zend_Translate::setCache($cache);
     Zend_Db_Table_Abstract::setDefaultMetadataCache($cache);
     self::set(self::CACHE, $cache);
     self::$cacheStatus = $_enabled;
 }
Example #30
0
 protected function _setTranslate()
 {
     self::$_translate = new Zend_Translate('gettext', SP_APP_PATH . DIRECTORY_SEPARATOR . 'locale', 'en', array('disableNotices' => true, 'scan' => Zend_Translate::LOCALE_DIRECTORY));
     //log untranslated string
     //self::$_translate->setOptions(array('log'=>self::$_log,'logUntranslated'=>true));
     self::$_translate->setCache(self::$_cache);
     Zend_Registry::getInstance()->set('Zend_Translate', self::$_translate);
 }