mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2024-11-26 12:08:45 +00:00
commit
8c76834ae4
@ -1,5 +1,10 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## 0.20.21
|
||||||
|
|
||||||
|
* `Resources`:
|
||||||
|
* Inited
|
||||||
|
|
||||||
## 0.20.20
|
## 0.20.20
|
||||||
|
|
||||||
* `Repos`:
|
* `Repos`:
|
||||||
|
@ -15,5 +15,5 @@ crypto_js_version=4.1.1
|
|||||||
# Project data
|
# Project data
|
||||||
|
|
||||||
group=dev.inmo
|
group=dev.inmo
|
||||||
version=0.20.20
|
version=0.20.21
|
||||||
android_code_version=226
|
android_code_version=227
|
||||||
|
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
@ -1,5 +1,5 @@
|
|||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
|
21
resources/build.gradle
Normal file
21
resources/build.gradle
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
plugins {
|
||||||
|
id "org.jetbrains.kotlin.multiplatform"
|
||||||
|
id "org.jetbrains.kotlin.plugin.serialization"
|
||||||
|
id "com.android.library"
|
||||||
|
}
|
||||||
|
|
||||||
|
apply from: "$mppJvmJsAndroidLinuxMingwLinuxArm64ProjectPresetPath"
|
||||||
|
|
||||||
|
kotlin {
|
||||||
|
sourceSets {
|
||||||
|
commonMain {
|
||||||
|
dependencies {
|
||||||
|
api project(":micro_utils.language_codes")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
androidMain {
|
||||||
|
dependsOn(jvmMain)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,21 @@
|
|||||||
|
package dev.inmo.micro_utils.strings
|
||||||
|
|
||||||
|
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) {
|
||||||
|
configuration.locales[0]
|
||||||
|
} else {
|
||||||
|
configuration.locale
|
||||||
|
}
|
||||||
|
)
|
||||||
|
fun StringResource.translation(resources: Resources): String = translation(resources.configuration)
|
||||||
|
fun StringResource.translation(context: Context): String = translation(context.resources)
|
||||||
|
|
||||||
|
fun Configuration.translation(resource: StringResource): String = resource.translation(this)
|
||||||
|
fun Resources.translation(resource: StringResource): String = configuration.translation(resource)
|
||||||
|
fun Context.translation(resource: StringResource): String = resources.translation(resource)
|
32
resources/src/commonMain/kotlin/StringResource.kt
Normal file
32
resources/src/commonMain/kotlin/StringResource.kt
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
package dev.inmo.micro_utils.strings
|
||||||
|
|
||||||
|
import dev.inmo.micro_utils.language_codes.IetfLanguageCode
|
||||||
|
|
||||||
|
class StringResource(
|
||||||
|
val default: String,
|
||||||
|
val map: Map<IetfLanguageCode, Lazy<String>>
|
||||||
|
) {
|
||||||
|
class Builder(
|
||||||
|
var default: String
|
||||||
|
) {
|
||||||
|
private val map = mutableMapOf<IetfLanguageCode, Lazy<String>>()
|
||||||
|
|
||||||
|
infix fun IetfLanguageCode.variant(value: Lazy<String>) {
|
||||||
|
map[this] = value
|
||||||
|
}
|
||||||
|
infix fun IetfLanguageCode.variant(value: String) = this variant lazyOf(value)
|
||||||
|
infix fun String.variant(value: Lazy<String>) = IetfLanguageCode(this) variant value
|
||||||
|
infix fun String.variant(value: String) = this variant lazyOf(value)
|
||||||
|
|
||||||
|
fun build() = StringResource(default, map.toMap())
|
||||||
|
}
|
||||||
|
|
||||||
|
fun translation(languageCode: IetfLanguageCode): String = (map[languageCode] ?: map[IetfLanguageCode(languageCode.withoutDialect)]) ?.value ?: default
|
||||||
|
}
|
||||||
|
|
||||||
|
inline fun buildStringResource(
|
||||||
|
default: String,
|
||||||
|
builder: StringResource.Builder.() -> Unit
|
||||||
|
): StringResource {
|
||||||
|
return StringResource.Builder(default).apply(builder).build()
|
||||||
|
}
|
10
resources/src/jvmMain/kotlin/StringResourceLocaleGetter.kt
Normal file
10
resources/src/jvmMain/kotlin/StringResourceLocaleGetter.kt
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
package dev.inmo.micro_utils.strings
|
||||||
|
|
||||||
|
import dev.inmo.micro_utils.language_codes.toIetfLanguageCode
|
||||||
|
import java.util.Locale
|
||||||
|
|
||||||
|
fun StringResource.translation(locale: Locale = Locale.getDefault()): String {
|
||||||
|
return translation(locale.toIetfLanguageCode())
|
||||||
|
}
|
||||||
|
|
||||||
|
fun Locale.translation(resource: StringResource): String = resource.translation(this)
|
@ -43,6 +43,8 @@ String[] includes = [
|
|||||||
":startup:plugin",
|
":startup:plugin",
|
||||||
":startup:launcher",
|
":startup:launcher",
|
||||||
|
|
||||||
|
":resources",
|
||||||
|
|
||||||
":fsm:common",
|
":fsm:common",
|
||||||
":fsm:repos:common",
|
":fsm:repos:common",
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user