bingtranslator-for-free
TypeScript icon, indicating that this package has built-in type declarations

1.0.4 • Public • Published

bing-translate

NPM version NPM Downloads License

A simple and free package for Bing Translator for Node.js.

Install

npm i bingtranslator-for-free

Usage

From auto-detected language to English:-

const { translate } = require('bingtranslator-for-free');

translate('Salut', null, 'en').then(res => {
  console.log(res.translation);
}).catch(err => {
  console.error(err);
});

Translation result

{
  // original text
  "text": "Salut",
  // user-specified language code
  "userLang": "auto-detect",
  // translated text
  "translation": "Hello",
  // `correctedText` is returned only when `correct` is set as `true`
  // supported since v1.1.0
  "correctedText": "",
  // detected language
  "language": {
    // language code of translated text
    "to": "en",
    // detected language code of original text
    "from": "fr",
    // score of language detection
    // supported since v1.1.0
    "score": 1
  }
}

API

translate(text, [from], [to], [correct], [raw], [userAgent], [proxyAgents])

text

Type: string

The text to be translated, can't be blank. The maximum text length is 1000.

from

Type: string Default: auto-detect

The language code of source text.

MUST be auto-detect or one of the codes/names (not case sensitive) contained in lang.json

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 lang.json.

correct

Type: boolean Default: false Since: v1.1.0

Whether to correct the input text.

Note that:

  1. There is currently a limit of 50 characters for correction service.
  2. Only the languages in the list are supported to be corrected.
raw

Type: boolean Default: false

Whether the translation result contains raw response from Bing API.

userAgent

Type: string

The header value of user-agent used in API requests.

Default:

Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36
proxyAgents

Type: Got['Agents'] Default: undefined Since: v2.4.0

Set agents of got for proxy.

Thanks

Great thanks to Bing Translator and plainheart.

Package Sidebar

Install

npm i bingtranslator-for-free

Weekly Downloads

3

Version

1.0.4

License

MIT

Unpacked Size

20.8 kB

Total Files

8

Last publish

Collaborators

  • codingtuto