Google翻译云API,翻译不正确 [英] Google Translate Cloud API, not translating correctly

本文介绍了Google翻译云API,翻译不正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近开始将Google Cloud Translate API与Python结合使用。我在把这个词翻译成泰卢固语时遇到了困难,泰卢固语是用英语写的。一般来说,我们使用的互联网或移动应用程序谷歌翻译都是正确的。但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

输出文本:我们已解决

推荐答案

基于我的评论,我也试图找出解决此问题的解决方案,我提供了我对此问题的解决方案的版本。我能可靠地工作的唯一经过测试的流程如下:(我使用的是谷歌云翻译)

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的输出,我设置了数字选项(可能的DID-You-Means-This音译的数量为1)

这篇关于Google翻译云API,翻译不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