Skip to content

Commit

Permalink
indicate source language in results
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzschmid committed Nov 19, 2017
1 parent d5f1dad commit fe78aea
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
13 changes: 8 additions & 5 deletions deepl.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,16 +101,19 @@ def main(wf):
translations = json.loads(response.text)['result']['translations']
target_lang = json.loads(response.text)['result']['target_lang'] or \
target_lang
source_lang = json.loads(response.text)['result']['source_lang']

for translation in translations:
beams = sorted(translation['beams'], key=lambda b: -1 * b['score'])
for beam in beams:
item = wf.decode(beam['postprocessed_sentence'])
wf.add_item(
title=item,
valid=True,
icon=langs.AVAILABLE_LANGS[target_lang]['icon'],
arg=item)

subtitle = 'Translated from ' + \
langs.AVAILABLE_LANGS[source_lang]['name']
icon = langs.AVAILABLE_LANGS[target_lang]['icon']

wf.add_item(title=item, subtitle=subtitle, valid=True, icon=icon,
arg=item)

wf.send_feedback()

Expand Down
2 changes: 1 addition & 1 deletion deepl_available_langs.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@
'IT': {'name': 'Italian', 'icon': 'lang_icons/it.png'},
'NL': {'name': 'Dutch', 'icon': 'lang_icons/nl.png'},
'PL': {'name': 'Polish', 'icon': 'lang_icons/pl.png'}
}
}

0 comments on commit fe78aea

Please sign in to comment.