improvements in language codes

This commit is contained in:
InsanusMokrassar 2023-02-19 19:34:42 +06:00
parent 18d63eb980
commit 85455ab21c
3 changed files with 20 additions and 0 deletions

View File

@ -2,6 +2,10 @@
## 0.16.11
* `LanguageCodes`:
* In android and JVM targets now available `toJavaLocale` and from Java `Locale` conversations from/to
`IetfLanguageCode`
## 0.16.10
* `Repos`:

View File

@ -5,3 +5,11 @@ plugins {
}
apply from: "$mppProjectWithSerializationPresetPath"
kotlin {
sourceSets {
jvmMain {
dependsOn androidMain
}
}
}

View File

@ -0,0 +1,8 @@
package dev.inmo.micro_utils.language_codes
import java.util.Locale
fun IetfLanguageCode.toJavaLocale(): Locale = Locale.forLanguageTag(code)
fun IetfLanguageCode?.toJavaLocaleOrDefault(): Locale = this ?.toJavaLocale() ?: Locale.getDefault()
fun Locale.toIetfLanguageCode(): IetfLanguageCode = IetfLanguageCode(toLanguageTag())