From 10d39c83cbde62fa9c3b7ac24dab17131ac25180 Mon Sep 17 00:00:00 2001 From: Calum Lind Date: Sat, 13 Oct 2018 22:49:10 +0100 Subject: [PATCH] [WebUI] Fix error escaping translated text In a previous commit d4023e7dde42 removed a decode for Python 3 but with translated text returned by gettext encoded on Python 2 the escape function would raise a UnicodeDecodeError trying to use ascii to decode. The fix is to decode the message returned by gettext on Python 2. --- deluge/ui/web/common.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/deluge/ui/web/common.py b/deluge/ui/web/common.py index 0935e2f57..de0afb76c 100644 --- a/deluge/ui/web/common.py +++ b/deluge/ui/web/common.py @@ -12,11 +12,14 @@ from __future__ import unicode_literals import gettext import zlib -from deluge import common +from deluge.common import PY2, get_version def _(text): - return gettext.gettext(text) + text_local = gettext.gettext(text) + if PY2: + return text_local.decode('utf-8') + return text_local def escape(text): @@ -51,7 +54,7 @@ try: A template that adds some built-ins to the rendering """ - builtins = {'_': _, 'escape': escape, 'version': common.get_version()} + builtins = {'_': _, 'escape': escape, 'version': get_version()} def render(self, *args, **data): data.update(self.builtins)