Commit 89691a5f authored by Michal Čihař's avatar Michal Čihař

Always UTF-8 encode text to machine translation services

parent 4dc56629
......@@ -49,7 +49,7 @@ class ApertiumTranslation(MachineTranslation):
'''
args = {
'langpair': 'en|%s' % language,
'q': text,
'q': text.encode('utf-8'),
}
if appsettings.MT_APERTIUM_KEY is not None:
args['key'] = appsettings.MT_APERTIUM_KEY
......
......@@ -47,7 +47,7 @@ class GlosbeTranslation(MachineTranslation):
'from': 'en',
'dest': language,
'format': 'json',
'phrase': text.strip(',.:?! ')
'phrase': text.strip(',.:?! ').encode('utf-8')
}
response = self.json_req(
'http://glosbe.com/gapi/translate',
......
......@@ -66,7 +66,7 @@ class GoogleTranslation(MachineTranslation):
response = self.json_req(
'https://www.googleapis.com/language/translate/v2/',
key=appsettings.MT_GOOGLE_KEY,
q=text,
q=text.encode('utf-8'),
source='en',
target=language,
)
......@@ -98,7 +98,7 @@ class GoogleWebTranslation(MachineTranslation):
response = self.json_req(
'http://translate.google.com/translate_a/t',
client='t',
text=text,
text=text.encode('utf-8'),
sl='en',
tl=language,
ie='UTF-8',
......
......@@ -116,7 +116,7 @@ class MicrosoftTranslation(MachineTranslation):
Downloads list of possible translations from a service.
'''
args = {
'text': text[:5000],
'text': text[:5000].encode('utf-8'),
'from': 'en',
'to': language,
'contentType': 'text/plain',
......
......@@ -69,7 +69,7 @@ class MyMemoryTranslation(MachineTranslation):
Downloads list of possible translations from MyMemory.
'''
args = {
'q': text.split('. ')[0][:500],
'q': text.split('. ')[0][:500].encode('utf-8'),
'langpair': 'en|%s' % language,
}
if appsettings.MT_MYMEMORY_EMAIL is not None:
......
......@@ -57,7 +57,7 @@ class OpenTranTranslation(MachineTranslation):
'''
response = self.json_req(
'http://en.%s.open-tran.eu/json/suggest/%s' % (
language, urllib.quote(text)
language, urllib.quote(text.encode('utf-8'))
)
)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment