free baidu translate
- Auto language detection
- Spelling correction
- Language correction
- Fast and reliable – it uses the same servers that fanyi.baidu.com uses
npm install --save translate-baidu2
const translate = require('translate-baidu2')
translate('hello')
.then((res) => {
console.log(res)
})
.catch((err) => {
console.error(err)
})
// => { from: "en", to: "zh", dst: "你好", src: "hello" }
Translate Baidu cannot to translate Stitching strings this will be OK
const translate = require('translate-baidu2')
const str = `
/**
* Returns an iterator allowing to go through all key/value pairs contained in this object.
*/
`
translate(str)
.then((res) => {
console.log(res)
})
.catch((err) => {
console.error(err)
})
// =>
// {
// from: 'en',
// to: 'zh',
// dst: '/**\n*返回一个迭代器,允许遍历此对象中包含的所有键/值对。\n*/\n',
// src:'/**\n* Returns an iterator allowing to go through all key/value pairs contained in this object.\n*\n'
// }
Type: string
The text to be translated
Type: object
Type: string
Default: auto
The text
language. Must be auto
or one of the codes/names (not case sensitive) contained in languages.js
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.
Type: Boolean
Default: false
Return to the Full Baidu translation result object
text
(string) – The translated text.
translate('Hello world', { from: 'en', to: 'nl' })
.then((res) => {
console.log(res)
//=> { from: "en", to: "zh", dst: "你好,世界", src:"Hello world"}
})
.catch((err) => {
console.error(err)
})
MIT © YLQZ