Language switching functionality is in the opensrp-client-core library. To implement in your project, you have to ensure you have included the library.
The opensrp-client-core library has a sample of how the language switching works. Feel free to try it out first.
...
- Ensure the opensrp-client-core library is part of the project requirements
- Ensure each class in your app extends (directly or indirectly) a class in client-core. If it doesn't then extend MultiLanguageActivity instead of AppCompatActivity.
- Ensure your project does not have hard-coded strings. Put all strings in string resources.
- Ensure all the strings in string resources are translated as required in corresponding folders such as values-fr/strings.xml, values-ar/strings.xml
- To ensure activity titles are translated, set the titles programmatically e.g. setTitle(R.string.app_name);
Once a user selects a language in your project, save the language as shown below
Info icon false LangUtils.saveLanguage(getApplicationContext(), LOCALE.getLanguage());
Then refresh the current activity. See below example
Info icon false Intent intent = new Intent(MainActivity.this, MainActivity.class);
getApplicationContext().startActivity(intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK));
Related articles
Filter by label (Content by label) | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
...