Skip to content

fluidsonic/fluid-locale

Repository files navigation

fluid-locale

Maven Central Tests Kotlin #fluid-libraries Slack Channel

Kotlin multiplatform locale library.
Experimental. Feel free to contribute!

Installation

build.gradle.kts:

dependencies {
	implementation("io.fluidsonic.locale:fluid-locale:0.13.0")
}

Usage

class Locale

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

class LanguageTag

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

License

Apache 2.0

About

Kotlin multiplatform locale library (experimental)

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages