Skip to content

Commit e34dd92

Browse files
committed
✨ Translations to message commands.
1 parent 4ffa826 commit e34dd92

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

src/i18n/utils.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,11 @@ def remove_none(d: dict[T, V]) -> dict[T, V]:
2828
"""Remove None values from a dictionary.
2929
3030
Args:
31+
----
3132
d (dict[T, V]): The dictionary to remove None values from.
3233
3334
Returns:
35+
-------
3436
dict[T, V]: The dictionary without None values.
3537
3638
"""
@@ -43,12 +45,15 @@ def merge_command_translations(
4345
"""Merge command translations into a single dictionary.
4446
4547
Args:
48+
----
4649
translations (list[ExtensionTranslation]): A list of translations.
4750
4851
Returns:
52+
-------
4953
dict[str, Deg1CommandTranslation] | None: A dictionary of command translations.
5054
5155
Raises:
56+
------
5257
None
5358
5459
"""
@@ -71,6 +76,7 @@ def merge_command_translations(
7176
discord.SlashCommand,
7277
discord.SlashCommandGroup,
7378
prefixed.Command, # pyright: ignore[reportMissingTypeArgument]
79+
discord.MessageCommand,
7480
)
7581

7682

@@ -85,19 +91,23 @@ def localize_commands( # noqa: PLR0912
8591
"""Recursively localize commands and their subcommands.
8692
8793
Args:
94+
----
8895
commands: List of commands to localize.
8996
translations: Translations for the commands.
9097
default_locale: The default locale to use.
9198
9299
Returns:
100+
-------
93101
None
94102
95103
"""
96104
logger.info("Localizing commands...")
97105
err = 0
98106
tot = 0
99107
for command in commands:
100-
if isinstance(command, discord.SlashCommand | discord.SlashCommandGroup | prefixed.Command):
108+
if isinstance(
109+
command, discord.SlashCommand | discord.SlashCommandGroup | prefixed.Command | discord.MessageCommand
110+
):
101111
tot += 1
102112
try:
103113
try:
@@ -121,7 +131,7 @@ def localize_commands( # noqa: PLR0912
121131
description = remove_none(translation.description.model_dump(by_alias=True))
122132
command.description = description.get(default_locale, command.description)
123133
if not isinstance(command, prefixed.Command):
124-
command.description_localizations = description
134+
command.description_localizations = description # pyright: ignore [reportAttributeAccessIssue]
125135
if translation.strings:
126136
command.translations = translation.strings # pyright: ignore[reportAttributeAccessIssue]
127137
if isinstance(command, discord.SlashCommand) and translation.options:
@@ -155,12 +165,15 @@ def load_translation(path: str) -> ExtensionTranslation:
155165
"""Load a translation from a file.
156166
157167
Args:
168+
----
158169
path (str): The path to the translation file.
159170
160171
Returns:
172+
-------
161173
ExtensionTranslation: The loaded translation.
162174
163175
Raises:
176+
------
164177
yaml.YAMLError: If the file is not a valid YAML file.
165178
166179
"""
@@ -177,11 +190,13 @@ def apply(
177190
"""Apply translations to the bot.
178191
179192
Args:
193+
----
180194
bot: The bot to apply translations to.
181195
translations: The translations to apply.
182196
default_locale: The default locale to use.
183197
184198
Returns:
199+
-------
185200
None
186201
187202
"""

0 commit comments

Comments
 (0)