Skip to content

Commit

Permalink
Encode MS Terminology text parameter as UTF-8 (#650)
Browse files Browse the repository at this point in the history
Also adds a more reliable check for the returned translations, which
cannot result in an error that len(results) throw if results is None.
  • Loading branch information
mathjazz committed Jul 27, 2017
1 parent 58f6655 commit 1428e84
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions pontoon/machinery/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def microsoft_terminology(request):

payload = {
'uuid': uuid4(),
'text': text,
'text': urllib.quote(text.encode('utf-8')),
'to': locale,
'max_result': 5
}
Expand All @@ -178,8 +178,10 @@ def microsoft_terminology(request):
translations = []
xpath = './/{http://api.terminology.microsoft.com/terminology}'
root = ET.fromstring(r.content)
if len(root.find(xpath + 'GetTranslationsResult')):
for translation in root.find(xpath + 'GetTranslationsResult'):
results = root.find(xpath + 'GetTranslationsResult')

if results is not None:
for translation in results:
translations.append({
'source': translation.find(xpath + 'OriginalText').text,
'target': translation.find(xpath + 'TranslatedText').text,
Expand Down

0 comments on commit 1428e84

Please sign in to comment.