0
votes

I am developing application that supports three languages

  1. English
  2. Simplified Chinese
  3. Traditional Chinese

    for that i have created two extra folders inside the res folder:

    • values-zh-rCH (for simplified Chinese)
    • values-zh-rTW (for traditional Chinese)
    • be default is values for English Language

I am using below function to change the languages `

    public void setLocale(String lang) {
       Locale myLocale = new Locale(lang);

       Resources res = getResources();

        DisplayMetrics dm = res.getDisplayMetrics();

       Configuration conf = res.getConfiguration();

        conf.locale = myLocale;

        res.updateConfiguration(conf, dm);

        Intent refresh = new Intent(this, StartMenuActivity.class);

       finish();

       startActivity(refresh);`

    }

and i am passing below values to the function

  • en
  • zh_CN
  • zh_TW

i have also tried below values

  • en
  • zh_rCN
  • zh_rTW

but its not working. what is the issue ? can anyone please suggest me ?

For testing purpose, I have created values-zh folder and passed zh to setLocale in that case language is being changed.

what this is not working with traditional and simplified Chinese?

1
Any solutions you got for this issue?, I too facing the same issue? - Brjv
@Brjv, Please see the answer below, i have just posted an answer. Please vote up question and answer. if it helps you out. thanks! - Abdul Aleem

1 Answers

4
votes

You can use below piece of code to solve your problem

 public void setLocale(String lang) {
    Locale myLocale;
    if (lang.equals("zh_CN")) {
        myLocale = Locale.SIMPLIFIED_CHINESE;
    } else if (lang.equals("zh_TW")) {
        myLocale = Locale.TRADITIONAL_CHINESE;
    } else {
        myLocale = new Locale(lang);
    }

    Locale.setDefault(myLocale);
    Resources res = getResources();
    DisplayMetrics dm = res.getDisplayMetrics();
    Configuration conf = res.getConfiguration();
    conf.locale = myLocale;
    res.updateConfiguration(conf, dm);
}