AppLocalizationContext

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

User and guild locales

The user and guild locales are set by UserLocaleProvider (by default Interaction.getUserLocale), and GuildLocaleProvider (by default Interaction.getGuildLocale) respectively.

You can implement your own locale provider to change the locales 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 Interaction.

See also

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.

Link copied to clipboard

Returns the Locale of the user.

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
open fun localizeUser(localizationPath: String, vararg entries: Localization.Entry): String

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

Link copied to clipboard
fun AppLocalizationContext.localizeUser(localizationPath: String, vararg entries: PairEntry): String

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

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

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

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

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

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

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): AppLocalizationContext

Returns a new localization context with the specified localization bundle.

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

Returns a new TextLocalizationContext with the specified guild locale.

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

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.