Skip to content

Commit

Permalink
fix: use forLanguageTag to create new Locale
Browse files Browse the repository at this point in the history
as the public constructor accepts a language ("pl”),
not a language tag (“pl-PL”). This fixes an issue where
the country is added on every save (”pl-PL-PL-PL”).
  • Loading branch information
Peeeep committed Jun 24, 2023
1 parent 8471852 commit 583d0e6
Showing 1 changed file with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ class LocalizationSettingsModule internal constructor(context: ReactApplicationC
* if country is not available in locale, then use system defaults (even if it's not 100% correct, like "pl-US")
**/
private fun getLanguageTag(language: String): String {
// if language have format language_COUNTRY, then return it
if (Locale(language).country != "") return Locale(language).toLanguageTag()
val locale = Locale.forLanguageTag(language);

// if language has format language-COUNTRY, then return it
if (locale.country != "") return locale.toLanguageTag()
// fallback for system country
return "$language-${Locale.getDefault().country}"
return Locale(locale.language, Locale.getDefault().country).toLanguageTag()
}


Expand Down

0 comments on commit 583d0e6

Please sign in to comment.