From aa2f90e1c5a86f6f37d2cb7e13b7eff5ac19fa80 Mon Sep 17 00:00:00 2001 From: profitroll Date: Sat, 3 May 2025 00:45:22 +0200 Subject: [PATCH] Introduced i18n to utility modules --- locale/en-US.json | 6 ++++++ modules/utils/event_utils.py | 13 +++++-------- modules/utils/validation_utils.py | 7 +++---- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/locale/en-US.json b/locale/en-US.json index dfdcaa9..7e3ff12 100644 --- a/locale/en-US.json +++ b/locale/en-US.json @@ -11,10 +11,16 @@ "event_created": "Event **{event_name}** has been created and will take place .", "event_dates_parsing_failed": "Could not parse start and end dates. Please, make sure these are provided in `DD.MM.YYYY HH:MM` format.", "event_details": "**Event details**\n\nName: {event_name}\nStarts: \nEnds: \n\nStages:\n{stages}", + "event_end_before_start": "Start date must be before end date", "event_end_date_parsing_failed": "Could not parse the end date. Please, make sure it is provided in `DD.MM.YYYY HH:MM` format.", + "event_end_past": "End date must not be in the past", + "event_is_cancelled": "This event was cancelled.", + "event_name_duplicate": "There can only be one active event with the same name", "event_not_editable": "Finished or ongoing events cannot be cancelled.", "event_not_found": "Event was not found.", + "event_ongoing_not_editable": "Ongoing events cannot be modified.", "event_start_date_parsing_failed": "Could not parse the start date. Please, make sure it is provided in `DD.MM.YYYY HH:MM` format.", + "event_start_past": "Start date must not be in the past", "event_updated": "Event **{event_name}** has been updated and will take place .", "guess_completed_event": "Congratulations! You have completed the event!", "guess_incorrect_channel": "Usage outside own event channel is not allowed.", diff --git a/modules/utils/event_utils.py b/modules/utils/event_utils.py index 4774bec..28500ab 100644 --- a/modules/utils/event_utils.py +++ b/modules/utils/event_utils.py @@ -6,6 +6,7 @@ from bson import ObjectId from discord import ( ApplicationContext, ) +from libbot.i18n import _ from modules.database import col_events @@ -22,18 +23,15 @@ async def validate_event_validity( end_date_internal: datetime = end_date.astimezone(ZoneInfo("UTC")) if to_utc else end_date if start_date_internal < datetime.now(tz=ZoneInfo("UTC")): - # TODO Make a nice message - await ctx.respond("Start date must not be in the past") + await ctx.respond(_("event_start_past", "messages", locale=ctx.locale)) return False if end_date_internal < datetime.now(tz=ZoneInfo("UTC")): - # TODO Make a nice message - await ctx.respond("End date must not be in the past") + await ctx.respond(_("event_end_past", "messages", locale=ctx.locale)) return False if start_date_internal >= end_date_internal: - # TODO Make a nice message - await ctx.respond("Start date must be before end date") + await ctx.respond(_("event_end_before_start", "messages", locale=ctx.locale)) return False # TODO Add validation for concurrent events. @@ -49,8 +47,7 @@ async def validate_event_validity( query["_id"] = {"$ne": event_id} if (await col_events.find_one(query)) is not None: - # TODO Make a nice message - await ctx.respond("There can only be one active event with the same name") + await ctx.respond(_("event_name_duplicate", "messages", locale=ctx.locale)) return False return True diff --git a/modules/utils/validation_utils.py b/modules/utils/validation_utils.py index f7f330f..924bf06 100644 --- a/modules/utils/validation_utils.py +++ b/modules/utils/validation_utils.py @@ -2,6 +2,7 @@ from datetime import datetime from zoneinfo import ZoneInfo from discord import ApplicationContext +from libbot.i18n import _ async def is_operation_confirmed(ctx: ApplicationContext, confirm: bool) -> bool: @@ -17,8 +18,7 @@ async def is_event_status_valid( event: "PycordEvent", ) -> bool: if event.is_cancelled: - # TODO Make a nice message - await ctx.respond("This event was cancelled.") + await ctx.respond(_("event_is_cancelled", "messages", locale=ctx.locale)) return False if ( @@ -26,8 +26,7 @@ async def is_event_status_valid( <= datetime.now(tz=ZoneInfo("UTC")) <= event.ends.replace(tzinfo=ZoneInfo("UTC")) ): - # TODO Make a nice message - await ctx.respond("Ongoing events cannot be modified.") + await ctx.respond(_("event_ongoing_not_editable", "messages", locale=ctx.locale)) return False return True