Kotlin multiplatform locale library.
Experimental. Feel free to contribute!
build.gradle.kts
:
dependencies {
implementation("io.fluidsonic.locale:fluid-locale:0.13.0")
}
For now this is only a thin layer over a LanguageTag
. To be improved.
val locale = Locale.forLanguageTag("en-us") // throws if tag is not well-formed
println(locale.language) // en
println(locale.region) // US
println(locale.toLanguageTag()) // en-US
val locale = Locale.forLanguageTagOrNull("a-b-c-1-2-3") // null if tag is not well-formed
println(locale) // null
val locale = Locale.forLanguage("en", region = "US")
println(locale.language) // en
println(locale.region) // US
println(locale.toLanguageTag()) // en-US
A class for BCP 47 language tags (e.g. en
, en-US
or sl-IT-nedis
).
val tag = LanguageTag.parse("ZH-HANT-cn-somevar") // throws if tag is not well-formed
println(tag.language) // zh
println(tag.script) // Hant
println(tag.region) // CN
println(tag.variants) // [somevar]
println(tag.toString()) // zh-Hant-CN-somevar
val tag = LanguageTag.parseOrNull("a-b-c-1-2-3") // null if tag is not well-formed
println(tag) // null
val tag = LanguageTag.forLanguage("ZH", script = "HANT", region = "cn", variants = listOf("somevar"))
println(tag.language) // zh
println(tag.script) // Hant
println(tag.region) // CN
println(tag.variants) // [somevar]
println(tag.toString()) // zh-Hant-CN-somevar
Apache 2.0