Lokal_Profil
Lokal_Profil

Reputation: 394

How to get all allowed languages for Wikidata

I'm writing a tool for interacting with Wikidata where labels and descriptions are added to items. But I would like to validate that the language is supported before trying to add it.

So my question is how do I get a list of the allowed language codes. The documentation describes this as UserLanguageCode but gives no info on retrieving the allowed values.

I know I can get a list of all of the used languages by doing the following SQL operation on the database, but that is both slow and inefficient: SELECT DISTINCT term_language FROM wb_terms.

As an aside is the list of allowed languages the same for MonolingualText statements?

Upvotes: 4

Views: 323

Answers (2)

Lucas Werkmeister
Lucas Werkmeister

Reputation: 2742

There is now an API for getting the supported content languages (API sandbox):

https://www.wikidata.org/w/api.php?action=query&meta=wbcontentlanguages&wbclcontext=term&format=json&formatversion=2

By default it just returns the language code, but you can add the name and/or autonym (name in that language) via the wbclprop parameter. (To control the language in which the name is returned, set the global uselang parameter.)

To get allowed monolingual text languages, set wbclcontext to monolingualtext instead of term; on Wikidata, you can also set it to term-lexicographical for all language codes supported on lexicographical data (almost but not quite identical to the term languages).

Upvotes: 4

pintoch
pintoch

Reputation: 2468

User hoo on IRC channel #wikidata found this solution:

Get the JSON payload at this address:

https://www.wikidata.org/w/api.php?action=paraminfo&modules=wbsetlabel

And extract

 modules[0].parameters[8].type

There are indeed less languages in this list than all the UI languages for MediaWiki.

Upvotes: 3

Related Questions