-
Hello, I managed to translate my commands using app_commands.locale_str and making a class app_commands.Translator itself, however in the case of hybrid_group the translation of their name is not working correctly, for example:
After translating it should be (pt-br):
But I end up with the result:
Any tips on how to resolve this? @commands.hybrid_group(name=app_commands.locale_str('gather'))
async def gather(self, ctx: discord.Interaction):
pass
@gather.command(name=app_commands.locale_str('wood'))
@app_commands.checks.cooldown(6, 300)
async def wood(self, ctx: commands.Context):
pass |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
Your name shouldn't have spaces in it, though I can't immediately see anything that would cause the |
Beta Was this translation helpful? Give feedback.
-
I corrected, there is no that space it's just the "wood" |
Beta Was this translation helpful? Give feedback.
-
I found the problem, for some reason when the hybrid_group passes to the Translator it doesn't come with a context of "TranslationContextLocation.command_name". from __future__ import annotations
import discord
from discord import app_commands
from discord.app_commands import TranslationContextLocation
from IsekaiTensei.discord_bot.utils.get_text import GetText
class IsekaiTranslator(app_commands.Translator):
async def translate(
self,
string: app_commands.locale_str,
locale: discord.Locale,
context: app_commands.TranslationContext,
) -> str | None:
try:
if context.location in (TranslationContextLocation.command_name,
TranslationContextLocation.command_description):
return GetText(context, locale).message(str(string))
elif context.location in (TranslationContextLocation.parameter_name,
TranslationContextLocation.parameter_description):
return GetText(context, locale).parameter(str(string))
elif context.location in (TranslationContextLocation.choice_name,):
return GetText(context, locale).choice(str(string))
else:
value = None
for method in [GetText(context, locale).message,
GetText(context, locale).parameter,
GetText(context, locale).choice]:
value = method(str(string))
if value is not None:
break
return value
except Exception as er:
print(er)
return str(string) |
Beta Was this translation helpful? Give feedback.
I found the problem, for some reason when the hybrid_group passes to the Translator it doesn't come with a context of "TranslationContextLocation.command_name".
In my code I observe these contexts to use in GetText (because my translations are in YML files), so it always ended up falling outside the conditionals, to correct I just added an else testing all possibilities, it's not the best way to do it but it worked...