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

[Enhancement] Set the locale based on user, system, and config settings #3645

Open
2 tasks
f-odhiambo opened this issue Dec 4, 2024 · 10 comments
Open
2 tasks

Comments

@f-odhiambo
Copy link
Contributor

f-odhiambo commented Dec 4, 2024

This enhancement uses the device settings to set the locale and language, and provides consistent prioritization for how to choose locales when a particular locale is not supported in the app.

  • Add the "default_locale" key to the app config.
    • The value must be a member of list that is the value for the "languages" key in the app config, e.g.
----
  "languages": [
    "es","en"
  ],
  "default_locale": "es",
----
  • Choose the language of the app based on the follow priority:
    1. If the user has stored a locale in the app settings or in their remote user profile, AND that locale is available in the app locales, use this locale
    2. If we are able to read the device default locale, AND that locale is available in the app locales, use this locale
    3. If the "default_locale" is set in the app config AND that locale is available in the app locales, use this locale
    4. Choose the locale that appears first in the list of "languages" in the app config
@f-odhiambo
Copy link
Contributor Author

@ndegwamartin please advise

@ndegwamartin
Copy link
Contributor

We could also introduce a new config entry for default language and have the users configure with that. That way we still have the flexibility for the list of languages e.g. how they are ordered in the context of a UX. e.g.

{
   "default_language": "en"
}

or

{
   "lang": "en"
}

@pld
Copy link
Member

pld commented Dec 6, 2024

Yea I think the more explicit "default_language" is the better approach. If none is specified we it seems reasonable that the expected behavior is to choose the first language from the list, since we have to choose something and we do not want the choice to be arbitrary.

@pld
Copy link
Member

pld commented Dec 6, 2024

On the other hand, what do we do if the config sets the default language to "es", but the device settings have the default language as "en". It seems odd to override the default device settings.

Asked another way, is the default setting here only used if the device doesn't have it's own default? Or if the device default isn't supported in the app? That's seems reasonable.

@f-odhiambo f-odhiambo changed the title [Enhancement] Make the default language the first ISO in the Application Config [Enhancement] Make the default language the first ISO code in the Application Config Dec 6, 2024
@ndegwamartin
Copy link
Contributor

We've previously (v1) overridden device settings with the app settings buy using the Language switcher

On the other hand, what do we do if the config sets the default language to "es", but the device settings have the default language as "en". It seems odd to override the default device settings.

Asked another way, is the default setting here only used if the device doesn't have it's own default? Or if the device default isn't supported in the app? That's seems reasonable.

@f-odhiambo
Copy link
Contributor Author

f-odhiambo commented Dec 9, 2024

Assuming we have the following scenario

App Config

  "languages": [
    "en",
    "id"
  ],
  ---
  "default_language": "id",
  ----

Questionnaire

    {
   "system": "urn:oid:2.16.578.1.12.4.1.1.8655",
   "display": "eCBIS Child Immunization",
   "_display": {
      "extension": [
         {
            "url": "http://hl7.org/fhir/StructureDefinition/translation",
            "extension": [
               {
                  "url": "lang",
                  "valueCode": "id"
               },
               {
                  "url": "content",
                  "valueString": "Imunisasi anak eCBIS"
               }
            ]
         }
      ]
   }
}
  1. User-Specified Language in App Configuration
  • Check if the app configuration explicitly specifies a preferred language for the user. This might be stored in the app’s local settings or a user profile.
  1. Available Languages in App Config
  • Verify if the languages array in the app config contains the language.
  • If the user’s preferred language is supported (languages contain it), use it. This will also assume that we order the ISO config maybe
  "languages": [
    "en",
    "id"
  ],
  ---
  1. Device Language
  • Retrieve the device’s current language setting (e.g., from Android’s locale).
  • If the device language matches one of the languages in the app config, set this as default.
  1. Fallback to Default Language in App Config
  • If none of the above criteria are met, use the first language in the languages array as the default (usually assumed to be the app’s primary language, e.g., "en").

@pld
Copy link
Member

pld commented Dec 9, 2024

I want to slightly clarify this.

In (2) this is checking if the user has already set their language manually, NOT if the app config has a default_language

in (4) it first checks for a default_language, and choose that if it exists, if not it goes by the ordering in the "languages" array

is that clear?

@f-odhiambo
Copy link
Contributor Author

Hey @pld for 4 is clear for 2

When you first install the app the user has not chosen anything. So if you have

  "languages": [
    "en",
    "id"
  ],
  ---

English should be the language else If you have

  "languages": [
  "id",
  "en"
],
---

Bahasa should be the language of choice

On resume app, we pick what the user has now selected manually in case a change was done

@pld
Copy link
Member

pld commented Dec 10, 2024

In most cases, we'll expect the user to never choose anything, if they haven't and if their device settings are set to "en" it'll load "en", if they're set to "id" it'll load "id". Otherwise, we'll check for "default_locale" in the config, and choose that, if that doesn't exist then we'll go w/what you've described

@pld pld changed the title [Enhancement] Make the default language the first ISO code in the Application Config [Enhancement] Set the language based on user, system, and config settings Dec 10, 2024
@pld pld changed the title [Enhancement] Set the language based on user, system, and config settings [Enhancement] Set the locale based on user, system, and config settings Dec 10, 2024
@pld
Copy link
Member

pld commented Dec 10, 2024

@f-odhiambo I've update the issue to reflect the above comments, let me know if there is anything that is still unclear, thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants