Skip to content

Commit

Permalink
[#20] Implement the i18n logic: added new gettext hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
DmitryBurnaev committed Dec 17, 2024
1 parent f0b889d commit 93905f4
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/handlers/bot_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"""

import logging
import gettext

from aiogram import F, Router
from aiogram.utils import markdown
Expand All @@ -22,6 +23,7 @@
from src.utils import parse_address, ParsedAddress

form_router = Router()
_ = gettext.gettext


@form_router.message(Command("address"))
Expand All @@ -31,12 +33,12 @@ async def command_address(message: Message, state: FSMContext) -> None:
"""
await state.set_state(UserAddressStatesGroup.address)
await message.answer(
"What do you want?",
_("What do you want?"),
reply_markup=ReplyKeyboardMarkup(
keyboard=[
[
KeyboardButton(text="Add Address"),
KeyboardButton(text="Remove Address"),
KeyboardButton(text=_("Add Address")),
KeyboardButton(text=_("Remove Address")),
]
],
resize_keyboard=True,
Expand All @@ -59,7 +61,7 @@ async def add_address_command(message: Message, state: FSMContext) -> None:
"""
await state.set_state(UserAddressStatesGroup.add_address)
await message.answer(
"Ok, Sent me your address (without city, default - SPB)",
_("Ok, Sent me your address (without city, default - SPB)"),
reply_markup=ReplyKeyboardRemove(),
)

Expand All @@ -82,7 +84,7 @@ async def remove_address_command(message: Message, state: FSMContext) -> None:
state_data = await state.get_data()
await state.set_state(UserAddressStatesGroup.remove_address)
await message.answer(
"What address do you want to remove?",
_("What address do you want to remove?"),
reply_markup=ReplyKeyboardMarkup(
keyboard=[
[
Expand Down Expand Up @@ -112,7 +114,12 @@ async def add_address_handler(message: Message, state: FSMContext) -> None:
await state.set_state(UserAddressStatesGroup.add_address)
await answer(
message,
f'Ups... we can\'t parse address "{message.text} (got {new_address!r})".',
_(
'Ups... we can\'t parse address "{message_text} (got {new_address})".'.format(
message_text=message.text,
new_address=repr(new_address),
)
),
reply_markup=ReplyKeyboardRemove(),
)
return
Expand Down

0 comments on commit 93905f4

Please sign in to comment.