Page MenuHomePhabricator

Develop a generic stand-alone service that adapts templates across wikis
Open, Needs TriagePublic

Description

Many templates have similar functionality in different wikis. There are several tasks and proposals to make the storage of such templates fully global: T52329, T66474, T6547, T121470, Global templates, etc.

Another thing could be done, whether the templates are fully global or not: A generic stand-alone service that adapts templates across wikis.

If templates are truly global, it will be easier to build such a thing. Indeed, such a service will be necessary for global templates to be effective. However, it's possible to make such a thing already now, while templates are not yet global. The Content Translation extension is currently able to adapt templates between languages, mostly by using Wikidata sitelinks, parameter names, and TemplateData aliases. This logic from Content Translation could be made autonomous and stand-alone, as a step to a full independent service of this kind.

Here's a simplistic example of how it will work. To adapt a transclusion of the Verse translation template with some content from English to Portuguese, it will post the following structure:

{
    sourcewiki: "enwiki",
    targetwiki: "ptwiki",
    template: "{{Cite encyclopedia|title=Lin Shu|year=1852|encyclopedia=Encyclopedia Translationica|publisher=Hundred Rivers Publishing House|location=Baichuan}}"
}

And it will get the following output:

{
    template: "{{Citar enciclopédia|titulo=Lin Shu|ano=1852|enciclopédia=Encyclopedia Translationica|publicado=Hundred Rivers Publishing House|local=Baichuan}}"
}

So:

  • The template name Cite encyclopedia is translated to Citar enciclopédia. This can be done now using sitelinks.
  • The parameters are translated:
    • title ➡️ titulo
    • year ➡️ ano
    • encyclopedia ➡️ enciclopédia
    • publisher ➡️ publicado
    • location ➡️ local

The parameter names can currently be mapped using TemplateData aliases. It's not perfect, but it works for Content Translation. It should become more structured in the Global templates age.

The parameter values are not translated in this example, and this shouldn't be a requirement for the first version of this service. Perhaps this can be added as a feature further down the road. The initial scope for this feature is just about translating the template title and parameter names as quickly and reliably as possible, without having to look them up manually in documentation.

If there is a nested template in the parameter value, the service should probably attempt to adapt it recursively, at least by default.

Having such a service independently of Content Translation will allow easier template handling in more contexts where it is useful. For example:

Visual Editor: It will be possible to copy a template (Ctrl-C) in one wiki and paste it (Ctrl-V) in another wiki . If the templates are properly mapped to each other, it will just work. Of course, the editor will probably have to change the parameter values, but the step of looking up the parameter names will disappear, which will be a significant improvement. This will probably also work in the 2017 wiki text editor.

2017 wikitext editor: It can probably be like in the Visual editor (see previous point), because it can do automatic transformations of wiki syntax.

Classic wikitext editor: It will be possible to have a stand-alone tool or a dialog box in the wiki text editor where the user will post the source template, indicate the source and the target languages, push a button, and get wiki text that can be pasted. Here's a mockup of how it can look like:

Step one: While editing an article, press an "Adapt template" button in the toolbar, and get this window:

צילום מסך 2020-11-19 בשעה 15.43.56.png (1×1 px, 41 KB)

Step two: Copy the template wikitext from another wiki. Select the language from which you copied. Paste it to the top textarea. After a few seconds, the bottom textarea shows the adapted template. Click "Insert" to add it:

צילום מסך 2020-11-19 בשעה 15.47.55.png (1×1 px, 90 KB)

Nothing will change in the frontend user interface of Content Translation. Internally, it will switch to using this service instead of using its own built-in template adaptation logic.

(In these mockups above, the adaptation is from English to Portuguese, as in the task description. The user interface is in English for easier understanding by everyone, but in reality the user interface will be in the language of the current wiki, in this case Portuguese.)

Here's a very high-level flowchart for the whole thing:

Template_adaptation_service_flowchart.svg.png (1×1 px, 288 KB)

Event Timeline

Amire80 renamed this task from develop a generic stand-alone service that adapts templates across wikis to Develop a generic stand-alone service that adapts templates across wikis.Feb 10 2020, 5:29 PM

Connected to this task proposal had 203 supporters in Community Wishlist Survey 2021.

I always appreciate your writeups, @Amire80 :)

such a service will be necessary for global templates to be effective. However, it's possible to make such a thing already now, while templates are not yet global.

Still true, I reckon. What's next for this? Looks like it got solid support in the 2021 wishlist, are there unresolved complexities to work out?

Along the lines of future dreams / completions, potential improvements when hitting a snag:

  1. When no translation is found, after "not available on the target wiki", ask "would you like to [[ link | translate the template ]], or [[ link | request a translation ]]?
  2. When parameters aren't found, after "their structure is different", say "here is a partially-translated template" and provide a best-effort translation with those params that seem to have clear matches.
In T243150#7462921, @Sj wrote:

I always appreciate your writeups, @Amire80 :)

Thank you, it means a lot ❤️

such a service will be necessary for global templates to be effective. However, it's possible to make such a thing already now, while templates are not yet global.

Still true, I reckon. What's next for this? Looks like it got solid support in the 2021 wishlist

Just to be precise, it's the Community Wish that got the most votes ever :)

are there unresolved complexities to work out?

Actually writing the code ;)

It's much less complicated than implementing the whole global templates system, but does require some work. I've done very little coding lately so I can't say how much exactly.

See T288568, though; it's marked as stalled at the moment, but it's probably not stalled forever.

Along the lines of future dreams / completions, potential improvements when hitting a snag:

  1. When no translation is found, after "not available on the target wiki", ask "would you like to [[ link | translate the template ]], or [[ link | request a translation ]]?
  2. When parameters aren't found, after "their structure is different", say "here is a partially-translated template" and provide a best-effort translation with those params that seem to have clear matches.

Yes, as future directions these definitely make sense.

Another future thing that I'd love and that many people have asked for is automatic parameter values adaptation. This task is only about parameter names. But I'd love to avoid scope creep, so the keyword is "future" :)

The alias-based approach may work when the original language is English, but likely won’t if it’s anything else (why would an enwiki template have Portuguese aliases?). Maybe a TemplateData maps mapping? In case of citation templates, the existing Citoid mapping could also be reused.

Yes. Reliance on aliases is a hack. Adding a dedicated property for parameters mapping is quite necessary. There should be a separate task for it, however—this one is only about refactoring cxserver to be usable outside Content Translation: "This logic from Content Translation could be made autonomous and stand-alone".

@Amire80 @Tacsipacsi @Lectrician1 this is obviously an extremely high value idea. What's the best way to help get it onto a roadmap?

  1. 8hrs for T288568
  2. define a related task for parameter mapping / parameter-value adaptation
  3. define an umbrella [spike] to discuss how to make this work, so these tickets can remain compact tasks
  4. tag this with something more than MW-Templates. Maybe editing + multilingual support? (this isn't just a tweak to template function, it is fundamental to editing workflows + giving more leverage to small communities, for the same reason templates exist)

NB a related idea was ~25th on this year's wishlist, but with a slightly different framing.