Skip to content
This repository was archived by the owner on Nov 1, 2021. It is now read-only.

Commit 9a7e371

Browse files
author
neon
committed
style: localize style fix
1 parent 82ca900 commit 9a7e371

File tree

1 file changed

+12
-7
lines changed
  • app-core/src/main/java/com/codee/app/core/extensions

1 file changed

+12
-7
lines changed

app-core/src/main/java/com/codee/app/core/extensions/Localized.kt

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,17 @@ import com.codee.app.resources.locale.Localized
66
import com.codee.app.resources.locale.get
77

88
fun <T> Localized<T>.localize(): T {
9-
val locale = ConfigurationCompat.getLocales(context.resources.configuration)[0]
9+
val locale = ConfigurationCompat
10+
.getLocales(context.resources.configuration)[0]
1011
.toCodeeLocale()
11-
val vars = variants.toList()
12-
return if(vars.any { it.first.languageCode == locale.languageCode }) {
13-
if(vars.any { it.first.countryCode == locale.countryCode })
14-
vars.first { it.first == locale }.second
15-
vars.first { it.first.languageCode == locale.languageCode }.second
16-
} else default
12+
13+
val variants = variants.toList()
14+
15+
val withLanguageCode = variants
16+
.filter { (k) -> k.languageCode == locale.languageCode }
17+
18+
val withCountryCode = withLanguageCode
19+
.firstOrNull { (k) -> k.countryCode == locale.countryCode }
20+
21+
return (withCountryCode ?: withLanguageCode.firstOrNull())?.second ?: default
1722
}

0 commit comments

Comments
 (0)