谷歌翻译不使用英语书写的Gujrati语言


# 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)

当我通过";kevu chale che badhu"在sample_ text中,输出保持不变;કેવુ ચલે છે બધુ"它将返回正确的输出。我也将源语言代码更改为gu,但没有任何更改。

目前,Google Cloud Translation API不支持将任何用拉丁字母书写的语言翻译为目标语言。在这个印地语问题跟踪器中也提出了同样的问题。如果您想为古吉拉特语提供此功能,请使用此链接提出功能请求。然而,我们目前无法提供ETA,但您可以通过参考此链接"STAR"该问题以接收自动更新并提供牵引力。

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

我个人认为谷歌不支持它是一个糟糕的答案,因为从拉丁输入字符(在语音上相当于输入者想要的语音(返回的目标语言是实际语言。因此";HI";在印地语中检测到,但返回的翻译与输入完全相同。如果谷歌能从音译的拉丁字符中检测到它是印地语,那么为什么不直接返回结果呢?

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)

谷歌过去允许在没有翻译成本的情况下进行检测,但现在已经不是这样了。

此外,谷歌的API在这种行为中是不一致的。例如,如果我键入俄语音译:"Privet";,我得到了";你好">

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

最新更新