From 46ff77c09f3af957a4fce444d96bf942ddf342e7 Mon Sep 17 00:00:00 2001 From: Oleg Broytman Date: Wed, 30 Mar 2016 20:52:11 +0300 Subject: [PATCH] Fix a bug: get translations even if locale isn't set --- m_librarian/translations.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/m_librarian/translations.py b/m_librarian/translations.py index e2234b9..a979472 100644 --- a/m_librarian/translations.py +++ b/m_librarian/translations.py @@ -4,12 +4,16 @@ import locale import os language = locale.getdefaultlocale()[0] -mo_filename = os.path.join( - os.path.dirname(__file__), 'translations', language + '.mo') -if os.path.exists(mo_filename): - mo_file = open(mo_filename, 'rb') - translation = gettext.GNUTranslations(mo_file) - mo_file.close() -else: - translation = gettext.NullTranslations() +translations = None + +if language: + mo_filename = os.path.join( + os.path.dirname(__file__), 'translations', language + '.mo') + if os.path.exists(mo_filename): + mo_file = open(mo_filename, 'rb') + translations = gettext.GNUTranslations(mo_file) + mo_file.close() + +if translations is None: + translations = gettext.NullTranslations() translation.install(unicode=True) -- 2.39.2