Skip to content

Commit 2e43d92

Browse files
authored
Merge pull request #3 from eevieapp/feature/fix-android-getLanguageTag
fix: use forLanguageTag to create new Locale
2 parents 8471852 + 583d0e6 commit 2e43d92

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

android/src/main/java/com/localizationsettings/LocalizationSettingsModule.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,12 @@ class LocalizationSettingsModule internal constructor(context: ReactApplicationC
2323
* if country is not available in locale, then use system defaults (even if it's not 100% correct, like "pl-US")
2424
**/
2525
private fun getLanguageTag(language: String): String {
26-
// if language have format language_COUNTRY, then return it
27-
if (Locale(language).country != "") return Locale(language).toLanguageTag()
26+
val locale = Locale.forLanguageTag(language);
27+
28+
// if language has format language-COUNTRY, then return it
29+
if (locale.country != "") return locale.toLanguageTag()
2830
// fallback for system country
29-
return "$language-${Locale.getDefault().country}"
31+
return Locale(locale.language, Locale.getDefault().country).toLanguageTag()
3032
}
3133

3234

0 commit comments

Comments
 (0)