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 了一圈资料,没看到解决办法