Jump to content
MediaWiki

API:Languagesearch/fr

From mediawiki.org
This page is a translated version of the page API:Languagesearch and the translation is 76% complete.
Cette page fait partie de la documentation de l'API MediaWiki Action.
API MediaWiki Action
Fonctions de base
Authentification
Comptes et utilisateurs
Opérations sur les pages
Chercher
Outils pour les développeurs
Tutoriels
v · d · e

requête GET pour chercher une langue dans un script suivant le nom, code ISO ou nom natif du langage

Documentation de l'API

La documentation qui suit est le résultat de Special:ApiHelp/languagesearch, généré automatiquement par la version pre-release de MediaWiki utilisée sur ce site (MediaWiki.org).

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

Exemple

Requête GET

Réponse

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

Exemple de code

Python

#!/usr/bin/python3
"""
 languagesearch.py
 MediaWiki API Demos
 Demo of `Languagesearch` module: Search for a language in any language
 MIT License
"""
importrequests
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
*/
varurl="https://en.wikipedia.org/w/api.php";
varparams={
action:"languagesearch",
search:"Gu",
format:"json"
};
url=url+"?origin=*";
Object.keys(params).forEach(function(key){url+="&"+key+"="+params[key];});
fetch(url)
.then(function(response){returnresponse.json();})
.then(function(response){
varlangs=response.languagesearch;
for(varlanginlangs){
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
*/
varparams={
action:'languagesearch',
search:'Gu',
format:'json'
},
api=newmw.Api();
api.get(params).done(function(data){
varlangs=data.languagesearch,
lang;
for(langinlangs){
console.log(lang+': '+langs[lang]);
}
});

Applications de démonstration


Erreurs possibles

Code Information
nosearch Le paramètre search doit être défini.

Notes supplémentaires

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

Voir aussi

AltStyle によって変換されたページ (->オリジナル) /