Commit 61928620 authored by Dmitry Shelepnev's avatar Dmitry Shelepnev
Browse files

Add translation for sopds_telebot.... but not working in management command

parent bad7dd3c
Loading
Loading
Loading
Loading
+55 −2
Original line number Diff line number Diff line
@@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2018-02-18 17:59+0300\n"
"POT-Creation-Date: 2018-04-03 22:20+0300\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@@ -259,7 +259,7 @@ msgstr "секция"
msgid "subsection"
msgstr "подсекция"

#: .\opds_catalog\sopdscan.py:232
#: .\opds_catalog\sopdscan.py:233
msgid "Unknown author"
msgstr "Неизвестный автор"

@@ -268,6 +268,59 @@ msgstr "Неизвестный автор"
msgid "All books by %(full_name)s"
msgstr "Все книги автора %(full_name)s"

#~ msgid ""
#~ "Hello %s!\n"
#~ "Unfortunately you do not have access to information. Please contact the "
#~ "bot administrator."
#~ msgstr ""
#~ "Здравствуйте %s!\n"
#~ "К сожалению у Вас отсутствует доступ к информации. Обратитесь к "
#~ "администратору бота."

#~ msgid "Denied access for user: %s"
#~ msgstr "Отказ в доступе для пользователя: %s"

#~ msgid ""
#~ "%(subtitle)s\n"
#~ "Hello %(username)s! To search for a book, enter part of her title or "
#~ "author:"
#~ msgstr ""
#~ "%(subtitle)s\n"
#~ "Здравствуйте %(username)s! Для поиска книги, введите часть ее "
#~ "наименования или автора:"

#~ msgid "(doubles:%s) "
#~ msgstr "(дубликатов:%s) "

#~ msgid "Too short for search, please try again."
#~ msgstr "Слишком короткая строка для поиска, попробуйте еще раз."

#~ msgid "I'm searching for the book: %s"
#~ msgstr "Выполняю поиск книги: %s"

#~ msgid "No results were found for your query, please try again."
#~ msgstr "По Вашему запросу ничего не найдено, попробуйте еще раз."

#~ msgid ""
#~ "Found %s books.\n"
#~ "I create list, after a few seconds, select the file to download:"
#~ msgstr ""
#~ "Найдено %s книг(и). \n"
#~ "Формирую список, через несколько секунд выберите нужную для скачивания:"

#~ msgid ""
#~ "The book on the link you specified is not found, try to repeat the book "
#~ "search first."
#~ msgstr ""
#~ "Книга по указанной Вами ссылке не найдена, попробуйте повторить поиск "
#~ "книги сначала."

#~ msgid "Annotation:"
#~ msgstr "Аннотация:"

#~ msgid "There was a technical error, please contact the Bot administrator."
#~ msgstr "Возникла техническая ошибка, обратитесь к администратору Бота."

#~ msgid "Book name:"
#~ msgstr "Название:"

+20 −17
Original line number Diff line number Diff line
@@ -10,15 +10,16 @@ from django.utils.html import strip_tags
from django.db.models import Q
from django.db import transaction, connection, connections
from django.contrib.auth.models import User
from django.urls import reverse
from django.utils.translation import ugettext as _
from django.utils import translation

from opds_catalog.models import Book, Author
from opds_catalog.models import Book
from opds_catalog import settings, dl
from opds_catalog.opds_paginator import Paginator as OPDS_Paginator
from sopds_web_backend.settings import HALF_PAGES_LINKS
from constance import config
from telegram.ext import Updater, CommandHandler, MessageHandler, Filters, RegexHandler, CallbackQueryHandler
from telegram import InlineKeyboardButton, InlineKeyboardMarkup, Document
from telegram import InlineKeyboardButton, InlineKeyboardMarkup
from telegram.error import InvalidToken

query_delimiter = "####"
@@ -26,7 +27,6 @@ query_delimiter = "####"

def CheckAuthDecorator(func):
    def wrapper(self, bot, update):

        if not config.SOPDS_TELEBOT_AUTH:
            return func(self, bot, update)

@@ -41,8 +41,8 @@ def CheckAuthDecorator(func):
            return func(self, bot, update)

        bot.sendMessage(chat_id=query.chat_id,
                        text="Здравствуйте %s!\nК сожалению у Вас отсутствует доступ к информации. Обратитесь к администратору бота." % username)
        self.logger.info("Denied access for user: %s" % username)
                        text=_("Hello %s!\nUnfortunately you do not have access to information. Please contact the bot administrator.") % username)
        self.logger.info(_("Denied access for user: %s") % username)

        return

@@ -50,6 +50,8 @@ def CheckAuthDecorator(func):

class Command(BaseCommand):
    help = 'SimpleOPDS Telegram Bot engine.'
    can_import_settings = True
    leave_locale_alone = True

    def add_arguments(self, parser):
        parser.add_argument('command', help='Use [ start | stop | restart ]')
@@ -62,6 +64,7 @@ class Command(BaseCommand):
        self.logger = logging.getLogger('')
        self.logger.setLevel(logging.DEBUG)
        formatter=logging.Formatter('%(asctime)s %(levelname)-8s %(message)s')
        translation.activate(config.SOPDS_LANGUAGE)

        if settings.LOGLEVEL!=logging.NOTSET:
            # Создаем обработчик для записи логов в файл
@@ -95,8 +98,8 @@ class Command(BaseCommand):
    @CheckAuthDecorator
    def startCommand(self, bot, update):

        bot.sendMessage(chat_id=update.message.chat_id, text="%s\nЗдравствуйте %s! Для поиска книги, введите часть ее наименования или автора:"%
                                                             (settings.SUBTITLE,update.message.from_user.username))
        bot.sendMessage(chat_id=update.message.chat_id, text=_("%(subtitle)s\nHello %(username)s! To search for a book, enter part of her title or author:")%
                                                             {'subtitle':settings.SUBTITLE,'username':update.message.from_user.username})
        self.logger.info("Start talking with user: %s"%update.message.from_user)
        return

