Bulgarian(Latin)toanylanguagetranslatingdoesnotwork
创始人
2024-12-26 07:30:14
0

在使用Google Translate API进行翻译时,如果将保加利亚语的语言代码设置为“bg”,则无法正常翻译。这种问题可能是因为Google Translate API仅支持保加利亚语的西里尔语版本(代码为“bg-BG”)。因此,解决该问题的方法是将保加利亚语的语言代码更改为“bg-BG”。

示例代码:

#原始代码
# translate_text.py

def translate_text(text, target):
    """
    Translates text into the target language.

    Target must be an ISO 639-1 language code.
    https://g.co/cloud/translate/v2/translate-reference#supported_languages
    """
    import six
    from google.cloud import translate_v2 as translate

    translate_client = translate.Client()

    if isinstance(text, six.binary_type):
        text = text.decode("utf-8")

    # Text can also be a sequence of strings, in which case this method
    # will return a sequence of results for each text.
    result = translate_client.translate(text, target_language=target)

    print(u"Text: {}".format(result["input"]))
    print(u"Translation: {}".format(result["translatedText"]))
    print(u"Detected source language: {}".format(result["detectedSourceLanguage"]))


translate_text("Hello world", "bg") #改为 "bg-BG"

修改后的代码:

# translate_text.py

def translate_text(text, target):
    """
    Translates text into the target language.

    Target must be an ISO 639-1 language code.
    https://g.co/cloud/translate/v2/translate-reference#supported_languages
    """
    import six
    from google.cloud import translate_v2 as translate

    translate_client = translate.Client()

    if isinstance(text, six.binary_type):
        text = text.decode("utf-8")

    # Text can also be a sequence of strings, in which case this method
    # will return a sequence of results for each text.
    result = translate_client.translate(text, target_language="bg-BG")

    print(u"Text: {}".format(result["input

相关内容

热门资讯

透视了解(WePoKe透视挂)... 透视了解(WePoKe透视挂)wepoke显示有(详细辅助总结教程)一贯真的有挂;致您一封信;亲爱W...
德州之星辅助挂!aa poke... 德州之星辅助挂!aa poker简介俱乐部辅助,(wePOKE)总是是有挂(详细透视攻略教程);原来...
wpk透视辅助工具!wpk代理... wpk透视辅助工具!wpk代理合作,(德州ai)从来存在有挂(详细辅助曝光教程);原来确实真的有挂(...
透视透视(微扑克辅助软件)微扑... 透视透视(微扑克辅助软件)微扑克脚本代写(详细辅助wpk教程)一直有挂;人气非常高,ai更新快且高清...
透视黑科技(德州ai机器人)g... 透视黑科技(德州ai机器人)gg扑克发牌系统(详细辅助教你教程)真是真的有挂您好,德州ai机器人,确...
aa扑克辅助!pokermas... aa扑克辅助!pokermaster外挂,(wEpoke)一直是有挂(详细辅助专业教程);致您一封信...
透视有挂(德州ai机器人)微扑... 透视有挂(德州ai机器人)微扑克辅助软件(详细辅助解密教程)一向是有挂您好,微扑克辅助软件,确实是有...
wpk真的有外挂!fishpo... wpk真的有外挂!fishpoker app辅助,(微扑克)真是真的有挂(详细透视可靠教程)准备好在...
透视安卓版(德州之星有外挂)a... 透视安卓版(德州之星有外挂)aapoker脚本透明(详细辅助wepoke教程)真是存在有挂;是一款可...
微扑克全自动机器人!aapok... 1、微扑克全自动机器人!aapoker辅助工具存在吗,(aaPoker)本然是真的有挂(详细透视攻略...