Page MenuHomePhabricator

Make an extension that will make {{lang-*}} templates global
Open, Needs TriagePublic

Description

The English Wikipedia has templates such as {{lang-fr}}, which put text into <span lang="fr"> tags. This is useful in every page that involves text in any foreign language, and since there are so many such articles in wiki sites in all languages, such templates are useful everywhere. At the moment, however, they have to be recreated in every wiki separately because we don't have global templates.

Plain HTML could be used, in theory, but actually it's not so good for several not-necessarily-obvious reasons:

  • It's longer to type.
  • It would be useful to deduce the default direction (dir attribute: ltr or rtl) from the language. HTML cannot do this, and writing it manually every time is inconvenient.
  • The lang and dir attributes work differently in different browsers. In particular, current versions of Firefox and Chrome implement automatic bidirectional isolation for every tag that has a dir attribute, so there's no need for RLM/LRM characters, unicode-bidi: isolate CSS, or a <bdi> tag. Microsoft Internet Explorer and Edge, however, don't seem to implement isolation, even though it has been specified in the HTML standard in one way or another since 2011, so they also need RLM/LRM characters to ensure correct display. Some day when these browsers become old and rare it will be possible to remove these no-longer-necessary control characters and use only pure language semantics, and it would be nice to be prepared for that by making their application centralized.

How exactly should it be implemented? One option is an extension with implementation of these templates as Lua modules, so they would be essentially global. Another option is adding a parser function, similarly to the Babel extension, although I am more inclined to the Lua option, because it will be an easier transition from the current implementation as a template.

Event Timeline

Amire80 created this task.Jun 4 2017, 8:00 AM
Restricted Application added a project: I18n. · View Herald TranscriptJun 4 2017, 8:00 AM
Restricted Application added a subscriber: Aklapper. · View Herald Transcript
Huji added a subscriber: Huji.EditedJun 4 2017, 9:38 AM

I like this idea. But I want to point out the obvious fact that the {{lang-*}} templates don't just add a <span> tag but also adds some descriptive text including the name of the language in the localized form. For instance, in English Wikipedia {{lang-fa|فلان}} will generate this output: <a href="/wiki/Persian_language" title="Persian language">Persian</a>: <span dir="rtl" xml:lang="fa" lang="fa">فلان</span>‎‎ and the output is different in German Wikipedia, Greek Wikipedia, etc.

Possible options we have include:

  • Using a different naming convention for the new global templates that *just* generate the <span> tag (e.g. {{lang-span-*}}) and then use them inside the existing {{lang-*}} templates in each WMF wiki
  • Use {{lang-*}} as the name for the new global templates, but make it such that is also generates the rest of the output, e.g. link to the language page, parentheses (in those wikis where their lang-* templates surrounds the output in parentheses), etc.

The problem with option 2 being that it requires a lot of i18n work, a lot of cross-checking to make sure we match the existing output of the existing templates on all wikis, etc. The problem with option 1, of course, is adoption (why bother changing your code to use a global template, when you already have it built into your template with some extra amount of code?)

True.

Of course, we need to do support both options: with and without the label with the language names. And possibly other forms as well.

The first description is just an initial idea, and it needs development. We also need to research the current templates, and not only in the English Wikipedia, but in the other projects as well.

We can probably pull the language names from CLDR.

TheDJ added a subscriber: TheDJ.EditedJun 4 2017, 6:57 PM

One more problem that could easily be solved if we had global modules/templates/ T121665: Investigation: Central global repository for templates, Lua modules and gadgets

Yes, but since we don't...

Amire80 moved this task from Untriaged to RTL on the I18n board.Feb 26 2018, 10:38 AM