public function testGetTranslationPageText()
 {
     $title = Title::newFromText(__CLASS__);
     $page = TranslatablePage::newFromText($title, '<translate>Hello <tvar|abc>peter!</></translate>');
     $prefix = $title->getPrefixedDBKey() . '/';
     $parse = $page->getParse();
     $collection = array();
     $expected = 'Hello peter!';
     $actual = $parse->getTranslationPageText($collection);
     $this->assertEquals($expected, $actual, 'Variable declarations are substituted when no translation');
     foreach ($parse->sections as $section) {
         $key = $prefix . $section->id;
         $message = new FatMessage($key, $section->getText());
         $message->setTranslation($section->getText());
         $collection[$key] = $message;
     }
     $actual = $parse->getTranslationPageText($collection);
     $this->assertEquals($expected, $actual, 'Variable declarations are substituted in source language');
     foreach ($parse->sections as $section) {
         $key = $prefix . $section->id;
         $message = new FatMessage($key, $section->getText());
         $message->setTranslation($section->getTextForTrans());
         $collection[$key] = $message;
     }
     $actual = $parse->getTranslationPageText($collection);
     $this->assertEquals($expected, $actual, 'Variable declarations are substituted in translation');
 }
 public function __construct($messages)
 {
     $keys = array_keys($messages);
     $this->keys = array_combine($keys, $keys);
     foreach ($messages as $key => $value) {
         $m = new FatMessage($key, $value);
         $m->setTranslation($value);
         $this->messages[$key] = $m;
     }
     $this->messages['foobar']->addTag('fuzzy');
 }
 public function __construct()
 {
     $msg = new FatMessage('translatedmsg', 'definition');
     $msg->setTranslation('translation');
     $this->messages['translatedmsg'] = $msg;
     $msg = new FatMessage('fuzzymsg', 'definition');
     $msg->addTag('fuzzy');
     $msg->setTranslation('!!FUZZY!!translation');
     $this->messages['fuzzymsg'] = $msg;
     $msg = new FatMessage('untranslatedmsg', 'definition');
     $this->messages['untranslatedmsg'] = $msg;
     $this->tags = array('fuzzy' => array('fuzzymsg'));
     $this->keys = array_flip(array_keys($this->messages));
 }
    public function testMsgctxtExport()
    {
        /** @var FileBasedMessageGroup $group */
        $group = MessageGroupBase::factory($this->groupConfiguration);
        $ffs = new GettextFFS($group);
        $object = new ReflectionObject($ffs);
        $method = $object->getMethod('formatMessageBlock');
        $method->setAccessible(true);
        $key = 'key';
        $m = new FatMessage('key', 'definition');
        $m->setTranslation('translation');
        $trans = array();
        $pot = array();
        $pluralCount = 0;
        $results = <<<GETTEXT
#
msgid "definition"
msgstr "translation"

#
msgctxt ""
msgid "definition"
msgstr "translation"

#
msgctxt "context"
msgid "definition"
msgstr "translation"
GETTEXT;
        $results = preg_split('/\\n\\n/', $results);
        // Case 1: no context
        $this->assertEquals($results[0], trim($method->invoke($ffs, $key, $m, $trans, $pot, $pluralCount)));
        // Case 2: empty context
        $pot['ctxt'] = '';
        $this->assertEquals($results[1], trim($method->invoke($ffs, $key, $m, $trans, $pot, $pluralCount)));
        // Case 3: context
        $pot['ctxt'] = 'context';
        $this->assertEquals($results[2], trim($method->invoke($ffs, $key, $m, $trans, $pot, $pluralCount)));
    }
Esempio n. 5
0
 public function getCheckBox()
 {
     $this->mustBeKnownMessage();
     global $wgTranslateDocumentationLanguageCode;
     $placeholder = Html::element('div', array('class' => 'mw-translate-messagechecks'));
     $page = $this->handle->getKey();
     $translation = $this->getTranslation();
     $code = $this->handle->getCode();
     $en = $this->getDefinition();
     if (strval($translation) === '') {
         return $placeholder;
     }
     if ($code === $wgTranslateDocumentationLanguageCode) {
         return null;
     }
     $checker = $this->group->getChecker();
     if (!$checker) {
         return null;
     }
     $message = new FatMessage($page, $en);
     // Take the contents from edit field as a translation
     $message->setTranslation($translation);
     $checks = $checker->checkMessage($message, $code);
     if (!count($checks)) {
         return $placeholder;
     }
     $checkMessages = array();
     foreach ($checks as $checkParams) {
         array_splice($checkParams, 1, 0, 'parseinline');
         $checkMessages[] = call_user_func_array('wfMsgExt', $checkParams);
     }
     return Html::rawElement('div', array('class' => 'mw-translate-messagechecks'), TranslateUtils::fieldset(wfMsgHtml('translate-edit-warnings'), implode('<hr />', $checkMessages), array('class' => 'mw-sp-translate-edit-warnings')));
 }
 /**
  * @param MessageHandle $handle
  * @param string $text
  * @return bool
  */
 protected static function checkNeedsFuzzy(MessageHandle $handle, $text)
 {
     // Check for explicit tag.
     $fuzzy = MessageHandle::hasFuzzyString($text);
     // Docs are exempt for checks
     if ($handle->isDoc()) {
         return $fuzzy;
     }
     // Not all groups have checkers
     $group = $handle->getGroup();
     $checker = $group->getChecker();
     if (!$checker) {
         return $fuzzy;
     }
     $code = $handle->getCode();
     $key = $handle->getKey();
     $en = $group->getMessage($key, $group->getSourceLanguage());
     $message = new FatMessage($key, $en);
     // Take the contents from edit field as a translation.
     $message->setTranslation($text);
     $checks = $checker->checkMessage($message, $code);
     if (count($checks)) {
         $fuzzy = true;
     }
     return $fuzzy;
 }
 public function getCheckBox()
 {
     $this->mustBeKnownMessage();
     global $wgTranslateDocumentationLanguageCode;
     $context = RequestContext::getMain();
     $title = $context->getOutput()->getTitle();
     list($alias, ) = SpecialPageFactory::resolveAlias($title->getText());
     $tux = SpecialTranslate::isBeta($context->getRequest()) && $title->isSpecialPage() && $alias === 'Translate';
     $formattedChecks = $tux ? FormatJson::encode(array()) : Html::element('div', array('class' => 'mw-translate-messagechecks'));
     $page = $this->handle->getKey();
     $translation = $this->getTranslation();
     $code = $this->handle->getCode();
     $en = $this->getDefinition();
     if (strval($translation) === '') {
         return $formattedChecks;
     }
     if ($code === $wgTranslateDocumentationLanguageCode) {
         return $formattedChecks;
     }
     // We need to get the primary group of the message. It may differ from
     // the supplied group (aggregate groups, dynamic groups).
     $checker = $this->handle->getGroup()->getChecker();
     if (!$checker) {
         return $formattedChecks;
     }
     $message = new FatMessage($page, $en);
     // Take the contents from edit field as a translation
     $message->setTranslation($translation);
     $checks = $checker->checkMessage($message, $code);
     if (!count($checks)) {
         return $formattedChecks;
     }
     $checkMessages = array();
     foreach ($checks as $checkParams) {
         $key = array_shift($checkParams);
         $checkMessages[] = $context->msg($key, $checkParams)->parse();
     }
     if ($tux) {
         $formattedChecks = FormatJson::encode($checkMessages);
     } else {
         $formattedChecks = Html::rawElement('div', array('class' => 'mw-translate-messagechecks'), TranslateUtils::fieldset($context->msg('translate-edit-warnings')->escaped(), implode('<hr />', $checkMessages), array('class' => 'mw-sp-translate-edit-warnings')));
     }
     return $formattedChecks;
 }