Socket
Book a DemoInstallSign in
Socket

wikipedia-translator

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

wikipedia-translator

Scrape translations from Wikipedia pages

latest
Source
npmnpm
Version
1.2.0
Version published
Maintainers
1
Created
Source

Wikipedia Translator Build Status

A node module that scrapes translations from Wikipedia pages

Instalation

npm install wikipedia-translator --save

Usage

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 up
  • language is an optional wikipedia language code string. Defaults to en.
  • callback takes two arguments: an error and the response object.

Tests

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

License

MIT

Keywords

wikipedia

FAQs

Package last updated on 10 Dec 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts