]> git.phdru.name Git - m_librarian.git/commitdiff
Feat: Get translations by language
authorOleg Broytman <phd@phdru.name>
Sun, 22 Apr 2018 19:03:31 +0000 (22:03 +0300)
committerOleg Broytman <phd@phdru.name>
Sun, 22 Apr 2018 20:57:43 +0000 (23:57 +0300)
Rename 'ru_RU' translations to just 'ru'.
Force language 'ru' for test_translations.py.

m_librarian/translations.py
m_librarian/translations/ru.mo [moved from m_librarian/translations/ru_RU.mo with 100% similarity]
m_librarian/translations/ru.po [moved from m_librarian/translations/ru_RU.po with 100% similarity]
tests/test_translations.py

index ba5f44c7f6c7719a2839c7182976b7b9e0de9a0d..e3cbce455d5b6a739c50d0a6b35711e0a8a505d1 100644 (file)
@@ -3,16 +3,25 @@ import gettext
 import locale
 import os
 
 import locale
 import os
 
-language = locale.getdefaultlocale()[0]
-translations = None
 
 
-if language:
+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()
     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]
+translations = None
+
+if language:
+    if language in ('ru_RU', 'Russian_Russia'):
+        language = 'ru'
+    translations = get_translations(language)
 
 if translations is None:
     translations = gettext.NullTranslations()
 
 if translations is None:
     translations = gettext.NullTranslations()
index 313d6d60542209c404bdbfb3c9206fdf23996520..ed451229808f626700e799a6421c08333a86d589 100644 (file)
@@ -1,14 +1,8 @@
 # coding: utf-8
 
 # coding: utf-8
 
-import os
-save_locale = os.environ.get('LC_CTYPE')
-os.environ['LC_CTYPE'] = 'ru_RU'
-
-from m_librarian.translations import translations  # noqa
-
-if save_locale:
-    os.environ['LC_CTYPE'] = save_locale
+from m_librarian.translations import get_translations
 
 
+translations = get_translations('ru')
 _ = getattr(translations, 'ugettext', None) or translations.gettext
 
 
 _ = getattr(translations, 'ugettext', None) or translations.gettext