无法从阿拉伯语翻译成英语谷歌翻译免费API

问题描述 投票:0回答:2

我正在使用 NodeJS 和这个 google URL 来翻译查询: 从英语到阿拉伯语效果很好

http://translate.googleapis.com/translate_a/single?client=gtx&sl=en&tl=ar&dt=t&q=你好

但是将 URL 翻译从阿拉伯语更改为英语时

http://translate.googleapis.com/translate_a/single?client=gtx&sl=ar&tl=en&dt=t&q=mırìbaba

返回无效输出“E1('”作为翻译

从浏览器点击上述 URL 将返回正确的输出,这是我的代码

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"
]
javascript node.js google-translate google-translation-api
2个回答
3
投票

试试这个。它对我有用

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);
});

-1
投票

我想退回你们商店在邮件中错误寄给我的商品,并将其换成我向您发送照片的原始订单。就这样。您的商店地址是什么,很快就会到那里交换并发回给我。谢谢你,Dorothy Rondeau 电子邮件 [电子邮件受保护]

© www.soinside.com 2019 - 2024. All rights reserved.