]> git.phdru.name Git - m_librarian.git/commitdiff
Fix a bug: get translations even if locale isn't set
authorOleg Broytman <phd@phdru.name>
Wed, 30 Mar 2016 17:52:11 +0000 (20:52 +0300)
committerOleg Broytman <phd@phdru.name>
Wed, 30 Mar 2016 17:52:11 +0000 (20:52 +0300)
m_librarian/translations.py

index e2234b948de750d12915633345b89b095a014ddb..a979472c454e94df377ccaf4e7c85a5c74bb22ac 100644 (file)
@@ -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)