commonMain.de.comahe.i18n4k.strings.LocalizedStringMap.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of i18n4k-core Show documentation
Show all versions of i18n4k-core Show documentation
i18n4k is a multiplatform (JVM, JS, native) library and code generator for Kotlin to handle internationalisation (i18n) in your program.
package de.comahe.i18n4k.strings
import de.comahe.i18n4k.Locale
import de.comahe.i18n4k.applyLocales
/**
* A simple implementation of [LocalizedString] that maps a locale values to string values.
*
* Attributes may also be specified with the `attributes` parameter.
*/
class LocalizedStringMap(
private val messages: Map,
private val attributes: LocalizedAttributable?
) : LocalizedString, LocalizedAttributable {
constructor(
vararg messages: Pair,
attributes: LocalizedAttributable? = null
) :
this(
messages = messages.fold(mutableMapOf()) { map, pair ->
map[pair.first] = pair.second
return@fold map
},
attributes = attributes
)
override fun getAttribute(attributeName: CharSequence, locale: Locale?): String? {
return attributes?.getAttribute(attributeName, locale)
}
override fun toString(): String = toString(null)
override fun toString(locale: Locale?): String =
applyLocales(locale) { messages[it] } ?: "?"
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy