I love the #SVG format. It's not perfect, but it has some amazing features, and with all the issues in its support across different browsers, it still remains a solid vector graphics format.

One of the things I love the most about #SVG is that it allows interaction and dynamic content without requiring #JavaScript. This isn't actually an #SVG feature _per se_, but it's related to the spec integrating support for #SMIL, and XML language for dynamic content.

#SVG also supports and incredibly powerful element: #switch. The combination of switch and #SMIL allows some impressively sophisticated things do be achieved in SVG without using #JavaScript or serverside funkiness, and honestly, I love these features SO MUCH that I really wish HTML was extended to support them too.
In fact, there was an attempt to add #SMIL support in #HTML: it was called #TIME (Timed Interactive Multimedia Extension)
https://en.wikipedia.org/wiki/HTML%2BTIME
proposed by #Microsoft and #Macromedia and, after being submitted to the #W3C, evolved into the W3C Note (not even a recommendation) for XHTML+SMIL
https://en.wikipedia.org/wiki/XHTML%2BSMIL
No other browser than #InternetExplorer ever added support for it, and honestly, I see that as a loss.
HTML+TIME - Wikipedia

WIth the integration of #MathML and #SVG standards into #HTML5, there is actually some of things moving forward in this direction, although I doubt any of the existing implementation actually plans on investing resources in it. One of the benefits of having more competition in this area would be better chances of a growth in this regard.
I actually wonder if some kind of #JavaScript polyfill could be created to implement support for these features without UA support. It would be suboptimal, similarly to how #MathJax is inferior to UA support for #MathML, but could work as a stopgap solution to promote the adoption and standardization of these extensions.

I've tried a quick test to see if you can exploit the #HTML5 inclusion of #SVG to have a <switch>. It doesn't really work as expected, so you have to do a double wrapping:

svg > switch > [foreignObject > your HTML here]+

which obviously doesn't work as expected …

You can _almost_ implement the #SVG `switch` element in pure #HTML + #CSS with something like:

switch > * {
display: none;
}
switch > *:lang(...) {
display: initial
}

with only one issue: there's no way to put in that :lang() pseudo-class “whatever the user asked for”. So you still need some #JavaScript or server-side assistance to bridge the gap between the user language selection and the styling.

So close …

OK, HTML <switch> can be polyfilled with 4 lines of CSS and a little bit of JavaScript to do the language check.

Oh boy this is a problem. Different UAs apply the #SVG #switch element in different ways when user asks for multiple language support.

So: the switch element is typically employed together with the systemLanguage attribute as a way to display different content depending on the language choice of the user. Per the spec, the element should select “the first child that matches the user's language preference”.

Now, there are two ways to do this when the user accepts multiple languages.

One is: for every language accepted by the user, find the first matching element.

The other is: find the first element that matches any of the user languages

Firefox seems to use the first strategy, WebKit and Blink browsers the second.

Which one is correct?

If I look at the SVG spec https://www.w3.org/TR/SVG/struct.html#ConditionalProcessingSystemLanguageAttribute, the systemLanguage attribute says:

> Evaluates to "true" if one of the language tags indicated by user preferences is a case-insensitive match of one of the language tags given in the value of this parameter, or if one of the language tags indicated by user preferences is a case-insensitive prefix of one of the language tags given in the value of this parameter such that the first tag character following the prefix is "-".

Document Structure — SVG 2

My interpretation of this is that the correct way is the second one (used in WebKit/Blink) rather than the first one. Looks like I'll have to open a new issue with Firefox …

OTOH, the spec also says:
https://www.w3.org/TR/SVG/struct.html#SwitchElement

> In SVG, when evaluating the ‘systemLanguage’ attribute, the order of evaluation of descendant elements of the ‘switch’ element must be as if the 'allowReorder' attribute, defined in the SMIL specification [SMIL] always has a value of 'yes'.

This means that a UA can reorder them so that the match with the highest q has priority, and this is correct too …

Document Structure — SVG 2

OK I hate the #SVG #switch element now. Both interpretations are correct: the indication about allowReorder is that if true the UA should prioritize languages by the user preference, but the UA is free to ignore it, so one may consider #Firefox to be better adhering to the spec spirit (give the user control), but WebKit/Blink are still correct simply by ignoring the possibility to reorder (which is good for speed).

Now, why is this important for me? Because I have to choose which strategy to implement in my JS of the polyfill for the #SwitchElement in #HTML: so far I've implemented the “fast” way (no reorder), but should I support the other one too?

To clarify, the difference is that with reordering, the reader has priority in choosing the version, without reorder it's the writer that chooses.

Let's say I write a text in Italian, but also produce an English translation. My preference as a writer would be for a reader that understand Italian, even if it's not their preferred language, to read the original Italian text. With the reordering, the user preference for English over Italian means they would get the translation, even if they could understand the original.

Anyway, I implemented the polyfill with reorder too.

One of the interesting advantages of the polyfill is that at least conceptually it can be overridden, for example providing interactive elements to allow users to force a specific language without changing the browser preferences. I'm not sure this is possible in SVG.

BTW if you're unfamiliar with how the #SVG #SwitchElement works, you can see it in action in the printable SVG template I prepared to play @Bouletcorp's “Hybrids” game:

http://wok.oblomov.eu/ludica/ibridi-shading.svg

Whatever text is there, it should be translated in your language (assuming it's one of: en, it, fr, de, ca, es, pt —if yours isn't there, and you let me know the singular for dice and player, I'll try adding them.)

Long form blog post about my attempts at bringing the #SVG #SwitchElement to #HTML
http://wok.oblomov.eu/tecnologia/switch-element/

And yes, I've been lazy. There's at last three SVG examples of #switch (BTW, contributions for currently unsupported languages are welcome), and only one small test file for HTML polyfill.

There's two reasons for that:
1. it's late
2. I actually want to have interesting content to try the switch on.

The <switch> element

Things I wish HTML inherited from SVG: the <switch> element

wok
@oblomov @Bouletcorp this is what I see
@u0421793 Looks like your browser is configured for English as user preferred language?