[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
This commit is contained in:
Flame442 2019-04-23 17:43:50 -04:00 committed by Will
parent da5fd7699e
commit 22c318fda3

View File

@ -1009,11 +1009,20 @@ class Core(commands.Cog, CoreLogic):
To reset to English, use "en-US". To reset to English, use "en-US".
""" """
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) i18n.set_locale(locale_name)
await ctx.bot.db.locale.set(locale_name) await ctx.bot.db.locale.set(locale_name)
await ctx.send(_("Locale has been set.")) 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() @_set.command()
@checks.is_owner() @checks.is_owner()
@ -1134,7 +1143,9 @@ class Core(commands.Cog, CoreLogic):
async with ctx.channel.typing(): async with ctx.channel.typing():
red_dist = pkg_resources.get_distribution("red-discordbot") red_dist = pkg_resources.get_distribution("red-discordbot")
red_path = Path(red_dist.location) / "redbot" 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: if not locale_list:
await ctx.send("No languages found.") await ctx.send("No languages found.")
return return