Google 翻译 API 无法识别特殊字符
Google Translate API not recognising special characters
我正在使用下面的google翻译代码
def translate_text(text):
if isinstance(text, six.binary_type):
text = text.decode("utf-8")
output= translate_client.translate(
text,
target_language= 'en')
return output['translatedText']
当运行以下代码时:
print(translate_text(' can\'t modify account id and l\'y faut utiliser l\'id de marc'))
我得到以下输出
"can't modify account id and use marc's id"
而不是
"can't modify account id and use marc's id"
得到答案,必须向函数添加一个额外的参数
def translate_text(text):
if isinstance(text, six.binary_type):
text = text.decode("utf-8")
output= translate_client.translate(
text,
format_='text', # <---- by default the value is HTML
target_language= 'en')
return output['translatedText']
我正在使用下面的google翻译代码
def translate_text(text):
if isinstance(text, six.binary_type):
text = text.decode("utf-8")
output= translate_client.translate(
text,
target_language= 'en')
return output['translatedText']
当运行以下代码时:
print(translate_text(' can\'t modify account id and l\'y faut utiliser l\'id de marc'))
我得到以下输出
"can't modify account id and use marc's id"
而不是
"can't modify account id and use marc's id"
得到答案,必须向函数添加一个额外的参数
def translate_text(text):
if isinstance(text, six.binary_type):
text = text.decode("utf-8")
output= translate_client.translate(
text,
format_='text', # <---- by default the value is HTML
target_language= 'en')
return output['translatedText']