【发布时间】:2018-10-19 00:19:03
【问题描述】:
当我尝试将法语字符写入文件时,某些字符看起来像
j'ai
我对西班牙语字符没有任何问题。我可能做错了什么?
"""Translates text into the target language.
Make sure your project is whitelisted.
Target must be an ISO 639-1 language code.
See https://g.co/cloud/translate/v2/translate-reference#supported_languages
"""
from google.cloud import translate
# Instantiates a client
translate_client = translate.Client()
# The target language
target = 'fr'
# Create a list of strings to translate.
test_list = []
new_list = []
for i in range(1) :
test_list.insert(i, 'I said, you know what, something, I\'m going to drop everything else off that I was doing and go through a period of a dry spell just to properly give it a chance when I started using it. ')
# Send 128 items per translation request and concatenate resulting translations into one list. (The max items per request for Google translate is 128.)
concat_result = []
for j in range(0, len(test_list), 128):
new_result = translate_client.translate(
test_list[j:j + 128], target_language=target)
concat_result += new_result
count = 0
for list in concat_result :
print(count, concat_result[count]['translatedText'])
count += 1
打印结果:
0 J'ai dit, vous savez quoi, quelque chose, je vais laisser tomber tout ce que je faisais et traverser une période de sécheresse simplement pour lui donner une chance de bien commencer à l'utiliser.
请忽略我正在翻译字符串列表而不是字符串。我正在测试发送批处理请求。
【问题讨论】:
-
我们需要更多的上下文。什么是
srt,它的compose()方法是什么?subs是什么?请提供minimal reproducible example,以便我们了解您的问题。 -
'看起来像'的 HTML 实体。 -
请确认您使用的是在github.com/cdown/srt 找到的 srt 库(您可能使用“pip install srt”安装它)
-
大家好。我是新来的,我为我不清楚的问题道歉。我想我通过稍微改变问题并提供一个完整的示例来更清楚地说明问题。
标签: python encoding google-translate