A simple and free API for Bing Translator for Node.js.
npm install bing-translate-api
From auto-detected language to English:
const { translate } = require('bing-translate-api');
translate('你好', null, 'en').then(res => {
console.log(res.translation);
}).catch(err => {
console.error(err);
});
Translation result
{
// original text
"text": "你好",
// 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": "zh-Hans",
// score of language detection
// supported since v1.1.0
"score": 1
}
}
Type: string
The text to be translated, can't be blank. The maximum text length is 5000.
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
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.
Type: boolean
Default: false
Since: v1.1.0
Whether to correct the input text.
Note that:
- There is currently a limit of 50 characters for correction service.
- Only the languages in the list are supported to be corrected.
Type: boolean
Default: false
Whether the translation result contains raw response from Bing API.
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/119.0.0.0 Safari/537.36 Edg/119.0.0.0
Type: Got['Agents']
Default: undefined
Since: v2.4.0
MIT © 2021-2023 plainheart.
Great thanks to Bing Translator for providing such an excellent translation service.
- Capacitor Bing Translator - A fork of this project that works in Capacitor.
- bing-translate-api-java - Bing translate API implemented in Java.