Page MenuHomePhabricator

Allow translatable templates to be shown in the user interface language
Open, MediumPublicFeature

Description

Usually, templates are a part of wiki page content, so translatable templates that are embedded in a page are shown in the page's language.

However, sometimes a template is more like user interface, and should be shown in the user interface language. Example: https://translatewiki.net/wiki/Template:Archivelink

I tried replacing it with https://translatewiki.net/wiki/Template:Archive_link (note the space)—a similar template that is properly translatable using the Translate extension. However, making it display in the UI language is tricky. The code {{Archive link{{#ifexist:Template:Archive link/{{UILANGCODE}}|/{{UILANGCODE}}|}}|/Archive}} works, but in addition to being not so readable, it also causes the {{Archive link}} template not to appear on Special:WhatLinksHere, and this is not great.

So it would be nice to have this feature in a less hacky way.

Event Timeline

Unfortunately using the UI language splits the parser cache by UI language, which can easily lead to an uncontrollably growing disk usage. It’s not by chance that {{UILANGCODE}} works only on translatewiki.net and not on WMF wikis. So if this feature gets implemented, we should get a green light from the Performance-Team before enabling it in Wikimedia production—and I fear we won’t get it. However, it doesn’t mean that the feature shouldn’t be implemented; if you’re comfortable with enabling it on translatewiki.net, it can be feature-flagged. If it gets green light on WMF, I’d be more than happy, as several templates use various workarounds to appear in UI language (one of them below), and they could be cleaned up.


Another hackish solution, which is widespread on mediawiki.org and Meta, and at least results in clean wikicode at the calling place (i.e. https://translatewiki.net/wiki/Project:News in this case) and keeps WhatLinksHere useful, is using a huge #switch around the actual template, like this:

{{#switch:<translate></translate>
|=<!-- here comes the actual template -->
|#default={{Archive link{{#ifexist:Template:Archive link/{{UILANGCODE}}|/{{UILANGCODE}}|}} | {{{1|}}} }}
}}

or, on Wikimedia wikis,

{{#switch:<translate></translate>
|=<!-- here comes the actual template -->
|#default={{#invoke:Template translation|renderTranslatedTemplate|template=Template:Archive link|uselang={{int:lang}}|noshift=1}}
}}

(Wikimedia wikis don’t have {{UILANGCODE}}, but they—at least the major multilingual ones—have Module:Template translation).

These codes work because the <translate></translate> code

  • doesn’t create a translation unit because it’s empty, so translators don’t see phantom translation units;
  • is removed in translations, so the first part (“if empty”) appears when the translation is transcluded;
  • but isn’t removed when directly transcluding the translation original, so the second part (“if not empty”) appears, which then in turn transcludes the correct translations.

(Edit: if you’re to use this, pay attention to turn translation-aware transclusion off, otherwise the translation original will never be transcluded.)

Nikerabbit triaged this task as Medium priority.Aug 1 2022, 11:38 AM
Nikerabbit changed the subtype of this task from "Task" to "Feature Request".

There are some templates setup on GovWiki and Meta-Wiki that work around this - but this would be a handy feature to have as that method can sometimes be prone to errors. Example templates: