bing-translate-api
v4.0.2
Published
A simple and free API for Bing & Microsoft Translator for Node.js
Downloads
55,116
Maintainers
Readme
bing-translate-api
A simple and free API for Bing Translator and Microsoft Translator for Node.js.
Install
npm install bing-translate-api
Usage
Microsoft Translator 🆕
Added since v4.0.0. More stable and powerful. Both free service and paid service are supported. Feel free to give it a try!
Read the README for more details.
Bing Translator
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
}
}
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.
NOTE:
- The maximum text length is up to 5000 characters only in China.
- In EPT mode (since
v3.0.0
), the maximum text length is currently 3000.
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
NOTE: The EPT mode (since v3.0.0
) only supports the languages contained in src/config.json#eptLangs. Any other language will fall back to the legacy mode, in which a 429 (Too Many Requests) error often occurs.
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.
NOTE: The EPT mode (since v3.0.0
) only supports the languages contained in src/config.json#eptLangs. Any other language will fall back to the legacy mode, in which a 429 (Too Many Requests) error often occurs.
correct
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.
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.
Refer to src/config.json#userAgent for the default user agent.
proxyAgents
Type: Got['Agents']
Default: undefined
Since: v2.4.0
License
MIT © 2021-2024 plainheart.
Thanks
Great thanks to Bing Translator for providing such an excellent translation service.
Related Projects
- Capacitor Bing Translator - A fork of this project that works in Capacitor.
- bing-translate-api-java - Bing translate API implemented in Java.
- i18n-translate-generator - CLI tool that automates the generation of localizations for all languages supported in your project.