diff --git a/cogs/config.py b/cogs/config.py index 9cc8b6a..187aac8 100644 --- a/cogs/config.py +++ b/cogs/config.py @@ -9,6 +9,7 @@ from discord import ( ) from discord.ext.commands import Cog from discord.utils import basic_autocomplete +from libbot.i18n import in_every_locale, _ from classes import PycordGuild from classes.pycord_bot import PycordBot @@ -21,25 +22,41 @@ class Config(Cog): def __init__(self, bot: PycordBot): self.bot: PycordBot = bot - # TODO Introduce i18n - command_group: SlashCommandGroup = SlashCommandGroup("config", "Guild management") + command_group: SlashCommandGroup = SlashCommandGroup( + name="config", + description=_("description", "commands", "config"), + description_localizations=in_every_locale("description", "commands", "config"), + ) - # TODO Introduce i18n @command_group.command( name="set", - description="Configure the guild", + description=_("description", "commands", "config_set"), + description_localizations=in_every_locale("description", "commands", "config_set"), + ) + @option( + "category", + description=_("description", "commands", "config_set", "options", "category"), + description_localizations=in_every_locale( + "description", "commands", "config_set", "options", "category" + ), + required=True, ) - @option("category", description="Category where channels for each user will be created", required=True) @option("channel", description="Text channel for admin notifications", required=True) @option( "timezone", - description="Timezone in which events take place", + description=_("description", "commands", "config_set", "options", "timezone"), + description_localizations=in_every_locale( + "description", "commands", "config_set", "options", "timezone" + ), autocomplete=basic_autocomplete(autocomplete_timezones), required=True, ) @option( "language", - description="Language for bot's messages", + description=_("description", "commands", "config_set", "options", "language"), + description_localizations=in_every_locale( + "description", "commands", "config_set", "options", "language" + ), autocomplete=basic_autocomplete(autocomplete_languages), required=True, ) @@ -56,7 +73,9 @@ class Config(Cog): try: timezone_parsed: ZoneInfo = ZoneInfo(timezone) except ZoneInfoNotFoundError: - await ctx.respond(f"Timezone {timezone} was not found.") + await ctx.respond( + self.bot._("timezone_invalid", "messages", locale=ctx.locale).format(timezone=timezone) + ) return await guild.update( @@ -67,44 +86,51 @@ class Config(Cog): language=language, ) - # TODO Make a nice message - await ctx.respond("Okay.") + await ctx.respond(self.bot._("config_set", "messages", locale=ctx.locale)) - # TODO Introduce i18n @command_group.command( name="reset", - description="Reset the guild's configuration", + description=_("description", "commands", "config_reset"), + description_localizations=in_every_locale("description", "commands", "config_reset"), + ) + @option( + "confirm", + description=_("description", "commands", "config_reset", "options", "confirm"), + description_localizations=in_every_locale( + "description", "commands", "config_reset", "options", "confirm" + ), + required=False, ) - @option("confirm", description="Confirmation of the operation", required=False) async def command_config_reset(self, ctx: ApplicationContext, confirm: bool = False) -> None: if confirm is None or not confirm: - # TODO Make a nice message - await ctx.respond("Operation not confirmed.") + await ctx.respond(self.bot._("operation_unconfirmed", "messages", locale=ctx.locale)) return guild: PycordGuild = await self.bot.find_guild(ctx.guild.id) await guild.purge(self.bot.cache) - # TODO Make a nice message - await ctx.respond("Okay.") + await ctx.respond(self.bot._("config_reset", "messages", locale=ctx.locale)) - # TODO Introduce i18n @command_group.command( name="show", - description="Show the guild's configuration", + description=_("description", "commands", "config_show"), + description_localizations=in_every_locale("description", "commands", "config_show"), ) async def command_config_show(self, ctx: ApplicationContext) -> None: guild: PycordGuild = await self.bot.find_guild(ctx.guild.id) if not guild.is_configured(): - # TODO Make a nice message - await ctx.respond("Guild is not configured.") + await ctx.respond(self.bot._("guild_unconfigured_admin", "messages", locale=ctx.locale)) return - # TODO Make a nice message await ctx.respond( - f"**Guild config**\n\nChannel: <#{guild.channel_id}>\nCategory: <#{guild.category_id}>\nTimezone: {guild.timezone}\nLanguage: {guild.language}" + self.bot._("config_show", "messages", locale=ctx.locale).format( + channel_id=guild.channel_id, + category_id=guild.category_id, + timezone=guild.timezone, + language=guild.language, + ) ) diff --git a/config_example.json b/config_example.json index d809b7b..a6dfc60 100644 --- a/config_example.json +++ b/config_example.json @@ -1,5 +1,5 @@ { - "locale": "en", + "locale": "en-US", "debug": false, "bot": { "owners": [ diff --git a/locale/en-US.json b/locale/en-US.json new file mode 100644 index 0000000..f40daae --- /dev/null +++ b/locale/en-US.json @@ -0,0 +1,44 @@ +{ + "messages": { + "operation_unconfirmed": "Operation not confirmed.", + "guild_unconfigured": "Guild is not configured. Please, report this to the administrator.", + "guild_unconfigured_admin": "Guild is not configured. Please, configure it using `/config set`.", + "timezone_invalid": "Timezone **{timezone}** was not found. Please, select one of the timezones provided by the autocompletion.", + "config_set": "Configuration has been updated. You can review it anytime using `/config show`.", + "config_reset": "Configuration has been reset. You can update it using `/config set`, otherwise no events can be held.", + "config_show": "**Guild config**\n\nChannel: <#{channel_id}>\nCategory: <#{category_id}>\nTimezone: {timezone}\nLanguage: {language}" + }, + "commands": { + "config": { + "description": "Guild management" + }, + "config_set": { + "description": "Configure the guild", + "options": { + "category": { + "description": "Category where channels for each user will be created" + }, + "channel": { + "description": "Text channel for admin notifications" + }, + "timezone": { + "description": "Timezone in which events take place" + }, + "language": { + "description": "Language for bot's messages" + } + } + }, + "config_reset": { + "description": "Reset the guild's configuration", + "options": { + "confirm": { + "description": "Confirmation of the operation" + } + } + }, + "config_show": { + "description": "Show the guild's configuration" + } + } +} diff --git a/locale/en.json b/locale/en.json deleted file mode 100644 index 699534c..0000000 --- a/locale/en.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "messages": {} -} diff --git a/locale/uk.json b/locale/uk.json deleted file mode 100644 index 0848176..0000000 --- a/locale/uk.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "messages": {} -} \ No newline at end of file