mirror of
https://github.com/aiogram/aiogram.git
synced 2026-04-08 16:37:47 +00:00
Refactor examples/i18n_example.py
This commit is contained in:
parent
d360538bba
commit
a78b93c5cd
5 changed files with 37 additions and 23 deletions
|
|
@ -97,15 +97,13 @@ class I18nMiddleware(BaseMiddleware):
|
|||
if locale not in self.locales:
|
||||
if n is 1:
|
||||
return singular
|
||||
else:
|
||||
return plural
|
||||
return plural
|
||||
|
||||
translator = self.locales[locale]
|
||||
|
||||
if plural is None:
|
||||
return translator.gettext(singular)
|
||||
else:
|
||||
return translator.ngettext(singular, plural, n)
|
||||
return translator.ngettext(singular, plural, n)
|
||||
|
||||
def lazy_gettext(self, singular, plural=None, n=1, locale=None, enable_cache=True) -> LazyProxy:
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from typing import Optional
|
||||
|
||||
import babel
|
||||
|
||||
from . import base
|
||||
|
|
@ -45,7 +47,7 @@ class User(base.TelegramObject):
|
|||
return self.full_name
|
||||
|
||||
@property
|
||||
def locale(self) -> babel.core.Locale or None:
|
||||
def locale(self) -> Optional[babel.core.Locale]:
|
||||
"""
|
||||
Get user's locale
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue