aiogram-i18n


Nameaiogram-i18n JSON
Version 1.3.4 PyPI version JSON
download
home_page
Summarysmall translation tools for aiogram
upload_time2023-12-31 14:46:14
maintainer
docs_urlNone
authorRootShinobi
requires_python>=3.8
licenseMIT License
keywords aiogram api asyncio bot fluent framework gnutext i18n telegram wrapper
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # aiogram_i18n

Installation:
```pip install aiogram_i18n```

To use FluentCompileCore:
```pip install fluent_compiler```

To use FluentRuntimeCore:
```pip install fluent.runtime```


```python
import asyncio
from contextlib import suppress
from logging import basicConfig, INFO
from typing import Any

from aiogram import Router, Dispatcher, F, Bot
from aiogram.enums import ParseMode
from aiogram.filters import CommandStart
from aiogram.types import Message

from aiogram_i18n import I18nContext, LazyProxy, I18nMiddleware
from aiogram_i18n.cores.fluent_runtime_core import FluentRuntimeCore
from aiogram_i18n.types import (
    ReplyKeyboardMarkup, KeyboardButton
    # you should import mutable objects from here if you want to use LazyProxy in them
)


router = Router(name=__name__)
rkb = ReplyKeyboardMarkup(
    keyboard=[
        [KeyboardButton(text=LazyProxy("help"))]  # or L.help()
    ], resize_keyboard=True
)


@router.message(CommandStart())
async def cmd_start(message: Message, i18n: I18nContext) -> Any:
    name = message.from_user.mention_html()
    return message.reply(
        text=i18n.get("hello", user=name),  # or i18n.hello(user=name)
        reply_markup=rkb
    )


@router.message(F.text == LazyProxy("help"))
async def cmd_help(message: Message) -> Any:
    return message.reply(text="-- " + message.text + " --")


async def main() -> None:
    basicConfig(level=INFO)
    bot = Bot("42:ABC", parse_mode=ParseMode.HTML)
    i18n_middleware = I18nMiddleware(
        core=FluentRuntimeCore(
            path="locales/{locale}/LC_MESSAGES"
        )
    )

    dp = Dispatcher()
    dp.include_router(router)
    i18n_middleware.setup(dispatcher=dp)

    await dp.start_polling(bot)


if __name__ == "__main__":
    with suppress(KeyboardInterrupt):
        asyncio.run(main())
```

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "aiogram-i18n",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "",
    "keywords": "aiogram,api,asyncio,bot,fluent,framework,gnutext,i18n,telegram,wrapper",
    "author": "RootShinobi",
    "author_email": "",
    "download_url": "https://files.pythonhosted.org/packages/e2/57/c8643bd36eaeb47a878890349db6d355714f7443fce6e3ab7ab2af69ccfc/aiogram_i18n-1.3.4.tar.gz",
    "platform": null,
    "description": "# aiogram_i18n\n\nInstallation:\n```pip install aiogram_i18n```\n\nTo use FluentCompileCore:\n```pip install fluent_compiler```\n\nTo use FluentRuntimeCore:\n```pip install fluent.runtime```\n\n\n```python\nimport asyncio\nfrom contextlib import suppress\nfrom logging import basicConfig, INFO\nfrom typing import Any\n\nfrom aiogram import Router, Dispatcher, F, Bot\nfrom aiogram.enums import ParseMode\nfrom aiogram.filters import CommandStart\nfrom aiogram.types import Message\n\nfrom aiogram_i18n import I18nContext, LazyProxy, I18nMiddleware\nfrom aiogram_i18n.cores.fluent_runtime_core import FluentRuntimeCore\nfrom aiogram_i18n.types import (\n    ReplyKeyboardMarkup, KeyboardButton\n    # you should import mutable objects from here if you want to use LazyProxy in them\n)\n\n\nrouter = Router(name=__name__)\nrkb = ReplyKeyboardMarkup(\n    keyboard=[\n        [KeyboardButton(text=LazyProxy(\"help\"))]  # or L.help()\n    ], resize_keyboard=True\n)\n\n\n@router.message(CommandStart())\nasync def cmd_start(message: Message, i18n: I18nContext) -> Any:\n    name = message.from_user.mention_html()\n    return message.reply(\n        text=i18n.get(\"hello\", user=name),  # or i18n.hello(user=name)\n        reply_markup=rkb\n    )\n\n\n@router.message(F.text == LazyProxy(\"help\"))\nasync def cmd_help(message: Message) -> Any:\n    return message.reply(text=\"-- \" + message.text + \" --\")\n\n\nasync def main() -> None:\n    basicConfig(level=INFO)\n    bot = Bot(\"42:ABC\", parse_mode=ParseMode.HTML)\n    i18n_middleware = I18nMiddleware(\n        core=FluentRuntimeCore(\n            path=\"locales/{locale}/LC_MESSAGES\"\n        )\n    )\n\n    dp = Dispatcher()\n    dp.include_router(router)\n    i18n_middleware.setup(dispatcher=dp)\n\n    await dp.start_polling(bot)\n\n\nif __name__ == \"__main__\":\n    with suppress(KeyboardInterrupt):\n        asyncio.run(main())\n```\n",
    "bugtrack_url": null,
    "license": "MIT License",
    "summary": "small translation tools for aiogram",
    "version": "1.3.4",
    "project_urls": {
        "Repository": "https://github.com/aiogram/aiogram_i18n"
    },
    "split_keywords": [
        "aiogram",
        "api",
        "asyncio",
        "bot",
        "fluent",
        "framework",
        "gnutext",
        "i18n",
        "telegram",
        "wrapper"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a6cdd6d2b9fd41772ceafabc1a965573538f6f141822b313527eaa5e778e41e3",
                "md5": "eedd02a0ef3ec434634a60de8e0be331",
                "sha256": "51ad31842b16dc6b79ed38073f221182d8b19f051ac75d18bc4d0ce823d99534"
            },
            "downloads": -1,
            "filename": "aiogram_i18n-1.3.4-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "eedd02a0ef3ec434634a60de8e0be331",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 33080,
            "upload_time": "2023-12-31T14:46:11",
            "upload_time_iso_8601": "2023-12-31T14:46:11.225591Z",
            "url": "https://files.pythonhosted.org/packages/a6/cd/d6d2b9fd41772ceafabc1a965573538f6f141822b313527eaa5e778e41e3/aiogram_i18n-1.3.4-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "e257c8643bd36eaeb47a878890349db6d355714f7443fce6e3ab7ab2af69ccfc",
                "md5": "1942950725bff92bc6dec103b96ad32c",
                "sha256": "44f14a911db401d4633cdeede97e771a70ab550072447215df07cd1a45840373"
            },
            "downloads": -1,
            "filename": "aiogram_i18n-1.3.4.tar.gz",
            "has_sig": false,
            "md5_digest": "1942950725bff92bc6dec103b96ad32c",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 25464,
            "upload_time": "2023-12-31T14:46:14",
            "upload_time_iso_8601": "2023-12-31T14:46:14.003820Z",
            "url": "https://files.pythonhosted.org/packages/e2/57/c8643bd36eaeb47a878890349db6d355714f7443fce6e3ab7ab2af69ccfc/aiogram_i18n-1.3.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-12-31 14:46:14",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "aiogram",
    "github_project": "aiogram_i18n",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "aiogram-i18n"
}
        
Elapsed time: 0.16695s