update dependencies and remove redundant usages of old IetfLanguageCode

This commit is contained in:
InsanusMokrassar 2023-12-21 23:25:36 +06:00
parent 48d3fe41f2
commit 1bd671685b
6 changed files with 22 additions and 17 deletions

View File

@ -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`

View File

@ -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"

View File

@ -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()

View File

@ -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) {

View File

@ -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<IetfLanguageCode, Lazy<String>>
val map: Map<IetfLang, Lazy<String>>
) {
class Builder(
var default: String
) {
private val map = mutableMapOf<IetfLanguageCode, Lazy<String>>()
private val map = mutableMapOf<IetfLang, Lazy<String>>()
infix fun IetfLanguageCode.variant(value: Lazy<String>) {
infix fun IetfLang.variant(value: Lazy<String>) {
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<String>) = IetfLanguageCode(this) variant value
infix fun String.variant(value: () -> String) = IetfLanguageCode(this) variant lazy(value)
infix fun String.variant(value: Lazy<String>) = 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 {

View File

@ -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)