All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.freya022.botcommands.api.localization.interaction.UserLocaleProvider.kt Maven / Gradle / Ivy

Go to download

A Kotlin-first (and Java) framework that makes creating Discord bots a piece of cake, using the JDA library.

There is a newer version: 3.0.0-alpha.18
Show newest version
package io.github.freya022.botcommands.api.localization.interaction

import io.github.freya022.botcommands.api.core.service.annotations.BService
import io.github.freya022.botcommands.api.core.service.annotations.InterfacedService
import io.github.freya022.botcommands.api.localization.context.AppLocalizationContext
import net.dv8tion.jda.api.interactions.DiscordLocale
import net.dv8tion.jda.api.interactions.Interaction
import java.util.*

/**
 * Provides the locale of a user in a Discord interaction,
 * may be useful if the user has set its own locale, for example.
 *
 * It is recommended to override both [getDiscordLocale] and [getLocale] for best results,
 * when using localization in events, and in [AppLocalizationContext].
 *
 * This returns [Interaction.getUserLocale] by default.
 *
 * ### Usage
 * Register your instance as a service with [@BService][BService].
 *
 * @see LocalizableInteraction
 * @see AppLocalizationContext
 */
@InterfacedService(acceptMultiple = false)
interface UserLocaleProvider {
    fun getDiscordLocale(interaction: Interaction): DiscordLocale

    fun getLocale(interaction: Interaction): Locale =
        getDiscordLocale(interaction).toLocale()
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy