user9477447
user9477447

Reputation: 43

How to fix 'translate() got an unexpected keyword argument 'format''

I face a problem when I translate text that return apostrophe like en: "this is me" == fr: "c'est moi", but I get " c'est moi". for that I want to specify the format to text, but when I execute the script I get:

TypeError: translate() got an unexpected keyword argument 'format'
from google.cloud import translate

# Instantiates a client
translate_client = translate.Client()

# The text to translate
text = u'this is me'
# The target language
target = 'fr'

# Translates some text into Russian
translation = translate_client.translate(
    text,
    target_language=target, format='text')

print(u'Text: {}'.format(text))
print(u'Translation: {}'.format(translation['translatedText']))

Upvotes: 4

Views: 4427

Answers (1)

MyNameIsCaleb
MyNameIsCaleb

Reputation: 4489

If you want to provide an argument for format you have to use format_ which takes optional arguments: [github code]

:type format_: str

:param format_: (Optional) One of text or html, to specify if the input text is plain text or HTML.

However this is for input text not output text. If you want to convert back to a real apostrophe you could use html.unescape as what you are getting back is the html representation of the character: [docs]

import html
print(html.unescape(text))

Upvotes: 3

Related Questions