Refactor examples/i18n_example.py

This commit is contained in:
Suren Khorenyan 2019-08-10 17:55:39 +03:00
parent d360538bba
commit a78b93c5cd
5 changed files with 37 additions and 23 deletions

View file

@ -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:
"""

View file

@ -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