【问题标题】:Google translator is not working with Gujrati language written in english谷歌翻译不适用于用英语写的古吉拉特语
【发布时间】:2022-01-19 05:52:50
【问题描述】:
# google-translate version 3.6.1

from os import environ
import os

from google.cloud import translate

os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = r"/multilingual-bot.json"

project_id = 'multilingual-bot'

assert project_id
parent = f"projects/{project_id}"
client = translate.TranslationServiceClient()
client.get_supported_languages(parent=parent, display_language_code="en")

sample_text = "kevu chale che badhu"
target_language_code = "en"
lan_response = client.detect_language(parent=parent, content=sample_text)
response = client.translate_text(contents=[sample_text],source_language_code='gu',target_language_code=target_language_code,parent=parent)
for translation in response.translations:
    print(translation.translated_text)
print(lan_response)

当我在 sample_text 中传递“kevu chale che badhu”时,输出保持不变,但如果我们用根语言更改它,即“કેવુ ચલે છે બધુ”,它将返回正确的输出。我也将源语言代码更改为 gu,但没有任何改变。

【问题讨论】:

  • 如果我的回答解决了您的问题,请考虑接受并点赞。如果没有,请告诉我,以便我改进答案。

标签: google-cloud-platform google-translate


【解决方案1】:

目前,Google Cloud Translation API 不支持将任何以拉丁字母书写的语言翻译成目标语言。 对于印地语,issue tracker 中也提出了同样的问题。如果您想为古吉拉特语提供此功能,请使用此link 提出功能请求。但是,我们目前无法提供预计到达时间,但您可以“星标”该问题以接收自动更新并通过引用为其提供牵引力到这个link

【讨论】:

  • google API 不支持音译,印地语只是一种情况。我可以很容易地用西里尔文或其他字母创建其他字母,这会导致 API 返回与输入相同的拉丁字符(具有讽刺意味的是,在响应中检测到正确的语言)......所以运行 xlate 两次,你得到仅当您使用翻译时,再次讽刺的是谷歌已弃用的音译 API。 :(
【解决方案2】:

我能找到并且已成功实施的唯一已知解决方案(处理印地语和其他语言)是音译输入。

我个人认为 Google 不支持它是一个糟糕的答案,因为从拉丁输入字符返回的目标语言(语音上等同于输入者所需的语音)是实际语言。因此在印地语中检测到“HI”,但返回的翻译与输入相同。如果 Google 可以从音译的拉丁字符中检测到它是印地语,那为什么不直接返回结果呢?

Steps to work around:
1. translate through translate-api as normal.  Use the latin characters as the inputs.
2. receive the results from the the translate, and ignore the returned translation. (It will be the same as the input latin). Collect the targetLanguageDetected field, and save this.
3. call google's (deprecated but still supported) transliterate interface, with the input language (received from step 2) and the same original latin character inputs (URL is: 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 is the original latin character text, srclang is the output from step 2, and numchoices is the number of "suggestions" that are generated from the input.
4. re run step 1, with the output from step 3 (the "HI" characters, or whatever alphabet is returned)

Google 过去允许检测而无需支付翻译费用,但现在不再是这种情况了。

此外,Google 的 API 在这种行为上也不一致。例如,如果我输入俄语音译: “女贞”,我得到“你好”

【讨论】:

    【解决方案3】:

    嗨,谷歌云控制台是为英语使用而设计的,你不是完全在管理员中它只是你管理的例子我尝试关闭我的谷歌可以控制台它没有工作我尝试了 sudo,它的工作方式与使用 sudo 下载语言包的方式相同apt 并使用 sudo 安装它,如果它不起作用,则在 sudo 中通过 sudo su 完成所有工作,这意味着谷歌不希望你这样做

    【讨论】:

    • 正如目前所写,您的答案尚不清楚。请edit 添加其他详细信息,以帮助其他人了解这如何解决所提出的问题。你可以找到更多关于如何写好答案的信息in the help center
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-16
    • 2014-02-23
    • 1970-01-01
    • 2023-03-27
    相关资源
    最近更新 更多