mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2024-12-19 07:07:16 +00:00
update dependencies and remove redundant usages of old IetfLanguageCode
This commit is contained in:
parent
48d3fe41f2
commit
1bd671685b
@ -2,6 +2,9 @@
|
|||||||
|
|
||||||
## 0.20.23
|
## 0.20.23
|
||||||
|
|
||||||
|
* `Versions`:
|
||||||
|
* `Koin`: `3.5.0` -> `3.5.3`
|
||||||
|
* `Okio`: `3.6.0` -> `3.7.0`
|
||||||
* `LanguageCodes`:
|
* `LanguageCodes`:
|
||||||
* Fixes in intermediate language codes (like `Chinese.Hans`)
|
* Fixes in intermediate language codes (like `Chinese.Hans`)
|
||||||
* Rename `IetfLanguageCode` to `IetfLang`
|
* Rename `IetfLanguageCode` to `IetfLang`
|
||||||
|
@ -17,9 +17,9 @@ ktor = "2.3.7"
|
|||||||
|
|
||||||
gh-release = "2.4.1"
|
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"
|
ksp = "1.9.21-1.0.16"
|
||||||
kotlin-poet = "1.15.3"
|
kotlin-poet = "1.15.3"
|
||||||
|
@ -2,7 +2,9 @@ package dev.inmo.micro_utils.language_codes
|
|||||||
|
|
||||||
import java.util.Locale
|
import java.util.Locale
|
||||||
|
|
||||||
fun IetfLanguageCode.toJavaLocale(): Locale = Locale.forLanguageTag(code)
|
fun IetfLang.toJavaLocale(): Locale = Locale.forLanguageTag(code)
|
||||||
fun IetfLanguageCode?.toJavaLocaleOrDefault(): Locale = this ?.toJavaLocale() ?: Locale.getDefault()
|
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()
|
||||||
|
@ -4,7 +4,6 @@ import android.content.Context
|
|||||||
import android.content.res.Configuration
|
import android.content.res.Configuration
|
||||||
import android.content.res.Resources
|
import android.content.res.Resources
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import dev.inmo.micro_utils.language_codes.toIetfLanguageCode
|
|
||||||
|
|
||||||
fun StringResource.translation(configuration: Configuration): String = translation(
|
fun StringResource.translation(configuration: Configuration): String = translation(
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package dev.inmo.micro_utils.strings
|
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:
|
* 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(
|
class StringResource(
|
||||||
val default: String,
|
val default: String,
|
||||||
val map: Map<IetfLanguageCode, Lazy<String>>
|
val map: Map<IetfLang, Lazy<String>>
|
||||||
) {
|
) {
|
||||||
class Builder(
|
class Builder(
|
||||||
var default: String
|
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
|
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: Lazy<String>) = IetfLang(this) variant value
|
||||||
infix fun String.variant(value: () -> String) = IetfLanguageCode(this) variant lazy(value)
|
infix fun String.variant(value: () -> String) = IetfLang(this) variant lazy(value)
|
||||||
infix fun String.variant(value: String) = this variant lazyOf(value)
|
infix fun String.variant(value: String) = this variant lazyOf(value)
|
||||||
|
|
||||||
fun build() = StringResource(default, map.toMap())
|
fun build() = StringResource(default, map.toMap())
|
||||||
}
|
}
|
||||||
|
|
||||||
fun translation(languageCode: IetfLanguageCode): String {
|
fun translation(languageCode: IetfLang): String {
|
||||||
map[languageCode] ?.let { return it.value }
|
map[languageCode] ?.let { return it.value }
|
||||||
|
|
||||||
return languageCode.parentLang ?.let {
|
return languageCode.parentLang ?.let {
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
package dev.inmo.micro_utils.strings
|
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
|
import java.util.Locale
|
||||||
|
|
||||||
fun StringResource.translation(locale: Locale = Locale.getDefault()): String {
|
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)
|
fun Locale.translation(resource: StringResource): String = resource.translation(this)
|
Loading…
Reference in New Issue
Block a user