0

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?

2
  • Any solutions you got for this issue?, I too facing the same issue?
    – Brjv
    Jul 4, 2016 at 17:06
  • @Brjv, Please see the answer below, i have just posted an answer. Please vote up question and answer. if it helps you out. thanks! Jul 5, 2016 at 3:51

1 Answer 1

4

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);
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.