最近,我开始在python中使用。I‘我很难用英语"parishkaram chesamu“来转换这个词。在一般的互联网或移动应用谷歌翻译,我们使用的是正确的。但是API再次返回相同的单词。
Google转换API:
输入文本: parishkaram chesamu
输出文本: parishkaram chesamu
参数:
text ='''parishkaram chesamu'''
target = "en"
output = translate_client.translate(text)
print(output)
{'translatedText': 'parishkaram chesamu', 'detectedSourceLanguage': 'te', 'input': 'parishkaram chesamu'}
================================
移动或互联网谷歌翻译:
输入文本: parishkaram chesamu
输出文本:我们已经解决了
发布于 2021-12-10 17:47:59
你在谷歌翻译网站上得到了一个翻译的答案,因为它实际上被翻译的是你文本框下的“你是指”文本,这是阿拉伯文字。
“您的意思”文本来自Google的拼写检查API (也就是建议使用Google搜索的替代搜索)。当您直接使用翻译API时,您将跳过拼写检查,这就是为什么您没有得到翻译,Arabzizi不是受支持的语言/格式,需要在翻译之前进行更正。
当您使用Java进行开发时,您可能有兴趣在这里使用Google拼写Java将此步骤添加到程序中。
如果将请求发送到以阿拉伯语编码的API,则需要翻译它,请参见:
POST https://translation.googleapis.com/language/translate/v2?key={YOUR_API_KEY}
{
"format": "text",
"q": [
"عاوز أروح على إل بيت"
],
"target": "en"
}
Response
200
- Show headers -
{
"data": {
"translations": [
{
"translatedText": "I want to go to the house",
"detectedSourceLanguage": "ar"
}
]
}
}
编辑:拼写检查API在这个日期是不可用的,要纠正这个问题,你可以强制用户文本被“音译”。一定要在这里读到
这是音译API的链接,它被废弃了,还有其他几种特定于环境的方法。
发布于 2022-01-20 22:02:31
基于我的评论,试图找出一个解决方案,以及,我提供了我的解决方案,为这个问题。唯一能够可靠工作的测试流程是:(我正在使用)
Step 1: translate your message into a language, it doesn't matter which.
Step 2: get the detectedLanguageCode value from the results in step 1
Step 3: run a transliteration on the original message, with the value from step 2. (I'm using google's deprecated translit API), with thanks to @Ali for providing it!
Step 4: re-run step 1, modifying the original message to be the transliterated output in step 3.
这是我代码中的一个片段,用于显示确切的伪流。(我删除了错误检查、背压等复杂性)。
// run request
let [response] = await translate(request);
request['contents'][0] = await transliterate(request.contents[0], response.translations[0].detectedLanguageCode);
[response] = await callWithRetry(request, interaction, channel);
return response;
音译是基于上面发布的链接,我收集并设置如下:
const url = `https://inputtools.google.com/request?text=${srcMessage}&itc=${srclang}-t-i0-und&num=${numChoices}&cp=0&cs=1&ie=utf-8&oe=utf-8&app=demopage`;
其中srcMessage是原始文本,srclang是步骤2的输出,我设置了数字选择(可能的数字-您的意思是-这个音译为1)。
https://stackoverflow.com/questions/70246066
复制相似问题