mirror of
https://github.com/aljazceru/chatgpt-telegram-bot.git
synced 2025-12-19 21:55:06 +01:00
added translations for messages from openai_helper
This commit is contained in:
@@ -14,29 +14,9 @@ from telegram.ext import ApplicationBuilder, ContextTypes, CommandHandler, Messa
|
||||
filters, InlineQueryHandler, Application, CallbackContext
|
||||
|
||||
from pydub import AudioSegment
|
||||
from openai_helper import OpenAIHelper
|
||||
from openai_helper import OpenAIHelper, localized_text
|
||||
from usage_tracker import UsageTracker
|
||||
|
||||
with open('translations.json', 'r', encoding='utf-8') as f:
|
||||
translations = json.load(f)
|
||||
|
||||
def localized_text(key, bot_language):
|
||||
"""
|
||||
Return translated text for a key in specified bot_language.
|
||||
Keys and translations can be found in the translations.json.
|
||||
"""
|
||||
try:
|
||||
return translations[bot_language][key]
|
||||
except KeyError:
|
||||
logging.warning(f"No translation available for bot_language code '{bot_language}' and key '{key}'")
|
||||
# Fallback to English if the translation is not available
|
||||
if key in translations['en']:
|
||||
return translations['en'][key]
|
||||
else:
|
||||
logging.warning(f"No english definition found for key '{key}' in translations.json")
|
||||
# return key as text
|
||||
return key
|
||||
|
||||
def message_text(message: Message) -> str:
|
||||
"""
|
||||
Returns the text of a message, excluding any bot commands.
|
||||
|
||||
Reference in New Issue
Block a user