discord-interactions.py

Localization

Class

Translations for command names, descriptions and choices.

from discord_interactions import Localization

Constructor

Localization(default_locale: str = 'en-US')
NameTypeDefaultDescription
default_localestr'en-US'

Methods

load_from_dict

def load_from_dict(data: Dict[str, Dict[str, str]]) -> None

Load translations from a dictionary.

load_from_json

def load_from_json(path: str | pathlib.Path) -> None

Load translations from a JSON file.

load_from_folder

def load_from_folder(folder: str | pathlib.Path) -> None

Load translations from a folder with one JSON file per locale.

get

def get(key: str, locale: str | None = None) -> str | TranslationSet

Get a translation or TranslationSet.

t

def t(key: str, locale: str, **kwargs) -> str

Get a translated string with formatting.

localizations

def localizations(key: str) -> Dict[str, str]

Get the localizations dict for the Discord API.

command

def command(name_key: str, description_key: str) -> Dict[str, Any]

Get localization data for a command.

option

def option(name_key: str, description_key: str) -> Dict[str, Any]

Get localization data for an option.

choice

def choice(name_key: str) -> Dict[str, Any]

Get localization data for a choice.

Type a name: create_button, ModalBuilder, cooldown.