Language Switching Implementation Guide

Language switching functionality is in the opensrp-client-core library.

The library has a sample of how the language switching works. Feel free to try it out first. 

To implement language switching in your project:-

  1. Ensure the opensrp-client-core library is part of the project requirements
  2. 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.
  3. Ensure your project does not have hard-coded strings. Put all strings in string resources. 
  4. Ensure all the strings in string resources are translated as required in corresponding folders such as values-fr/strings.xml, values-ar/strings.xml
  5. To ensure activity titles are translated, set the titles programmatically e.g. setTitle(R.string.app_name);
  6. Once a user selects a language in your project, save the language as shown below

    LangUtils.saveLanguage(getApplicationContext(), LOCALE.getLanguage());

    Then refresh the current activity. See below example

    Intent intent = new Intent(MainActivity.this, MainActivity.class);
    getApplicationContext().startActivity(intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK));