Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

translate-google

shikar12.3kMIT1.5.0

A free and unlimited for Google Translate, Multi-translation support object input

translate, google, translator, free, unlimited, language, batch, multi, object, token

readme

Translate Google

free google translate

Change Log

Features

  • Auto language detection
  • Spelling correction
  • Language correction
  • Fast and reliable – it uses the same servers that translate.google.com uses

Install

npm install --save translate-google

Usage

Perfect support object:

const translate = require('translate-google')
const tranObj = {
  a: 1,
  b: '1',
  c: "How are you?\nI'm nice.",
  d: [true, 'true', 'hi', { a: 'hello', b: ['world']}],
}

translate(tranObj, {to: 'zh-cn', except:['a']}).then(res => {
    console.log(res)
}).catch(err => {
    console.error(err)
})

// => { a: 1, b: '1', c: "你好吗?\n我很好。", d: [true, 'true', '嗨', { a: 'hello', b: ['世界']}] }

From automatic language detection to English:

const translate = require('translate-google')

translate('I speak Chinese', {to: 'zh-cn'}).then(res => {
    console.log(res)
}).catch(err => {
    console.error(err)
})

From English to Dutch with a typo:

translate('I speak Chinese!', {from: 'en', to: 'zh-cn'}).then(res => {
    console.log(res)
}).catch(err => {
    console.error(err)
})

translate for array or object:

translate({a: 'I speak Chinese!', b: ['hello', 'world']}, {from: 'en', to: 'zh-cn'}).then(res => {
    console.log(res)
}).catch(err => {
    console.error(err)
})

API

translate(text, options)

text

Type: string, object, array The text to be translated

options

Type: object

from

Type: string Default: auto The text language. Must be auto or one of the codes/names (not case sensitive) contained in languages.js

to

Type: string Default: en The language in which the text should be translated. Must be one of the codes/names (not case sensitive) contained in languages.js.

except

Type: array Default:[] Attributes in excluded objects do not participate in translation

Returns an object:

  • text (string, object, array) – The translated text.
translate(['I speak Chinese\nHello world', 'hello'], {from: 'en', to: 'nl'}).then(res => {
    console.log(res);
    //=> ["我说中文\n你好世界","你好"]
}).catch(err => {
    console.error(err);
});

License

MIT © Shikar

changelog

Change Log

1.4.3 [2020-08-10]

Fixed

  • Clone a new input so that it will not affect the original variable

1.4.2 [2020-07-28]

Changed

  • Changed url params processing method

1.4.1 [2020-07-27]

Changed

  • Change the submission module of post

1.4.0 [2020-07-16]

Fixed

  • Fixed Lots of translations bug

1.3.4 [2019-01-15]

Added

  • Added object translation exclusions
  • Remove the duplicate part of the translation

    Fixed

  • Fixed Object bug

1.3.4 [2019-01-12]

Fixed

  • Translate a large number of characters using POST method

1.3.3 [2019-01-10]

Added

  • Object mode translation: Excluding non-words that do not participate in translation

1.3.2 [2019-01-10]

Added

  • Object mode translation: Exclude numbers, URLs, keywords in translate

1.3.1 [2019-01-09]

Fixed

  • Fixed some bug

1.3.0 [2019-01-09]

Changed

  • Perfect support object