@@ -160,7 +163,7 @@ class Command(BaseCommand):
        response = ''
        for b in items:
            authors = ', '.join([a['full_name'] for a in b['authors']])
            doubles = '(дубликатов:%s) '%b['doubles'] if b['doubles'] else ''
            doubles = _("(doubles:%s) ")%b['doubles'] if b['doubles'] else ''
            response+='<b>%(title)s</b>\n%(author)s\n%(dbl)s/download%(link)s\n\n'%{'title':b['title'], 'author':authors,'link':b['id'], 'dbl':doubles}

        buttons = [InlineKeyboardButton('1 <<', callback_data='%s%s%s'%(query,query_delimiter,1)),
@@ -179,9 +182,9 @@ class Command(BaseCommand):
        self.logger.info("Got message from user %s: %s" % (update.message.from_user.username, query))

        if len(query)<3:
            response = 'Слишком короткая строка для поиска, попробуйте еще раз.'
            response = _("Too short for search, please try again.")
        else:
            response = 'Выполняю поиск книги: %s' % (query)
            response = _("I'm searching for the book: %s") % (query)

        bot.send_message(chat_id=update.message.chat_id, text=response)
        self.logger.info("Send message to user %s: %s" % (update.message.from_user.username,response))
@@ -193,12 +196,12 @@ class Command(BaseCommand):
        books_count = books.count()

        if books_count == 0:
            response = 'По Вашему запросу ничего не найдено, попробуйте еще раз.'
            response = _("No results were found for your query, please try again.")
            bot.send_message(chat_id=update.message.chat_id, text=response)
            self.logger.info("Send message to user %s: %s" % (update.message.from_user.username,response))
            return

        response = 'Найдено %s книг(и). \nФормирую список, через несколько секунд выберите нужную для скачивания:' % books_count
        response = _("Found %s books.\nI create list, after a few seconds, select the file to download:") % books_count
        bot.send_message(chat_id=update.message.chat_id, text=response)
        self.logger.info("Send message to user %s: %s" % (update.message.from_user.username, response))

@@ -236,13 +239,13 @@ class Command(BaseCommand):
            book=None

        if book==None:
            response = 'Книга по указанной Вами ссылке не найдена, попробуйте повторить поиск книги сначала.'
            response = _("The book on the link you specified is not found, try to repeat the book search first.")
            bot.sendMessage(chat_id=update.message.chat_id, text=response, parse_mode='HTML')
            self.logger.info("Not find download links: %s" % response)
            return

        authors = ', '.join([a['full_name'] for a in book.authors.values()])
        response = '<b>%(title)s</b>\n%(author)s\n<b>Аннотация:</b>%(annotation)s\n' % {'title': book.title, 'author': authors, 'annotation':book.annotation}
        response = ('<b>%(title)s</b>\n%(author)s\n<b>'+_("Annotation:")+'</b>%(annotation)s\n') % {'title': book.title, 'author': authors, 'annotation':book.annotation}

        buttons = [InlineKeyboardButton(book.format.upper(), callback_data='/getfileorig%s'%book_id)]
        if not book.format in settings.NOZIP_FORMATS:
@@ -273,7 +276,7 @@ class Command(BaseCommand):
            book=None

        if book==None:
            response = 'Книга по указанной Вами ссылке не найдена, попробуйте повторить поиск книги сначала.'
            response = _("The book on the link you specified is not found, try to repeat the book search first.")
            bot.sendMessage(chat_id=callback_query.message.chat_id, text=response, parse_mode='HTML')
            self.logger.info("Not find download links: %s" % response)
            return
@@ -305,7 +308,7 @@ class Command(BaseCommand):
            document.close()
            self.logger.info("Send file: %s" % filename)
        else:
            response = 'Возникла техническая ошибка, обратитесь к администратору сайта.'
            response = _("There was a technical error, please contact the Bot administrator.")
            bot.sendMessage(chat_id=callback_query.message.chat_id, text=response, parse_mode='HTML')
            self.logger.info("Book get error: %s" % response)
            return
+2.47 KiB

File added.

No diff preview for this file type.

+79 −0
Original line number Diff line number Diff line
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2018-04-03 22:20+0300\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=4; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n"
"%10<=4 && (n%100<12 || n%100>14) ? 1 : n%10==0 || (n%10>=5 && n%10<=9) || (n"
"%100>=11 && n%100<=14)? 2 : 3);\n"
#: .\opds_catalog\management\commands\sopds_telebot.py:45
#, python-format
msgid ""
"Hello %s!\n"
"Unfortunately you do not have access to information. Please contact the bot "
"administrator."
msgstr "Здравствуйте %s!\nК сожалению у Вас отсутствует доступ к информации. Обратитесь к администратору бота."

#: .\opds_catalog\management\commands\sopds_telebot.py:46
#, python-format
msgid "Denied access for user: %s"
msgstr "Отказ в доступе для пользователя: %s"

#: .\opds_catalog\management\commands\sopds_telebot.py:99
#, python-format
msgid ""
"%(subtitle)s\n"
"Hello %(username)s! To search for a book, enter part of her title or author:"
msgstr "%(subtitle)s\nЗдравствуйте %(username)s! Для поиска книги, введите часть ее наименования или автора:"

#: .\opds_catalog\management\commands\sopds_telebot.py:164
#, python-format
msgid "(doubles:%s) "
msgstr "(дубликатов:%s) "

#: .\opds_catalog\management\commands\sopds_telebot.py:183
msgid "Too short for search, please try again."
msgstr "Слишком короткая строка для поиска, попробуйте еще раз."

#: .\opds_catalog\management\commands\sopds_telebot.py:185
#, python-format
msgid "I'm searching for the book: %s"
msgstr "Выполняю поиск книги: %s"

#: .\opds_catalog\management\commands\sopds_telebot.py:197
msgid "No results were found for your query, please try again."
msgstr "По Вашему запросу ничего не найдено, попробуйте еще раз."

#: .\opds_catalog\management\commands\sopds_telebot.py:202
#, python-format
msgid ""
"Found %s books.\n"
"I create list, after a few seconds, select the file to download:"
msgstr "Найдено %s книг(и). \nФормирую список, через несколько секунд выберите нужную для скачивания:"

#: .\opds_catalog\management\commands\sopds_telebot.py:240
#: .\opds_catalog\management\commands\sopds_telebot.py:277
msgid ""
"The book on the link you specified is not found, try to repeat the book "
"search first."
msgstr "Книга по указанной Вами ссылке не найдена, попробуйте повторить поиск книги сначала."

#: .\opds_catalog\management\commands\sopds_telebot.py:246
msgid "Annotation:"
msgstr "Аннотация:"

#: .\opds_catalog\management\commands\sopds_telebot.py:309
msgid "There was a technical error, please contact the Bot administrator."
msgstr "Возникла техническая ошибка, обратитесь к администратору Бота."
Loading