Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retrieving the translation section in the Wiktionary API

I am interested in translating English words to a specific language (e.g. Russian). I have read the whole Wiktionary API manual but I have not found a good way. For the word “dog” I can obtain the whole section that contains translations to other languages, by using the wiktionary API in the following way:

http://en.wiktionary.org/w/api.php?action=query&titles=dog&prop=revisions&rvprop=content&rvsection=11

The translations section number is not constant and it is different for various words. For “dog” the translation section number is 11 but for “cat” I need rvsection=7. Is it possible to obtain a translation to a specific language for any English word without downloading the whole translation section?

like image 396
Krzysztof Avatar asked Oct 17 '25 12:10

Krzysztof


2 Answers

You can get quite a lot of the translations by requesting the interwiki links from the API. I have written a simple JS app using this approach: http://jsfiddle.net/karlb/PxfrJ/11/ .

like image 91
Karl Bartel Avatar answered Oct 20 '25 03:10

Karl Bartel


You can use this to help translate "dog" from English to Russian. This URL finds the internal links that start with "ru" for pages with the title "dog" : https://en.wiktionary.org/w/api.php?action=query&prop=iwlinks&titles=dog&iwprop=url&iwprefix=ru&format=json&continue=

I emphasize help because you will get many ambiguous translations which you might want to disambiguate using categories and other things.

That URL has "iwprop=url" so you can easily click the links but in your application I suggest you use this: https://en.wiktionary.org/w/api.php?action=query&prop=iwlinks&titles=dog&iwprefix=ru&format=json&continue= and make the links yourself.

like image 33
Justin Harris Avatar answered Oct 20 '25 03:10

Justin Harris