From 1bd671685b6df9a444802060fb87dd5ccbf0caf1 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 21 Dec 2023 23:25:36 +0600 Subject: [PATCH] update dependencies and remove redundant usages of old IetfLanguageCode --- CHANGELOG.md | 3 +++ gradle/libs.versions.toml | 4 ++-- language_codes/src/jvmMain/kotlin/Locale.kt | 8 +++++--- .../kotlin/StringResourceContextGetter.kt | 1 - .../src/commonMain/kotlin/StringResource.kt | 19 ++++++++++--------- .../kotlin/StringResourceLocaleGetter.kt | 4 ++-- 6 files changed, 22 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7946fce7ef6..272cdf894ed 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ ## 0.20.23 +* `Versions`: + * `Koin`: `3.5.0` -> `3.5.3` + * `Okio`: `3.6.0` -> `3.7.0` * `LanguageCodes`: * Fixes in intermediate language codes (like `Chinese.Hans`) * Rename `IetfLanguageCode` to `IetfLang` diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index cc51a4a7db2..eadff0f3862 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -17,9 +17,9 @@ ktor = "2.3.7" gh-release = "2.4.1" -koin = "3.5.0" +koin = "3.5.3" -okio = "3.6.0" +okio = "3.7.0" ksp = "1.9.21-1.0.16" kotlin-poet = "1.15.3" diff --git a/language_codes/src/jvmMain/kotlin/Locale.kt b/language_codes/src/jvmMain/kotlin/Locale.kt index 5f361402f2c..618130b2b79 100644 --- a/language_codes/src/jvmMain/kotlin/Locale.kt +++ b/language_codes/src/jvmMain/kotlin/Locale.kt @@ -2,7 +2,9 @@ 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 IetfLang.toJavaLocale(): Locale = Locale.forLanguageTag(code) +fun IetfLang?.toJavaLocaleOrDefault(): Locale = this?.toJavaLocale() ?: Locale.getDefault() -fun Locale.toIetfLanguageCode(): IetfLanguageCode = IetfLanguageCode(toLanguageTag()) +fun Locale.toIetfLang(): IetfLang = IetfLang(toLanguageTag()) +@Deprecated("Renamed", ReplaceWith("this.toIetfLang()", "dev.inmo.micro_utils.language_codes.toIetfLang")) +fun Locale.toIetfLanguageCode(): IetfLang = toIetfLang() diff --git a/resources/src/androidMain/kotlin/StringResourceContextGetter.kt b/resources/src/androidMain/kotlin/StringResourceContextGetter.kt index 8ce918ecf94..d049df0e28c 100644 --- a/resources/src/androidMain/kotlin/StringResourceContextGetter.kt +++ b/resources/src/androidMain/kotlin/StringResourceContextGetter.kt @@ -4,7 +4,6 @@ import android.content.Context import android.content.res.Configuration import android.content.res.Resources import android.os.Build -import dev.inmo.micro_utils.language_codes.toIetfLanguageCode fun StringResource.translation(configuration: Configuration): String = translation( if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { diff --git a/resources/src/commonMain/kotlin/StringResource.kt b/resources/src/commonMain/kotlin/StringResource.kt index 37cacb69b75..4ccb0fb8fcc 100644 --- a/resources/src/commonMain/kotlin/StringResource.kt +++ b/resources/src/commonMain/kotlin/StringResource.kt @@ -1,6 +1,6 @@ package dev.inmo.micro_utils.strings -import dev.inmo.micro_utils.language_codes.IetfLanguageCode +import dev.inmo.micro_utils.language_codes.IetfLang /** * Use this class as a type of your strings object fields. For example: @@ -17,28 +17,29 @@ import dev.inmo.micro_utils.language_codes.IetfLanguageCode */ class StringResource( val default: String, - val map: Map> + val map: Map> ) { class Builder( var default: String ) { - private val map = mutableMapOf>() + private val map = mutableMapOf>() - infix fun IetfLanguageCode.variant(value: Lazy) { + infix fun IetfLang.variant(value: Lazy) { map[this] = value } - infix fun IetfLanguageCode.variant(value: () -> String) = this variant lazy(value) - infix fun IetfLanguageCode.variant(value: String) = this variant lazyOf(value) + + infix fun IetfLang.variant(value: () -> String) = this variant lazy(value) + infix fun IetfLang.variant(value: String) = this variant lazyOf(value) - infix fun String.variant(value: Lazy) = IetfLanguageCode(this) variant value - infix fun String.variant(value: () -> String) = IetfLanguageCode(this) variant lazy(value) + infix fun String.variant(value: Lazy) = IetfLang(this) variant value + infix fun String.variant(value: () -> String) = IetfLang(this) variant lazy(value) infix fun String.variant(value: String) = this variant lazyOf(value) fun build() = StringResource(default, map.toMap()) } - fun translation(languageCode: IetfLanguageCode): String { + fun translation(languageCode: IetfLang): String { map[languageCode] ?.let { return it.value } return languageCode.parentLang ?.let { diff --git a/resources/src/jvmMain/kotlin/StringResourceLocaleGetter.kt b/resources/src/jvmMain/kotlin/StringResourceLocaleGetter.kt index 486ca85403b..03a121ee8ec 100644 --- a/resources/src/jvmMain/kotlin/StringResourceLocaleGetter.kt +++ b/resources/src/jvmMain/kotlin/StringResourceLocaleGetter.kt @@ -1,10 +1,10 @@ package dev.inmo.micro_utils.strings -import dev.inmo.micro_utils.language_codes.toIetfLanguageCode +import dev.inmo.micro_utils.language_codes.toIetfLang import java.util.Locale fun StringResource.translation(locale: Locale = Locale.getDefault()): String { - return translation(locale.toIetfLanguageCode()) + return translation(locale.toIetfLang()) } fun Locale.translation(resource: StringResource): String = resource.translation(this) \ No newline at end of file