]> git.phdru.name Git - m_librarian.git/commitdiff
Use gettext
authorOleg Broytman <phd@phdru.name>
Tue, 29 Mar 2016 19:41:57 +0000 (22:41 +0300)
committerOleg Broytman <phd@phdru.name>
Tue, 29 Mar 2016 19:41:57 +0000 (22:41 +0300)
Add Russian translation.

m_librarian/translations.py [new file with mode: 0644]
m_librarian/translations/Makefile [new file with mode: 0644]
m_librarian/translations/ru_RU.mo [new file with mode: 0644]
m_librarian/translations/ru_RU.po [new file with mode: 0644]
scripts/ml-search.py

diff --git a/m_librarian/translations.py b/m_librarian/translations.py
new file mode 100644 (file)
index 0000000..e2234b9
--- /dev/null
@@ -0,0 +1,15 @@
+
+import gettext
+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()
+translation.install(unicode=True)
diff --git a/m_librarian/translations/Makefile b/m_librarian/translations/Makefile
new file mode 100644 (file)
index 0000000..912175c
--- /dev/null
@@ -0,0 +1,8 @@
+%.mo: %.po
+       msgfmt -o $@ -- $<
+
+po_files = $(shell echo *.po)
+mo_files = $(patsubst %.po,%.mo,$(po_files))
+
+.PHONY: all
+all: $(mo_files)
diff --git a/m_librarian/translations/ru_RU.mo b/m_librarian/translations/ru_RU.mo
new file mode 100644 (file)
index 0000000..dc37a20
Binary files /dev/null and b/m_librarian/translations/ru_RU.mo differ
diff --git a/m_librarian/translations/ru_RU.po b/m_librarian/translations/ru_RU.po
new file mode 100644 (file)
index 0000000..91ffe2c
--- /dev/null
@@ -0,0 +1,18 @@
+# Russian translation
+# Copyright 2016 (C) PhiloSoft Design
+# Created by Oleg Broytman <phd@phdru.name>
+#
+msgid ""
+msgstr ""
+"Project-Id-Version: 0.0.3\n"
+"POT-Creation-Date: 2016-03-29\n"
+"PO-Revision-Date: 2016-03-29\n"
+"Last-Translator: Oleg Broytman <phd@phdru.name>\n"
+"Language-Team: None yet\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=utf-8\n"
+"Content-Transfer-Encoding: 8-bit\n"
+"Generated-By: pygettext.py 1.5\n"
+
+msgid "books"
+msgstr "книг"
index e6827f7fa66d48d480ed4d583b5f63ba8873a349..daef7a01de9674f899da97d350d96346a2b38db2 100755 (executable)
@@ -1,10 +1,10 @@
 #! /usr/bin/env python
-# coding: utf-8
 
 import argparse
 from m_lib.defenc import default_encoding
 from m_librarian.search import search_authors, search_books, \
     search_extensions, search_genres, search_languages
+import m_librarian.translations
 
 
 def _search_authors(args):
@@ -19,7 +19,7 @@ def _search_authors(args):
                            (author.surname, author.name, author.misc_name))
         full_name = u' '.join(full_name)
         print full_name.encode(default_encoding), \
-            u"(книг: %d)".encode(default_encoding) % author.count
+            (u"(%s: %d)" % (_('books'), author.count)).encode(default_encoding)
 
 
 if __name__ == '__main__':