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