Skip to content

Commit

Permalink
Fix #16.
Browse files Browse the repository at this point in the history
  • Loading branch information
Egor committed Jul 18, 2019
1 parent 14e5718 commit 542dd7f
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
4 changes: 4 additions & 0 deletions core/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ async def language_choice_handler(query: types.CallbackQuery, callback_data: dic
await query.answer()
await db.update_user(query.from_user.id,
locale=callback_data['user_locale'])

from core.strings import i18n
i18n.ctx_locale.set(callback_data['user_locale'])

await bot.send_message(query.from_user.id,
strings.language_set)

Expand Down
5 changes: 4 additions & 1 deletion core/strings/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
from .scripts import (
on_startup,
LANGUAGE_MAPPING
LANGUAGE_MAPPING,
i18n
)


from .keys import *
7 changes: 6 additions & 1 deletion core/strings/keys.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
from .scripts import _
from .scripts import i18n

# no f-strings here!


def _(string, cache_enable=False):
return i18n.lazy_gettext(string, cache_enable=cache_enable)


start_cmd = _("start_cmd_text")
help_cmd = _("help_command_text, formats: {name}")
drop_cmd = _("drop_cmd_text")
Expand Down
2 changes: 0 additions & 2 deletions core/strings/scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ def on_startup(dp: Dispatcher):
dp.middleware.setup(i18n)


_ = i18n.lazy_gettext

LANGUAGE_MAPPING = {
'ru': 'Русский',
'en': 'Английский'
Expand Down

0 comments on commit 542dd7f

Please sign in to comment.