commonMain.de.comahe.i18n4k.strings.LocalizedAttributeMap.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.
The newest version!
package de.comahe.i18n4k.strings
import de.comahe.i18n4k.Locale
import de.comahe.i18n4k.applyLocales
/** A map of attribute values per locale that can be used attribute-based message formatters. */
class LocalizedAttributeMap(
/** Key: attribute name; Value: map of locale to values */
private val attributes: Map>
) : LocalizedAttributable {
/** Uses a list of triples: attribute name, locale, value */
constructor(vararg attributes: Triple) : this(
attributes.fold(
mutableMapOf>()
) { map, triple ->
val localeValues = map.getOrPut(triple.first) { mutableMapOf() }
localeValues[triple.second] = triple.third
return@fold map
}
)
override fun getAttribute(attributeName: CharSequence, locale: Locale?): String? {
val localeValues = attributes[attributeName] ?: return null
return applyLocales(locale) { localeValues[it] }
}
}