使用 Google Translate 翻译国家名称的时候容易翻译错

9 天前
 xinmans

def translate_text(text, target_language='zh-cn', max_retries=3): translation = None retries = 0

translator = Translator(service_urls=['translate.googleapis.com'], user_agent=get_random_user_agent())

while translation is None and retries < max_retries:
    try:
        translation = translator.translate(text, dest=target_language).text
        sleep(1)
    except Exception as e:
        if retries >= 2:
            sleep(5)
            retries += 1
            continue
if translation is None:
    logging.warning(f"Translation <<<{text}>>> failed: {e}, have retry {retries} times, will jump to next line.")
    return text
else:
    logging.info(f"Translation <<<{text}>>> success: {translation}")
    return translation
    
    

2024-06-27 16:17:57 INFO Translation <<<Georgia>>> success: 乔治亚州 2024-06-27 16:17:58 INFO Translation <<<Portugal>>> success: 葡萄牙 2024-06-27 16:17:58 INFO Translated countries: ['乔治亚州', '葡萄牙']

Georgia 没有正确的翻译成格鲁吉亚,而是翻译成了乔治亚州,Turkey 翻译成了火鸡

这个有办法设置吗? Google 了一圈资料,没看到解决办法

519 次点击
所在节点    问与答
7 条回复
alfchin
9 天前
要有上下文才不会错。加个上文进去翻译完取最后一段就好
yyzh
9 天前
上下文联想+1
riggzh
9 天前
本来乔治亚州也是 Georgia
vacuitym
9 天前
这种需要上下文,感觉很适合用 AI 处理
LLaMA2
9 天前
笨点的方法

Georgia 和 Turkey 等所有国家的名称 全部使用 "country xxxxxx"

这样,得到的结果是 “国家 格鲁吉亚”和"国家 土耳其"
Ericcccccccc
9 天前
Turkey 翻译成了火鸡 有啥问题
xinmans
8 天前
@LLaMA2 有道理啊,好办法,我试试

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/1053134

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX