1

I'm having some troubles with the Google Translate API.

Example;

When translating the title of this article:

http://vtimes.com.au/dua-xe-f1-thu-ngua-chien-bat-them-benh-2622229.html

(Đua xe F1: Thử "ngựa chiến" bắt thêm bệnh)

The quote marks come back as &quot

When using translate.google.com it obviously come's back as you want it.

Am I missing some encoding or something(?) Gah! Help :D

Code snippet:

service = build('translate', 'v2',
                 developerKey=self.config['google-api']['dev-key'])
    try:
        title = (service.translations().list(
            source=source,
            target='en',
            q=text
        ).execute())['translations'][0]['translatedText']
    except (KeyError, IndexError):
        return text
    return title

1 Answer 1

1

There was an easy solution to this. The html package saved the day.

import html

service = ...
   ...
...

return html.unescape(title)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.