Salz0 / telegram_flea

A open-source flea market bot, to be used in any Community
MIT License
9 stars 20 forks source link

🌐 Implement Multi-Language Support for the Bot Using aiogram's Built-in i18n 🌍 #6

Closed Salz0 closed 1 year ago

Salz0 commented 1 year ago

Description 📝: Implement support for multiple languages in the bot using Aiogram's built-in i18n features. The language setting will not be interactive and will be a bot-level configuration.

Requirements 📋: Installation: Install any necessary packages for i18n. Configuration: Configure i18n settings in Aiogram bot. Translations: Add translation files for supported languages. Fallback: Ensure there's a fallback language (ENGLISH or UKRAINIAN) if the set language translation isn't available. Acceptance Criteria 🎯:

from aiogram import Bot, types
from aiogram.dispatcher import Dispatcher
from aiogram.contrib.fsm_storage.memory import MemoryStorage
from aiogram.contrib.middlewares.i18n import I18nMiddleware

bot = Bot(token='YOUR_BOT_TOKEN')
storage = MemoryStorage()
dp = Dispatcher(bot, storage=storage)

i18n = I18nMiddleware('bot', 'path/to/locales')
dp.middleware.setup(i18n)

Add Translation Files: Create .po files and automate .mo creation for supported languages in the /locales directory.

Configure Language in Bot: Set the language to be used in the bot settings, and not allow users to change it.

@dp.message_handler(commands=['start'])
async def send_welcome(message: types.Message):
    await message.reply(i18n.t('bot.start_message'))

Test: Make sure all features work in the specified language, and a fallback language is used when necessary.

vessaldaneshvar commented 1 year ago

hello I want to work this issue. please assign this task to me.

Salz0 commented 1 year ago

hello

I want to work this issue.

please assign this task to me.

Hey! You can work on it right-away, create a pull request and I will merge if everything is fine 🙏