[i18n] Fix some missing i18n strings in the whole bot (#2633)

This commit is contained in:
PredaaA 2019-06-29 17:13:53 +02:00 committed by Toby Harradine
parent 8a72840de0
commit 03fe3ee720
8 changed files with 56 additions and 39 deletions

View File

@ -122,7 +122,11 @@ class General(commands.Cog):
author = ctx.author author = ctx.author
player_choice = your_choice.choice player_choice = your_choice.choice
if not player_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)) red_choice = choice((RPS.rock, RPS.paper, RPS.scissors))
cond = { cond = {
(RPS.rock, RPS.paper): False, (RPS.rock, RPS.paper): False,

View File

@ -249,7 +249,7 @@ class KickBanMixin(MixinMeta):
errors = {} errors = {}
async def show_results(): 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: if errors:
text += _("\nErrors:\n") text += _("\nErrors:\n")
text += "\n".join(errors.values()) text += "\n".join(errors.values())

View File

@ -101,7 +101,7 @@ class ModInfo(MixinMeta):
user_joined = joined_at.strftime("%d %b %Y %H:%M") user_joined = joined_at.strftime("%d %b %Y %H:%M")
else: else:
since_joined = "?" since_joined = "?"
user_joined = "Unknown" user_joined = _("Unknown")
user_created = user.created_at.strftime("%d %b %Y %H:%M") user_created = user.created_at.strftime("%d %b %Y %H:%M")
voice_state = user.voice voice_state = user.voice
member_number = ( member_number = (

View File

@ -66,7 +66,7 @@ class ModLog(commands.Cog):
await ctx.send_help() await ctx.send_help()
lines = [] lines = []
for ct in casetypes: 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}") lines.append(f"{ct.name} : {enabled}")
await ctx.send(_("Current settings:\n") + box("\n".join(lines))) 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 casetype.set_enabled(not enabled)
await ctx.send( await ctx.send(
_("Case creation for {action_name} actions is now {enabled}.").format( _("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")
) )
) )

View File

@ -183,7 +183,9 @@ class Streams(commands.Cog):
async def twitch_alert_channel(self, ctx: commands.Context, channel_name: str): async def twitch_alert_channel(self, ctx: commands.Context, channel_name: str):
"""Toggle alerts in this channel for a Twitch stream.""" """Toggle alerts in this channel for a Twitch stream."""
if re.fullmatch(r"<#\d+>", channel_name): 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 return
await self.stream_alert(ctx, TwitchStream, channel_name.lower()) await self.stream_alert(ctx, TwitchStream, channel_name.lower())
@ -374,7 +376,7 @@ class Streams(commands.Cog):
if message is not None: if message is not None:
guild = ctx.guild guild = ctx.guild
await self.db.guild(guild).live_message_mention.set(message) 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: else:
await ctx.send_help() await ctx.send_help()
@ -390,7 +392,7 @@ class Streams(commands.Cog):
if message is not None: if message is not None:
guild = ctx.guild guild = ctx.guild
await self.db.guild(guild).live_message_nomention.set(message) 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: else:
await ctx.send_help() await ctx.send_help()

View File

@ -5,6 +5,7 @@ from .errors import (
InvalidYoutubeCredentials, InvalidYoutubeCredentials,
InvalidTwitchCredentials, InvalidTwitchCredentials,
) )
from redbot.core.i18n import Translator
from random import choice, sample from random import choice, sample
from string import ascii_letters from string import ascii_letters
from typing import ClassVar, Optional from typing import ClassVar, Optional
@ -22,6 +23,8 @@ YOUTUBE_CHANNELS_ENDPOINT = YOUTUBE_BASE_URL + "/channels"
YOUTUBE_SEARCH_ENDPOINT = YOUTUBE_BASE_URL + "/search" YOUTUBE_SEARCH_ENDPOINT = YOUTUBE_BASE_URL + "/search"
YOUTUBE_VIDEOS_ENDPOINT = YOUTUBE_BASE_URL + "/videos" YOUTUBE_VIDEOS_ENDPOINT = YOUTUBE_BASE_URL + "/videos"
_ = Translator("Streams", __file__)
def rnd(url): def rnd(url):
"""Appends a random parameter to the url to avoid Discord's caching""" """Appends a random parameter to the url to avoid Discord's caching"""
@ -217,13 +220,13 @@ class TwitchStream(Stream):
status += " - Rerun" status += " - Rerun"
embed = discord.Embed(title=status, url=url, color=0x6441A4) embed = discord.Embed(title=status, url=url, color=0x6441A4)
embed.set_author(name=channel["display_name"]) embed.set_author(name=channel["display_name"])
embed.add_field(name="Followers", value=channel["followers"]) embed.add_field(name=_("Followers"), value=channel["followers"])
embed.add_field(name="Total views", value=channel["views"]) embed.add_field(name=_("Total views"), value=channel["views"])
embed.set_thumbnail(url=logo) embed.set_thumbnail(url=logo)
if data["stream"]["preview"]["medium"]: if data["stream"]["preview"]["medium"]:
embed.set_image(url=rnd(data["stream"]["preview"]["medium"])) embed.set_image(url=rnd(data["stream"]["preview"]["medium"]))
if channel["game"]: if channel["game"]:
embed.set_footer(text="Playing: " + channel["game"]) embed.set_footer(text=_("Playing: ") + channel["game"])
return embed return embed
@ -261,11 +264,11 @@ class HitboxStream(Stream):
url = channel["channel_link"] url = channel["channel_link"]
embed = discord.Embed(title=livestream["media_status"], url=url, color=0x98CB00) embed = discord.Embed(title=livestream["media_status"], url=url, color=0x98CB00)
embed.set_author(name=livestream["media_name"]) 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"]) embed.set_thumbnail(url=base_url + channel["user_logo"])
if livestream["media_thumbnail"]: if livestream["media_thumbnail"]:
embed.set_image(url=rnd(base_url + 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 return embed
@ -300,8 +303,8 @@ class MixerStream(Stream):
url = "https://mixer.com/" + data["token"] url = "https://mixer.com/" + data["token"]
embed = discord.Embed(title=data["name"], url=url) embed = discord.Embed(title=data["name"], url=url)
embed.set_author(name=user["username"]) embed.set_author(name=user["username"])
embed.add_field(name="Followers", value=data["numFollowers"]) embed.add_field(name=_("Followers"), value=data["numFollowers"])
embed.add_field(name="Total views", value=data["viewersTotal"]) embed.add_field(name=_("Total views"), value=data["viewersTotal"])
if user["avatarUrl"]: if user["avatarUrl"]:
embed.set_thumbnail(url=user["avatarUrl"]) embed.set_thumbnail(url=user["avatarUrl"])
else: else:
@ -310,7 +313,7 @@ class MixerStream(Stream):
embed.set_image(url=rnd(data["thumbnail"]["url"])) embed.set_image(url=rnd(data["thumbnail"]["url"]))
embed.color = 0x4C90F3 # pylint: disable=assigning-non-slot embed.color = 0x4C90F3 # pylint: disable=assigning-non-slot
if data["type"] is not None: if data["type"] is not None:
embed.set_footer(text="Playing: " + data["type"]["name"]) embed.set_footer(text=_("Playing: ") + data["type"]["name"])
return embed return embed
@ -346,18 +349,18 @@ class PicartoStream(Stream):
embed = discord.Embed(title=data["title"], url=url, color=0x4C90F3) embed = discord.Embed(title=data["title"], url=url, color=0x4C90F3)
embed.set_author(name=data["name"]) embed.set_author(name=data["name"])
embed.set_image(url=rnd(thumbnail)) embed.set_image(url=rnd(thumbnail))
embed.add_field(name="Followers", value=data["followers"]) embed.add_field(name=_("Followers"), value=data["followers"])
embed.add_field(name="Total views", value=data["viewers_total"]) embed.add_field(name=_("Total views"), value=data["viewers_total"])
embed.set_thumbnail(url=avatar) embed.set_thumbnail(url=avatar)
data["tags"] = ", ".join(data["tags"]) data["tags"] = ", ".join(data["tags"])
if not data["tags"]: if not data["tags"]:
data["tags"] = "None" data["tags"] = _("None")
if data["adult"]: if data["adult"]:
data["adult"] = "NSFW | " data["adult"] = _("NSFW | ")
else: else:
data["adult"] = "" 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 return embed

View File

@ -233,7 +233,7 @@ class Dev(commands.Cog):
cleaned = self.cleanup_code(response.content) cleaned = self.cleanup_code(response.content)
if cleaned in ("quit", "exit", "exit()"): if cleaned in ("quit", "exit", "exit()"):
await ctx.send("Exiting.") await ctx.send(_("Exiting."))
self.sessions.remove(ctx.channel.id) self.sessions.remove(ctx.channel.id)
return return

View File

@ -12,6 +12,7 @@ from .utils.common_filters import (
filter_urls, filter_urls,
escape_spoilers, escape_spoilers,
) )
from .i18n import Translator
__all__ = [ __all__ = [
"Case", "Case",
@ -37,6 +38,9 @@ _CASES = "CASES"
_SCHEMA_VERSION = 2 _SCHEMA_VERSION = 2
_ = Translator("ModLog", __file__)
async def _init(): async def _init():
global _conf global _conf
_conf = Config.get_conf(None, 1354799444, cog_name="ModLog") _conf = Config.get_conf(None, 1354799444, cog_name="ModLog")
@ -158,18 +162,18 @@ class Case:
""" """
casetype = await get_casetype(self.action_type) casetype = await get_casetype(self.action_type)
title = "{}".format( 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: if self.reason:
reason = "**Reason:** {}".format(self.reason) reason = _("**Reason:** {}").format(self.reason)
else: 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: if self.moderator is not None:
moderator = escape_spoilers(f"{self.moderator} ({self.moderator.id})") moderator = escape_spoilers(f"{self.moderator} ({self.moderator.id})")
else: else:
moderator = "Unknown" moderator = _("Unknown")
until = None until = None
duration = None duration = None
if self.until: if self.until:
@ -209,36 +213,40 @@ class Case:
if avatar_url is not None: if avatar_url is not None:
emb.set_author(name=user, icon_url=avatar_url) 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: if until and duration:
emb.add_field(name="Until", value=until) emb.add_field(name=_("Until"), value=until)
emb.add_field(name="Duration", value=duration) emb.add_field(name=_("Duration"), value=duration)
if isinstance(self.channel, int): 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: 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: if amended_by:
emb.add_field(name="Amended by", value=amended_by) emb.add_field(name=_("Amended by"), value=amended_by)
if last_modified: 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) emb.timestamp = datetime.fromtimestamp(self.created_at)
return emb return emb
else: else:
user = filter_mass_mentions(filter_urls(user)) # Further sanitization outside embeds user = filter_mass_mentions(filter_urls(user)) # Further sanitization outside embeds
case_text = "" case_text = ""
case_text += "{}\n".format(title) case_text += "{}\n".format(title)
case_text += "**User:** {}\n".format(user) case_text += _("**User:** {}\n").format(user)
case_text += "**Moderator:** {}\n".format(moderator) case_text += _("**Moderator:** {}\n").format(moderator)
case_text += "{}\n".format(reason) case_text += "{}\n".format(reason)
if until and duration: 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: if self.channel:
case_text += "**Channel**: {}\n".format(self.channel.name) case_text += _("**Channel**: {}\n").format(self.channel.name)
if amended_by: if amended_by:
case_text += "**Amended by:** {}\n".format(amended_by) case_text += _("**Amended by:** {}\n").format(amended_by)
if last_modified: 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() return case_text.strip()
def to_json(self) -> dict: def to_json(self) -> dict: