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.
scripts/i18n_callback_query.py
1from aiogram import F, Router2from aiogram.filters.callback_data import CallbackData3from aiogram.types import CallbackQuery4from aiogram_i18n import I18nContext567class LanguageSelectionCD(CallbackData, prefix="lang"):8code: str9update_in: str101112class LocaleStore:13async def save_user_locale(self, user_id: int, locale: str) -> None:14raise NotImplementedError151617router = Router()181920@router.callback_query(LanguageSelectionCD.filter(F.update_in == "pm"))21async def set_new_language(22callback: CallbackQuery,23callback_data: LanguageSelectionCD,24i18n: I18nContext,25locale_store: LocaleStore,26) -> None:27await locale_store.save_user_locale(28user_id=callback.from_user.id,29locale=callback_data.code,30)31await i18n.set_locale(locale=callback_data.code)32await callback.answer(i18n.language.changed_success())3334await callback.message.edit_text(35i18n.language.select_prompt(),36reply_markup=None,37)38