jenkins-bot has submitted this change and it was merged.
Change subject: LanguageWithConversion has a new reverseTranslate() function.
......................................................................
LanguageWithConversion has a new reverseTranslate() function.
It tries to work out the original string in source language.
Some other test cases are added too.
Change-Id: I38298ceb608edd50600b93176b2e88c75b0335e6
---
M lib/includes/LanguageWithConversion.php
M lib/tests/phpunit/LanguageWithConversionTest.php
2 files changed, 42 insertions(+), 0 deletions(-)
Approvals:
Daniel Kinzler: Looks good to me, approved
jenkins-bot: Verified
diff --git a/lib/includes/LanguageWithConversion.php
b/lib/includes/LanguageWithConversion.php
index 802d568..6e1c1d7 100644
--- a/lib/includes/LanguageWithConversion.php
+++ b/lib/includes/LanguageWithConversion.php
@@ -226,6 +226,22 @@
}
/**
+ * Try to work out the original data (in source language) from a given
translation output.
+ *
+ * @param $text String
+ * @return String
+ */
+ public function reverseTranslate( $text ) {
+ if ( $this->parentLanguage ) {
+ return $this->parentLanguage->getConverter()->translate(
+ $text, $this->sourceLanguageCode
+ );
+ } else {
+ return $text;
+ }
+ }
+
+ /**
* Insert a text snippet which will be translated later.
*
* Due to the implementation of language converter, massive
diff --git a/lib/tests/phpunit/LanguageWithConversionTest.php
b/lib/tests/phpunit/LanguageWithConversionTest.php
index c13a6ac..d86c7ae 100644
--- a/lib/tests/phpunit/LanguageWithConversionTest.php
+++ b/lib/tests/phpunit/LanguageWithConversionTest.php
@@ -129,8 +129,34 @@
}
}
+ /**
+ * @dataProvider provideTranslate
+ */
+ public function testReverseTranslate( $langCode, $sourceLangCode,
$translations ) {
+ if ( $sourceLangCode === null ) {
+ $sourceLangCode = $langCode;
+ $langCode = null;
+ }
+ $obj = LanguageWithConversion::factory( $sourceLangCode,
$langCode );
+ foreach ( $translations as $text => $translatedText ) {
+ $this->assertEquals( $obj->reverseTranslate( $text ),
$translatedText );
+ }
+ }
+
public function provideTranslate() {
return array(
+ array( 'de', null, array(
+ 'foo' => 'foo',
+ 'bar' => 'bar',
+ ) ),
+ array( 'zh', null, array(
+ '測試' => '測試',
+ '测试' => '测试',
+ ) ),
+ array( 'zh-cn', null, array(
+ '測試' => '測試',
+ '测试' => '测试',
+ ) ),
array( 'zh-cn', 'zh-tw', array(
'測試' => '测试',
) ),
--
To view, visit https://gerrit.wikimedia.org/r/73754
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I38298ceb608edd50600b93176b2e88c75b0335e6
Gerrit-PatchSet: 6
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Liangent <[email protected]>
Gerrit-Reviewer: Aude <[email protected]>
Gerrit-Reviewer: Daniel Kinzler <[email protected]>
Gerrit-Reviewer: Denny Vrandecic <[email protected]>
Gerrit-Reviewer: Liangent <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits