mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-12-05 17:02:32 -05:00
[Core/Core Cogs] Prevent translation errors and use formatting utils (#5435)
* Use proper syntax for inline formatting in core_commands * use proper formating utils in core and core cogs wherever reasonable * tests are awesome * ensure "(continued)" is translated in help.py * add colons to translatable strings for easier context comprehension by translators * Thx flame :) Co-authored-by: Flame442 <34169552+Flame442@users.noreply.github.com> * good point Co-authored-by: Dav <dav@mail.stopdavabuse.de> Co-authored-by: Flame442 <34169552+Flame442@users.noreply.github.com>
This commit is contained in:
@@ -42,7 +42,15 @@ from ..i18n import Translator
|
||||
from ..utils import menus
|
||||
from ..utils.mod import mass_purge
|
||||
from ..utils._internal_utils import fuzzy_command_search, format_fuzzy_results
|
||||
from ..utils.chat_formatting import box, humanize_list, humanize_number, humanize_timedelta, pagify
|
||||
from ..utils.chat_formatting import (
|
||||
bold,
|
||||
box,
|
||||
humanize_list,
|
||||
humanize_number,
|
||||
humanize_timedelta,
|
||||
pagify,
|
||||
underline,
|
||||
)
|
||||
|
||||
__all__ = ["red_help", "RedHelpFormatter", "HelpSettings", "HelpFormatterABC"]
|
||||
|
||||
@@ -274,9 +282,12 @@ class RedHelpFormatter(HelpFormatterABC):
|
||||
@staticmethod
|
||||
def get_default_tagline(ctx: Context):
|
||||
return _(
|
||||
"Type {ctx.clean_prefix}help <command> for more info on a command. "
|
||||
"You can also type {ctx.clean_prefix}help <category> for more info on a category."
|
||||
).format(ctx=ctx)
|
||||
"Type {command1} for more info on a command. "
|
||||
"You can also type {command2} for more info on a category."
|
||||
).format(
|
||||
command1=f"{ctx.clean_prefix}help <command>",
|
||||
command2=f"{ctx.clean_prefix}help <category>",
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def get_command_signature(ctx: Context, command: commands.Command) -> str:
|
||||
@@ -390,9 +401,9 @@ class RedHelpFormatter(HelpFormatterABC):
|
||||
)
|
||||
for i, page in enumerate(pagify(subtext, page_length=500, shorten_by=0)):
|
||||
if i == 0:
|
||||
title = _("**__Subcommands:__**")
|
||||
title = bold(underline(_("Subcommands:")))
|
||||
else:
|
||||
title = _("**__Subcommands:__** (continued)")
|
||||
title = bold(underline(_("Subcommands: (continued)")))
|
||||
field = EmbedField(title, page, False)
|
||||
emb["fields"].append(field)
|
||||
|
||||
@@ -560,14 +571,14 @@ class RedHelpFormatter(HelpFormatterABC):
|
||||
return a_line[:67].rstrip() + "..."
|
||||
|
||||
command_text = "\n".join(
|
||||
shorten_line(f"**{name}** {command.format_shortdoc_for_context(ctx)}")
|
||||
shorten_line(f"{bold(name)} {command.format_shortdoc_for_context(ctx)}")
|
||||
for name, command in sorted(coms.items())
|
||||
)
|
||||
for i, page in enumerate(pagify(command_text, page_length=500, shorten_by=0)):
|
||||
if i == 0:
|
||||
title = _("**__Commands:__**")
|
||||
title = f"{underline(bold(_('Commands:')))}"
|
||||
else:
|
||||
title = _("**__Commands:__** (continued)")
|
||||
title = f"{underline(bold(_('Commands: (continued)')))}"
|
||||
field = EmbedField(title, page, False)
|
||||
emb["fields"].append(field)
|
||||
|
||||
@@ -617,9 +628,9 @@ class RedHelpFormatter(HelpFormatterABC):
|
||||
for cog_name, data in coms:
|
||||
|
||||
if cog_name:
|
||||
title = f"**__{cog_name}:__**"
|
||||
title = f"{underline(bold(cog_name))}:"
|
||||
else:
|
||||
title = _("**__No Category:__**")
|
||||
title = f"{underline(bold(_('No Category:')))}"
|
||||
|
||||
def shorten_line(a_line: str) -> str:
|
||||
if len(a_line) < 70: # embed max width needs to be lower
|
||||
@@ -736,7 +747,7 @@ class RedHelpFormatter(HelpFormatterABC):
|
||||
else:
|
||||
await ctx.send(ret)
|
||||
elif help_settings.verify_exists:
|
||||
ret = _("Help topic for *{command_name}* not found.").format(command_name=help_for)
|
||||
ret = _("Help topic for {command_name} not found.").format(command_name=bold(help_for))
|
||||
if use_embeds:
|
||||
ret = discord.Embed(color=(await ctx.embed_color()), description=ret)
|
||||
ret.set_author(
|
||||
@@ -753,8 +764,8 @@ class RedHelpFormatter(HelpFormatterABC):
|
||||
"""
|
||||
Sends an error
|
||||
"""
|
||||
ret = _("Command *{command_name}* has no subcommand named *{not_found}*.").format(
|
||||
command_name=command.qualified_name, not_found=not_found[0]
|
||||
ret = _("Command {command_name} has no subcommand named {not_found}.").format(
|
||||
command_name=bold(command.qualified_name), not_found=bold(not_found[0])
|
||||
)
|
||||
if await self.embed_requested(ctx):
|
||||
ret = discord.Embed(color=(await ctx.embed_color()), description=ret)
|
||||
|
||||
@@ -2612,7 +2612,7 @@ class Core(commands.commands._RuleDropper, commands.Cog, CoreLogic):
|
||||
status = ctx.bot.guilds[0].me.status if len(ctx.bot.guilds) > 0 else discord.Status.online
|
||||
await ctx.bot.change_presence(status=status, activity=game)
|
||||
if game:
|
||||
await ctx.send(_("Status set to ``Playing {game.name}``.").format(game=game))
|
||||
await ctx.send(_("Status set to `Playing {game.name}`.").format(game=game))
|
||||
else:
|
||||
await ctx.send(_("Game cleared."))
|
||||
|
||||
@@ -2646,7 +2646,7 @@ class Core(commands.commands._RuleDropper, commands.Cog, CoreLogic):
|
||||
await ctx.bot.change_presence(status=status, activity=activity)
|
||||
if activity:
|
||||
await ctx.send(
|
||||
_("Status set to ``Listening to {listening}``.").format(listening=listening)
|
||||
_("Status set to `Listening to {listening}`.").format(listening=listening)
|
||||
)
|
||||
else:
|
||||
await ctx.send(_("Listening cleared."))
|
||||
@@ -2678,7 +2678,7 @@ class Core(commands.commands._RuleDropper, commands.Cog, CoreLogic):
|
||||
activity = None
|
||||
await ctx.bot.change_presence(status=status, activity=activity)
|
||||
if activity:
|
||||
await ctx.send(_("Status set to ``Watching {watching}``.").format(watching=watching))
|
||||
await ctx.send(_("Status set to `Watching {watching}`.").format(watching=watching))
|
||||
else:
|
||||
await ctx.send(_("Watching cleared."))
|
||||
|
||||
@@ -2712,7 +2712,7 @@ class Core(commands.commands._RuleDropper, commands.Cog, CoreLogic):
|
||||
await ctx.bot.change_presence(status=status, activity=activity)
|
||||
if activity:
|
||||
await ctx.send(
|
||||
_("Status set to ``Competing in {competing}``.").format(competing=competing)
|
||||
_("Status set to `Competing in {competing}`.").format(competing=competing)
|
||||
)
|
||||
else:
|
||||
await ctx.send(_("Competing cleared."))
|
||||
@@ -3115,7 +3115,7 @@ class Core(commands.commands._RuleDropper, commands.Cog, CoreLogic):
|
||||
Secrets are not shown.
|
||||
|
||||
**Example:**
|
||||
- `[p]set api list``
|
||||
- `[p]set api list`
|
||||
"""
|
||||
|
||||
services: dict = await ctx.bot.get_shared_api_tokens()
|
||||
@@ -3589,7 +3589,7 @@ class Core(commands.commands._RuleDropper, commands.Cog, CoreLogic):
|
||||
Warning: These settings may not be accurate if the default formatter is not in use.
|
||||
|
||||
**Example:**
|
||||
- `[p]helpset showsettings``
|
||||
- `[p]helpset showsettings`
|
||||
"""
|
||||
|
||||
help_settings = await commands.help.HelpSettings.from_context(ctx)
|
||||
@@ -3611,7 +3611,7 @@ class Core(commands.commands._RuleDropper, commands.Cog, CoreLogic):
|
||||
This resets [botname]'s help formatter to the default formatter.
|
||||
|
||||
**Example:**
|
||||
- `[p]helpset resetformatter``
|
||||
- `[p]helpset resetformatter`
|
||||
"""
|
||||
|
||||
ctx.bot.reset_help_formatter()
|
||||
@@ -3631,7 +3631,7 @@ class Core(commands.commands._RuleDropper, commands.Cog, CoreLogic):
|
||||
This may not have an impact when using custom formatters from 3rd party cogs
|
||||
|
||||
**Example:**
|
||||
- `[p]helpset resetsettings``
|
||||
- `[p]helpset resetsettings`
|
||||
"""
|
||||
await ctx.bot._config.help.clear()
|
||||
await ctx.send(
|
||||
|
||||
@@ -15,7 +15,7 @@ from .utils.common_filters import (
|
||||
filter_urls,
|
||||
escape_spoilers,
|
||||
)
|
||||
from .utils.chat_formatting import pagify
|
||||
from .utils.chat_formatting import bold, pagify
|
||||
from .i18n import Translator, set_contextual_locales_from_guild
|
||||
|
||||
from .generic_casetypes import all_generics
|
||||
@@ -486,7 +486,7 @@ class Case:
|
||||
|
||||
if embed:
|
||||
if self.reason:
|
||||
reason = _("**Reason:** {}").format(self.reason)
|
||||
reason = f"{bold(_('Reason:'))} {self.reason}"
|
||||
if len(reason) > 2048:
|
||||
reason = (
|
||||
next(
|
||||
@@ -521,7 +521,7 @@ class Case:
|
||||
return emb
|
||||
else:
|
||||
if self.reason:
|
||||
reason = _("**Reason:** {}").format(self.reason)
|
||||
reason = f"{bold(_('Reason:'))} {self.reason}"
|
||||
if len(reason) > 1000:
|
||||
reason = (
|
||||
next(
|
||||
@@ -536,20 +536,20 @@ class Case:
|
||||
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 += f"{bold(_('User:'))} {user}\n"
|
||||
case_text += f"{bold(_('Moderator:'))} {moderator}\n"
|
||||
case_text += "{}\n".format(reason)
|
||||
if until and duration:
|
||||
case_text += _("**Until:** {}\n**Duration:** {}\n").format(until, duration)
|
||||
case_text += f"{bold(_('Until:'))} {until}\n{bold(_('Duration:'))} {duration}\n"
|
||||
if self.channel:
|
||||
if isinstance(self.channel, int):
|
||||
case_text += _("**Channel**: {} (Deleted)\n").format(self.channel)
|
||||
case_text += f"{bold(_('Channel:'))} {self.channel} {_('(Deleted)')}\n"
|
||||
else:
|
||||
case_text += _("**Channel**: {}\n").format(self.channel.name)
|
||||
case_text += f"{bold(_('Channel:'))} {self.channel.name}\n"
|
||||
if amended_by:
|
||||
case_text += _("**Amended by:** {}\n").format(amended_by)
|
||||
case_text += f"{bold(_('Amended by:'))} {amended_by}\n"
|
||||
if last_modified:
|
||||
case_text += _("**Last modified at:** {}\n").format(last_modified)
|
||||
case_text += f"{bold(_('Last modified at:'))} {last_modified}\n"
|
||||
return case_text.strip()
|
||||
|
||||
def to_json(self) -> dict:
|
||||
|
||||
Reference in New Issue
Block a user