Nikerabbit has uploaded a new change for review. https://gerrit.wikimedia.org/r/60648
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, 57 insertions(+), 4 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Translate refs/changes/48/60648/1 diff --git a/tag/TPParse.php b/tag/TPParse.php index 84a298d..96f783c 100644 --- a/tag/TPParse.php +++ b/tag/TPParse.php @@ -192,20 +192,27 @@ $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(); } - // Substitute variables into section text and substitute text into document + // Substitute variables ($1) into section text $sectiontext = self::replaceVariables( $s->getVariables(), $sectiontext ); + // Substitute the section to the template $text = str_replace( $ph, $sectiontext, $text ); } $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: newchange Gerrit-Change-Id: Ie822dbf36de82c6b206b28492942b62e73022257 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Translate Gerrit-Branch: master Gerrit-Owner: Nikerabbit <niklas.laxst...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits