From 22c318fda33c7a529304e678b98ac5fef9537942 Mon Sep 17 00:00:00 2001 From: Flame442 <34169552+Flame442@users.noreply.github.com> Date: Tue, 23 Apr 2019 17:43:50 -0400 Subject: [PATCH] [Core] Adds a check to [p]set locale (#2553) * Adds a check to [p]set locale Fixes #2552 I would like a little bit of feedback on this change. - Right now, `locale_name` is case sensitive. Should that remain case sensitive or should I allow it to accept it case insensitively? - I made the invalid locale string an i18n string, however I don't know the process for how those are supposed to be made or if that will break anything. Should that remain an i18n string or should I make it a normal string? * Case insensitivity and explicit en-US -`[p]set locale` is now case insensitive -`en-US` added to `[p]listlocales` instead of only existing in `[p]set locale`'s help text * Remove spacing --- redbot/core/core_commands.py | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/redbot/core/core_commands.py b/redbot/core/core_commands.py index 4d5d46c89..5604a0106 100644 --- a/redbot/core/core_commands.py +++ b/redbot/core/core_commands.py @@ -1009,11 +1009,20 @@ class Core(commands.Cog, CoreLogic): To reset to English, use "en-US". """ - i18n.set_locale(locale_name) - - await ctx.bot.db.locale.set(locale_name) - - await ctx.send(_("Locale has been set.")) + red_dist = pkg_resources.get_distribution("red-discordbot") + red_path = Path(red_dist.location) / "redbot" + locale_list = [loc.stem.lower() for loc in list(red_path.glob("**/*.po"))] + if locale_name.lower() in locale_list or locale_name.lower() == "en-us": + i18n.set_locale(locale_name) + await ctx.bot.db.locale.set(locale_name) + await ctx.send(_("Locale has been set.")) + else: + await ctx.send( + _( + "Invalid locale. Use `{prefix}listlocales` to get " + "a list of available locales." + ).format(prefix=ctx.prefix) + ) @_set.command() @checks.is_owner() @@ -1134,7 +1143,9 @@ class Core(commands.Cog, CoreLogic): async with ctx.channel.typing(): red_dist = pkg_resources.get_distribution("red-discordbot") red_path = Path(red_dist.location) / "redbot" - locale_list = sorted(set([loc.stem for loc in list(red_path.glob("**/*.po"))])) + locale_list = [loc.stem for loc in list(red_path.glob("**/*.po"))] + locale_list.append("en-US") + locale_list = sorted(set(locale_list)) if not locale_list: await ctx.send("No languages found.") return