/** * Loads a particular message catalogue. Use read() to * to get the array of messages. The catalogue loading sequence * is as follows: * * # [1] Call getCatalogueList($catalogue) to get a list of variants for for the specified $catalogue. * # [2] For each of the variants, call getSource($variant) to get the resource, could be a file or catalogue ID. * # [3] Verify that this resource is valid by calling isValidSource($source) * # [4] Try to get the messages from the cache * # [5] If a cache miss, call load($source) to load the message array * # [6] Store the messages to cache. * # [7] Continue with the foreach loop, e.g. goto [2]. * * @param string a catalogue to load * @return boolean always true * @see read() */ function load($catalogue = 'messages') { $variants = $this->getCatalogueList($catalogue); $this->messages = array(); foreach ($variants as $variant) { $source = $this->getSource($variant); if ($this->isValidSource($source) == false) { continue; } $loadData = true; if ($this->cache) { $data = $this->cache->get($variant, $this->culture, $this->getLastModified($source)); if (is_array($data)) { $this->messages[$variant] = $data; $loadData = false; } unset($data); } if ($loadData) { $data =& $this->loadData($source); if (is_array($data)) { $this->messages[$variant] = $data; if ($this->cache) { $this->cache->save($data, $variant, $this->culture); } } unset($data); } } return true; }
public function createMessageSource($dir) { if (in_array(sfConfig::get('sf_i18n_source'), array('Creole', 'MySQL', 'SQLite'))) { $messageSource = sfMessageSource::factory(sfConfig::get('sf_i18n_source'), sfConfig::get('sf_i18n_database', 'default')); } else { $messageSource = sfMessageSource::factory(sfConfig::get('sf_i18n_source'), $dir); } if (sfConfig::get('sf_i18n_cache')) { $subdir = str_replace(str_replace('/', DIRECTORY_SEPARATOR, sfConfig::get('sf_root_dir')), '', $dir); $cacheDir = str_replace('/', DIRECTORY_SEPARATOR, sfConfig::get('sf_i18n_cache_dir') . $subdir); $cache = new sfMessageCache(); $cache->initialize(array('cacheDir' => $cacheDir, 'lifeTime' => 86400)); $messageSource->setCache($cache); } return $messageSource; }