This repository was archived by the owner on Nov 1, 2021. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +12
-7
lines changed
app-core/src/main/java/com/codee/app/core/extensions Expand file tree Collapse file tree 1 file changed +12
-7
lines changed Original file line number Diff line number Diff line change @@ -6,12 +6,17 @@ import com.codee.app.resources.locale.Localized
6
6
import com.codee.app.resources.locale.get
7
7
8
8
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 ]
10
11
.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
17
22
}
You can’t perform that action at this time.
0 commit comments