Jarry1250 has uploaded a new change for review.
https://gerrit.wikimedia.org/r/156133
Change subject: Move language splitting logic from analyse() to
makeTranslationReady()
......................................................................
Move language splitting logic from analyse() to makeTranslationReady()
Although the SVG spec supports multi-language text tags (e.g. "en,fr,de")
these are a really poor idea since (a) they are confusing to read and
(b) the desired translations could diverge at any point. So get rid at
the earliest possible juncture, i.e. in makeTranslationReady().
Fix associated tests that relied on order of <text> elements.
Change-Id: I9a0aa022315e38e7cb7eae0563d05cf4837de637
---
M SVGFile.php
M tests/phpunit/SVGFileTest.php
2 files changed, 28 insertions(+), 11 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/TranslateSvg
refs/changes/33/156133/1
diff --git a/SVGFile.php b/SVGFile.php
index a0b15f6..d703265 100644
--- a/SVGFile.php
+++ b/SVGFile.php
@@ -203,11 +203,27 @@
}
$language =
$sibling->hasAttribute( 'systemLanguage' ) ?
$sibling->getAttribute(
'systemLanguage' ) : 'fallback';
- if ( in_array( $language,
$languagesPresent ) ) {
- // Two tags for the
same language
- return false;
+ $realLangs = preg_split( '/,
*/', $language );
+ foreach( $realLangs as
$realLang ) {
+ if( count( $realLangs )
> 1 ) {
+ // Although the
SVG spec supports multi-language text tags (e.g. "en,fr,de")
+ // these are a
really poor idea since (a) they are confusing to read and (b) the
+ // desired
translations could diverge at any point. So get rid.
+
$singleLanguageNode = clone $sibling;
+
$singleLanguageNode->setAttribute( 'systemLanguage', $realLang );
+
$switch->appendChild( $singleLanguageNode );
+ }
+ if ( in_array(
$realLang, $languagesPresent ) ) {
+ // Two tags for
the same language
+ return false;
+ }
+ $languagesPresent[] =
$realLang;
}
- $languagesPresent[] = $language;
+
+ if( count( $realLangs ) > 1 ) {
+ // If still present,
remove the original multi-language
+ $switch->removeChild(
$sibling );
+ }
}
}
} else {
@@ -301,10 +317,8 @@
$childTspan =
$fallbackText->getElementsByTagName( 'tspan' )->item( $counter - 1 );
$childId =
$childTspan->getAttribute( 'id' );
- foreach( $realLangs as
$realLang ) {
-
$translations[$childId][$realLang] = TranslateSvgUtils::nodeToArray( $child );
-
$translations[$childId][$realLang]['data-parent'] = $textId;
- }
+
$translations[$childId][$langCode] = TranslateSvgUtils::nodeToArray( $child );
+
$translations[$childId][$langCode]['data-parent'] = $textId;
if ( $text->hasAttribute(
'data-children' ) ) {
$existing =
$text->getAttribute( 'data-children' );
$text->setAttribute(
'data-children', "$existing|$childId" );
@@ -458,7 +472,10 @@
"svg:text[@systemLanguage='$language']|text[@systemLanguage='$language']";
$existing = $this->xpath->query( $path, $switch
);
if ( $existing->length == 1 ) {
- // Only one matching text node, replace
+ // Only one matching text node, replace
if different
+ if ( TranslateSvgUtils::nodeToArray(
$newTextTag ) === TranslateSvgUtils::nodeToArray( $existing->item( 0 ) ) ) {
+ continue;
+ }
$switch->replaceChild( $newTextTag,
$existing->item( 0 ) );
} elseif ( $existing->length == 0 ) {
// No matching text node for this
language, so we'll create one
diff --git a/tests/phpunit/SVGFileTest.php b/tests/phpunit/SVGFileTest.php
index 31727c8..ec83b0c 100644
--- a/tests/phpunit/SVGFileTest.php
+++ b/tests/phpunit/SVGFileTest.php
@@ -281,14 +281,14 @@
public function testGetSavedLanguages() {
$expected = array(
- 'de', 'fr', 'nl', 'tlh-ca', 'en'
+ 'de', 'fr', 'en', 'nl', 'tlh-ca'
);
$this->assertEquals( $expected, $this->svg->getSavedLanguages()
);
}
public function testGetSavedLanguagesFiltered() {
$expected = array(
- 'full' => array( 'fr', 'nl', 'tlh-ca', 'en' ),
+ 'full' => array( 'fr', 'en', 'nl', 'tlh-ca' ),
'partial' => array( 'de' )
);
$this->assertEquals( $expected,
$this->svg->getSavedLanguagesFiltered() );
--
To view, visit https://gerrit.wikimedia.org/r/156133
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I9a0aa022315e38e7cb7eae0563d05cf4837de637
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/TranslateSvg
Gerrit-Branch: master
Gerrit-Owner: Jarry1250 <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits