1.0.1 • Published 6 years ago

yandex-translator v1.0.1

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

yandex-translator

Introduction

yandex-translator is a a promise based implementation of Yandex Translate API for node.js

API key

To start using Yandex Translate API we need to get an API key first, which we will get it from the API key request form after having created an account the registration page.

Installation

npm install yandex-translator --save

Getting started

Import the yandex-translator package with with the API key obtained from the API key request form.

const yandexTranslator = require('yandex-translator')(apiKey);

Functions

yandexTranslator.getAvailableLanguages(parameters)

Get the languages that yandex-translator support their translation:

yandexTranslator.getAvailableLanguages().then(
    (result) => {
        console.log(result);
    },
    (error) => {
        console.log(error);
    }
);

The parameters parameter is an object which can contain any of the following attributes:

AttributeTypeDescriptionDefault value
uistringThe returned language names are output in the language corresponding to the code in this parameter. The supported language codes are shown in the list of supported languages.
resultFormatstringThe result format which can be either JSON or XML.JSON
apiKeystringAnother API key to run only this request withThe same value as the initialized API key.

yandexTranslator.detectLanguage(parameters)

Detect a text language:

yandexTranslator.detectLanguage({text: 'Bonjour'}).then(
    (result) => {
        console.log(result);
    },
    (error) => {
        console.log(error);
    }
);

The parameters parameter is an object which can contain any of the following attributes:

AttributeTypeDescriptionDefault value
text*stringThe text that we want to detect it's language.
hintsarrayAn array of the most likely languages (they will be given preference when detecting the text language).[]
resultFormatstringThe result format which can be either JSON or XML.JSON
apiKeystringAnother API key to run only this request withThe same value as the initialized API key.

yandexTranslator.detectLanguage(parameters)

Translate a text:

yandexTranslator.translate({text: 'Bonjour', to: 'en'}).then(
    (result) => {
        console.log(result);
    },
    (error) => {
        console.log(error);
    }
);

The parameters parameter is an object which can contain any of the following attributes:

AttributeTypeDescriptionDefault value
text*stringThe text that we want to detect it's language.
to*stringThe language which the text will be translated to.
fromstringThe source language of the text. If it's then the service will try to detect the source language automatically.
optionsintegerWhether the response should include the automatically detected language of the text being translated: 1 to include the automatically detected language of the text, 0 to not1
formatstringThe text format which can be plain (Text without markup) or html (Text in HTML format).plain
hintsarrayAn array of the most likely languages (they will be given preference when detecting the text language).[]
resultFormatstringThe result format which can be either JSON or XML.JSON
apiKeystringAnother API key to run only this request withThe same value as the initialized API key.

Task Lists

  • Add CLI support
  • Add browser integration
  • Create tests

License

MIT.

1.0.1

6 years ago

1.0.0

6 years ago