From a383e1b7d9e816991a36ba23e5d22f85d2a6d387 Mon Sep 17 00:00:00 2001 From: Michael Weiser Date: Mon, 8 Apr 2019 15:17:53 +0000 Subject: Force gettext to use unicode on python2 On python2 gettext returns str() which is not unicode() there and causes those feared encoding errors if anything formatted into those translated strings is not ascii. Force gettext to return unicode strings but only on python2 because it's default on python3 anyway and the respective parameters doesn't exist there. --- peekaboo/daemon.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/peekaboo/daemon.py b/peekaboo/daemon.py index 736f883..bc77580 100644 --- a/peekaboo/daemon.py +++ b/peekaboo/daemon.py @@ -271,7 +271,11 @@ def run(): logger.debug('Installing report message translations') translation = gettext.translation(locale_domain, locale_dir, languages, fallback=True) - translation.install() + # python2's gettext needs to be told explicitly to return unicode strings + loc_kwargs = {} + if sys.version_info[0] < 3: + loc_kwargs = {'unicode': True} + translation.install(loc_kwargs) # establish a connection to the database try: -- cgit v1.2.3