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

io.github.freya022.botcommands.api.localization.LocalizationMap.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

import io.github.freya022.botcommands.api.localization.providers.LocalizationMapProvider
import org.jetbrains.annotations.UnmodifiableView
import java.util.*

/**
 * Common interface to retrieve [localization templates][LocalizationTemplate] from a path.
 */
interface LocalizationMap {
    /**
     * Returns the effective locale of this localization map.
     *
     * **Note:** This doesn't need to be the locale passed by [LocalizationMapProvider.fromBundleOrParent].
     */
    val effectiveLocale: Locale

    /**
     * Returns an unmodifiable set of keys this localization map contains,
     * or `null` if unsupported.
     */
    val keys: @UnmodifiableView Set?

    /**
     * Returns the [LocalizationTemplate] with the corresponding path,
     * or `null` if there is no such entry.
     */
    operator fun get(path: String): LocalizationTemplate?
}

fun createDelegated(current: LocalizationMap?, parent: LocalizationMap): LocalizationMap {
    if (current == null) return parent

    return object : LocalizationMap {
        override val effectiveLocale: Locale
            get() = current.effectiveLocale

        override val keys: Set?
            get() = current.keys

        override fun get(path: String): LocalizationTemplate? =
            current[path] ?: parent[path]
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy