Page MenuHomePhabricator

Create API module for language autodetection
Closed, InvalidPublic

Description

Various part of MediaWiki (such as the installer, or ULS) autodetect the language of a request and match it to the closest MediaWiki / Translatewiki language code, but the capability is not exposed via the API.

There should be a single service that does this, it should be part of MediaWiki core, and it should be available from the API (maybe as part of userinfo), so that tools which use Wikimedia's internationalization system can easily find the best supported language. In a first approximation, the internal logic should probably be something like this:

  • if the user is logged in, use the interface language
  • allow extensions to provide a language via a hook (ULS would check for the language cookie here)
  • parse the Accept-Language header, go through it in decreasing order of priority, and try to match language tags or the first components of language tags to MediaWiki language names.

Event Timeline

Tgr created this task.Apr 27 2018, 1:53 PM
Restricted Application added a subscriber: Aklapper. · View Herald TranscriptApr 27 2018, 1:53 PM
Anomie closed this task as Invalid.Apr 27 2018, 2:32 PM
Anomie added a subscriber: Anomie.

Closing as invalid because this already exists.

In T193247, @Tgr wrote:

Various part of MediaWiki (such as the installer, or ULS) autodetect the language of a request and match it to the closest MediaWiki / Translatewiki language code

The installer just uses the Accept-Language header. You could easily enough duplicate this with a query like https://www.mediawiki.org/w/api.php?action=query&meta=userinfo|siteinfo&uiprop=acceptlang&siprop=languages and then find the first code from 'acceptlang' which is in 'languages', which is pretty much what the installer does.

ULS hooks into the standard uselang handling, so you should be able to simply use a query like https://www.mediawiki.org/w/api.php?action=query&uselang=user&responselanginfo=1 to get the effective language. I don't know of a wiki with $wgULSAnonCanChangeLanguage true to fully test it, though.

Tgr added a comment.Apr 27 2018, 3:20 PM

Not having to duplicate the logic in every client is exactly the point, especially because the logic will hopefully become more sophisticated in the future (geoip etc) and clients that are written today should get such improvements for free.

The problem with querying the user language is that it is limited by caching considerations (which is while Wikimedia wikis just force English on everyone who is not logged in) while clients might not be. Granted, using a different language from the wiki UI can also be confusing (in the case of a gadget or browser extension).

Not having to duplicate the logic in every client is exactly the point,

What's to duplicate? It's already just one API call, namely https://www.mediawiki.org/w/api.php?action=query&uselang=user&responselanginfo=1

The problem with querying the user language is that it is limited by caching considerations (which is while Wikimedia wikis just force English on everyone who is not logged in) while clients might not be.

You seem to be proposing that ULS would also have to hook some new hook to do more or less the same thing it already does except without having $wgULSAnonCanChangeLanguage to disable it.

Granted, using a different language from the wiki UI can also be confusing (in the case of a gadget or browser extension).

Indeed.

Vvjjkkii renamed this task from Create API module for language autodetection to c3daaaaaaa.Jul 1 2018, 1:13 AM
Vvjjkkii reopened this task as Open.
Vvjjkkii triaged this task as High priority.
Vvjjkkii updated the task description. (Show Details)
Vvjjkkii removed a subscriber: Aklapper.
Yann renamed this task from c3daaaaaaa to Create API module for language autodetection.Jul 1 2018, 1:16 PM
Yann raised the priority of this task from High to Needs Triage.
Yann updated the task description. (Show Details)
Yann closed this task as Invalid.
Yann added a subscriber: Aklapper.