Skip to content

Translator #9160

Answered by Rapptz
mi66mc asked this question in Q&A
Dec 30, 2022 · 2 comments · 1 reply
Discussion options

You must be logged in to vote

The general idea for translation is hopefully simple, first you need to make an app_commands.Translator subclass that contains the necessary implementation for dealing with your localisation. For example:

from __future__ import annotations

import discord
from discord import app_commands

class MyTranslator(app_commands.Translator):
    async def translate(
        self,
        string: app_commands.locale_str,
        locale: discord.Locale,
        context: app_commands.TranslationContext,
    ) -> str | None:
        # For this example, we can translate a few words in Japanese...
        message = str(string)
        if locale is discord.Locale.japanese:
            if message == 'Hello!'

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@mi66mc
Comment options

Answer selected by mi66mc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants