Process Popen force utf-8

This commit is contained in:
resteve 2015-02-12 17:43:33 +01:00
parent fa6fd8d807
commit f8f3063ce1

View file

@ -35,9 +35,14 @@ class TranslateWizardTranslation:
@classmethod
def get_translation_from_apertium(cls, text, source_lang, target_lang):
proccess = Popen('echo "%s" | apertium %s-%s' %
(text, source_lang[:2], target_lang[:2]),
shell=True, stdout=PIPE, stderr=PIPE)
cmd = 'echo "%s" | apertium %s-%s' % (
text,
source_lang[:2],
target_lang[:2],
)
# force utf8 - TypeError: execv() arg 2 must contain only strings
cmd = cmd.encode('utf-8')
proccess = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE)
out, error = proccess.communicate()
if error:
cls.raise_user_error('error_translating', error_args=(text,))