本文整理汇总了PHP中TranslateUtils::getContents方法的典型用法代码示例。如果您正苦于以下问题:PHP TranslateUtils::getContents方法的具体用法?PHP TranslateUtils::getContents怎么用?PHP TranslateUtils::getContents使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TranslateUtils
的用法示例。
在下文中一共展示了TranslateUtils::getContents方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getDefinitions
public function getDefinitions()
{
$groups = MessageGroups::getAllGroups();
$keys = array();
/**
* @var $g MessageGroup
*/
foreach ($groups as $g) {
$states = $g->getMessageGroupStates()->getStates();
foreach (array_keys($states) as $state) {
$keys["Translate-workflow-state-{$state}"] = $state;
}
}
$defs = TranslateUtils::getContents(array_keys($keys), $this->getNamespace());
foreach ($keys as $key => $state) {
if (!isset($defs[$key])) {
// @todo Use jobqueue
$title = Title::makeTitleSafe($this->getNamespace(), $key);
$page = new WikiPage($title);
$content = ContentHandler::makeContent($state, $title);
$page->doEditContent($content, wfMessage('translate-workflow-autocreated-summary', $state)->inContentLanguage()->text(), 0, false, FuzzyBot::getUser());
} else {
// Use the wiki translation as definition if available.
// getContents returns array( content, last author )
list($content, ) = $defs[$key];
$keys[$key] = $content;
}
}
return $keys;
}
示例2: getTranslations
/**
* Returns all translations of a given message.
* @param MessageHandle $handle Language code is ignored.
* @return array[]
* @since 2012-12-18
*/
public static function getTranslations(MessageHandle $handle)
{
$namespace = $handle->getTitle()->getNamespace();
$base = $handle->getKey();
$dbr = wfGetDB(DB_SLAVE);
$res = $dbr->select('page', array('page_namespace', 'page_title'), array('page_namespace' => $namespace, 'page_title ' . $dbr->buildLike("{$base}/", $dbr->anyString())), __METHOD__, array('ORDER BY' => 'page_title', 'USE INDEX' => 'name_title'));
$titles = array();
foreach ($res as $row) {
$titles[] = $row->page_title;
}
if ($titles === array()) {
return array();
}
$pageInfo = TranslateUtils::getContents($titles, $namespace);
return $pageInfo;
}
示例3: execute
public function execute()
{
$params = $this->extractRequestParams();
$title = Title::newFromText($params['title']);
if (!$title) {
$this->dieUsage('Invalid title');
}
$handle = new MessageHandle($title);
if (!$handle->isValid()) {
$this->dieUsage('Title does not correspond to a translatable message');
}
$base = Title::makeTitle($title->getNamespace(), $handle->getKey());
$namespace = $base->getNamespace();
$message = $base->getDBKey();
$dbr = wfGetDB(DB_SLAVE);
$res = $dbr->select('page', array('page_namespace', 'page_title'), array('page_namespace' => $namespace, 'page_title ' . $dbr->buildLike("{$message}/", $dbr->anyString())), __METHOD__, array('ORDER BY' => 'page_title', 'USE INDEX' => 'name_title'));
$titles = array();
foreach ($res as $row) {
$titles[] = $row->page_title;
}
$pageInfo = TranslateUtils::getContents($titles, $namespace);
$result = $this->getResult();
$pages = array();
$count = 0;
foreach ($pageInfo as $key => $info) {
if (++$count <= $params['offset']) {
continue;
}
$tTitle = Title::makeTitle($namespace, $key);
$tHandle = new MessageHandle($tTitle);
$data = array('title' => $tTitle->getPrefixedText(), 'language' => $tHandle->getCode(), 'lasttranslator' => $info[1]);
$fuzzy = MessageHandle::hasFuzzyString($info[0]) || $tHandle->isFuzzy();
if ($fuzzy) {
$data['fuzzy'] = 'fuzzy';
}
$translation = str_replace(TRANSLATE_FUZZY, '', $info[0]);
$result->setContent($data, $translation);
$fit = $result->addValue(array('query', $this->getModuleName()), null, $data);
if (!$fit) {
$this->setContinueEnumParameter('offset', $count);
break;
}
}
$result->setIndexedTagName_internal(array('query', $this->getModuleName()), 'message');
}
示例4: showTranslations
/**
* Builds a table with all translations of $title.
*
* @param $title Title (default: null)
* @return void
*/
function showTranslations(Title $title)
{
global $wgOut, $wgUser, $wgLang;
$sk = $wgUser->getSkin();
$namespace = $title->getNamespace();
$message = $title->getDBkey();
$inMessageGroup = TranslateUtils::messageKeyToGroup($title->getNamespace(), $title->getText());
if (!$inMessageGroup) {
$wgOut->addWikiMsg('translate-translations-no-message', $title->getPrefixedText());
return;
}
$dbr = wfGetDB(DB_SLAVE);
$res = $dbr->select('page', array('page_namespace', 'page_title'), array('page_namespace' => $namespace, 'page_title ' . $dbr->buildLike("{$message}/", $dbr->anyString())), __METHOD__, array('ORDER BY' => 'page_title', 'USE INDEX' => 'name_title'));
if (!$res->numRows()) {
$wgOut->addWikiMsg('translate-translations-no-message', $title->getPrefixedText());
return;
} else {
$wgOut->addWikiMsg('translate-translations-count', $wgLang->formatNum($res->numRows()));
}
// Normal output.
$titles = array();
foreach ($res as $s) {
$titles[] = $s->page_title;
}
$pageInfo = TranslateUtils::getContents($titles, $namespace);
$tableheader = Xml::openElement('table', array('class' => 'mw-sp-translate-table sortable'));
$tableheader .= Xml::openElement('tr');
$tableheader .= Xml::element('th', null, wfMsg('allmessagesname'));
$tableheader .= Xml::element('th', null, wfMsg('allmessagescurrent'));
$tableheader .= Xml::closeElement('tr');
// Adapted version of TranslateUtils:makeListing() by Nikerabbit.
$out = $tableheader;
$canTranslate = $wgUser->isAllowed('translate');
$ajaxPageList = array();
$historyText = " <sup>" . wfMsgHtml('translate-translations-history-short') . "</sup> ";
foreach ($res as $s) {
$key = $s->page_title;
$tTitle = Title::makeTitle($s->page_namespace, $key);
$ajaxPageList[] = $tTitle->getPrefixedDBkey();
$code = $this->getCode($s->page_title);
$text = TranslateUtils::getLanguageName($code, false, $wgLang->getCode()) . " ({$code})";
$text = htmlspecialchars($text);
if ($canTranslate) {
$tools['edit'] = TranslationHelpers::ajaxEditLink($tTitle, $text);
} else {
$tools['edit'] = $sk->link($tTitle, $text);
}
$tools['history'] = $sk->link($tTitle, $historyText, array('action', 'title' => wfMsg('history-title', $tTitle->getPrefixedDBkey())), array('action' => 'history'));
if (TranslateEditAddons::isFuzzy($tTitle)) {
$class = 'orig';
} else {
$class = 'def';
}
$leftColumn = $tools['history'] . $tools['edit'];
$out .= Xml::tags('tr', array('class' => $class), Xml::tags('td', null, $leftColumn) . Xml::tags('td', array('lang' => $code, 'dir' => Language::factory($code)->getDir()), TranslateUtils::convertWhiteSpaceToHTML($pageInfo[$key][0])));
}
$out .= Xml::closeElement('table');
$wgOut->addHTML($out);
$vars = array('trlKeys' => $ajaxPageList);
$wgOut->addScript(Skin::makeVariablesScript($vars));
}