From: Oleg Broytman Date: Wed, 30 Mar 2016 17:52:11 +0000 (+0300) Subject: Fix a bug: get translations even if locale isn't set X-Git-Tag: 0.0.4~41 X-Git-Url: https://git.phdru.name/?a=commitdiff_plain;h=46ff77c09f3af957a4fce444d96bf942ddf342e7;p=m_librarian.git Fix a bug: get translations even if locale isn't set --- 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)