protected function loadMessagesFromCache($groups) { $messages = array(); foreach ($groups as $group) { if ($group instanceof MessageGroupOld) { $messages += $group->getDefinitions(); continue; } if ($group instanceof AggregateMessageGroup) { $messages += $this->loadMessagesFromCache($group->getGroups()); continue; } $cache = new MessageGroupCache($group); if ($cache->exists()) { foreach ($cache->getKeys() as $key) { $messages[$key] = $cache->get($key); } } } return $messages; }
/** * @param $hugearray array * @param $g * @param $ignore bool */ protected function checkAndAdd(&$hugearray, $g, $ignore = false) { if ($g instanceof MessageGroupBase) { $cache = new MessageGroupCache($g); if ($cache->exists()) { $keys = $cache->getKeys(); } else { $keys = array_keys($g->getDefinitions()); } } else { $messages = $g->getDefinitions(); if (!is_array($messages)) { return; } $keys = array_keys($messages); } $id = $g->getId(); STDOUT("{$id} ", 'main'); $namespace = $g->getNamespace(); foreach ($keys as $key) { # Force all keys to lower case, because the case doesn't matter and it is # easier to do comparing when the case of first letter is unknown, because # mediawiki forces it to upper case $key = TranslateUtils::normaliseKey($namespace, $key); if (isset($hugearray[$key])) { if (!$ignore) { $to = implode(', ', (array) $hugearray[$key]); STDERR("Key {$key} already belongs to {$to}, conflict with {$id}"); } if (is_array($hugearray[$key])) { // Hard work is already done, just add a new reference $hugearray[$key][] =& $id; } else { // Store the actual reference, then remove it from array, to not // replace the references value, but to store a array of new // references instead. References are hard! $value =& $hugearray[$key]; unset($hugearray[$key]); $hugearray[$key] = array(&$value, &$id); } } else { $hugearray[$key] =& $id; } } unset($id); // Disconnect the previous references to this $id }
/** * @param string $key Message key * @param string $code Language code * @return string|null */ public function getMessage($key, $code) { $cache = new MessageGroupCache($this, $code); if ($cache->exists()) { $msg = $cache->get($key); if ($msg !== false) { return $msg; } // Try harder $nkey = str_replace(' ', '_', strtolower($key)); $keys = $cache->getKeys(); foreach ($keys as $k) { if ($nkey === str_replace(' ', '_', strtolower($k))) { return $cache->get($k); } } return null; } else { return null; } }
public function initCollection( $code ) { $messages = array(); foreach ( $this->getGroups() as $group ) { $cache = new MessageGroupCache( $group ); if ( $cache->exists() ) { foreach ( $cache->getKeys() as $key ) { $messages[$key] = $cache->get( $key ); } } else { // BC for MessageGroupOld $messages += $group->load( $this->getSourceLanguage() ); } } $namespace = $this->getNamespace(); $definitions = new MessageDefinitions( $messages, $namespace ); $collection = MessageCollection::newFromDefinitions( $definitions, $code ); $this->setTags( $collection ); return $collection; }