Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: changing the OS locale doesn't change the app locale #4323

Merged
merged 3 commits into from Oct 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -310,13 +310,16 @@ class ProductEditNutritionFactsFragment : ProductEditFragment() {
getModifierIndex(nutriments[nutriment]?.modifier)

private fun updateServingSize(servingSize: String) {
try {
val (value, unit) = parseServing(servingSize)

val (value, unit) = parseServing(servingSize)

binding.servingSize.setText(value)
binding.servingSize.setText(value)

if (unit != null) {
binding.servingSize.unitSpinner?.setSelection(getServingUnitIndex(unit))
if (unit != null) {
binding.servingSize.unitSpinner?.setSelection(getServingUnitIndex(unit))
}
} catch (exception : IllegalArgumentException) {
binding.servingSize.setText("")
}
}

Expand Down
Expand Up @@ -40,12 +40,14 @@ class LocaleManager @Inject constructor(
private var currentLocale: Locale

init {
currentLocale = getLanguageFromPrefs()?.let {
LocaleUtils.parseLocale(it)
} ?: Locale.getDefault()
currentLocale = reloadLocale()
}

fun restoreLocalizedContext(context: Context) = changeAppLanguage(context, currentLocale)
fun restoreLocalizedContext(context: Context): Context = changeAppLanguage(context, reloadLocale())

private fun reloadLocale() = getLanguageFromPrefs()?.let {
LocaleUtils.parseLocale(it)
} ?: Locale.getDefault()

/**
* Get the language of the app [Locale] (Selected in settings).
Expand Down