jenkins-bot has submitted this change and it was merged.
Change subject: (bug 46925) <tvar|> visible on translation pages in source
language
......................................................................
(bug 46925) <tvar|> visible on translation pages in source language
Bug: 46925
Change-Id: Ie822dbf36de82c6b206b28492942b62e73022257
---
M tag/TPParse.php
A tests/TPParseTest.php
2 files changed, 55 insertions(+), 3 deletions(-)
Approvals:
Siebrand: Looks good to me, approved
jenkins-bot: Verified
diff --git a/tag/TPParse.php b/tag/TPParse.php
index ec70c35..37038df 100644
--- a/tag/TPParse.php
+++ b/tag/TPParse.php
@@ -191,8 +191,14 @@
$sectiontext = $msg->translation();
}
- // Use the original text if no translation is available
- if ( $sectiontext === null ) {
+ // Use the original text if no translation is available.
+
+ // For the source language, this will actually be the
source, which
+ // contains variable declarations (tvar) instead of
variables ($1).
+ // The getTextForTrans will convert declarations to
normal variables
+ // for us so that the variable substitutions below will
also work
+ // for the source language.
+ if ( $sectiontext === null || $sectiontext ===
$s->getText() ) {
$sectiontext = $s->getTextForTrans();
}
@@ -204,7 +210,7 @@
$nph = array();
$text = TranslatablePage::armourNowiki( $nph, $text );
- // Remove translation markup
+ // Remove translation markup from the template to produce final
text
$cb = array( __CLASS__, 'replaceTagCb' );
$text = preg_replace_callback(
'~(<translate>)(.*)(</translate>)~sU', $cb, $text );
$text = TranslatablePage::unArmourNowiki( $nph, $text );
diff --git a/tests/TPParseTest.php b/tests/TPParseTest.php
new file mode 100644
index 0000000..05f879d
--- /dev/null
+++ b/tests/TPParseTest.php
@@ -0,0 +1,46 @@
+<?php
+/**
+ * Unit tests for class TPParse
+ *
+ * @author Niklas Laxström
+ * @license GPL2+
+ * @file
+ */
+
+/**
+ * Unit tests for class TPParse
+ * @ingroup PageTranslation
+ */
+class TPParseTest extends MediaWikiTestCase {
+ 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' );
+ }
+}
--
To view, visit https://gerrit.wikimedia.org/r/60648
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ie822dbf36de82c6b206b28492942b62e73022257
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/Translate
Gerrit-Branch: master
Gerrit-Owner: Nikerabbit <[email protected]>
Gerrit-Reviewer: Siebrand <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits