improvements in resources

This commit is contained in:
InsanusMokrassar 2024-01-11 23:01:10 +06:00
parent cc623b1097
commit 805ab32b24
3 changed files with 19 additions and 1 deletions

View File

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

View File

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

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