本文整理汇总了PHP中TranslateUtils类的典型用法代码示例。如果您正苦于以下问题:PHP TranslateUtils类的具体用法?PHP TranslateUtils怎么用?PHP TranslateUtils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TranslateUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getMessageParameters
public function getMessageParameters()
{
$params = parent::getMessageParameters();
$type = $this->entry->getFullType();
if ($type === 'translationreview/message') {
$targetPage = $this->makePageLink($this->entry->getTarget(), array('oldid' => $params[3]));
$params[2] = Message::rawParam($targetPage);
} elseif ($type === 'translationreview/group') {
/*
* - 3: language code
* - 4: label of the message group
* - 5: old state
* - 6: new state
*/
$uiLanguage = $this->context->getLanguage();
$language = $params[3];
$targetPage = $this->makePageLinkWithText($this->entry->getTarget(), $params[4], array('language' => $language));
$params[2] = Message::rawParam($targetPage);
$params[3] = TranslateUtils::getLanguageName($language, $uiLanguage->getCode());
$params[5] = $this->formatStateMessage($params[5]);
$params[6] = $this->formatStateMessage($params[6]);
} elseif ($type === 'translatorsandbox/rejected') {
// No point linking to the user page which cannot have existed
$params[2] = $this->entry->getTarget()->getText();
} elseif ($type === 'translatorsandbox/promoted') {
// Gender for the target
$params[3] = User::newFromId($params[3])->getName();
}
return $params;
}
示例2: run
function run()
{
// Initialization
$title = $this->title;
list(, $code) = TranslateUtils::figureMessage($title->getPrefixedText());
// Return the actual translation page...
$page = TranslatablePage::isTranslationPage($title);
if (!$page) {
var_dump($this->params);
var_dump($title);
throw new MWException("Oops, this should not happen!");
}
$group = $page->getMessageGroup();
$collection = $group->initCollection($code);
$text = $page->getParse()->getTranslationPageText($collection);
// Other stuff
$user = $this->getUser();
$summary = $this->getSummary();
$flags = $this->getFlags();
$page = WikiPage::factory($title);
// @todo FuzzyBot hack
PageTranslationHooks::$allowTargetEdit = true;
$content = ContentHandler::makeContent($text, $page->getTitle());
$page->doEditContent($content, $summary, $flags, false, $user);
PageTranslationHooks::$allowTargetEdit = false;
return true;
}
示例3: toolboxAllTranslations
/**
* Adds link in toolbox to Special:Prefixindex to show all other
* available translations for a message. Only shown when it
* actually is a translatable/translated message.
*
* @param $skin Skin
*
* @return bool
*/
static function toolboxAllTranslations( &$skin ) {
global $wgTranslateMessageNamespaces;
if ( method_exists( $skin, 'getSkin' ) ) {
$title = $skin->getSkin()->getTitle();
} else {
global $wgTitle;
$title = $wgTitle;
}
$ns = $title->getNamespace();
if ( !in_array( $ns, $wgTranslateMessageNamespaces ) ) {
return true;
}
$inMessageGroup = TranslateUtils::messageKeyToGroup( $title->getNamespace(), $title->getBaseText() );
if ( $inMessageGroup ) {
// Add a slash at the end, to not have basename in the result of Special:Prefixindex
$message = $title->getNsText() . ":" . $title->getBaseText();
$desc = wfMsg( 'translate-sidebar-alltrans' );
$url = htmlspecialchars( SpecialPage::getTitleFor( 'Translations' )->getLocalURL( 'message=' . $message ) );
// Add the actual toolbox entry.
// Add newlines and tabs for nicer HTML output.
echo( "\n\t\t\t\t<li id=\"t-alltrans\"><a href=\"$url\">$desc</a></li>\n" );
}
return true;
}
示例4: execute
public function execute()
{
$groupIds = explode(',', trim($this->getOption('group')));
$groupIds = MessageGroups::expandWildcards($groupIds);
$groups = MessageGroups::getGroupsById($groupIds);
if (!count($groups)) {
$this->error("ESG2: No valid message groups identified.", 1);
}
$start = $this->getOption('start') ? strtotime($this->getOption('start')) : false;
$end = $this->getOption('end') ? strtotime($this->getOption('end')) : false;
$this->output("Conflict times: " . wfTimestamp(TS_ISO_8601, $start) . " - " . wfTimestamp(TS_ISO_8601, $end) . "\n");
$codes = array_filter(array_map('trim', explode(',', $this->getOption('lang'))));
$supportedCodes = array_keys(TranslateUtils::getLanguageNames('en'));
ksort($supportedCodes);
if ($codes[0] === '*') {
$codes = $supportedCodes;
}
/** @var FileBasedMessageGroup $group */
foreach ($groups as $groupId => &$group) {
if ($group->isMeta()) {
$this->output("Skipping meta message group {$groupId}.\n");
continue;
}
$this->output("{$group->getLabel()} ", $group);
foreach ($codes as $code) {
// No sync possible for unsupported language codes.
if (!in_array($code, $supportedCodes)) {
$this->output("Unsupported code " . $code . ": skipping.\n");
continue;
}
$file = $group->getSourceFilePath($code);
if (!$file) {
continue;
}
if (!file_exists($file)) {
continue;
}
$cs = new ChangeSyncer($group, $this);
$cs->setProgressCallback(array($this, 'myOutput'));
$cs->interactive = !$this->hasOption('noask');
$cs->nocolor = $this->hasOption('nocolor');
$cs->norc = $this->hasOption('norc');
# @todo FIXME: Make this auto detect.
# Guess last modified date of the file from either git, svn or filesystem
if ($this->hasOption('git')) {
$ts = $cs->getTimestampsFromGit($file);
} else {
$ts = $cs->getTimestampsFromSvn($file);
}
if (!$ts) {
$ts = $cs->getTimestampsFromFs($file);
}
$this->output("Modify time for {$code}: " . wfTimestamp(TS_ISO_8601, $ts) . "\n");
$cs->checkConflicts($code, $start, $end, $ts);
}
unset($group);
}
// Print timestamp if the user wants to store it
$this->output(wfTimestamp(TS_RFC2822) . "\n");
}
示例5: getForm
/**
* Returns HTML5 output of the form
* GLOBALS: $wgLang, $wgScript
* @return string
*/
protected function getForm() {
global $wgLang, $wgScript;
$form = Xml::tags( 'form',
array(
'action' => $wgScript,
'method' => 'get'
),
'<table><tr><td>' .
wfMsgHtml( 'translate-page-language' ) .
'</td><td>' .
TranslateUtils::languageSelector( $wgLang->getCode(), $this->options['language'] ) .
'</td></tr><tr><td>' .
wfMsgHtml( 'translate-magic-module' ) .
'</td><td>' .
$this->moduleSelector( $this->options['module'] ) .
'</td></tr><tr><td colspan="2">' .
Xml::submitButton( wfMsg( 'translate-magic-submit' ) ) . ' ' .
Xml::submitButton( wfMsg( 'translate-magic-cm-export' ), array( 'name' => 'export' ) ) .
'</td></tr></table>' .
Html::hidden( 'title', $this->getTitle()->getPrefixedText() )
);
return $form;
}
示例6: testTokenRetrieval
/** @dataProvider provideTokenClasses */
public function testTokenRetrieval($id, $class)
{
// Make sure we have the right to get the token
global $wgGroupPermissions;
$wgGroupPermissions['*'][$class::getRight()] = true;
RequestContext::getMain()->getUser()->clearInstanceCache();
// Reread above global
// We should be getting anonymous user token
$expected = $class::getToken();
$this->assertNotSame(false, $expected, 'We did not get a valid token');
$actionString = TranslateUtils::getTokenAction($id);
$params = wfCgiToArray($actionString);
$req = new FauxRequest($params);
$api = new ApiMain($req);
$api->execute();
if (defined('ApiResult::META_CONTENT')) {
$data = $api->getResult()->getResultData(null, array('Strip' => 'all'));
} else {
$data = $api->getResultData();
}
if (isset($data['query'])) {
foreach ($data['query']['pages'] as $page) {
$this->assertSame($expected, $page[$id . 'token']);
}
} else {
$this->assertArrayHasKey('tokens', $data, 'Result has tokens');
$this->assertSame($expected, $data['tokens'][$id . 'token']);
}
}
示例7: 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;
}
示例8: doHeader
protected function doHeader( MessageCollection $collection ) {
global $wgSitename, $wgTranslateDocumentationLanguageCode;
$code = $collection->code;
$name = TranslateUtils::getLanguageName( $code );
$native = TranslateUtils::getLanguageName( $code, true );
if ( $wgTranslateDocumentationLanguageCode ) {
$docu = "\n * See the $wgTranslateDocumentationLanguageCode 'language' for message documentation incl. usage of parameters";
} else {
$docu = '';
}
$authors = $this->doAuthors( $collection );
$output = <<<PHP
/** $name ($native)
* $docu
* To improve a translation please visit http://$wgSitename
*
* @ingroup Language
* @file
*
$authors */
PHP;
return $output;
}
示例9: getMessage
/**
* Returns of stored translation of message specified by the $key in language
* code $code.
*
* @param string $key Key of the message.
* @param string $code Language code.
* @return string|null The translation or null if it doesn't exists.
*/
public function getMessage($key, $code)
{
if ($code && $this->getSourceLanguage() !== $code) {
return TranslateUtils::getMessageContent($key, $code);
} else {
return TranslateUtils::getMessageContent($key, false);
}
}
示例10: execute
public function execute($par)
{
$request = $this->getRequest();
$par = (string) $par;
// Yes, the use of getVal() and getText() is wanted, see bug T22365
$this->text = $request->getVal('wpTitle', $par);
$this->title = Title::newFromText($this->text);
$this->reason = $request->getText('reason');
// Checkboxes that default being checked are tricky
$this->doSubpages = $request->getBool('subpages', !$request->wasPosted());
$user = $this->getUser();
if ($this->doBasicChecks() !== true) {
return;
}
$out = $this->getOutput();
// Real stuff starts here
if (TranslatablePage::isSourcePage($this->title)) {
$title = $this->msg('pt-deletepage-full-title', $this->title->getPrefixedText());
$out->setPagetitle($title);
$this->code = '';
$this->page = TranslatablePage::newFromTitle($this->title);
} else {
$page = TranslatablePage::isTranslationPage($this->title);
if ($page) {
$title = $this->msg('pt-deletepage-lang-title', $this->title->getPrefixedText());
$out->setPagetitle($title);
list(, $this->code) = TranslateUtils::figureMessage($this->title->getText());
$this->page = $page;
} else {
throw new ErrorPageError('pt-deletepage-invalid-title', 'pt-deletepage-invalid-text');
}
}
if (!$user->isAllowed('pagetranslation')) {
throw new PermissionsError('pagetranslation');
}
// Is there really no better way to do this?
$subactionText = $request->getText('subaction');
switch ($subactionText) {
case $this->msg('pt-deletepage-action-check')->text():
$subaction = 'check';
break;
case $this->msg('pt-deletepage-action-perform')->text():
$subaction = 'perform';
break;
case $this->msg('pt-deletepage-action-other')->text():
$subaction = '';
break;
default:
$subaction = '';
}
if ($subaction === 'check' && $this->checkToken() && $request->wasPosted()) {
$this->showConfirmation();
} elseif ($subaction === 'perform' && $this->checkToken() && $request->wasPosted()) {
$this->performAction();
} else {
$this->showForm();
}
}
开发者ID:HuijiWiki,项目名称:mediawiki-extensions-Translate,代码行数:58,代码来源:SpecialPageTranslationDeletePage.php
示例11: getData
public function getData()
{
$translation = null;
$title = $this->handle->getTitle();
$translation = TranslateUtils::getMessageContent($this->handle->getKey(), $this->handle->getCode(), $title->getNamespace());
Hooks::run('TranslatePrefillTranslation', array(&$translation, $this->handle));
$fuzzy = MessageHandle::hasFuzzyString($translation) || $this->handle->isFuzzy();
$translation = str_replace(TRANSLATE_FUZZY, '', $translation);
return array('language' => $this->handle->getCode(), 'fuzzy' => $fuzzy, 'value' => $translation);
}
示例12: doHeader
protected function doHeader(MessageCollection $collection)
{
global $wgSitename;
$code = $collection->code;
$name = TranslateUtils::getLanguageName($code);
$native = TranslateUtils::getLanguageName($code, $code);
$output = "# Messages for {$name} ({$native})\n";
$output .= "# Exported from {$wgSitename}\n\n";
return $output;
}
示例13: getData
public function getData()
{
global $wgTranslateDocumentationLanguageCode, $wgContLang;
if (!$wgTranslateDocumentationLanguageCode) {
throw new TranslationHelperException('Message documentation is disabled');
}
$page = $this->handle->getKey();
$ns = $this->handle->getTitle()->getNamespace();
$info = TranslateUtils::getMessageContent($page, $wgTranslateDocumentationLanguageCode, $ns);
return array('language' => $wgContLang->getCode(), 'value' => $info, 'html' => $this->context->getOutput()->parse($info));
}
示例14: doHeader
/**
* @param $collection MessageCollection
* @return string
*/
protected function doHeader(MessageCollection $collection)
{
global $wgSitename;
global $wgTranslateYamlLibrary;
$code = $collection->code;
$name = TranslateUtils::getLanguageName($code);
$native = TranslateUtils::getLanguageName($code, $code);
$output = "# Messages for {$name} ({$native})\n";
$output .= "# Exported from {$wgSitename}\n";
if (isset($wgTranslateYamlLibrary)) {
$output .= "# Export driver: {$wgTranslateYamlLibrary}\n";
}
return $output;
}
示例15: execute
public function execute()
{
$hours = (int) $this->getOption('days');
$hours = $hours ? $hours * 7 : 7 * 24;
$top = (int) $this->getOption('top');
$top = $top ? $top : 10;
$bots = $this->hasOption('bots');
$namespaces = array();
if ($this->hasOption('ns')) {
$input = explode(',', $this->getOption('ns'));
foreach ($input as $namespace) {
if (is_numeric($namespace)) {
array_push($namespaces, $namespace);
}
}
}
/**
* Select set of edits to report on
*/
$rows = TranslateUtils::translationChanges($hours, $bots, $namespaces);
/**
* Get counts for edits per language code after filtering out edits by FuzzyBot
*/
$codes = array();
global $wgTranslateFuzzyBotName;
foreach ($rows as $_) {
// Filter out edits by $wgTranslateFuzzyBotName
if ($_->rc_user_text === $wgTranslateFuzzyBotName) {
continue;
}
list(, $code) = TranslateUtils::figureMessage($_->rc_title);
if (!isset($codes[$code])) {
$codes[$code] = 0;
}
$codes[$code]++;
}
/**
* Sort counts and report descending up to $top rows.
*/
arsort($codes);
$i = 0;
foreach ($codes as $code => $num) {
if ($i++ === $top) {
break;
}
$this->output("{$code}\t{$num}\n");
}
}