Jump to content

API:Languagesearch/ru: Difference between revisions

From mediawiki.org
Content deleted Content added
FuzzyBot (talk | contribs)
Updating to match new version of source page
FuzzyBot (talk | contribs)
Updating to match new version of source page
 
(2 intermediate revisions by the same user not shown)
Line 9: Line 9:
</div>
</div>


{{Api help|languagesearch|frame=yes}}
{| style="color: black; background-color: #f8f8f8; border-spacing: 20px; border: 1px solid darkgray;"
|{{Api help|languagesearch}}
|}


<div lang="en" dir="ltr" class="mw-content-ltr">
<div lang="en" dir="ltr" class="mw-content-ltr">
Line 56: Line 54:


* [[File:ULS-GeoIP.png|thumb|212x212px|<span lang="en" dir="ltr" class="mw-content-ltr">Screenshot of Universal Language Selector tool that uses this API</span>]] <span lang="en" dir="ltr" class="mw-content-ltr">Provided and primarily used by the {{ll|Extension:UniversalLanguageSelector}} that allows users to select a language and configure its support in an easy way.</span>
* [[File:ULS-GeoIP.png|thumb|212x212px|<span lang="en" dir="ltr" class="mw-content-ltr">Screenshot of Universal Language Selector tool that uses this API</span>]] <span lang="en" dir="ltr" class="mw-content-ltr">Provided and primarily used by the {{ll|Extension:UniversalLanguageSelector}} that allows users to select a language and configure its support in an easy way.</span>
* <span lang="en" dir="ltr" class="mw-content-ltr">[https://github.com/roni93/TransBot/ Telegram translation bot] that accepts input via chat message for language selection. Link to the code using the API is [https://github.com/roni93/TransBot/blob/master/MediaWikiAPI.js#L184 here].</span>
* <span lang="en" dir="ltr" class="mw-content-ltr">[https://github.com/roni93/TransBot/ Telegram translation bot] that accepts input via chat message for language selection.</span> <span lang="en" dir="ltr" class="mw-content-ltr">See [https://github.com/roni93/TransBot/blob/master/MediaWikiAPI.js#L184 the code using the API].</span>




Line 78: Line 76:
* <span lang="en" dir="ltr" class="mw-content-ltr">Internally, this API stores a very long list of language names in many different languages. The major source for this list is [[w:Common_Locale_Data_Repository|Common Locale Data Repository]] along with a few manual additions.</span>
* <span lang="en" dir="ltr" class="mw-content-ltr">Internally, this API stores a very long list of language names in many different languages. The major source for this list is [[w:Common_Locale_Data_Repository|Common Locale Data Repository]] along with a few manual additions.</span>


<span id="See_also"></span>
== См. также ==
== См. также ==



Latest revision as of 21:41, 1 March 2026

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

API documentation

action=languagesearch

(main | languagesearch)

Search for language names in any script.

Specific parameters:
Other general parameters are available.
search

Search string.

This parameter is required.
typos

Number of spelling mistakes allowed in the search string.

Type: integer
Default: 1

Example

GET request

Response

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

Sample code


Python

#!/usr/bin/python3

"""
    languagesearch.py

    MediaWiki API Demos
    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"

PARAMS = {
    "action": "languagesearch",
    "search": "Gu", #Could be name of the language, its iso code or native name
    "format": "json"
}

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

LANG = DATA['languagesearch']
for code, name in LANG.items():
    print(code + ": " + name)

PHP

<?php
/*
    languagesearch.php

    MediaWiki API Demos
    Demo of `Languagesearch` module: Search for a language in any language

    MIT License
*/

$endPoint = "https://en.wikipedia.org/w/api.php";
$params = [
    "action" => "languagesearch",
    "search" => "Gu",
    "format" => "json"
];

$url = $endPoint . "?" . http_build_query( $params );

$ch = curl_init( $url );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
$output = curl_exec( $ch );
curl_close( $ch );

$result = json_decode( $output, true );

foreach( $result["languagesearch"] as $langcode => $langname ) {
    echo( $langcode . ": " . $langname . "\n" );
}

JavaScript

/*
    languagesearch.js

    MediaWiki API Demos
    Demo of `Languagesearch` module: Search for a language in any language

    MIT License
*/

var url = "https://en.wikipedia.org/w/api.php"; 

var params = {
    action: "languagesearch",
    search: "Gu",
    format: "json"
};

url = url + "?origin=*";
Object.keys(params).forEach(function(key){url += "&" + key + "=" + params[key];});

fetch(url)
    .then(function(response){return response.json();})
    .then(function(response) {
        var langs = response.languagesearch;
        for (var lang in langs) {
            console.log(lang + ": " + langs[lang] );
        }
    })
    .catch(function(error){console.log(error);});

MediaWiki JS

/*
	languagesearch.js

	MediaWiki API Demos
	Demo of `Languagesearch` module: Search for a language in any language

	MIT License
*/

var params = {
		action: 'languagesearch',
		search: 'Gu',
		format: 'json'
	},
	api = new mw.Api();

api.get( params ).done( function ( data ) {
	var langs = data.languagesearch,
		lang;
	for ( lang in langs ) {
		console.log( lang + ': ' + langs[ lang ] );
	}
} );

Demo app(s)


Possible errors

Code Info
nosearch Параметр search должен быть задан.

Additional notes

  • 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.

См. также