I am using discord.py
to build a Discord bot that includes interactive views with buttons. Each button performs specific actions related to message embed manipulation. I want to localize the button labels so they are displayed in the user’s locale or default to the guild’s locale. Below is a simplified version of my setup:
class EmbedCreatorView(discord.ui.View):
@discord.ui.button(label="commands.admin.embed.buttons.setTitle", style=discord.ButtonStyle.primary)
async def set_title(self, interaction: discord.Interaction, button: discord.ui.Button):
...
# Modal interaction here
# More buttons with similar structure...
The button labels are initialized with keys for localization. Here’s how I localize strings within interaction responses:
await interaction.response.send_message(tanjunLocalizer.localize(
self.commandInfo.locale, "commands.admin.embed.previewSent"
), ephemeral=True)
tanjunLocalizer
is just my implementation of a localzer
So my questions are:
- How can I dynamically set the button labels based on each user’s locale at the time of interaction?
- If individual user localization isn’t feasible, how can I set the labels based on the guild’s default locale?
Thank you in advance!