Page MenuHomePhabricator

Add a way to query in wikitext whether the current page is translatable/translated
Closed, ResolvedPublicFeature

Description

Sometimes templates are used on both pages translated with the Translate extension and pages not (or manually) translated. Such templates may want to behave one way on translatable and translated pages, but another one on not/manually translated ones, for example:

  • m:Template:Inprogress uses the UI language ({{int:lang}} hack), but I’d like to change it to use the page language on translated pages;
  • m:Template:H:f Help transcludes the extremely expensive {{languages}} template (450+ #ifexist calls per transclusion), even though it makes little sense on pages like Help:Signature, where there’s a <languages/> bar at the top of the page.

If there was a magic word to differentiate between translatable/translated pages and not/manually translated ones, these could produce optimal result on both types of pages.

Event Timeline

Sounds fairly similar to wgTranslatePageTranslation mw.config value in JavaScript. It is 'source' on source pages (Project:Translatable page), 'translation' on translation pages (Project:Translatable page/fr), and unset on all other pages. It wouldn't be difficult to implement, but to me it seems like it would be simpler to use a |lang= parameter for the first example and a parameter to not show or replace the languages template in the second example.

Yes, it can be worked around by passing some parameters, but

  • several recent changes to Translate aim at making users’ life easier (e.g. translation-aware transclusion instead of using {{TNT}} all the time, efforts to make Translate syntax compatible with Parsoid/VisualEditor), and passing an extra parameter is inconvenient, especially if the template is used on a lot of pages or many times per page; and
  • if a parameter needs to be passed, it’s guaranteed that someone, at some point, will leave the parameter out (for example, the suggested |lang= parameter would make no change for a large number of users because the template is translated into only three languages, all other users get the English text, regardless of whether it’s because of the page language or the UI language).
Nikerabbit renamed this task from Allow querying whether the current page is translatable/translated to Add a way to query whether the current page is translatable/translated in wikitext.Sep 7 2021, 12:06 PM
Tacsipacsi renamed this task from Add a way to query whether the current page is translatable/translated in wikitext to Add a way to query in wikitext whether the current page is translatable/translated.Sep 7 2021, 10:52 PM

Change 913677 had a related patch set uploaded (by Tacsipacsi; author: Tacsipacsi):

[mediawiki/extensions/Translate@master] Introduce TRANSLATABLEPAGE magic word

https://gerrit.wikimedia.org/r/913677

Tacsipacsi changed the task status from Open to In Progress.Apr 30 2023, 5:48 PM
Tacsipacsi claimed this task.

Sounds fairly similar to wgTranslatePageTranslation mw.config value in JavaScript. It is 'source' on source pages (Project:Translatable page), 'translation' on translation pages (Project:Translatable page/fr), and unset on all other pages.

I ended up implementing a slightly different logic, matching how <languages /> works rather than how this mw.config value does. The difference is when the page has been prepared for translation but hasn’t been marked yet:

StagewgTranslatePageTranslation config value<languages />
<translate> tags added, page not yet saved (edit preview)nullDoesn’t appear
<translate> tags added, page saved but not yet marked for translation'source'Doesn’t appear
Page marked for translation'source'Appears

I think it would be quite confusing if the magic word worked differently after saving the page than in preview, and introducing a third logic wouldn’t improve the situation either.

Change 913677 merged by jenkins-bot:

[mediawiki/extensions/Translate@master] Introduce TRANSLATABLEPAGE magic word

https://gerrit.wikimedia.org/r/913677