150 lines
6.9 KiB
Python
150 lines
6.9 KiB
Python
"""
|
|
Internationalization module for the Lichess Telegram Bot
|
|
English language only
|
|
"""
|
|
|
|
from typing import Optional
|
|
|
|
# Translation dictionary (English only)
|
|
TRANSLATIONS = {
|
|
'en': {
|
|
# Start command
|
|
'start_message': (
|
|
"The bot tracks one or more players on Lichess.\n"
|
|
"It shows ratings, daily, yesterday and weekly activity.\n"
|
|
"When specifying a user_token (with puzzle read permission), you can also get puzzle data.\n"
|
|
"The bot supports automatic checks at specified intervals and sends a report if there was activity during that time.\n\n"
|
|
"Example for a week:\n"
|
|
"🧩 Puzzles: 114 (✅ 81 - ❌ 33)\n\n"
|
|
"🔥 Blitz — 5 games • 🔴 -10\n"
|
|
"Rating: 2245\n"
|
|
"✅ Wins: 1\n"
|
|
"❌ Losses: 3\n"
|
|
"🤝 Draws: 1\n\n"
|
|
"🐇 Rapid — 19 games • 🟢 +20\n"
|
|
"Rating: 2248\n"
|
|
"✅ Wins: 8\n"
|
|
"❌ Losses: 4\n"
|
|
"🤝 Draws: 7\n\n"
|
|
"📋 Available commands:\n"
|
|
"/addgamer - Add a Lichess player to track (username only)\n"
|
|
"/addtoken - Add a player with a token to get puzzle data\n"
|
|
"/getgamers - Select active player (for which /today and other commands will work)\n"
|
|
"/delgamer - Remove a player from the tracked list\n"
|
|
"/today - Statistics for today\n"
|
|
"/yesterday - Statistics for yesterday\n"
|
|
"/week - Statistics for the week\n"
|
|
"/lastYear_or_1000games - Statistics for the last year or last 1000 rated games (whichever comes first)\n"
|
|
"/setperiod - Set up periodic notifications for the active player\n"
|
|
"(active player changes in the /getgamers menu)\n"
|
|
"/support - Contact the developer for support and feedback"
|
|
),
|
|
|
|
# Add gamer commands
|
|
'addgamer_prompt': "👤 Enter the Lichess username of the player to track:",
|
|
'addtoken_prompt': (
|
|
"🔑 Enter the Lichess API token to get puzzle data.\n"
|
|
"The token is created in profile settings — give it only puzzle:read permission.\n"
|
|
"After that, the player corresponding to this token will be added."
|
|
),
|
|
'token_added': "✅ Token added for player {username}!",
|
|
'gamer_added_with_token': "✅ Player {username} added with token!",
|
|
'gamer_added': "✅ Player {username} successfully added!",
|
|
'invalid_token': "❌ Invalid token. Please try again.",
|
|
'token_username_error': "❌ Failed to get username from token. Please try again.",
|
|
'empty_username': "❌ Username cannot be empty. Please try again.",
|
|
'user_not_found': "❌ Player {username} not found on Lichess. Check the spelling of the name.",
|
|
|
|
# Get gamers
|
|
'no_gamers': "📭 No players in database. Use /addgamer to add.",
|
|
'loading_ratings': "🔄 Loading player ratings...",
|
|
'select_active_gamer': "👥 <b>Select active player:</b>\n\n",
|
|
'active_gamer_set': "✅ Active player: {username}",
|
|
'gamer_not_found': "❌ Player not found",
|
|
|
|
# Delete gamer
|
|
'no_gamers_to_delete': "📭 You have no tracked players.",
|
|
'loading_gamers': "🔄 Loading player list...",
|
|
'select_gamer_to_delete': "🗑️ <b>Select player to delete:</b>\n\n",
|
|
'gamer_deleted': "✅ Player <b>{username}</b> removed from tracked list.",
|
|
'active_gamer_deleted': "✅ Player <b>{username}</b> removed from tracked list.\n\n⚠️ You deleted the active player. Use the /getgamers command to select a player for which the /today, /yesterday, /week commands will work.",
|
|
'last_gamer_deleted': "✅ Player <b>{username}</b> removed from tracked list.\n\n⚠️ You deleted the last player. Use the /addgamer command to add a new tracked player.",
|
|
'delete_failed': "❌ Failed to delete player",
|
|
|
|
# Stats commands
|
|
'no_active_gamer': "❌ No active player. Use /getgamers to select.",
|
|
'unknown_period': "❌ Unknown period",
|
|
'no_data': "📭 No data",
|
|
'stats_title': "📊 Statistics {username} • {date_range}\n\n",
|
|
'puzzles_section': "🧩 Puzzles: {total} (✅ {solved} - ❌ {unsolved})\n\n",
|
|
'games_section': "{emoji} {game_type} — {games_count} games • {rating_change}\nRating: {rating}\n✅ Wins: {wins}\n❌ Losses: {losses}\n🤝 Draws: {draws}\n\n",
|
|
|
|
# Set period
|
|
'select_period': "⏱️ Select period for player {username}:\n📱 Notifications will be sent to personal messages",
|
|
'notifications_disabled': "✅ Notifications disabled for {username}",
|
|
'period_set': "✅ Period {period} minutes set for {username}\n📱 Notifications will be sent to personal messages",
|
|
'disable_notifications': "❌ Disable notifications",
|
|
'period_minutes': "⏰ {period} minutes",
|
|
|
|
# Period notification
|
|
'period_1_minute': "for 1 minute",
|
|
'period_2_3_4_minutes': "for {period} minutes",
|
|
'period_minutes_text': "for {period} minutes",
|
|
'period_notification_title': "📊 Statistics {username} • {period_text}\n\n",
|
|
'period_puzzles_section': "🧩 Puzzles: {total} (✅ {solved} - ❌ {failed})\n\n",
|
|
'period_games_section': "{emoji} {game_type} — {games_count} games • {rating_change}\nRating: {rating}\n✅ Wins: {wins}\n❌ Losses: {losses}\n🤝 Draws: {draws}\n\n",
|
|
'no_activity': "📭 No activity for this period",
|
|
|
|
# Support
|
|
'support_message': (
|
|
"💬 <b>Support & Feedback</b>\n\n"
|
|
"You can write to the service developer directly and report a problem, suggest new features, or ask a question.\n\n"
|
|
"I will be happy to review every message and respond to it.\n\n"
|
|
"The developer accepts messages in <b>English</b> and <b>Russian</b> languages.\n\n"
|
|
"📧 Contact: <a href=\"https://t.me/vrubelr\">@vrubelr</a>\n\n"
|
|
"📦 Bot version: <b>{version}</b>"
|
|
),
|
|
|
|
# Common
|
|
'period_minutes_suffix': "m",
|
|
}
|
|
}
|
|
|
|
|
|
def get_user_language(update) -> str:
|
|
"""
|
|
Always return English language.
|
|
"""
|
|
return 'en'
|
|
|
|
|
|
def t(key: str, lang: str = 'en', **kwargs) -> str:
|
|
"""
|
|
Translate a key (always English).
|
|
|
|
Args:
|
|
key: Translation key
|
|
lang: Language code (ignored, always uses English)
|
|
**kwargs: Format arguments for the translation string
|
|
|
|
Returns:
|
|
Translated string with formatted arguments
|
|
"""
|
|
translation = TRANSLATIONS['en'].get(key, key)
|
|
|
|
# Format the string if kwargs provided
|
|
if kwargs:
|
|
try:
|
|
return translation.format(**kwargs)
|
|
except KeyError:
|
|
# If formatting fails, return the translation as-is
|
|
return translation
|
|
|
|
return translation
|
|
|
|
|
|
def get_lang_from_update(update) -> str:
|
|
"""
|
|
Always return English.
|
|
"""
|
|
return 'en'
|