Skip to main content

Aiogram Translation Plugin 🌐

Supported Python versions PyPI version PyPI downloads wakatime

About 📘

The Aiogram Translation Plugin is a convenient and powerful tool for integrating multilingual support into Aiogram-based Telegram bots. It enables seamless translation and language handling, making your bot accessible to a wider, global audience.

Installation 📥

python -m pip install -U aiogram-translation 

Usage 🛠️

To use the Aiogram Translation Plugin in your bot, import the necessary classes from aiogram_translation. Set up your languages, default language, and register the translator with your dispatcher. Here's a basic example:

main.py

from aiogram import Dispatcher, Bot, F
from aiogram.types import Message, InlineKeyboardMarkup, InlineKeyboardButton, CallbackQuery

from aiogram_translation import Translator
from translations import *

from os import getenv

bot = Bot(getenv("TELEGRAM_TOKEN"))
dispatcher = Dispatcher()
translator = Translator()

translator.include([
    English(),
    Russian(),
    Ukrainian()
])
translator.set_default('ru')
translator.register(dispatcher)


@dispatcher.message()
async def on_message(message: Message, language: BaseTranslation):
    kb = InlineKeyboardMarkup(resize_keyboard=True, inline_keyboard=[[InlineKeyboardButton(text=language.start_button,
                                                                                           callback_data="hoooray")]])
    await message.reply(language.start_message, reply_markup=kb)


@dispatcher.callback_query(F.data == "hoooray")
async def on_hooray(query: CallbackQuery, language: BaseTranslation):
    await query.answer(language.start_button_alert, show_alert=True)


dispatcher.run_polling(bot)

translations.py

from aiogram_translation.models import BaseTranslationBuilder


class BaseTranslation(BaseTranslationBuilder):
    start_message: str
    start_button: str
    start_button_alert: str

    link_lang_message: str


class English(BaseTranslation):
    key = "en"
    name = "English"

    start_message = "👋 Hi, I'm bot!"
    start_button = "❤️ Click me!"
    start_button_alert = "🎉 Hooray!"


class Russian(BaseTranslation):
    key = "ru"
    name = "Русский (Russian)"

    start_message = "👋 Привет, я бот"
    start_button = "❤️ Нажми на меня"
    start_button_alert = "🎉 Ура!"


class Ukrainian(BaseTranslation):
    key = "uk"
    name = "Український (Ukrainian)"

    start_message = "👋 Привіт, я бот"
    start_button = "❤️ Натисни на мене"
    start_button_alert = "🎉 Ура!"

Troubleshooting 🚨

If you encounter issues or have queries, feel free to check our Issues section on GitHub.

Contribution 🤝

Contributions are welcome. Please fork the repository, make your changes, and submit a pull request.

License 📜

This project is licensed under the MIT License - see the LICENSE file for details.

Metadata

Release files for aiogram-translation 2.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for aiogram-translation 2.0.1
File Size Uploaded Provenance
aiogram_translation-2.0.1.tar.gz 4.6 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for aiogram-translation 2.0.1
File Interpreter ABI Platform
aiogram_translation-2.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 10.8 kB

Release files / aiogram_translation-2.0.1.tar.gz

Download URL aiogram_translation-2.0.1.tar.gz
Size 4.6 kB
Tags Source
SHA-256 checksum
How to use checksums
ac84d99ad3f4c0f12d55ead058d6130b591919337f93dc3a6c91410b20c7c3bf
BLAKE2b-256 checksum
How to use checksums
537c3469cebb42f8149a6bbcd4b479ccd0eb6ddba8c96d25aa7a2368e51e0b12
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.7.1 CPython/3.12.0 Darwin/23.1.0

Release files / aiogram_translation-2.0.1-py3-none-any.whl

Download URL aiogram_translation-2.0.1-py3-none-any.whl
Size 6.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1edd0b941ddd79d902dad83fb03dff1782f881ea86fa24f458ce7fd73cf13b3b
BLAKE2b-256 checksum
How to use checksums
1674fdf90f807f594e4a9130e0378276b6f9b8a6ce2fafaaf0a48ad6df95c359
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.7.1 CPython/3.12.0 Darwin/23.1.0

Security for aiogram-translation 2.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page