/** * Given a language, try and fetch messages from that language and its fallbacks. * * @see MessageCache::get * @param Language|StubObject $lang Preferred language * @param string $lckey Lowercase key for the message (as for localisation cache) * @param bool $useDB Whether to include messages from the wiki database * @param bool[] $alreadyTried Contains true for each language that has been tried already * @return string|bool The message, or false if not found */ private function getMessageForLang($lang, $lckey, $useDB, &$alreadyTried) { global $wgContLang; $langcode = $lang->getCode(); // Try checking the database for the requested language if ($useDB) { $uckey = $wgContLang->ucfirst($lckey); if (!isset($alreadyTried[$langcode])) { $message = $this->getMsgFromNamespace($this->getMessagePageName($langcode, $uckey), $langcode); if ($message !== false) { return $message; } $alreadyTried[$langcode] = true; } } else { $uckey = null; } // Check the CDB cache $message = $lang->getMessage($lckey); if ($message !== null) { return $message; } // Try checking the database for all of the fallback languages if ($useDB) { $fallbackChain = Language::getFallbacksFor($langcode); foreach ($fallbackChain as $code) { if (isset($alreadyTried[$code])) { continue; } $message = $this->getMsgFromNamespace($this->getMessagePageName($code, $uckey), $code); if ($message !== false) { return $message; } $alreadyTried[$code] = true; } } return false; }
/** * Given a language, try and fetch messages from that language. * * Will also consider fallbacks of that language, the site language, and fallbacks for * the site language. * * @see MessageCache::get * @param Language|StubObject $lang Preferred language * @param string $lckey Lowercase key for the message (as for localisation cache) * @param bool $useDB Whether to include messages from the wiki database * @return string|bool The message, or false if not found */ protected function getMessageFromFallbackChain($lang, $lckey, $useDB) { global $wgLanguageCode, $wgContLang; $uckey = $wgContLang->ucfirst($lckey); $langcode = $lang->getCode(); $message = false; // First try the requested language. if ($useDB) { if ($langcode === $wgLanguageCode) { // Messages created in the content language will not have the /lang extension $message = $this->getMsgFromNamespace($uckey, $langcode); } else { $message = $this->getMsgFromNamespace("{$uckey}/{$langcode}", $langcode); } } if ($message !== false) { return $message; } // Check the CDB cache $message = $lang->getMessage($lckey); if ($message !== null) { return $message; } list($fallbackChain, $siteFallbackChain) = Language::getFallbacksIncludingSiteLanguage($langcode); // Next try checking the database for all of the fallback languages of the requested language. if ($useDB) { foreach ($fallbackChain as $code) { if ($code === $wgLanguageCode) { // Messages created in the content language will not have the /lang extension $message = $this->getMsgFromNamespace($uckey, $code); } else { $message = $this->getMsgFromNamespace("{$uckey}/{$code}", $code); } if ($message !== false) { // Found the message. return $message; } } } // Now try checking the site language. if ($useDB) { $message = $this->getMsgFromNamespace($uckey, $wgLanguageCode); if ($message !== false) { return $message; } } $message = $wgContLang->getMessage($lckey); if ($message !== null) { return $message; } // Finally try the DB for the site language's fallbacks. if ($useDB) { foreach ($siteFallbackChain as $code) { $message = $this->getMsgFromNamespace("{$uckey}/{$code}", $code); if ($message === false && $code === $wgLanguageCode) { // Messages created in the content language will not have the /lang extension $message = $this->getMsgFromNamespace($uckey, $code); } if ($message !== false) { // Found the message. return $message; } } } return false; }