A node module that scrapes translations from Wikipedia pages
npm install wikipedia-translator --save
var translate = require('wikipedia-translator');
// Specify a language:
translate('gato', 'es' function(err, translation) {
console.log(translation);
});
// Or omit the language to default to English:
translate('cheese', function(err, translation) {
console.log(translation);
});
// Results look like this:
{
query: 'cheese',
lang: 'en',
url: 'http://en.wikipedia.org/wiki/cheese',
translations: [{
word: 'kaas',
lang: 'af',
href: '//af.wikipedia.org/wiki/Kaas'
}, {
word: 'cīese',
lang: 'ang',
href: '//ang.wikipedia.org/wiki/C%C4%ABese'
}, {
word: 'جبن',
lang: 'ar',
href: '//ar.wikipedia.org/wiki/%D8%AC%D8%A8%D9%86'
}, {
word: 'queso',
lang: 'an',
href: '//an.wikipedia.org/wiki/Queso'
}, {
word: 'ܓܒܬܐ',
lang: 'arc',
href: '//arc.wikipedia.org/wiki/%DC%93%DC%92%DC%AC%DC%90'
}, {
word: 'quesu',
lang: 'ast',
href: '//ast.wikipedia.org/wiki/Quesu'
}]
}
query
is the word to look uplanguage
is an optional wikipedia language code string. Defaults toen
.callback
takes two arguments: an error and the response object.
npm test
wikipedia-translator
✓ translates known words
✓ includes the query and query lang in the result object
✓ gracefully handles queries that don't yield results
✓ defaults to English (en) wikipedia
✓ allows wikipedia language code as second param
MIT