Page MenuHomePhabricator

Tell whether or not a page is translatable via API
Open, Needs TriagePublic

Description

There should be a way to tell whether or not a page is translatable (thus by extension, whether or not it makes sense to add Special:MyLanguage/ in front of it) via the API. The fact that a page is translatable is exposed in the Javascript config in the page source as "wgTranslatePageTranslation":"source", but the same is not possible find via the API.

Event Timeline

While not a very clean solution, {{TRANSLATABLEPAGE}} introduced in T290239 (which is not exactly the same as wgTranslatePageTranslation, see T290239#8815322) can be used: https://meta.wikimedia.org/w/api.php?action=expandtemplates&title=Main%20Page&text={{TRANSLATABLEPAGE}} returns Main Page because it’s translatable, while https://meta.wikimedia.org/w/api.php?action=expandtemplates&title=Template:TNT&text={{TRANSLATABLEPAGE}} returns an empty string because Template:TNT is not translatable.

The solution I ended up with (with help from Nikerabbit IIRC) was to use ?action=parse&prop=modules|jsonconfigvars and check whether "ext.translate" is in "modulestyles". It works, but feels hacky.

whether or not it makes sense to add Special:MyLanguage/ in front of it) via the API

I would just add it everywhere. If the page is not translatable then it should be (unless it is a content wiki mainspace page) or a page on a monolingual wiki.

I see that there are also

{
    "propname": "translate-has-languages-tag"
},
{
    "propname": "translate-is-translation"
},

page props.

So https://meta.wikimedia.org/w/api.php?action=query&format=json&prop=pageprops&meta=&titles=Stewards&formatversion=2&ppcontinue=&ppprop= has former with "1", and https://meta.wikimedia.org/w/api.php?action=query&format=json&prop=pageprops&meta=&titles=Stewards%2Fen&formatversion=2&ppcontinue=&ppprop= has both of them with "1". https://test.wikipedia.org/w/api.php?action=query&format=json&prop=pageprops&meta=&titles=Translatable+page+without+languages+tag&formatversion=2&ppcontinue=&ppprop= does not have any of those, so translatable pages without <languages/> cannot be detected that way it seems, but I can think of few usecases where one would prefer to not have <languages/>

but I can think of few usecases where one would prefer to not have <languages/>

Like any translatable page on translatewiki.net because it's using the interlanguage links functionality.

https://test.wikipedia.org/w/api.php?action=query&format=json&prop=pageprops&meta=&titles=Translatable+page+without+languages+tag&formatversion=2&ppcontinue=&ppprop= does not have any of those, so translatable pages without <languages/> cannot be detected that way it seems, but I can think of few usecases where one would prefer to not have <languages/>

{{TRANSLATABLEPAGE}} doesn’t work on that page either, but I think it’s not because it doesn’t have a <languages/> tag, but rather because you moved the page immediately after marking it for translation, which probably interfered with the job queue jobs of Translate. (Notice that the Translate this page link doesn’t work either, and if you preview the page with <languages/> added, it doesn’t show anything.)

To showcase a non-broken page without <languages/>, translatewiki:Translating:Index, pageprops doesn’t return anything, but expandtemplates does.

(unless it is a content wiki mainspace page) or a page on a monolingual wiki.

Or a discussion page, or a page that contains no language content, or a page that’s in a non-translatable namespace (module, file etc.).