Localization

This sections documents everything related to application commands’ localization support.

Classes

LocalizationProtocol

class disnake.LocalizationProtocol[source]

Manages a key-value mapping of localizations.

This is an abstract class, a concrete implementation is provided as LocalizationStore.

New in version 2.5.

abstractmethod get(key)[source]

Returns localizations for the specified key.

Parameters:

key (str) – The lookup key.

Raises:

LocalizationKeyError – May be raised if no localizations for the provided key were found, depending on the implementation.

Returns:

The localizations for the provided key. May return None if no localizations could be found.

Return type:

Optional[Dict[str, str]]

load(path)[source]

Adds localizations from the provided path.

Parameters:

path (Union[str, os.PathLike]) – The path to the file/directory to load.

Raises:

RuntimeError – The provided path is invalid or couldn’t be loaded

reload()[source]

Clears localizations and reloads all previously loaded sources again. If an exception occurs, the previous data gets restored and the exception is re-raised.

LocalizationStore

class disnake.LocalizationStore(*, strict)[source]

Manages a key-value mapping of localizations using .json files.

New in version 2.5.

strict

Specifies whether get() raises an exception if localizations for a provided key couldn’t be found.

Type:

bool

get(key)[source]

Returns localizations for the specified key.

Parameters:

key (str) – The lookup key.

Raises:

LocalizationKeyError – No localizations for the provided key were found. Raised only if strict is enabled, returns None otherwise.

Returns:

The localizations for the provided key. Returns None if no localizations could be found and strict is disabled.

Return type:

Optional[Dict[str, str]]

load(path)[source]

Adds localizations from the provided path to the store. If the path points to a file, the file gets loaded. If it’s a directory, all .json files in that directory get loaded (non-recursive).

Parameters:

path (Union[str, os.PathLike]) – The path to the file/directory to load.

Raises:

RuntimeError – The provided path is invalid or couldn’t be loaded

reload()[source]

Clears localizations and reloads all previously loaded files/directories again. If an exception occurs, the previous data gets restored and the exception is re-raised. See load() for possible raised exceptions.

Localized

class disnake.Localized(string=None, *, key=..., data=...)[source]

A container type used for localized parameters.

Exactly one of key or data must be provided.

There is an alias for this called Localised.

New in version 2.5.

Parameters:
  • string (Optional[str]) – The default (non-localized) value of the string. Whether this is optional or not depends on the localized parameter type.

  • key (str) – A localization key used for lookups. Incompatible with data.

  • data (Union[Dict[Locale, str], Dict[str, str]]) – A mapping of locales to localized values. Incompatible with key.

LocalizationValue

class disnake.LocalizationValue(localizations)[source]

Container type for (pending) localization data.

New in version 2.5.

property data[source]

A dict with a locale -> localization mapping, if available.

Type:

Optional[Dict[str, str]]

Enumerations

Locale

class disnake.Locale[source]

Represents supported locales by Discord.

New in version 2.5.

bg

The bg (Bulgarian) locale.

cs

The cs (Czech) locale.

da

The da (Danish) locale.

de

The de (German) locale.

el

The el (Greek) locale.

en_GB

The en-GB (English, UK) locale.

en_US

The en-US (English, US) locale.

es_ES

The es-ES (Spanish) locale.

es_LATAM

The es-419 (Spanish, LATAM) locale.

New in version 2.10.

fi

The fi (Finnish) locale.

fr

The fr (French) locale.

hi

The hi (Hindi) locale.

hr

The hr (Croatian) locale.

hu

The hu (Hungarian) locale.

id

The id (Indonesian) locale.

New in version 2.8.

it

The it (Italian) locale.

ja

The ja (Japanese) locale.

ko

The ko (Korean) locale.

lt

The lt (Lithuanian) locale.

nl

The nl (Dutch) locale.

no

The no (Norwegian) locale.

pl

The pl (Polish) locale.

pt_BR

The pt-BR (Portuguese) locale.

ro

The ro (Romanian) locale.

ru

The ru (Russian) locale.

sv_SE

The sv-SE (Swedish) locale.

th

The th (Thai) locale.

tr

The tr (Turkish) locale.

uk

The uk (Ukrainian) locale.

vi

The vi (Vietnamese) locale.

zh_CN

The zh-CN (Chinese, China) locale.

zh_TW

The zh-TW (Chinese, Taiwan) locale.