-
Can someone show me an translator example using |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
|
Beta Was this translation helpful? Give feedback.
-
The general idea for translation is hopefully simple, first you need to make an 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!':
return 'こんにちは!'
elif message == 'Goodbye!':
return 'さようなら!'
# Otherwise we don't handle it
return None Obviously a more complicated implementation of Afterwards you set the translator using |
Beta Was this translation helpful? Give feedback.
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: