From c3baed6ff87ae74b951807ba6c8d386bb07c9399 Mon Sep 17 00:00:00 2001 From: Oleg Broytman Date: Tue, 29 Mar 2016 22:41:57 +0300 Subject: [PATCH] Use gettext Add Russian translation. --- m_librarian/translations.py | 15 +++++++++++++++ m_librarian/translations/Makefile | 8 ++++++++ m_librarian/translations/ru_RU.mo | Bin 0 -> 376 bytes m_librarian/translations/ru_RU.po | 18 ++++++++++++++++++ scripts/ml-search.py | 4 ++-- 5 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 m_librarian/translations.py create mode 100644 m_librarian/translations/Makefile create mode 100644 m_librarian/translations/ru_RU.mo create mode 100644 m_librarian/translations/ru_RU.po 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 0000000000000000000000000000000000000000..dc37a20dbfeeae09030e2b1c366a014e248baed1 GIT binary patch literal 376 zcmZXP%}T>S5XYk^NRD2-c-RMUV$!12wTiSBDYQ09(DOE#rqN_KY$jqJ#3%70g71(g z@L8OAum}IlkNubr{`0-R^X9O&nM3A?*=2@Ir;zF1cg(?-<2>@Y#~8kI{Hp8y)6$sd z$_cG`!kA#1zysPUGg=DY^S!l*$iXR0EI ztkPAk$XF>BIi_M{O+$s!Vpy(|E5_EIRs~+VGo{m7r3ewKLW*0XQ8Y;Id^(?OYz3b0 zj*TYNJiIB{58*2vm$}OHxro=wR!A2$tzfXJ>rAZB!bHa=$#g2k0G1iKH>lC_QVEP2 ZDas~A>ZW;RBLeTlb=uGNtNm!-ogWzrXR81J literal 0 HcmV?d00001 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__': -- 2.39.5