Page MenuHomePhabricator

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


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

Restricted Application added a subscriber: Aklapper. · View Herald Transcript

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?)


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.

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