Commit 803e2e92 authored by Michal Čihař's avatar Michal Čihař

Pass unit to translation services

This will allow them to do more introspection if needed
parent 894e86c4
......@@ -43,7 +43,7 @@ class ApertiumTranslation(MachineTranslation):
for item in data['responseData']
if item['sourceLanguage'] == 'en']
def download_translations(self, language, text):
def download_translations(self, language, text, unit):
'''
Downloads list of possible translations from a service.
'''
......
......@@ -116,7 +116,7 @@ class MachineTranslation(object):
'''
return []
def download_translations(self, language, text):
def download_translations(self, language, text, unit):
'''
Downloads list of possible translations from a service.
'''
......@@ -164,7 +164,7 @@ class MachineTranslation(object):
'''
return language in self.supported_languages
def translate(self, language, text):
def translate(self, language, text, unit):
'''
Returns list of machine translations.
'''
......@@ -173,7 +173,7 @@ class MachineTranslation(object):
return []
try:
translations = self.download_translations(language, text)
translations = self.download_translations(language, text, unit)
return [{'text': trans[0], 'quality': trans[1], 'source': trans[2]}
for trans in translations]
......
......@@ -33,7 +33,7 @@ class DummyTranslation(MachineTranslation):
'''
return set(('cs',))
def download_translations(self, language, text):
def download_translations(self, language, text, unit):
'''
Dummy translation supports just single phrase.
'''
......
......@@ -39,7 +39,7 @@ class GlosbeTranslation(MachineTranslation):
'''
return True
def download_translations(self, language, text):
def download_translations(self, language, text, unit):
'''
Downloads list of possible translations from a service.
'''
......
......@@ -33,7 +33,7 @@ class GoogleTranslation(MachineTranslation):
'''
return True
def download_translations(self, language, text):
def download_translations(self, language, text, unit):
'''
Downloads list of possible translations from a service.
'''
......
......@@ -107,7 +107,7 @@ class MicrosoftTranslation(MachineTranslation):
data = self.json_req(LIST_URL)
return data
def download_translations(self, language, text):
def download_translations(self, language, text, unit):
'''
Downloads list of possible translations from a service.
'''
......
......@@ -62,7 +62,7 @@ class MyMemoryTranslation(MachineTranslation):
source
)
def download_translations(self, language, text):
def download_translations(self, language, text, unit):
'''
Downloads list of possible translations from a service.
'''
......
......@@ -50,7 +50,7 @@ class OpenTranTranslation(MachineTranslation):
self.name
)
def download_translations(self, language, text):
def download_translations(self, language, text, unit):
'''
Downloads list of possible translations from a service.
'''
......
......@@ -52,7 +52,7 @@ class TMServerTranslation(MachineTranslation):
'''
return True
def download_translations(self, language, text):
def download_translations(self, language, text, unit):
'''
Downloads list of possible translations from a service.
'''
......
......@@ -97,7 +97,8 @@ def translate(request, unit_id):
try:
response['translations'] = translation_service.translate(
unit.translation.language.code,
unit.get_source_plurals()[0]
unit.get_source_plurals()[0],
unit
)
response['responseStatus'] = 200
except Exception as exc:
......
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