TextLocalizationContext

Interface helping in localizing content, supports preset localization bundles, localization prefixes, and context-aware localization.

Guild locale

The guild locale is set by GuildLocaleProvider (by default Guild.getLocale).

You can implement your own locale provider to change the locale used by this localization context.

Manual usage

While instances of this interface are primarily injected with @LocalizationBundle, you can also construct instances of this interface with LocalizationContext.create.

Instances are only injectable if the event is a subclass of either Interaction or MessageReceivedEvent.

See also

Inheritors

Properties

Link copied to clipboard

The locale used when no locale is specified, the best locale is picked in this order:

Link copied to clipboard

Returns the DiscordLocale of the guild.

Link copied to clipboard

Returns the localization bundle of the current context.

Link copied to clipboard
abstract val localizationPrefix: String?

Returns the localization prefix of the current context.

Functions

Link copied to clipboard
abstract fun hasGuildLocale(): Boolean

Whether this localization context has a Guild locale.

Link copied to clipboard
open fun localize(localizationPath: String, vararg entries: Localization.Entry): String

Localizes the provided path, with the best locale available.

abstract fun localize(locale: DiscordLocale, localizationPath: String, vararg entries: Localization.Entry): String

Localizes the provided path, with the provided locale.

Link copied to clipboard
fun LocalizationContext.localize(localizationPath: String, vararg entries: PairEntry): String

Localizes the provided path, with the best locale available.

fun LocalizationContext.localize(locale: DiscordLocale, localizationPath: String, vararg entries: PairEntry): String

Localizes the provided path, with the provided locale.

Link copied to clipboard
open fun localizeGuild(localizationPath: String, vararg entries: Localization.Entry): String

Localizes the provided path, with the guild's locale.

Link copied to clipboard
fun TextLocalizationContext.localizeGuild(localizationPath: String, vararg entries: PairEntry): String

Localizes the provided path, with the guild's locale.

Link copied to clipboard
open fun localizeGuildOrNull(localizationPath: String, vararg entries: Localization.Entry): String?

Localizes the provided path, with the guild's locale, or returns null if the path does not exist.

Link copied to clipboard
fun TextLocalizationContext.localizeGuildOrNull(localizationPath: String, vararg entries: PairEntry): String?

Localizes the provided path, with the guild's locale, or returns null if the path does not exist.

Link copied to clipboard
open fun localizeOrNull(localizationPath: String, vararg entries: Localization.Entry): String?

Localizes the provided path, with the best locale available, or returns null if the path does not exist.

abstract fun localizeOrNull(locale: DiscordLocale, localizationPath: String, vararg entries: Localization.Entry): String?

Localizes the provided path, with the provided locale, or returns null if the path does not exist.

Link copied to clipboard
fun LocalizationContext.localizeOrNull(localizationPath: String, vararg entries: PairEntry): String?

Localizes the provided path, with the best locale available, or returns null if the path does not exist.

fun LocalizationContext.localizeOrNull(locale: DiscordLocale, localizationPath: String, vararg entries: PairEntry): String?

Localizes the provided path, with the provided locale, or returns null if the path does not exist.

Link copied to clipboard
@CheckReturnValue
abstract override fun switchBundle(localizationBundle: String): TextLocalizationContext

Returns a new localization context with the specified localization bundle, and resets the localization prefix.

Link copied to clipboard
@CheckReturnValue
abstract override fun withBundle(localizationBundle: String): TextLocalizationContext

Returns a new localization context with the specified localization bundle.

Link copied to clipboard
@CheckReturnValue
abstract fun withGuildLocale(guildLocale: DiscordLocale?): TextLocalizationContext

Returns a new TextLocalizationContext with the specified guild locale.

Link copied to clipboard
@CheckReturnValue
abstract override fun withPrefix(localizationPrefix: String?): TextLocalizationContext

Returns a new localization context with the specified localization prefix.

Link copied to clipboard
@CheckReturnValue
abstract fun withUserLocale(userLocale: DiscordLocale?): AppLocalizationContext

Returns a new AppLocalizationContext with the specified user locale.