From: Oleg Broytman Date: Tue, 29 Mar 2016 19:41:57 +0000 (+0300) Subject: Use gettext X-Git-Tag: 0.0.4~43 X-Git-Url: https://git.phdru.name/?a=commitdiff_plain;h=c3baed6ff87ae74b951807ba6c8d386bb07c9399;p=m_librarian.git Use gettext Add Russian translation. --- diff --git a/m_librarian/translations.py b/m_librarian/translations.py new file mode 100644 index 0000000..e2234b9 --- /dev/null +++ b/m_librarian/translations.py @@ -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 index 0000000..912175c --- /dev/null +++ b/m_librarian/translations/Makefile @@ -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 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 index 0000000..91ffe2c --- /dev/null +++ b/m_librarian/translations/ru_RU.po @@ -0,0 +1,18 @@ +# Russian translation +# Copyright 2016 (C) PhiloSoft Design +# Created by Oleg Broytman +# +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 \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 "книг" diff --git a/scripts/ml-search.py b/scripts/ml-search.py index e6827f7..daef7a0 100755 --- a/scripts/ml-search.py +++ b/scripts/ml-search.py @@ -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__':