EN language only

This commit is contained in:
vrubelroman 2025-11-12 23:20:01 +03:00
parent 3ec1fe614d
commit 3362bf89e2
4 changed files with 353 additions and 94 deletions

136
LichessClientTG_bot/i18n.py Normal file
View file

@ -0,0 +1,136 @@
"""
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"
"/setperiod - Set up periodic notifications for the active player\n"
"(active player changes in the /getgamers menu)"
),
# 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.",
'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",
# 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'