Wikipedia's API query - problem with getting data in different language

Wikipedia's API query - problem with getting data in different language
0

#1

Hello there,

I’m getting lots of usage out of the Wiki API Sandbox, it’s a really useful tool.

The generaterd URL query is good, i get the wanted content, but i don’t know where to find the proper setting for different languages.

Look at those two URLs:

  1. Looking for a term in english:

https://en.wikipedia.org/w/api.php?action=query&format=json&prop=extracts&callback=&utf8=1&formatversion=latest&exlimit=1&exintro=1&explaintext=1&exsectionformat=plain&exvariant=pl&titles=Poland

(I couldn’t post the link because of the built-in tool, but this above is what you get when click on the link ended with “&titles=Poland”)

  1. And then the same word in polish language ("&titles=Polska"):

https://en.wikipedia.org/w/api.php?action=query&format=json&prop=extracts&callback=&utf8=1&formatversion=latest&exlimit=1&exintro=1&explaintext=1&exsectionformat=plain&exvariant=pl&titles=Polska

I see that in the FreeCodeCamp’s preview project the phrase is looked up no matter which language i choose:
https://codepen.io/FreeCodeCamp/full/wGqEga/

Is there a setting in the wiki’s API that fixes this language problem?


#2

Hello @sebastianhew I think it has to do with the query string you use, for example:

English - http://en.wikipedia.org
French - https://fr.wikipedia.org
Russian - https://ru.wikipedia.org


#3

I know, but there must be some kind of redirecting setting. In the FreeCodeCamp’s project i linked above, it gives a proper response no matter what language is chosen. I could type “Polonge” and it redirects to “Poland” somehow


#4

That interesting. When I type ‘Polonge’ in mine it returns nothing at all… When I type ‘Poland’ it returns 10 English articles. When I type ‘Polska’ I again get 10 English articles.

I think perhaps I am misunderstanding the issue you are seeing?

When I changed the URL to https://ru.wikipedia.org in my program everything came back in Russian…


#5

Try typing “Pologne” here : https://codepen.io/FreeCodeCamp/full/wGqEga/

You will get results in english, no matter which language you choose. I don’t know how to do this . And i assume there’s no link switching here.


#6

You appear to be using:

var api = ‘https://en.wikipedia.org/w/api.php?format=json&action=query&generator=search&gsrnamespace=0&gsrlimit=10&prop=pageimages|extracts&pilimit=max&exintro&explaintext&exsentences=1&exlimit=max&gsrsearch=’;

for all the queries. Everything is suppose to come back in English.

When I edited your code to point at the ru Russian website your webpage responded in Russian!


#7

From your codepen:

Click to Enlarge…


#8

Your link works fine. I think it couldn’t work because i wasn’t using search generator in my query, so it’s kind of logical that when i try to get the text in proper language i can’t automatically change the language (first of all because there are articles that doesn’t have other language versions)


#9

Yes, I don’t think you can get to to response automatically, best you could do maybe is pick a few languages and allow the user to pick one which would then pick the appropriate query string.

But I could be wrong. If you find a way to make it work please post back, I’d be very interested in seeing it work…