mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2024-11-18 14:23:50 +00:00
improvements in resources
This commit is contained in:
parent
cc623b1097
commit
805ab32b24
@ -2,6 +2,10 @@
|
||||
|
||||
## 0.20.26
|
||||
|
||||
* `Resources`:
|
||||
* Add opportunity to get default translation by passing `null` as `IetfLang` argument
|
||||
* Add several useful extensions to get translations in `JS` target
|
||||
|
||||
## 0.20.25
|
||||
|
||||
* `Colors`:
|
||||
|
@ -39,7 +39,10 @@ class StringResource(
|
||||
fun build() = StringResource(default, map.toMap())
|
||||
}
|
||||
|
||||
fun translation(languageCode: IetfLang): String {
|
||||
fun translation(languageCode: IetfLang?): String {
|
||||
if (languageCode == null) {
|
||||
return default
|
||||
}
|
||||
map[languageCode] ?.let { return it.value }
|
||||
|
||||
return languageCode.parentLang ?.let {
|
||||
|
11
resources/src/jsMain/kotlin/StringResourceExtensions.kt
Normal file
11
resources/src/jsMain/kotlin/StringResourceExtensions.kt
Normal file
@ -0,0 +1,11 @@
|
||||
package dev.inmo.micro_utils.strings
|
||||
|
||||
import dev.inmo.micro_utils.language_codes.IetfLang
|
||||
import kotlinx.browser.window
|
||||
import org.w3c.dom.NavigatorLanguage
|
||||
|
||||
fun StringResource.translation(language: NavigatorLanguage) = translation(
|
||||
language.language.unsafeCast<String?>() ?.let { IetfLang(it) }
|
||||
)
|
||||
|
||||
fun StringResource.translation() = translation(window.navigator)
|
Loading…
Reference in New Issue
Block a user