Page MenuHomePhabricator

Add API to check language code validity / get all valid language codes
Closed, ResolvedPublic

Related Objects

Event Timeline

Well, which one is it – do we add an API to check language code validity, or one to get all valid language codes? :)

Personally, I’d favor one to get all valid language codes for lexeme terms (i. e. lemmas, representations and glosses – currently we use the same validator for all of them), and expose it perhaps via action=query&meta=siteinfo as a new siprop.

Alternatively, for client-side checking we could also expose the list via a ResourceLoader module?

It seems that we do this differently for Monolingual texts atm: There this is handled via wikibase.WikibaseContentLanguages which is basically an access wrapper for mw.config.get( 'wgULSLanguages' ) (some languages supported by the backed are missing, though). This is being discussed in T124758.

Input validation is then being handled by the api (after an attempt save).

Talking to @Addshore, we probably want to go for something along the lines of [[https://www.wikidata.org/w/api.php?action=query&meta=wikibasecontentlanguages&context=gloss|action=query&meta=wikibasecontentlanguages&context=gloss]].

One question I just came across… what language shall we show the available languages in? Shall we use autonyms (native names)? What about languages that are not in CLDR?

We can either integrate these names into the API output (which is ok for autonyms, but maybe a little uggly otherwise, if this depends on the user's lang) or fetch them from ULS (as far as they're available… does ULS have all CLDR langs?).

Alternatively we could just resort to language codes and not show any names…

Autonyms where possible. We do it in other places as well.

What’s the problem with including the names in the user language in the API output? That doesn’t feel ugly to me.

Perhaps the output structure could be something like this:

"wikibasecontentlanguages": {
  "en": {
    "code": "en",
    "autonym": "English",
    "name": "inglés"
  },
  // ...
}

with some kind of wbclprops parameter to select what you want (wbclprops=code|autonym|name).

Lucas_Werkmeister_WMDE added a subscriber: hoo.

Since I’m running out of other things to do, I’ll take a stab at implementing one suggestion for such an API module.

Change 452710 had a related patch set uploaded (by Lucas Werkmeister (WMDE); owner: Lucas Werkmeister (WMDE)):
[mediawiki/extensions/Wikibase@master] WIP: Centrally collect various kinds of content languages

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

Change 452711 had a related patch set uploaded (by Lucas Werkmeister (WMDE); owner: Lucas Werkmeister (WMDE)):
[mediawiki/extensions/Wikibase@master] WIP: Add API to query content languages

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

Change 452712 had a related patch set uploaded (by Lucas Werkmeister (WMDE); owner: Lucas Werkmeister (WMDE)):
[mediawiki/extensions/WikibaseLexeme@master] Register lexicographical content languages

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

Change 454238 had a related patch set uploaded (by Hoo man; owner: Hoo man):
[mediawiki/extensions/Wikibase@master] Add WikibaseContentLanguagesProvider

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

Change 452710 merged by jenkins-bot:
[mediawiki/extensions/Wikibase@master] Centrally collect various kinds of content languages

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

Change 452712 merged by jenkins-bot:
[mediawiki/extensions/WikibaseLexeme@master] Register lexicographical content languages

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

Change 452711 merged by jenkins-bot:
[mediawiki/extensions/Wikibase@master] Add API to query content languages

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

Change 454238 abandoned by Hoo man:
Add WikibaseContentLanguagesProvider

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