<div align="center">
# Aiogram Translation Plugin 🌐
[![Supported Python versions](https://img.shields.io/pypi/pyversions/aiogram-translation.svg?logo=python&logoColor=FFE873)](https://pypi.org/project/aiogram-translation)
[![PyPI version](https://img.shields.io/pypi/v/aiogram-translation.svg?logo=pypi&logoColor=FFE873)](https://pypi.org/project/aiogram-translation)
[![PyPI downloads](https://img.shields.io/pypi/dm/aiogram-translation.svg)](https://pypi.org/project/aiogram-translation)
[![wakatime](https://wakatime.com/badge/github/barabum0/aiogram-translation.svg)](https://wakatime.com/badge/github/barabum0/aiogram-translation)
</div>
## 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 📥
```shell
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`
```python
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`
```python
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](https://github.com/barabum0/aiogram-translation/issues) 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](LICENSE) file for details.
Raw data
{
"_id": null,
"home_page": "https://github.com/barabum0/aiogram-translation",
"name": "aiogram-translation",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.10,<4.0",
"maintainer_email": "",
"keywords": "python,aiogram,telegram,pydantic,translation",
"author": "Roman Poltorabatko",
"author_email": "barabum@duck.com",
"download_url": "https://files.pythonhosted.org/packages/53/7c/3469cebb42f8149a6bbcd4b479ccd0eb6ddba8c96d25aa7a2368e51e0b12/aiogram_translation-2.0.1.tar.gz",
"platform": null,
"description": "<div align=\"center\">\n\n# Aiogram Translation Plugin \ud83c\udf10\n\n[![Supported Python versions](https://img.shields.io/pypi/pyversions/aiogram-translation.svg?logo=python&logoColor=FFE873)](https://pypi.org/project/aiogram-translation)\n[![PyPI version](https://img.shields.io/pypi/v/aiogram-translation.svg?logo=pypi&logoColor=FFE873)](https://pypi.org/project/aiogram-translation)\n[![PyPI downloads](https://img.shields.io/pypi/dm/aiogram-translation.svg)](https://pypi.org/project/aiogram-translation)\n[![wakatime](https://wakatime.com/badge/github/barabum0/aiogram-translation.svg)](https://wakatime.com/badge/github/barabum0/aiogram-translation)\n\n</div>\n\n## About \ud83d\udcd8\n\nThe 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.\n\n## Installation \ud83d\udce5\n\n```shell\npython -m pip install -U aiogram-translation \n```\n\n## Usage \ud83d\udee0\ufe0f\n\nTo 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:\n\n`main.py` \n```python\nfrom aiogram import Dispatcher, Bot, F\nfrom aiogram.types import Message, InlineKeyboardMarkup, InlineKeyboardButton, CallbackQuery\n\nfrom aiogram_translation import Translator\nfrom translations import *\n\nfrom os import getenv\n\nbot = Bot(getenv(\"TELEGRAM_TOKEN\"))\ndispatcher = Dispatcher()\ntranslator = Translator()\n\ntranslator.include([\n English(),\n Russian(),\n Ukrainian()\n])\ntranslator.set_default('ru')\ntranslator.register(dispatcher)\n\n\n@dispatcher.message()\nasync def on_message(message: Message, language: BaseTranslation):\n kb = InlineKeyboardMarkup(resize_keyboard=True, inline_keyboard=[[InlineKeyboardButton(text=language.start_button,\n callback_data=\"hoooray\")]])\n await message.reply(language.start_message, reply_markup=kb)\n\n\n@dispatcher.callback_query(F.data == \"hoooray\")\nasync def on_hooray(query: CallbackQuery, language: BaseTranslation):\n await query.answer(language.start_button_alert, show_alert=True)\n\n\ndispatcher.run_polling(bot)\n```\n\n`translations.py`\n```python\nfrom aiogram_translation.models import BaseTranslationBuilder\n\n\nclass BaseTranslation(BaseTranslationBuilder):\n start_message: str\n start_button: str\n start_button_alert: str\n\n link_lang_message: str\n\n\nclass English(BaseTranslation):\n key = \"en\"\n name = \"English\"\n\n start_message = \"\ud83d\udc4b Hi, I'm bot!\"\n start_button = \"\u2764\ufe0f Click me!\"\n start_button_alert = \"\ud83c\udf89 Hooray!\"\n\n\nclass Russian(BaseTranslation):\n key = \"ru\"\n name = \"\u0420\u0443\u0441\u0441\u043a\u0438\u0439 (Russian)\"\n\n start_message = \"\ud83d\udc4b \u041f\u0440\u0438\u0432\u0435\u0442, \u044f \u0431\u043e\u0442\"\n start_button = \"\u2764\ufe0f \u041d\u0430\u0436\u043c\u0438 \u043d\u0430 \u043c\u0435\u043d\u044f\"\n start_button_alert = \"\ud83c\udf89 \u0423\u0440\u0430!\"\n\n\nclass Ukrainian(BaseTranslation):\n key = \"uk\"\n name = \"\u0423\u043a\u0440\u0430\u0457\u043d\u0441\u044c\u043a\u0438\u0439 (Ukrainian)\"\n\n start_message = \"\ud83d\udc4b \u041f\u0440\u0438\u0432\u0456\u0442, \u044f \u0431\u043e\u0442\"\n start_button = \"\u2764\ufe0f \u041d\u0430\u0442\u0438\u0441\u043d\u0438 \u043d\u0430 \u043c\u0435\u043d\u0435\"\n start_button_alert = \"\ud83c\udf89 \u0423\u0440\u0430!\"\n```\n\n\n## Troubleshooting \ud83d\udea8\n\nIf you encounter issues or have queries, feel free to check our [Issues section](https://github.com/barabum0/aiogram-translation/issues) on GitHub.\n\n## Contribution \ud83e\udd1d\n\nContributions are welcome. Please fork the repository, make your changes, and submit a pull request.\n\n## License \ud83d\udcdc\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.",
"bugtrack_url": null,
"license": "MIT",
"summary": "Simple aiogram translation plugin built using pydantic.",
"version": "2.0.1",
"project_urls": {
"Homepage": "https://github.com/barabum0/aiogram-translation",
"Repository": "https://github.com/barabum0/aiogram-translation",
"bug_tracker": "https://github.com/barabum0/aiogram-translation/issues",
"source": "https://github.com/barabum0/aiogram-translation"
},
"split_keywords": [
"python",
"aiogram",
"telegram",
"pydantic",
"translation"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "1674fdf90f807f594e4a9130e0378276b6f9b8a6ce2fafaaf0a48ad6df95c359",
"md5": "6d92775d3debc71cb0570598b96932bf",
"sha256": "1edd0b941ddd79d902dad83fb03dff1782f881ea86fa24f458ce7fd73cf13b3b"
},
"downloads": -1,
"filename": "aiogram_translation-2.0.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "6d92775d3debc71cb0570598b96932bf",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.10,<4.0",
"size": 6180,
"upload_time": "2023-12-12T17:48:01",
"upload_time_iso_8601": "2023-12-12T17:48:01.707021Z",
"url": "https://files.pythonhosted.org/packages/16/74/fdf90f807f594e4a9130e0378276b6f9b8a6ce2fafaaf0a48ad6df95c359/aiogram_translation-2.0.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "537c3469cebb42f8149a6bbcd4b479ccd0eb6ddba8c96d25aa7a2368e51e0b12",
"md5": "41e6392cceec0bd46cac078f3fd071de",
"sha256": "ac84d99ad3f4c0f12d55ead058d6130b591919337f93dc3a6c91410b20c7c3bf"
},
"downloads": -1,
"filename": "aiogram_translation-2.0.1.tar.gz",
"has_sig": false,
"md5_digest": "41e6392cceec0bd46cac078f3fd071de",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.10,<4.0",
"size": 4593,
"upload_time": "2023-12-12T17:48:05",
"upload_time_iso_8601": "2023-12-12T17:48:05.514130Z",
"url": "https://files.pythonhosted.org/packages/53/7c/3469cebb42f8149a6bbcd4b479ccd0eb6ddba8c96d25aa7a2368e51e0b12/aiogram_translation-2.0.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-12-12 17:48:05",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "barabum0",
"github_project": "aiogram-translation",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "aiogram-translation"
}