🚨 Active Supply Chain Attack:node-ipc Package Compromised.Learn More
Socket
Book a DemoSign in
Socket

translateer

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

translateer

Light-weight Google translator in Node.js

latest
npmnpm
Version
2.0.2
Version published
Weekly downloads
17
70%
Maintainers
1
Weekly downloads
 
Created
Source

translateer

Light-weight translator

Installation

Using npm or yarn

npm install translateer --save
yarn add translateer --save

How to use

const translator  = require('tranlateer');

translate

translate is a function with only one object argument which is specified below.

q [optional] default is empty, the word/sentence you want to query.
from [optional] default is auto, used to specify the language of q.
to [optional] default is en, used to specify the language for translation.
version [optional] default is 1.0, used to specify the version of API.

Examples for API v1.0 (Default)

translator.translate({
  q: 'hello world',
  to: 'es'
})
.then(res => res.json())
.then(console.log);

// Hola Mundo

Examples for API v2.0

translator.translate({
  q: 'hello world',
  to: 'es',
  v: '2.0'
})
.then(res => res.json())
.then(console.log);

/*
{
  "sentences": [
    {
      "trans": "Hola Mundo",
      "orig": "hello world",
      "backend": 1
    }
  ],
  "src": "en",
  "alternative_translations": [
    {
      "src_phrase": "hello world",
      "alternative": [
        {
          "word_postproc": "Hola Mundo",
          "score": 1000,
          "has_preceeding_space": true,
          "attach_to_next_token": false
        },
        {
          "word_postproc": "Hola Mundo",
          "score": 1000,
          "has_preceeding_space": true,
          "attach_to_next_token": false
        }
      ],
      "srcunicodeoffsets": [
        {
          "begin": 0,
          "end": 11
        }
      ],
      "raw_src_segment": "hello world",
      "start_pos": 0,
      "end_pos": 0
    }
  ],
  "confidence": 0.71052581,
  "ld_result": {
    "srclangs": [
      "en"
    ],
    "srclangs_confidences": [
      0.71052581
    ],
    "extended_srclangs": [
      "en"
    ]
  }
}
*/

getAudio

getAudio is a function returning the url of the audio file

q [optional] default is empty, the word/sentence you want to query.
to [optional] default is auto detected, used to specify the language for translation.
speed [optional] default is 1, used to specify the audio speed.

Example

translator.getAudio({
  q: 'hello world'
})
.then(console.log);
// https://translate.google.com/translate_tts?ie=UTF-8&q=test&tl=en&total=1&idx=0&textlen=4&tk=290146.141044&client=t&prev=input&ttsspeed=1 

Copyright (C) 2017 Tony Ngan, released under the MIT License.

FAQs

Package last updated on 24 Jan 2017

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