X-Git-Url: https://git.phdru.name/?a=blobdiff_plain;f=m_librarian%2Ftranslations.py;h=e3cbce455d5b6a739c50d0a6b35711e0a8a505d1;hb=c02531fc55b9bc998de8bf825507bf0d3e53b74e;hp=e2234b948de750d12915633345b89b095a014ddb;hpb=c3baed6ff87ae74b951807ba6c8d386bb07c9399;p=m_librarian.git diff --git a/m_librarian/translations.py b/m_librarian/translations.py index e2234b9..e3cbce4 100644 --- a/m_librarian/translations.py +++ b/m_librarian/translations.py @@ -3,13 +3,25 @@ import gettext import locale import os + +def get_translations(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() + return translations + return None + + 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() -translation.install(unicode=True) +translations = None + +if language: + if language in ('ru_RU', 'Russian_Russia'): + language = 'ru' + translations = get_translations(language) + +if translations is None: + translations = gettext.NullTranslations()