Skip to content

Locales

LocaleMap dataclass #

Bases: LocaleBuilder

An implementation of crescent.LocaleBuilder that allows you to declare locales as kwargs.

import crescent
from crescent.ext import locales

@bot.include
@crescent.command(name=locales.LocaleMap("fallback", en_US="english-name", fr="french-name"))
async def command(ctx: crescent.Context):
    ...

fallback property #

fallback: str

Return the name used when there is no localization for a language.

build #

build() -> dict[str, str]

Builds the locales for a command. Returns a Mapping of language codes to strings.

Discord API Docs Localization.

i18n #

i18n(fallback: str)

Bases: LocaleBuilder

An implementation of crescent.LocaleBuilder that uses python-i18n.

⚠️ Translations must be loaded before any commands.

import crescent
import i18n
from crescent.ext import locales

i18n.add_translation("name", "translated-name", locale="en")

@bot.include
@crescent.command(name=locales.i18n("name"))
async def command(ctx: crescent.Context):
    ...

fallback property #

fallback: str

Return the name used when there is no localization for a language.

build #

build() -> dict[str, str]

Builds the locales for a command. Returns a Mapping of language codes to strings.

Discord API Docs Localization.