openfoodfacts / smooth-app

🤳🥫 The new Open Food Facts mobile application for Android and iOS, crafted with Flutter and Dart
https://world.openfoodfacts.org/open-food-facts-mobile-app?utm_source=off&utf_medium=web&utm_campaign=github-repo
Apache License 2.0
827 stars 277 forks source link

Food preferences language does not change immediately after app language change #4878

Closed teolemon closed 9 months ago

teolemon commented 10 months ago

What

monsieurtanuki commented 10 months ago

Food preferences language does not change immediately after app language change

@teolemon If you mean the following data, that's because we use the server for localized data:

[{
  "id": "not_important",
  "name": "Not important"
}, {
  "id": "important",
  "name": "Important",
  "factor": 1
}, {
  "id": "very_important",
  "name": "Very important",
  "factor": 2
}, {
  "id": "mandatory",
  "name": "Mandatory",
  "factor": 4,
  "minimum_match": 20
}]

Given the very small number of labels to localize in init_preferences_en.json (4) we could do that as "normal" .arb translations, instead of using the server for that, what do you think?

PS: the same solution may not apply regarding init_attributes_groups_en.json because there are much more items to localize (or we limit to a couple of local localizations per attribute as a fallback while downloading).

[{
  "attributes": [{
    "icon_url": "https://static.openfoodfacts.org/images/attributes/dist/nutriscore-a.svg",
    "setting_note": "The Nutri-Score is computed and can be taken into account for all products, even if is not displayed on the packaging.",
    "name": "Nutri-Score",
    "default": "very_important",
    "setting_name": "Good nutritional quality (Nutri-Score)",
    "id": "nutriscore"
  }, {

...

abdullah-khudher commented 10 months ago

@teolemon I didn't face this bug when I tried to change the language (in debug mode).

What i did: 1- Open the app. 2- Go to App settings screen. 3- Change language.

Please see the video: https://www.youtube.com/shorts/8Rj9cmulnq0

monsieurtanuki commented 9 months ago

@abdullah-khudher The call to refresh is instant anyway. But how fast will the download be? And haven't we cached the downloaded file in a previous language change?

monsieurtanuki commented 9 months ago

@teolemon There's no way we can solve this issue as is:

That said, if you want to have a better "demo" effect, we can imagine something specific (like pre-downloading specific language localizations in dev mode).

But there's something not working here; it looks like you have to close the app so that in the next restart the localizations will be downloaded (if needed) and displayed. @LuanRoger Do you feel like solving this issue?

LuanRoger commented 9 months ago

Sure! I'll investigate this later, but what I've figure out for now:

that's because we use the server for localized data.

That's made by the ProductPreferences, but he's just called once since the app started (more specifically on app_navigator), so probably, this is the only moment that the localization is pulled from the server, when the app starts.

Some possible solutions I can think for now:

monsieurtanuki commented 9 months ago

@LuanRoger Let me give you some additional info:

TL;DR It used to work, the main thing here is to call the specific localization refresh method when we change languages as an async without await.