Page MenuHomePhabricator

SVG translate Tool ignores inherit group-attributes
Open, Needs TriagePublic5 Estimated Story PointsBUG REPORT

Description

Steps to Reproduce:
https://tools.wmflabs.org/svgtranslate/File:COVID-19_Health_care_limit.svg

Actual Results:
German text is in default

Screenshot_2020-03-19 COVID-19 Health care limit svg SVG Translate.png (1×1 px, 90 KB)

Expected Results:
German should be a language to choose

Event Timeline

@JoKalliauer I believe that, if one first visits the page without any previously selected language, German is a language to choose. When I first tested with no previous selections, German was not the default language. Rather, I saw "Select Language" as default (see screenshot example below):

Screen Shot 2020-04-14 at 4.49.14 PM.png (590×1 px, 79 KB)

However, if I then selected German and then went back to the page, German would be set as the default. This can be tested with incognito on your browser. But I'll ask the team about this, so that I can make sure that I didn't miss anything.

The file is in a format that SVG Translate does not know how to handle, but SVG Translate does not recognize that problem.

The file originally had a switch element whose children were g elements. SVG Translate uses a query rather than traversing the tree, so it can find text elements within g elements that have a systemLanguage attribute (and are therefore untranslatable).

Apply SVG Translate resulted in the following nested switch elements:

<switch font-family="Liberation Sans" font-size="36">
 <g systemLanguage="de">
  <text x="8.86" y="36.09"><tspan>Zahl der</tspan><tspan x="8.86" y="81.56">Infizierten</tspan></text>
  <text x="583.32" y="571.49" text-anchor="middle"><tspan>Zeit ab der ersten Infektion</tspan></text>
  <text x="779.93" y="315.45"><tspan>Kapazität des</tspan><tspan x="779.93" y="360.45">Gesundheitssystems</tspan></text>
  <text x="385.51" y="116.89"><tspan>ohne Vorkehrungen</tspan></text>
  <text x="1237" y="427.92" text-anchor="end"><tspan>Vorkehrungen wie</tspan><tspan x="1237" y="472.92">soziale Distanzierung</tspan><tspan x="1237" y="517.92">Telework</tspan></text>
 </g>
 <g>
  <switch>
   <text x="8.86" y="36.09" systemLanguage="el"><tspan>Αριθμός</tspan><tspan x="8.86" y="81.56" id="trsvg11-el">κρουσμάτων</tspan></text>
   <text x="8.86" y="36.09" systemLanguage="hu"><tspan>Fertözöttek száma</tspan><tspan x="8.86" y="81.56"> </tspan></text>
   <text x="8.86" y="36.09"><tspan>Number of</tspan><tspan x="8.86" y="81.56">people infected</tspan></text>
  </switch>
  <switch>
   <text x="583.32" y="571.49" text-anchor="middle" systemLanguage="el"><tspan>Χρόνος από το πρώτο κρούσμα</tspan></text>
   <text x="583.32" y="571.49" text-anchor="middle" systemLanguage="hu"><tspan>Az elsö fertözéstöl számított idö</tspan></text>
   <text x="583.32" y="571.49" text-anchor="middle"><tspan>Time from the first infection</tspan></text>
  </switch>
  <switch>
   <text x="779.93" y="315.45" systemLanguage="el"><tspan id="trsvg13-el">Δυνατότητες</tspan><tspan x="779.93" y="360.45">συστήματος υγείας</tspan></text>
   <text x="779.93" y="315.45" systemLanguage="hu"><tspan>Egészségügyi</tspan><tspan x="779.93" y="360.45">ellátás</tspan></text>
   <text x="779.93" y="315.45"><tspan>Health care</tspan><tspan x="779.93" y="360.45">capacity</tspan></text>
  </switch>
  <switch>
   <text x="385.51" y="116.89" systemLanguage="el"><tspan id="trsvg15-el">χωρίς προφυλάξεις</tspan></text>
   <text x="385.51" y="116.89" systemLanguage="hu"><tspan id="trsvg15-hu">Óvintèzkedèsek nèlkül</tspan></text>
   <text x="385.51" y="116.89"><tspan id="trsvg15">without precautions</tspan></text>
  </switch>
  <switch>
   <text x="1237" y="427.92" text-anchor="end" systemLanguage="el"><tspan>κοινωνική απομάκρυνση</tspan></text>
   <text x="1237" y="427.92" text-anchor="end" systemLanguage="hu"><tspan>Társadalmi elkülönülés</tspan></text>
   <text x="1237" y="427.92" text-anchor="end"><tspan>social distancing</tspan></text>
  </switch>
 </g>
</switch>

So the real confusion is the improper file format. User Mrmw fixed the file in January 2021, so SVG Translate should work on the file now.

SVG Translate should do a better job of checking for patterns it does not handle.

Same issue as T298811.

Describe limitations of the tool.
T250330

SVG Translate finds translations by looking for text elements. It uses $this->document->getElementsByTagName('text') to find those elements.

That method will find text elements that are already filtered with a <code>systemLanguage</code> attribute. Consider an example SVG that has

Example SVG
<switch>
  <g systemLanguage="de">
    <text>German text that cannot be translated into other languages</text>
  </g>
  <g>
    <text>Default text</text>
  </g>
</switch>

SVG Translate will find both text elements. It performs a simple context check at line 298:

src/Model/Svg/SvgFile.php
// Sort out switches
if ('switch' !== $text->parentNode->nodeName
    && 'svg:switch' !== $text->parentNode->nodeName
) {
    // Every text should now be in a switch
    $switch = $this->document->createElementNS($defaultNS, 'switch');
    $text->parentNode->insertBefore($switch, $text);
    // Move node into new sibling <switch> element
    $switch->appendChild($text);
}

If the text element has a switch parent, then it is left alone. Otherwise, the text element is wrapped with a switch.

Consequently, both text elements in the SVG example will be wrapped with an additional switch. Their parents are g elements. SVG Translate does not recognize that the text elements are already contained within an ancestral switch.

Each text element should check its ancestors. If any ancestor has a systemLanguage attribute, then the routine should return false (abort the translation). If any grandparent or higher ancestor is a switch, then the routine should return false. (The latter test will be too conservative on Adobe files.)

I would also refuse to translate any SVG file that had an element with a requiredFeatures or requiredExtensions attribute.

A general requirement for SVG Translate is that only text elements may have systemLanguage attributes. I haven't seen a file do this, but it is possible:

SVG with tspan translations
<text>
  <tspan systemLanguage="en">English</tspan>
  <tspan systemLanguage="de">Deutsch</tspan>
</text>