Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from bundle
Use when building or fixing aiogram 3 bots that need aiogram_i18n with Fluent/FTL, topic-aware reply handling, Telegram quote and forward-origin context, and pr
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/i18n-managers.md
1# aiogram_i18n Managers23This reference is based on the published `aiogram_i18n` source code.45Primary sources:6- README and runtime example: https://github.com/aiogram/i18n7- `middleware.py`: `I18nMiddleware(core=..., manager=..., default_locale=...)`8- `managers/base.py`9- `managers/const.py`10- `managers/memory.py`11- `managers/fsm.py`12- `managers/redis.py`1314## Core idea1516`aiogram_i18n` uses a manager abstraction for locale storage and resolution.1718The middleware:19- keeps a `core`20- keeps a `manager`21- calls `manager.locale_getter(...)` on each update22- exposes `manager.locale_setter(...)` through the runtime context2324In source, `I18nMiddleware` defaults to `MemoryManager()` when no manager is provided.2526## BaseManager2728`BaseManager` defines the locale storage contract:29- `get_locale(...) -> str`30- `set_locale(...) -> None`31- optional `startup(...)`32- optional `shutdown(...)`3334It also exposes callable wrappers:35- `locale_getter`36- `locale_setter`3738That means runtime code can work against one manager interface while storage stays replaceable.3940## Built-in managers4142### ConstManager4344Use when locale is fixed for the whole runtime.4546Behavior from source:47- `get_locale()` returns `default_locale`48- `set_locale(...)` raises runtime error because this manager is immutable4950### MemoryManager5152Use when you want an in-process locale store keyed by aiogram FSM state key.5354Behavior from source:55- stores locale in an in-memory dict56- reads and writes locale by `FSMContext.key`57- simple, but process-local and non-persistent5859### FSMManager6061Use when locale should live in FSM data.6263Behavior from source:64- reads locale from FSM data by a configurable key, default `locale`65- writes locale through `state.update_data(...)`66- validates at startup that dispatcher is configured with FSM middleware6768### RedisManager6970Use when locale should persist in Redis.7172Behavior from source:73- uses aiogram Redis FSM primitives and key builder74- stores locale under a Redis key derived from `state.key`75- accepts either `Redis` or `ConnectionPool`7677## Practical selection guide7879- use `ConstManager` for single-locale bots or test setups80- use `MemoryManager` for simple local state without persistence81- use `FSMManager` when locale belongs to conversational state82- use `RedisManager` when locale must survive restarts and scale across workers8384## Important limitation8586In the sources reviewed, `aiogram_i18n` documents runtime middleware and locale managers.8788It does not document a built-in translation extraction or code-generation CLI in the same way. Treat translation extraction, catalog generation, and locale scaffolding as a separate project toolchain concern unless your repository provides an explicit command for them.89