Page MenuHomePhabricator

Adapt ContentTranslation to using the TemplateTranslation Lua module
Closed, DeclinedPublic


At Wikimania 2016 I met @Blahma, who showed me Lua modules that he wrote to adapt templates between languages. It can easily solve some of the template adaptation issues that we have in CX in a scalable way—it will put most of the parameter adaptation work in the hands of the editor communities.

I tested it in the Czech and the Hebrew Wikipedias, and it works.

The way in which it works is this:

  • It has the main Lua module. In cs.wikipedia it's . It implements the generic template adaptation code, which works for all templates. It adapts templates from other modules into Czech (cs).
  • For every source language there is a module in a subpage with the source language code, for example, for Slovak it's It defines a list of templates that can be adapted.
  • For every template there is a module in a subpage, such as . "Infobox Slovenská obec" is the name of the template in the source language, and this module defines the name of the target language template ("Infobox - sídlo světa"), and maps between the parameters. The mapping can be simple, just copying the values (o['jméno'] = i['Názov']), and it can also do other transformation if needed (o['název celku 3'] = '[[' .. i['Región'] .. ']]').
  • The module is invoked by writing: `{{#invoke:TemplateTranslation/sk|Infobox Slovenská obec|` ... and then all the arguments are copied from the source template.

Invoking the module creates a template that is adapted to the target language. It can also be invoked as {{subst:#invoke....

What we can do in CX is the following:

  • When encountering a template (e.g. {{Cite web|param1 = value1|param2 = value2}}) in the source language (e.g. "en") check whether the target language has [[Module:TemplateTranslation/en/Cite web]].
  • If it exists, insert {{subst:#invoke:TemplateTranslation/en|Cite web|param1 = value1|param2 = value2}} to the translation.

We can also move the json template adaptation files that we currently have to this, and let the communities maintain them.

Event Timeline

Amire80 created this task.Jun 26 2016, 1:28 PM
Restricted Application added subscribers: Zppix, Aklapper. · View Herald TranscriptJun 26 2016, 1:28 PM
Amire80 renamed this task from Adapt ContentTranslation to using the TemplateTranslation module to Adapt ContentTranslation to using the TemplateTranslation Lua module.Jun 26 2016, 1:56 PM
Amire80 moved this task from Needs Triage to Bugs on the ContentTranslation board.Jul 4 2016, 2:31 PM

Adding to ContentTranslation-out-of-beta. We won't necessarily do it precisely this way, but we'll at least do something related.

Blahma added a comment.Jul 4 2016, 5:22 PM

Does it therefore make sense that I now ask a volunteer programmer from the Czech Wikipedia community to start creating Lua modules that work this way? Or should we rather wait for the new solution be implemented first?

The answer probably depends laso on whether that new solution will be something universal, such that it can be used also in common editing, both in VisualEditor and wikitext - like in the case of the present solution.

Template translation is actually a general MediaWiki problem, rather than limited to ContentTranslation. Any final approach addressing this problem should therefore, in my opinion, preserve such universality.

To save the community even more work, information from TemplateData should be utilized whenever applicable (such as to determine the recommended order of parameters on the output - which is mostly a matter of convenience, but important to people who edit wikitext, such as in infoboxes). The proposed solution does not do this at the moment, so the order of parameters and whether they are obligatory must be provided explicitely.

Amire80 triaged this task as Normal priority.Jul 22 2016, 1:28 PM
Amire80 closed this task as Declined.Sep 7 2016, 12:25 PM

Closing this.

The actual implementation will probably be as detailed in T143857, although the work by @Blahma was definitely an inspiration. Thanks!