mirror of
https://github.com/aiogram/aiogram.git
synced 2025-12-09 09:22:03 +00:00
Add lazy_gettext method
This commit is contained in:
parent
183e664a75
commit
28dc56cc88
1 changed files with 4 additions and 0 deletions
|
|
@ -4,6 +4,7 @@ from contextvars import ContextVar
|
||||||
from typing import Any, Dict, Tuple
|
from typing import Any, Dict, Tuple
|
||||||
|
|
||||||
from babel import Locale
|
from babel import Locale
|
||||||
|
from babel.support import LazyProxy
|
||||||
|
|
||||||
from ... import types
|
from ... import types
|
||||||
from ...dispatcher.middlewares import BaseMiddleware
|
from ...dispatcher.middlewares import BaseMiddleware
|
||||||
|
|
@ -106,6 +107,9 @@ class I18nMiddleware(BaseMiddleware):
|
||||||
else:
|
else:
|
||||||
return translator.ngettext(singular, plural, n)
|
return translator.ngettext(singular, plural, n)
|
||||||
|
|
||||||
|
def lazy_gettext(self, singular, plural=None, n=1, locale=None) -> LazyProxy:
|
||||||
|
return LazyProxy(self.gettext, singular, plural, n, locale)
|
||||||
|
|
||||||
# noinspection PyMethodMayBeStatic,PyUnusedLocal
|
# noinspection PyMethodMayBeStatic,PyUnusedLocal
|
||||||
async def get_user_locale(self, action: str, args: Tuple[Any]) -> str:
|
async def get_user_locale(self, action: str, args: Tuple[Any]) -> str:
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue