API:Languagesearch

From MediaWiki.org
Jump to navigation Jump to search
Other languages: English

GET Request to search for a language in any script by its name, ISO code or native name

API documentation[edit]




action=languagesearch

(main | languagesearch)
  • This module requires read rights.
  • Source: UniversalLanguageSelector
  • License: GPL-2.0-or-later

Search for language names in any script.

Parameters:
search

Search string.

This parameter is required.
typos

Number of spelling mistakes allowed in the search string.

Type: integer
Default: 1

Example[edit]

GET Request[edit]

Response[edit]

{
    "languagesearch": {
        "gu": "gujarati",
        "gaa": "ga",
        "gn": "guarani",
        ...
    }
}

Sample code[edit]

languagesearch.py

#!/usr/bin/python3

"""
    languagesearch.py

    MediaWiki Action API Code Samples
    Demo of `Languagesearch` module: Search for a language in any language
    MIT license
"""

import requests

S = requests.Session()

URL = "https://en.wikipedia.org/w/api.php"

LANG_NAME = "Gu" #Could be name of the language, its iso code or native name

PARAMS = {
    'action':"languagesearch",
    'search':LANG_NAME,
    'format':"json"
}

R = S.get(url=URL, params=PARAMS)
DATA = R.json()

print(DATA['languagesearch'])

Demo app(s)[edit]

  • Screenshot of Universal Language Selector tool that uses this API
    Primarily used by the Extension:UniversalLanguageSelector that allows users to select a language and configure its support in an easy way.
  • Telegram translation bot that accepts input via chat message for language selection. Link to the code using the API is here.

Possible errors[edit]

Code Info
nosearch The "search" parameter must be set

Additional notes[edit]

  • Internally, this API stores a very long list of language names in many different languages. The major source for this list is Common Locale Data Repository along with a few manual additions.

See also[edit]