Skip to main content

aiogram-dialog-i18n

PyPI version codecov Tests Status License ruff ty

Translated text widget for aiogram-dialog powered by aiogram-i18n.

uv add aiogram-dialog-i18n
# or
pip install aiogram-dialog-i18n

Usage

Set up I18nMiddleware from aiogram-i18n as usual: the widget takes I18nContext from middleware_data["i18n"] (its default context_key).

hello-user = Hello, { $name }! Balance: { $balance }
payment-method = • { $method }
pay-btn = Pay
from aiogram_dialog import Window
from aiogram_dialog.widgets.kbd import Button
from aiogram_dialog.widgets.text import Format, List
from magic_filter import F

from aiogram_dialog_i18n import I18nFormat, T

Window(
    I18nFormat("hello-user", name=F["user"].full_name, balance=Format("{balance:.2f}")),
    List(T("payment-method", method=F["item"]), F["methods"]),
    Button(T("pay-btn"), id="pay", when=F["methods"]),
    state=...,
)

I18nFormat(key, locale=None, /, *, when=None, **params)

Renders the translation key with params in the current locale of the user. It is a regular aiogram-dialog text widget, so it works wherever a text is expected: Window, Button, List, Multi, …. T is a short alias.

Params

Every param is a Value:

  • a text widget is rendered (Format, Const, another I18nFormat, …);
  • a MagicFilter is resolved against window data;
  • anything else (str, int, float, bool) is passed as is.

None becomes an empty string.

I18nFormat(
    "hello-user",
    name=F["user"].full_name,  # magic filter over window data
    balance=Format("{balance:.2f}"),  # any text widget
    vip=True,  # constant
)

Locale

By default the locale of the user is used. The second positional argument overrides it and is a Value too:

I18nFormat("k", "en")  # fixed locale
I18nFormat("k", F["lang"])  # locale from window data
I18nFormat("k", locale=F["lang"])  # not a locale: a message param named "locale"

key and locale are positional-only, like in I18nContext.get, so a message can still have a param called locale. when is the usual aiogram-dialog visibility condition, not a message param.

Release files for aiogram-dialog-i18n 0.1.0

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-dialog-i18n 0.1.0
File Size Uploaded
aiogram_dialog_i18n-0.1.0.tar.gz 4.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for aiogram-dialog-i18n 0.1.0
File Interpreter ABI Platform
aiogram_dialog_i18n-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 9.6 kB

Release files / aiogram_dialog_i18n-0.1.0.tar.gz

Download URL aiogram_dialog_i18n-0.1.0.tar.gz
Size 4.2 kB
Tags Source
SHA-256 checksum
How to use checksums
8b67a4f57b9550153b0afe52c12b4ecb144d9640196103f0e9ed676d864ae95c
BLAKE2b-256 checksum
How to use checksums
d9f5491c865a9f6a415b52d0f13a221a418a6b597a07e79618ac7db34d96b290
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.18 {"installer":{"name":"uv","version":"0.12.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / aiogram_dialog_i18n-0.1.0-py3-none-any.whl

Download URL aiogram_dialog_i18n-0.1.0-py3-none-any.whl
Size 5.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
34dbcbcefa4e8bfb172c5966a77f0521d342be389df33f8c0fcd301f30b84093
BLAKE2b-256 checksum
How to use checksums
a5c10027a4b8a65308acb925709bd1989f98dd3e9e4d8f903485346ad985bc3e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.18 {"installer":{"name":"uv","version":"0.12.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release history Release notifications | RSS feed

0.2.0

2 release files

This release

0.1.0 This release

2 release files

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