from dataclasses import dataclass, field
from typing import Any, Tuple

from aiogram.contrib.middlewares.i18n import I18nMiddleware as BaseI18nMiddleware


@dataclass
class LanguageData:
    flag: str
    title: str
    label: str = field(init=False, default=None)

    def __post_init__(self):
        self.label = f"{self.flag} {self.title}"


class I18nMiddleware(BaseI18nMiddleware):
    AVAILABLE_LANGUAGES = {
        "en": LanguageData("🇺🇸", "English"),
        "ru": LanguageData("🇷🇺", "Русский"),
        "uk": LanguageData("🇺🇦", "Українська"),
    }

    async def get_user_locale(self, action: str, args: Tuple[Any]) -> str:
        data: dict = args[-1]
        if "chat" in data:
            return data["chat"].language or self.default
        return self.default

3d7ca1f380676aa62c6bd9fa97b700835ee26e12
<mask token>


class I18nMiddleware(BaseI18nMiddleware):
    AVAILABLE_LANGUAGES = {'en': LanguageData('🇺🇸', 'English'), 'ru':
        LanguageData('🇷🇺', 'Русский'), 'uk': LanguageData('🇺🇦', 'Українська')}

    async def get_user_locale(self, action: str, args: Tuple[Any]) ->str:
        data: dict = args[-1]
        if 'chat' in data:
            return data['chat'].language or self.default
        return self.default

<mask token>


@dataclass
class LanguageData:
    flag: str
    title: str
    label: str = field(init=False, default=None)
    <mask token>


class I18nMiddleware(BaseI18nMiddleware):
    AVAILABLE_LANGUAGES = {'en': LanguageData('🇺🇸', 'English'), 'ru':
        LanguageData('🇷🇺', 'Русский'), 'uk': LanguageData('🇺🇦', 'Українська')}

    async def get_user_locale(self, action: str, args: Tuple[Any]) ->str:
        data: dict = args[-1]
        if 'chat' in data:
            return data['chat'].language or self.default
        return self.default

<mask token>


@dataclass
class LanguageData:
    flag: str
    title: str
    label: str = field(init=False, default=None)

    def __post_init__(self):
        self.label = f'{self.flag} {self.title}'


class I18nMiddleware(BaseI18nMiddleware):
    AVAILABLE_LANGUAGES = {'en': LanguageData('🇺🇸', 'English'), 'ru':
        LanguageData('🇷🇺', 'Русский'), 'uk': LanguageData('🇺🇦', 'Українська')}

    async def get_user_locale(self, action: str, args: Tuple[Any]) ->str:
        data: dict = args[-1]
        if 'chat' in data:
            return data['chat'].language or self.default
        return self.default

from dataclasses import dataclass, field
from typing import Any, Tuple
from aiogram.contrib.middlewares.i18n import I18nMiddleware as BaseI18nMiddleware


@dataclass
class LanguageData:
    flag: str
    title: str
    label: str = field(init=False, default=None)

    def __post_init__(self):
        self.label = f'{self.flag} {self.title}'


class I18nMiddleware(BaseI18nMiddleware):
    AVAILABLE_LANGUAGES = {'en': LanguageData('🇺🇸', 'English'), 'ru':
        LanguageData('🇷🇺', 'Русский'), 'uk': LanguageData('🇺🇦', 'Українська')}

    async def get_user_locale(self, action: str, args: Tuple[Any]) ->str:
        data: dict = args[-1]
        if 'chat' in data:
            return data['chat'].language or self.default
        return self.default

from dataclasses import dataclass, field
from typing import Any, Tuple

from aiogram.contrib.middlewares.i18n import I18nMiddleware as BaseI18nMiddleware


@dataclass
class LanguageData:
    flag: str
    title: str
    label: str = field(init=False, default=None)

    def __post_init__(self):
        self.label = f"{self.flag} {self.title}"


class I18nMiddleware(BaseI18nMiddleware):
    AVAILABLE_LANGUAGES = {
        "en": LanguageData("🇺🇸", "English"),
        "ru": LanguageData("🇷🇺", "Русский"),
        "uk": LanguageData("🇺🇦", "Українська"),
    }

    async def get_user_locale(self, action: str, args: Tuple[Any]) -> str:
        data: dict = args[-1]
        if "chat" in data:
            return data["chat"].language or self.default
        return self.default
