1.0.0 • Published 6 years ago

ya-translate v1.0.0

Weekly downloads
1
License
MIT
Repository
github
Last release
6 years ago

ya-translate

Node.js module for Yandex Translate API's translate method.

npm install ya-translate --save

Get your own API key first.

How to use

  const translate = require('ya-translate')(YOUR-API-KEY)


  // Translates to English by default

  translate('Parli italiano?')
    .then(console.log)
    .catch(console.error)

    // { code: 200,
    //   detected: { lang: 'it' },
    //   lang: 'it-en',
    //   text: [ 'Do you speak Italian?' ] }


  // Translates to a language of your choice
  // (yes, the translation might be wrong)

  translate('Parli italiano?', 'de')
    .then(console.log)
    .catch(console.error)

    // { code: 200,
    //   detected: { lang: 'it' },
    //   lang: 'it-de',
    //   text: [ 'Sprechen sie deutsch?' ] }


  // Can use an object as in the Yandex.Translate API

  translate({lang: 'ru', text: 'You can pass an object (see the Yandex.Translate docs)'})

    // { code: 200,
    // lang: 'en-ru',
    // text: [ 'Вы можете передать объект (см. Яндекс.Перевод документов)' ] }


  // Can translate many texts at once

  translate(({lang: 'zh-en', text: ['\u5F00\u6E90', '\u8F6F\u4EF6']})
    .then(console.log)
    .catch(console.error)
  // { code: 200, lang: 'zh-en', text: [ 'Open source', 'Software' ] }

Links