diff --git a/redbot/cogs/general/general.py b/redbot/cogs/general/general.py index 133ca58ba..4c85da434 100644 --- a/redbot/cogs/general/general.py +++ b/redbot/cogs/general/general.py @@ -122,7 +122,11 @@ class General(commands.Cog): author = ctx.author player_choice = your_choice.choice if not player_choice: - return await ctx.send("This isn't a valid option. Try rock, paper, or scissors.") + return await ctx.send( + _("This isn't a valid option. Try {r}, {p}, or {s}.").format( + r="rock", p="paper", s="scissors" + ) + ) red_choice = choice((RPS.rock, RPS.paper, RPS.scissors)) cond = { (RPS.rock, RPS.paper): False, diff --git a/redbot/cogs/mod/kickban.py b/redbot/cogs/mod/kickban.py index dc7c9e7da..f408f5c47 100644 --- a/redbot/cogs/mod/kickban.py +++ b/redbot/cogs/mod/kickban.py @@ -249,7 +249,7 @@ class KickBanMixin(MixinMeta): errors = {} async def show_results(): - text = _("Banned {num} users from the server.".format(num=len(banned))) + text = _("Banned {num} users from the server.").format(num=len(banned)) if errors: text += _("\nErrors:\n") text += "\n".join(errors.values()) diff --git a/redbot/cogs/mod/names.py b/redbot/cogs/mod/names.py index e3e7a269b..6c44bab1b 100644 --- a/redbot/cogs/mod/names.py +++ b/redbot/cogs/mod/names.py @@ -101,7 +101,7 @@ class ModInfo(MixinMeta): user_joined = joined_at.strftime("%d %b %Y %H:%M") else: since_joined = "?" - user_joined = "Unknown" + user_joined = _("Unknown") user_created = user.created_at.strftime("%d %b %Y %H:%M") voice_state = user.voice member_number = ( diff --git a/redbot/cogs/modlog/modlog.py b/redbot/cogs/modlog/modlog.py index 3bb0fb9f0..2b1b3e36f 100644 --- a/redbot/cogs/modlog/modlog.py +++ b/redbot/cogs/modlog/modlog.py @@ -66,7 +66,7 @@ class ModLog(commands.Cog): await ctx.send_help() lines = [] for ct in casetypes: - enabled = "enabled" if await ct.is_enabled() else "disabled" + enabled = _("enabled") if await ct.is_enabled() else _("disabled") lines.append(f"{ct.name} : {enabled}") await ctx.send(_("Current settings:\n") + box("\n".join(lines))) @@ -80,7 +80,7 @@ class ModLog(commands.Cog): await casetype.set_enabled(not enabled) await ctx.send( _("Case creation for {action_name} actions is now {enabled}.").format( - action_name=action, enabled="enabled" if not enabled else "disabled" + action_name=action, enabled=_("enabled") if not enabled else _("disabled") ) ) diff --git a/redbot/cogs/streams/streams.py b/redbot/cogs/streams/streams.py index 83a67f4fc..cfb591c95 100644 --- a/redbot/cogs/streams/streams.py +++ b/redbot/cogs/streams/streams.py @@ -183,7 +183,9 @@ class Streams(commands.Cog): async def twitch_alert_channel(self, ctx: commands.Context, channel_name: str): """Toggle alerts in this channel for a Twitch stream.""" if re.fullmatch(r"<#\d+>", channel_name): - await ctx.send("Please supply the name of a *Twitch* channel, not a Discord channel.") + await ctx.send( + _("Please supply the name of a *Twitch* channel, not a Discord channel.") + ) return await self.stream_alert(ctx, TwitchStream, channel_name.lower()) @@ -374,7 +376,7 @@ class Streams(commands.Cog): if message is not None: guild = ctx.guild await self.db.guild(guild).live_message_mention.set(message) - await ctx.send(_("stream alert message set!")) + await ctx.send(_("Stream alert message set!")) else: await ctx.send_help() @@ -390,7 +392,7 @@ class Streams(commands.Cog): if message is not None: guild = ctx.guild await self.db.guild(guild).live_message_nomention.set(message) - await ctx.send(_("stream alert message set!")) + await ctx.send(_("Stream alert message set!")) else: await ctx.send_help() diff --git a/redbot/cogs/streams/streamtypes.py b/redbot/cogs/streams/streamtypes.py index 6c6a6c681..45e83661c 100644 --- a/redbot/cogs/streams/streamtypes.py +++ b/redbot/cogs/streams/streamtypes.py @@ -5,6 +5,7 @@ from .errors import ( InvalidYoutubeCredentials, InvalidTwitchCredentials, ) +from redbot.core.i18n import Translator from random import choice, sample from string import ascii_letters from typing import ClassVar, Optional @@ -22,6 +23,8 @@ YOUTUBE_CHANNELS_ENDPOINT = YOUTUBE_BASE_URL + "/channels" YOUTUBE_SEARCH_ENDPOINT = YOUTUBE_BASE_URL + "/search" YOUTUBE_VIDEOS_ENDPOINT = YOUTUBE_BASE_URL + "/videos" +_ = Translator("Streams", __file__) + def rnd(url): """Appends a random parameter to the url to avoid Discord's caching""" @@ -217,13 +220,13 @@ class TwitchStream(Stream): status += " - Rerun" embed = discord.Embed(title=status, url=url, color=0x6441A4) embed.set_author(name=channel["display_name"]) - embed.add_field(name="Followers", value=channel["followers"]) - embed.add_field(name="Total views", value=channel["views"]) + embed.add_field(name=_("Followers"), value=channel["followers"]) + embed.add_field(name=_("Total views"), value=channel["views"]) embed.set_thumbnail(url=logo) if data["stream"]["preview"]["medium"]: embed.set_image(url=rnd(data["stream"]["preview"]["medium"])) if channel["game"]: - embed.set_footer(text="Playing: " + channel["game"]) + embed.set_footer(text=_("Playing: ") + channel["game"]) return embed @@ -261,11 +264,11 @@ class HitboxStream(Stream): url = channel["channel_link"] embed = discord.Embed(title=livestream["media_status"], url=url, color=0x98CB00) embed.set_author(name=livestream["media_name"]) - embed.add_field(name="Followers", value=channel["followers"]) + embed.add_field(name=_("Followers"), value=channel["followers"]) embed.set_thumbnail(url=base_url + channel["user_logo"]) if livestream["media_thumbnail"]: embed.set_image(url=rnd(base_url + livestream["media_thumbnail"])) - embed.set_footer(text="Playing: " + livestream["category_name"]) + embed.set_footer(text=_("Playing: ") + livestream["category_name"]) return embed @@ -300,8 +303,8 @@ class MixerStream(Stream): url = "https://mixer.com/" + data["token"] embed = discord.Embed(title=data["name"], url=url) embed.set_author(name=user["username"]) - embed.add_field(name="Followers", value=data["numFollowers"]) - embed.add_field(name="Total views", value=data["viewersTotal"]) + embed.add_field(name=_("Followers"), value=data["numFollowers"]) + embed.add_field(name=_("Total views"), value=data["viewersTotal"]) if user["avatarUrl"]: embed.set_thumbnail(url=user["avatarUrl"]) else: @@ -310,7 +313,7 @@ class MixerStream(Stream): embed.set_image(url=rnd(data["thumbnail"]["url"])) embed.color = 0x4C90F3 # pylint: disable=assigning-non-slot if data["type"] is not None: - embed.set_footer(text="Playing: " + data["type"]["name"]) + embed.set_footer(text=_("Playing: ") + data["type"]["name"]) return embed @@ -346,18 +349,18 @@ class PicartoStream(Stream): embed = discord.Embed(title=data["title"], url=url, color=0x4C90F3) embed.set_author(name=data["name"]) embed.set_image(url=rnd(thumbnail)) - embed.add_field(name="Followers", value=data["followers"]) - embed.add_field(name="Total views", value=data["viewers_total"]) + embed.add_field(name=_("Followers"), value=data["followers"]) + embed.add_field(name=_("Total views"), value=data["viewers_total"]) embed.set_thumbnail(url=avatar) data["tags"] = ", ".join(data["tags"]) if not data["tags"]: - data["tags"] = "None" + data["tags"] = _("None") if data["adult"]: - data["adult"] = "NSFW | " + data["adult"] = _("NSFW | ") else: data["adult"] = "" - embed.set_footer(text="{adult}Category: {category} | Tags: {tags}".format(**data)) + embed.set_footer(text=_("{adult}Category: {category} | Tags: {tags}").format(**data)) return embed diff --git a/redbot/core/dev_commands.py b/redbot/core/dev_commands.py index e7e5c74e1..488d13f03 100644 --- a/redbot/core/dev_commands.py +++ b/redbot/core/dev_commands.py @@ -233,7 +233,7 @@ class Dev(commands.Cog): cleaned = self.cleanup_code(response.content) if cleaned in ("quit", "exit", "exit()"): - await ctx.send("Exiting.") + await ctx.send(_("Exiting.")) self.sessions.remove(ctx.channel.id) return diff --git a/redbot/core/modlog.py b/redbot/core/modlog.py index a804f7b40..a834c3d8d 100644 --- a/redbot/core/modlog.py +++ b/redbot/core/modlog.py @@ -12,6 +12,7 @@ from .utils.common_filters import ( filter_urls, escape_spoilers, ) +from .i18n import Translator __all__ = [ "Case", @@ -37,6 +38,9 @@ _CASES = "CASES" _SCHEMA_VERSION = 2 +_ = Translator("ModLog", __file__) + + async def _init(): global _conf _conf = Config.get_conf(None, 1354799444, cog_name="ModLog") @@ -158,18 +162,18 @@ class Case: """ casetype = await get_casetype(self.action_type) title = "{}".format( - "Case #{} | {} {}".format(self.case_number, casetype.case_str, casetype.image) + _("Case #{} | {} {}").format(self.case_number, casetype.case_str, casetype.image) ) if self.reason: - reason = "**Reason:** {}".format(self.reason) + reason = _("**Reason:** {}").format(self.reason) else: - reason = "**Reason:** Use the `reason` command to add it" + reason = _("**Reason:** Use the `reason` command to add it") if self.moderator is not None: moderator = escape_spoilers(f"{self.moderator} ({self.moderator.id})") else: - moderator = "Unknown" + moderator = _("Unknown") until = None duration = None if self.until: @@ -209,36 +213,40 @@ class Case: if avatar_url is not None: emb.set_author(name=user, icon_url=avatar_url) - emb.add_field(name="Moderator", value=moderator, inline=False) + emb.add_field(name=_("Moderator"), value=moderator, inline=False) if until and duration: - emb.add_field(name="Until", value=until) - emb.add_field(name="Duration", value=duration) + emb.add_field(name=_("Until"), value=until) + emb.add_field(name=_("Duration"), value=duration) if isinstance(self.channel, int): - emb.add_field(name="Channel", value=f"{self.channel} (deleted)", inline=False) + emb.add_field( + name=_("Channel"), + value=_("{channel} (deleted)").format(channel=self.channel), + inline=False, + ) elif self.channel is not None: - emb.add_field(name="Channel", value=self.channel.name, inline=False) + emb.add_field(name=_("Channel"), value=self.channel.name, inline=False) if amended_by: - emb.add_field(name="Amended by", value=amended_by) + emb.add_field(name=_("Amended by"), value=amended_by) if last_modified: - emb.add_field(name="Last modified at", value=last_modified) + emb.add_field(name=_("Last modified at"), value=last_modified) emb.timestamp = datetime.fromtimestamp(self.created_at) return emb else: user = filter_mass_mentions(filter_urls(user)) # Further sanitization outside embeds case_text = "" case_text += "{}\n".format(title) - case_text += "**User:** {}\n".format(user) - case_text += "**Moderator:** {}\n".format(moderator) + case_text += _("**User:** {}\n").format(user) + case_text += _("**Moderator:** {}\n").format(moderator) case_text += "{}\n".format(reason) if until and duration: - case_text += "**Until:** {}\n**Duration:** {}\n".format(until, duration) + case_text += _("**Until:** {}\n**Duration:** {}\n").format(until, duration) if self.channel: - case_text += "**Channel**: {}\n".format(self.channel.name) + case_text += _("**Channel**: {}\n").format(self.channel.name) if amended_by: - case_text += "**Amended by:** {}\n".format(amended_by) + case_text += _("**Amended by:** {}\n").format(amended_by) if last_modified: - case_text += "**Last modified at:** {}\n".format(last_modified) + case_text += _("**Last modified at:** {}\n").format(last_modified) return case_text.strip() def to_json(self) -> dict: