mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2025-12-17 03:35:52 +00:00
Compare commits
6 Commits
0.26.5
...
fce47897d5
| Author | SHA1 | Date | |
|---|---|---|---|
| fce47897d5 | |||
| 0b701a3e99 | |||
| 9dad353957 | |||
| 89e16b7bdb | |||
| c2965da341 | |||
| ffb072dc5f |
@@ -1,5 +1,13 @@
|
||||
# Changelog
|
||||
|
||||
## 0.26.7
|
||||
|
||||
## 0.26.6
|
||||
|
||||
* `Versions`:
|
||||
* `Ktor`: `3.3.0` -> `3.3.1`
|
||||
* `Okio`: `3.16.0` -> `3.16.2`
|
||||
|
||||
## 0.26.5
|
||||
|
||||
* `Versions`:
|
||||
|
||||
@@ -18,5 +18,5 @@ crypto_js_version=4.1.1
|
||||
# Project data
|
||||
|
||||
group=dev.inmo
|
||||
version=0.26.5
|
||||
android_code_version=304
|
||||
version=0.26.7
|
||||
android_code_version=306
|
||||
|
||||
@@ -10,7 +10,7 @@ kslog = "1.5.1"
|
||||
|
||||
jb-compose = "1.8.2"
|
||||
jb-exposed = "0.61.0"
|
||||
jb-dokka = "2.0.0"
|
||||
jb-dokka = "2.1.0"
|
||||
|
||||
# 3.50.3.0 contains bug https://github.com/InsanusMokrassar/MicroUtils/actions/runs/18138301958/job/51629588088
|
||||
sqlite = "3.50.1.0"
|
||||
@@ -18,13 +18,13 @@ sqlite = "3.50.1.0"
|
||||
korlibs = "5.4.0"
|
||||
uuid = "0.8.4"
|
||||
|
||||
ktor = "3.3.0"
|
||||
ktor = "3.3.1"
|
||||
|
||||
gh-release = "2.5.2"
|
||||
|
||||
koin = "4.1.1"
|
||||
|
||||
okio = "3.16.0"
|
||||
okio = "3.16.2"
|
||||
|
||||
ksp = "2.2.20-2.0.3"
|
||||
kotlin-poet = "2.2.0"
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
package dev.inmo.micro_utils.language_codes
|
||||
|
||||
expect val currentIetfLang: IetfLang?
|
||||
6
language_codes/src/jsMain/kotlin/CurrentIetfLang.js.kt
Normal file
6
language_codes/src/jsMain/kotlin/CurrentIetfLang.js.kt
Normal file
@@ -0,0 +1,6 @@
|
||||
package dev.inmo.micro_utils.language_codes
|
||||
|
||||
import kotlinx.browser.window
|
||||
|
||||
actual val currentIetfLang: IetfLang?
|
||||
get() = window.navigator.language.unsafeCast<String?>() ?.let { IetfLang(it) }
|
||||
6
language_codes/src/jvmMain/kotlin/CurrentIetfLang.jvm.kt
Normal file
6
language_codes/src/jvmMain/kotlin/CurrentIetfLang.jvm.kt
Normal file
@@ -0,0 +1,6 @@
|
||||
package dev.inmo.micro_utils.language_codes
|
||||
|
||||
import java.util.Locale
|
||||
|
||||
actual val currentIetfLang: IetfLang?
|
||||
get() = Locale.getDefault() ?.toIetfLang()
|
||||
@@ -0,0 +1,27 @@
|
||||
package dev.inmo.micro_utils.language_codes
|
||||
|
||||
import dev.inmo.micro_utils.language_codes.IetfLang
|
||||
import kotlinx.cinterop.ExperimentalForeignApi
|
||||
import kotlinx.cinterop.allocArray
|
||||
import kotlinx.cinterop.memScoped
|
||||
import kotlinx.cinterop.toKString
|
||||
import platform.posix.getenv
|
||||
import platform.windows.GetUserDefaultLocaleName
|
||||
import platform.windows.LOCALE_NAME_MAX_LENGTH
|
||||
import platform.windows.WCHARVar
|
||||
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
actual val currentIetfLang: IetfLang?
|
||||
get() {
|
||||
val rawLocale = memScoped {
|
||||
val buffer = allocArray<WCHARVar>(LOCALE_NAME_MAX_LENGTH)
|
||||
val result = GetUserDefaultLocaleName(buffer, LOCALE_NAME_MAX_LENGTH)
|
||||
|
||||
if (result > 0) {
|
||||
// Convert WCHAR* to String
|
||||
buffer.toKString()
|
||||
}
|
||||
"en-US" // fallback
|
||||
}
|
||||
return IetfLang(rawLocale)
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package dev.inmo.micro_utils.language_codes
|
||||
|
||||
import kotlinx.cinterop.ExperimentalForeignApi
|
||||
import kotlinx.cinterop.toKString
|
||||
import platform.posix.getenv
|
||||
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
actual val currentIetfLang: IetfLang?
|
||||
get() {
|
||||
val localeStr = getenv("LANG") ?.toKString() ?.replace("_", "-") ?: "en-US"
|
||||
return IetfLang(localeStr)
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package dev.inmo.micro_utils.language_codes
|
||||
|
||||
external interface Navigator {
|
||||
val language: String
|
||||
}
|
||||
|
||||
external val navigator: Navigator
|
||||
|
||||
actual val currentIetfLang: IetfLang?
|
||||
get() = IetfLang(navigator.language)
|
||||
20
resources/compose/build.gradle
Normal file
20
resources/compose/build.gradle
Normal file
@@ -0,0 +1,20 @@
|
||||
plugins {
|
||||
id "org.jetbrains.kotlin.multiplatform"
|
||||
id "org.jetbrains.kotlin.plugin.serialization"
|
||||
id "com.android.library"
|
||||
alias(libs.plugins.jb.compose)
|
||||
alias(libs.plugins.kt.jb.compose)
|
||||
}
|
||||
|
||||
apply from: "$mppComposeJvmJsWasmJsAndroidLinuxMingwLinuxArm64Project"
|
||||
|
||||
kotlin {
|
||||
sourceSets {
|
||||
commonMain {
|
||||
dependencies {
|
||||
api libs.kt.coroutines
|
||||
api project(":micro_utils.resources")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package dev.inmo.micro_utils.resources.compose
|
||||
|
||||
import android.os.Build
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.platform.LocalConfiguration
|
||||
import dev.inmo.micro_utils.language_codes.IetfLang
|
||||
import dev.inmo.micro_utils.language_codes.toIetfLang
|
||||
|
||||
@Composable
|
||||
actual fun getCurrentLocale(): IetfLang? {
|
||||
val configuration = LocalConfiguration.current
|
||||
|
||||
val locale = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||
if (configuration.locales.isEmpty) {
|
||||
return null
|
||||
}
|
||||
configuration.locales.get(0)
|
||||
} else {
|
||||
@Suppress("DEPRECATION")
|
||||
configuration.locale
|
||||
}
|
||||
|
||||
return locale.toIetfLang()
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package dev.inmo.micro_utils.resources.compose
|
||||
|
||||
import androidx.compose.runtime.Composable
|
||||
import dev.inmo.micro_utils.language_codes.IetfLang
|
||||
|
||||
@Composable
|
||||
expect fun getCurrentLocale(): IetfLang?
|
||||
@@ -0,0 +1,10 @@
|
||||
package dev.inmo.micro_utils.resources.compose
|
||||
|
||||
import androidx.compose.runtime.Composable
|
||||
import dev.inmo.micro_utils.strings.StringResource
|
||||
|
||||
@Suppress("unused")
|
||||
@Composable
|
||||
fun StringResource.composeTranslation(): String {
|
||||
return translation(getCurrentLocale())
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package dev.inmo.micro_utils.resources.compose
|
||||
|
||||
import dev.inmo.micro_utils.language_codes.IetfLang
|
||||
import dev.inmo.micro_utils.language_codes.currentIetfLang
|
||||
|
||||
@androidx.compose.runtime.Composable
|
||||
actual fun getCurrentLocale(): IetfLang? {
|
||||
return currentIetfLang
|
||||
}
|
||||
10
resources/compose/src/jvmMain/kotlin/GetCurrentLocale.jvm.kt
Normal file
10
resources/compose/src/jvmMain/kotlin/GetCurrentLocale.jvm.kt
Normal file
@@ -0,0 +1,10 @@
|
||||
package dev.inmo.micro_utils.resources.compose
|
||||
|
||||
import androidx.compose.ui.text.intl.Locale
|
||||
import dev.inmo.micro_utils.language_codes.IetfLang
|
||||
import dev.inmo.micro_utils.language_codes.currentIetfLang
|
||||
|
||||
@androidx.compose.runtime.Composable
|
||||
actual fun getCurrentLocale(): IetfLang? {
|
||||
return currentIetfLang
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package dev.inmo.micro_utils.resources.compose
|
||||
|
||||
import dev.inmo.micro_utils.language_codes.IetfLang
|
||||
import dev.inmo.micro_utils.language_codes.currentIetfLang
|
||||
|
||||
@androidx.compose.runtime.Composable
|
||||
actual fun getCurrentLocale(): IetfLang? {
|
||||
return currentIetfLang
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package dev.inmo.micro_utils.resources.compose
|
||||
|
||||
import dev.inmo.micro_utils.language_codes.IetfLang
|
||||
import dev.inmo.micro_utils.language_codes.currentIetfLang
|
||||
|
||||
@androidx.compose.runtime.Composable
|
||||
actual fun getCurrentLocale(): IetfLang? {
|
||||
return currentIetfLang
|
||||
}
|
||||
@@ -50,6 +50,7 @@ String[] includes = [
|
||||
":colors:common",
|
||||
|
||||
":resources",
|
||||
":resources:compose",
|
||||
|
||||
":fsm:common",
|
||||
":fsm:repos:common",
|
||||
|
||||
Reference in New Issue
Block a user