Skip to content

Commit

Permalink
[ADD] Translations for premium user interactions
Browse files Browse the repository at this point in the history
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
  • Loading branch information
maschlr committed Aug 28, 2024
1 parent 0941f55 commit 8f41070
Show file tree
Hide file tree
Showing 14 changed files with 136 additions and 39 deletions.
35 changes: 28 additions & 7 deletions summaree_bot/bot/audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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
Expand Down
64 changes: 49 additions & 15 deletions summaree_bot/bot/premium.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -240,24 +247,35 @@ 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,
duration=product.premium_period.value,
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(
Expand Down Expand Up @@ -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(
Expand Down
6 changes: 6 additions & 0 deletions summaree_bot/templates/data/de/premium_active_de.md.jinja2
Original file line number Diff line number Diff line change
@@ -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?
4 changes: 4 additions & 0 deletions summaree_bot/templates/data/de/premium_inactive_de.md.jinja2
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
🌟 Premium ist derzeit inaktiv\.

{% include 'sale_suffix.md.jinja2' %}
Möchtest du Premium-Funktionen kaufen?
9 changes: 4 additions & 5 deletions summaree_bot/templates/data/de/sale_suffix_de.md.jinja2
Original file line number Diff line number Diff line change
@@ -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 -%}
6 changes: 6 additions & 0 deletions summaree_bot/templates/data/es/premium_active_es.md.jinja2
Original file line number Diff line number Diff line change
@@ -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?
4 changes: 4 additions & 0 deletions summaree_bot/templates/data/es/premium_inactive_es.md.jinja2
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
🌟 Premium no está activo\.

{% include 'sale_suffix.md.jinja2' %}
¿Te gustaría comprar funciones premium?
9 changes: 4 additions & 5 deletions summaree_bot/templates/data/es/sale_suffix_es.md.jinja2
Original file line number Diff line number Diff line change
@@ -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 -%}
4 changes: 4 additions & 0 deletions summaree_bot/templates/data/premium_inactive.md.jinja2
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
🌟 Premium is currently inactive\.

{% include 'sale_suffix.md.jinja2' %}
Would you like to buy premium features?
6 changes: 6 additions & 0 deletions summaree_bot/templates/data/ru/premium_active_ru.md.jinja2
Original file line number Diff line number Diff line change
@@ -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' %}
Хотите продлить премиум-функции?
4 changes: 4 additions & 0 deletions summaree_bot/templates/data/ru/premium_inactive_ru.md.jinja2
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
🌟 Премиум в настоящее время неактивен.

{% include 'sale_suffix.md.jinja2' %}
Хотите приобрести премиум-функции?
9 changes: 4 additions & 5 deletions summaree_bot/templates/data/ru/sale_suffix_ru.md.jinja2
Original file line number Diff line number Diff line change
@@ -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 -%}
2 changes: 1 addition & 1 deletion summaree_bot/templates/data/sale_suffix.md.jinja2
Original file line number Diff line number Diff line change
@@ -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 -%}
13 changes: 12 additions & 1 deletion summaree_bot/templates/templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
}


Expand Down

0 comments on commit 8f41070

Please sign in to comment.