无法从阿拉伯语翻译成英语 Google 免费翻译 api
unable to translate from Arabic to English Google translate free api
我正在使用 nodeJS 和这个 google URL 来翻译查询:
从英语到阿拉伯语工作正常
http://translate.googleapis.com/translate_a/single?client=gtx&sl=en&tl=ar&dt=t&q=Hello
但是当更改 URL 从阿拉伯语到英语的翻译时
http://translate.googleapis.com/translate_a/single?client=gtx&sl=ar&tl=en&dt=t&q=مرحبا
returns 无效输出 "E1 ('" 作为翻译
从浏览器点击 URL 上方时将 return 正确输出,这是我的代码
const request = require('request');
let endPoint = null;
if (language == 'english') {
endPoint = "https://translate.googleapis.com/translate_a/single?client=gtx&sl=ar&tl=en&dt=t&ie=UTF-8&oe=UTF-8&q="+text;
} else {
endPoint = 'http://translate.googleapis.com/translate_a/single?client=gtx&sl=en&tl=ar&dt=t&q=' + text;
}
return request(endPoint, function (error, response, body) {
console.log(body);
});
下面是输出
[
[
[
"مرحبا",
"Hello",
null,
null,
1
]
],
null,
"en"
]
[
[
[
"E1 ('",
"E1-('",
null,
null,
3
]
],
null,
"ar"
]
试试这个。它对我有用
let text = "مرحب"
let endPoint = 'https://translate.googleapis.com/translate_a/single?client=gtx&sl=ar&tl=en&dt=t&ie=UTF-8&oe=UTF-8&q=' + encodeURIComponent(text);
request(endPoint, function (error, response, body) {
console.log(body);
});
我正在使用 nodeJS 和这个 google URL 来翻译查询: 从英语到阿拉伯语工作正常
http://translate.googleapis.com/translate_a/single?client=gtx&sl=en&tl=ar&dt=t&q=Hello
但是当更改 URL 从阿拉伯语到英语的翻译时
http://translate.googleapis.com/translate_a/single?client=gtx&sl=ar&tl=en&dt=t&q=مرحبا
returns 无效输出 "E1 ('" 作为翻译
从浏览器点击 URL 上方时将 return 正确输出,这是我的代码
const request = require('request');
let endPoint = null;
if (language == 'english') {
endPoint = "https://translate.googleapis.com/translate_a/single?client=gtx&sl=ar&tl=en&dt=t&ie=UTF-8&oe=UTF-8&q="+text;
} else {
endPoint = 'http://translate.googleapis.com/translate_a/single?client=gtx&sl=en&tl=ar&dt=t&q=' + text;
}
return request(endPoint, function (error, response, body) {
console.log(body);
});
下面是输出
[
[
[
"مرحبا",
"Hello",
null,
null,
1
]
],
null,
"en"
]
[
[
[
"E1 ('",
"E1-('",
null,
null,
3
]
],
null,
"ar"
]
试试这个。它对我有用
let text = "مرحب"
let endPoint = 'https://translate.googleapis.com/translate_a/single?client=gtx&sl=ar&tl=en&dt=t&ie=UTF-8&oe=UTF-8&q=' + encodeURIComponent(text);
request(endPoint, function (error, response, body) {
console.log(body);
});