Work In Progress
This documentation is in beta. It's missing lots of content, search is broken, and many links go nowhere. These problems will be fixed before release, but there's plenty of work left!
Skip to main content

Internationalisation (i18n)

The i18n { } builder allows you to configure how your bot handles translations and retrieves locales for internationalisation and localisation.

Kord Extensions provides built-in translations for several locales, listed in the SupportedLocales object. You can contribute your own translations (or check in on our progress) on Weblate.

ExtensibleBot(TOKEN) {
// ...

i18n {
defaultLocale = SupportedLocales.SPANISH

applicationCommandLocale(SupportedLocales.ALL_LOCALES_SET)

interactionUserLocaleResolver()
interactionGuildLocaleResolver()
}
}

Builders

localeResolver { ... }Lambda Returns: Locale?

Register a custom locale resolver.

Locale resolvers return a Locale or null based on the parameters passed in, defining which locale should be used for translations in that context. This also allows you to write configuration commands so users can pick their preferred locale, if you wish.

You can register multiple locale resolvers, and they'll be tried (in registration order) until one of them returns something other than null.

For more information, see [[the i18n documentation]].

Lambda Arguments
guildType: GuildBehavior?

A [[Behavior]] representing the current guild, if any.

channelType: ChannelBehavior?

A [[Behavior]] representing the current channel, if any.

userType: UserBehavior?

A [[Behavior]] representing the current user, if any.

interactionType: Interaction?

A [[Behavior]] representing the current interaction, if any.

translationsProvider { ... }Lambda Returns: TranslationsProvider

Register a callback that constructs and returns an alternative implementation of the TranslationsProvider type, if needed.

Lambda Arguments
defaultLocaleBuilderType: () -> Locale

A callable object that returns the configured default locale.

Functions

applicationCommandLocale(...)

Registers the given locales as application command locales. Your bot uses these locales to translate application commands when they're registered with Discord.

Supply SupportedLocales.ALL_LOCALES_SET to support all locales that Kord Extensions provides translations for.

Arguments
localesTypes:LocaleCollection<Locale>

Locales you want your bot to support.

interactionGuildLocaleResolver(...)

Registers a default locale resolver which attempts to resolve locales using the language set in the current guild's server settings.

interactionUserLocaleResolver(...)

Registers a default locale resolver which attempts to resolve locales using the current user's Discord language setting.

Properties

var defaultLocaleType: LocaleDefault: SupportedLocales.ENGLISH

Your bot's default locale.

This is the locale used as the default locale when registering application commands, and when the locale resolvers don't return one.