From 8f41070d903563847d4c8bf83e27923d6a64a046 Mon Sep 17 00:00:00 2001 From: "Marten (msc)" Date: Wed, 28 Aug 2024 10:39:39 -0500 Subject: [PATCH] [ADD] Translations for premium user interactions translate markup keyboard under summary Translate prefix for summary message translate the "no, thanks" button in the premium keyboard markup template for premium message when no subscription create + translate missing templates, finish translating texts in premium.py --- summaree_bot/bot/audio.py | 35 ++++++++-- summaree_bot/bot/premium.py | 64 ++++++++++++++----- .../data/de/premium_active_de.md.jinja2 | 6 ++ .../data/de/premium_inactive_de.md.jinja2 | 4 ++ .../data/de/sale_suffix_de.md.jinja2 | 9 ++- .../data/es/premium_active_es.md.jinja2 | 6 ++ .../data/es/premium_inactive_es.md.jinja2 | 4 ++ .../data/es/sale_suffix_es.md.jinja2 | 9 ++- .../templates/data/premium_inactive.md.jinja2 | 4 ++ .../data/ru/premium_active_ru.md.jinja2 | 6 ++ .../data/ru/premium_inactive_ru.md.jinja2 | 4 ++ .../data/ru/sale_suffix_ru.md.jinja2 | 9 ++- .../templates/data/sale_suffix.md.jinja2 | 2 +- summaree_bot/templates/templates.py | 13 +++- 14 files changed, 136 insertions(+), 39 deletions(-) create mode 100644 summaree_bot/templates/data/de/premium_active_de.md.jinja2 create mode 100644 summaree_bot/templates/data/de/premium_inactive_de.md.jinja2 create mode 100644 summaree_bot/templates/data/es/premium_active_es.md.jinja2 create mode 100644 summaree_bot/templates/data/es/premium_inactive_es.md.jinja2 create mode 100644 summaree_bot/templates/data/premium_inactive.md.jinja2 create mode 100644 summaree_bot/templates/data/ru/premium_active_ru.md.jinja2 create mode 100644 summaree_bot/templates/data/ru/premium_inactive_ru.md.jinja2 diff --git a/summaree_bot/bot/audio.py b/summaree_bot/bot/audio.py index 85289a5..6dcd2b0 100644 --- a/summaree_bot/bot/audio.py +++ b/summaree_bot/bot/audio.py @@ -65,16 +65,23 @@ async def get_summary_msg(update: Update, context: ContextTypes.DEFAULT_TYPE) -> bot_msg = _get_summary_message(update, context, summary) # add button for elaboration + lang_to_button_text = { + "en": ["📖 Full transcript", "🪄 Give me more"], + "de": ["📖 Volles Transcript", "🪄 Mehr Kontext"], + "es": ["📖 Transcripción completa", "🪄 Más contexto"], + "ru": ["📖 Полный транскрипт", "🪄 Больше контекста"], + } + button_texts = lang_to_button_text.get(update.effective_user.language_code, lang_to_button_text["en"]) buttons = [ InlineKeyboardButton( - "📖 Full transcript", + button_texts[0], callback_data={ "fnc": "elaborate", "kwargs": {"transcript_id": summary.transcript_id}, }, ), InlineKeyboardButton( - "🪄 Give me more", + button_texts[1], callback_data={ "fnc": "elaborate", "kwargs": {"summary_id": summary.id}, @@ -118,14 +125,28 @@ def _get_summary_message(update: Update, context: DbSessionContext, summary: Sum else: msg = "\n".join(f"- {topic.text}" for topic in sorted(summary.topics, key=lambda t: t.order)) - # add language info if different if (summary_language := summary.transcript.input_language) and summary_language != chat.language: - prefix = "\n".join( - [ + # add language info if different + lang_to_lang_prefix = { + "en": [ f"Voice message/audio language: {summary.transcript.input_language.flag_emoji}", f"Summary language: {chat.language.flag_emoji}", - ] - ) + ], + "de": [ + f"Sprachnachricht/Audio-Sprache: {summary.transcript.input_language.flag_emoji}", + f"Zusammenfassungssprache: {chat.language.flag_emoji}", + ], + "es": [ + f"Lenguaje del mensaje de voz/audio: {summary.transcript.input_language.flag_emoji}", + f"Lenguaje de la resumen: {chat.language.flag_emoji}", + ], + "ru": [ + f"Язык аудиосообщения/аудио: {summary.transcript.input_language.flag_emoji}", + f"Язык резюме: {chat.language.flag_emoji}", + ], + } + prefix_lines = lang_to_lang_prefix.get(update.effective_user.language_code, lang_to_lang_prefix["en"]) + prefix = "\n".join(prefix_lines) text = f"{prefix}\n\n{msg}" else: text = msg diff --git a/summaree_bot/bot/premium.py b/summaree_bot/bot/premium.py index 5035777..7fffb5a 100644 --- a/summaree_bot/bot/premium.py +++ b/summaree_bot/bot/premium.py @@ -158,7 +158,14 @@ def get_subscription_keyboard( ] for period, text in period_to_keyboard_button_text.items() ] - keyboard_buttons.append([InlineKeyboardButton("😌 No, thanks", callback_data={"fnc": "remove_inline_keyboard"})]) + lang_to_remove_button_text = { + "en": "😌 No, thanks", + "ru": "😌 Нет, спасибо", + "de": "😌 Nein, danke", + "es": "😌 No, gracias", + } + remove_button_text = lang_to_remove_button_text.get(ietf_tag, lang_to_remove_button_text["en"]) + keyboard_buttons.append([InlineKeyboardButton(remove_button_text, callback_data={"fnc": "remove_inline_keyboard"})]) if return_products: return InlineKeyboardMarkup(keyboard_buttons), periods_to_products else: @@ -204,8 +211,8 @@ def _premium_handler(update: Update, context: DbSessionContext) -> BotMessage: # -> ask user if subscription should be bought else: reply_markup, periods_to_products = get_subscription_keyboard(update, context, return_products=True) - - text = r"You currently have no active subscription\. " + get_sale_text(periods_to_products) + template = get_template("premium_inactive", update) + text = template.render(periods_to_products=periods_to_products) return BotMessage( chat_id=update.effective_chat.id, text=text, @@ -240,7 +247,7 @@ def _payment_callback(update: Update, context: DbSessionContext, product_id: int # create subscription start_date = datetime.now(dt.UTC) - end_date = start_date + timedelta(days=product.premium_period.value) + start_date + timedelta(days=product.premium_period.value) subscription = create_subscription( session, tg_user_id=tg_user.id, @@ -248,16 +255,27 @@ def _payment_callback(update: Update, context: DbSessionContext, product_id: int chat_id=chat_id, start_date=start_date, ) - - title = "summar.ee premium subscription" + lang_to_title = { + "en": "summar.ee premium", + "ru": "summar.ee премиум", + "de": "summar.ee Premium", + "es": "summar.ee premium", + } + title = lang_to_title.get(update.effective_user.language_code, lang_to_title["en"]) # In order to get a provider_token see https://core.telegram.org/bots/payments#getting-a-token currency = "XTR" price = product.discounted_price - days = product.premium_period.value - description = ( - f"Premium features for {days} days (from {start_date.strftime('%x')} to {end_date.strftime('%x')}; " - "ends automatically)" - ) + lang_to_description = { + "en": "Premium features for {days} days (from {start_date.strftime('%x')} to {end_date.strftime('%x')}; " + "ends automatically)", + "ru": "Премиум-функции на {days} дней (с {start_date.strftime('%x')} по {end_date.strftime('%x')}; " + "автоматически продлевается)", + "de": "Premium-Funktionen für {days} Tage (von {start_date.strftime('%x')} bis {end_date.strftime('%x')}; " + "automatisch verlängert)", + "es": "Premium por {days} días (desde {start_date.strftime('%x')} hasta {end_date.strftime('%x')}; " + "se renueva automáticamente)", + } + description = lang_to_description.get(update.effective_user.language_code, lang_to_description["en"]) prices = [LabeledPrice(description, price)] invoice = Invoice( @@ -456,11 +474,27 @@ def referral(update: Update, context: DbSessionContext, token: str) -> BotMessag ) session.add(subscription) - user_msg = BotMessage( - text=( - "🥳 You have successfully activated your 14 day trial premium subscription" - f"(ends at {end_date.strftime('%x')})" + lang_to_text = { + "en": ( + "🥳 You have successfully activated your 14 day trial premium features" + f" (ends on {end_date.strftime('%x')})" + ), + "ru": ( + "🥳 Вы успешно активировали 14-дневную пробную версию премиум-функций" + f" (заканчивается {end_date.strftime('%x')})" + ), + "de": ( + "🥳 Du hast deine 14-tägige Testversion der Premium-Funktionen erfolgreich aktiviert" + f" (endet am {end_date.strftime('%x')})" ), + "es": ( + "🥳 Has activado con éxito tu prueba de 14 días de las funciones premium" + f" (termina el {end_date.strftime('%x')})" + ), + } + text = lang_to_text.get(update.effective_user.language_code, lang_to_text["en"]) + user_msg = BotMessage( + text=text, chat_id=update.effective_chat.id, ) admin_group_msg = AdminChannelMessage( diff --git a/summaree_bot/templates/data/de/premium_active_de.md.jinja2 b/summaree_bot/templates/data/de/premium_active_de.md.jinja2 new file mode 100644 index 0000000..dfac43c --- /dev/null +++ b/summaree_bot/templates/data/de/premium_active_de.md.jinja2 @@ -0,0 +1,6 @@ +🌟 Premium is aktiv: +{% for subscription in subscriptions -%} +\- 📅 {{ escape_markdown(subscription.start_date.strftime('%x')) }} \- {{ escape_markdown(subscription.end_date.strftime('%x')) }} @ chat {{ escape_markdown(subscription.chat.title or subscription.chat.username) }} +{% endfor %} +{% include 'sale_suffix_de.md.jinja2' %} +Möchtest du die Premium-Funktionen verlängern? diff --git a/summaree_bot/templates/data/de/premium_inactive_de.md.jinja2 b/summaree_bot/templates/data/de/premium_inactive_de.md.jinja2 new file mode 100644 index 0000000..5365202 --- /dev/null +++ b/summaree_bot/templates/data/de/premium_inactive_de.md.jinja2 @@ -0,0 +1,4 @@ +🌟 Premium ist derzeit inaktiv\. + +{% include 'sale_suffix.md.jinja2' %} +Möchtest du Premium-Funktionen kaufen? diff --git a/summaree_bot/templates/data/de/sale_suffix_de.md.jinja2 b/summaree_bot/templates/data/de/sale_suffix_de.md.jinja2 index dbac975..6a86c3f 100644 --- a/summaree_bot/templates/data/de/sale_suffix_de.md.jinja2 +++ b/summaree_bot/templates/data/de/sale_suffix_de.md.jinja2 @@ -1,5 +1,4 @@ -Premium ist aktuell on SALE: -{% for premium_period, product in periods_to_products.items() %} -\- {{ premium_period.value }} Tage für ⭐{{ product.discounted_price }} \(~${{ product.price }} ➡️ {{(1-product.discounted_price/product.price)*100:.0f}}% OFF\!\) -{% endfor %} -Möchtest du Premium kaufen? +Es läuft eine **Aktion**: +{% for premium_period, product in periods_to_products.items() -%} +\- {{ premium_period.value }} Tage für ⭐{{ product.discounted_price }} \(~{{ product.price }}~ ➡️ {{ '%i' % ((1-product.discounted_price/product.price)*100) }}% Rabatt\!\) +{% endfor -%} diff --git a/summaree_bot/templates/data/es/premium_active_es.md.jinja2 b/summaree_bot/templates/data/es/premium_active_es.md.jinja2 new file mode 100644 index 0000000..f40d347 --- /dev/null +++ b/summaree_bot/templates/data/es/premium_active_es.md.jinja2 @@ -0,0 +1,6 @@ +🌟 Premium está activo: +{% for subscription in subscriptions -%} +\- 📅 {{ escape_markdown(subscription.start_date.strftime('%x')) }} \- {{ escape_markdown(subscription.end_date.strftime('%x')) }} @ chat {{ escape_markdown(subscription.chat.title or subscription.chat.username) }} +{% endfor %} +{% include 'sale_suffix_es.md.jinja2' %} +¿Te gustaría extender las funciones premium? diff --git a/summaree_bot/templates/data/es/premium_inactive_es.md.jinja2 b/summaree_bot/templates/data/es/premium_inactive_es.md.jinja2 new file mode 100644 index 0000000..2681959 --- /dev/null +++ b/summaree_bot/templates/data/es/premium_inactive_es.md.jinja2 @@ -0,0 +1,4 @@ +🌟 Premium no está activo\. + +{% include 'sale_suffix.md.jinja2' %} +¿Te gustaría comprar funciones premium? diff --git a/summaree_bot/templates/data/es/sale_suffix_es.md.jinja2 b/summaree_bot/templates/data/es/sale_suffix_es.md.jinja2 index ef57114..872311a 100644 --- a/summaree_bot/templates/data/es/sale_suffix_es.md.jinja2 +++ b/summaree_bot/templates/data/es/sale_suffix_es.md.jinja2 @@ -1,5 +1,4 @@ -¡Premium está en OFERTA AHORA MISMO: -{% for premium_period, product in periods_to_products.items() %} -\- {{ premium_period.value }} días por ⭐{{ product.discounted_price }} \(~${{ product.price }} ➡️ {{(1-product.discounted_price/product.price)*100:.0f}}% DE DESCUENTO\!\) -{% endfor %} -¿Te gustaría comprar premium? +¡Está en OFERTA AHORA MISMO: +{% for premium_period, product in periods_to_products.items() -%} +\- {{ premium_period.value }} días por ⭐{{ product.discounted_price }} \(~{{ product.price }}~ ➡️ {{ '%i' % ((1-product.discounted_price/product.price)*100) }}% OFF\!\) +{% endfor -%} diff --git a/summaree_bot/templates/data/premium_inactive.md.jinja2 b/summaree_bot/templates/data/premium_inactive.md.jinja2 new file mode 100644 index 0000000..7eb7f50 --- /dev/null +++ b/summaree_bot/templates/data/premium_inactive.md.jinja2 @@ -0,0 +1,4 @@ +🌟 Premium is currently inactive\. + +{% include 'sale_suffix.md.jinja2' %} +Would you like to buy premium features? diff --git a/summaree_bot/templates/data/ru/premium_active_ru.md.jinja2 b/summaree_bot/templates/data/ru/premium_active_ru.md.jinja2 new file mode 100644 index 0000000..fc37059 --- /dev/null +++ b/summaree_bot/templates/data/ru/premium_active_ru.md.jinja2 @@ -0,0 +1,6 @@ +🌟 Премиум в настоящее время активен: +{% for subscription in subscriptions -%} +\- 📅 {{ escape_markdown(subscription.start_date.strftime('%x')) }} \- {{ escape_markdown(subscription.end_date.strftime('%x')) }} @ чат {{ escape_markdown(subscription.chat.title or subscription.chat.username) }} +{% endfor %} +{% include 'sale_suffix_ru.md.jinja2' %} +Хотите продлить премиум-функции? diff --git a/summaree_bot/templates/data/ru/premium_inactive_ru.md.jinja2 b/summaree_bot/templates/data/ru/premium_inactive_ru.md.jinja2 new file mode 100644 index 0000000..a25faac --- /dev/null +++ b/summaree_bot/templates/data/ru/premium_inactive_ru.md.jinja2 @@ -0,0 +1,4 @@ +🌟 Премиум в настоящее время неактивен. + +{% include 'sale_suffix.md.jinja2' %} +Хотите приобрести премиум-функции? diff --git a/summaree_bot/templates/data/ru/sale_suffix_ru.md.jinja2 b/summaree_bot/templates/data/ru/sale_suffix_ru.md.jinja2 index 104a066..4c35dd2 100644 --- a/summaree_bot/templates/data/ru/sale_suffix_ru.md.jinja2 +++ b/summaree_bot/templates/data/ru/sale_suffix_ru.md.jinja2 @@ -1,5 +1,4 @@ -Премиум сейчас в РАСПРОДАЖЕ: -{% for premium_period, product in periods_to_products.items() %} -\- {{ premium_period.value }} дней за ⭐{{ product.discounted_price }} \(~${{ product.price }} ➡️ {{(1-product.discounted_price/product.price)*100:.0f}}% СКИДКА\!\) -{% endfor %} -Хотите купить премиум? +Сейчас действует РАСПРОДАЖА: +{% for premium_period, product in periods_to_products.items() -%} +\- {{ premium_period.value }} дней за ⭐{{ product.discounted_price }} \(~{{ product.price }}~ ➡️ скидка {{ '%i' % ((1-product.discounted_price/product.price)*100) }}%\!\) +{% endfor -%} diff --git a/summaree_bot/templates/data/sale_suffix.md.jinja2 b/summaree_bot/templates/data/sale_suffix.md.jinja2 index 5733eb1..45889a4 100644 --- a/summaree_bot/templates/data/sale_suffix.md.jinja2 +++ b/summaree_bot/templates/data/sale_suffix.md.jinja2 @@ -1,4 +1,4 @@ -Premium is on SALE right NOW: +SALE right NOW: {% for premium_period, product in periods_to_products.items() -%} \- {{ premium_period.value }} days for ⭐{{ product.discounted_price }} \(~{{ product.price }}~ ➡️ {{ '%i' % ((1-product.discounted_price/product.price)*100) }}% OFF\!\) {% endfor -%} diff --git a/summaree_bot/templates/templates.py b/summaree_bot/templates/templates.py index 213b3b9..fdb507e 100644 --- a/summaree_bot/templates/templates.py +++ b/summaree_bot/templates/templates.py @@ -42,7 +42,18 @@ }, "token_email": {"en": "token_email.html.jinja2"}, "register": {"en": "register.md.jinja2"}, - "premium_active": {"en": "premium_active.md.jinja2"}, + "premium_active": { + "en": "premium_active.md.jinja2", + "ru": "premium_active_ru.md.jinja2", + "es": "premium_active_es.md.jinja2", + "de": "premium_active_de.md.jinja2", + }, + "premium_inactive": { + "en": "premium_inactive.md.jinja2", + "ru": "premium_inactive_ru.md.jinja2", + "es": "premium_inactive_es.md.jinja2", + "de": "premium_inactive_de.md.jinja2", + }, }