WIP: Locale strings

This commit is contained in:
2023-08-29 16:32:37 +02:00
parent 029a965860
commit 9cda8859da
14 changed files with 214 additions and 78 deletions

View File

@@ -10,24 +10,37 @@ from modules.database import col_locations
async def search_name(app: PyroClient, message: Message) -> Union[Location, None]:
user = await app.find_user(message.from_user)
location: Union[Location, None] = None
await message.reply_text(
"Please, send me a location name. It should be the name used in your local authorities' garbage collection schedule. This usually is a name of the district or even the town itself.",
reply_markup=ForceReply(placeholder="Location name"),
app._("location_request_name", "messages", locale=user.locale),
reply_markup=ForceReply(
placeholder=app._("location_name", "force_replies", locale=user.locale)
),
)
while location is None:
answer = await listen_message(app, message.chat.id, 300)
if answer is None or answer.text == "/cancel":
await message.reply_text("Cancelled.", reply_markup=ReplyKeyboardRemove())
await message.reply_text(
app._("cancelled", "messages", locale=user.locale),
reply_markup=ReplyKeyboardRemove(),
)
return
if answer.text is None:
await message.reply_text(
"Please, send the name of the location as a text. You can also abort this operation with /cancel command.",
reply_markup=ForceReply(placeholder="Location name"),
app._("location_name_invalid", "messages", locale=user.locale).format(
cancel_notice=app._("cancel", "messages", locale=user.locale)
),
reply_markup=ForceReply(
placeholder=app._(
"location_name", "force_replies", locale=user.locale
)
),
)
continue
@@ -37,8 +50,14 @@ async def search_name(app: PyroClient, message: Message) -> Union[Location, None
if len(locations) == 0:
await message.reply_text(
"Could not find any locations by this name. Try rephrasing it or make sure you use the same location language and name itself as it in written by your local authorities in garbage collection schedule.\n\nYou can also abort this operation with /cancel command.",
reply_markup=ForceReply(placeholder="Location name"),
app._("location_name_empty", "messages", locale=user.locale).format(
cancel_notice=app._("cancel", "messages", locale=user.locale)
),
reply_markup=ForceReply(
placeholder=app._(
"location_name", "force_replies", locale=user.locale
)
),
)
continue
@@ -46,7 +65,8 @@ async def search_name(app: PyroClient, message: Message) -> Union[Location, None
keyboard.add(*[ReplyButton(db_record["name"]) for db_record in locations])
await message.reply_text(
"Select the location using the keyboard", reply_markup=keyboard
app._("location_select", "messages", locale=user.locale),
reply_markup=keyboard,
)
while True:
@@ -54,7 +74,8 @@ async def search_name(app: PyroClient, message: Message) -> Union[Location, None
if answer is None or answer.text == "/cancel":
await message.reply_text(
"Cancelled.", reply_markup=ReplyKeyboardRemove()
app._("cancelled", "messages", locale=user.locale),
reply_markup=ReplyKeyboardRemove(),
)
return
@@ -64,7 +85,9 @@ async def search_name(app: PyroClient, message: Message) -> Union[Location, None
if answer.text is None or location is None:
await answer.reply_text(
"Please, select a valid location using keyboard provided. Use /cancel if you want to cancel this operation.",
app._("selection_invalid", "messages", locale=user.locale).format(
cancel_notice=app._("cancel", "messages", locale=user.locale)
)
)
continue