Reputation: 41
I have put simplified Chinese in values-zh-rCN , zh and traditional Chinese in values-zh-rTW. But on changing locale it always load strings from zH. Here is how i am changing Locale.
public void setLanguage(String languageCode, String countryCode){
Locale locale = new Locale(languageCode, countryCode);
Locale.setDefault(locale);
Configuration config = getResources().getConfiguration();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
setSystemLocale(config, locale);
} else {
setSystemLocaleLegacy(config, locale);
}
BaseSharedPreference.getInstance().setLanguage(locale.getLanguage());
recreate();
}
Upvotes: 2
Views: 4660
Reputation: 323
In Android 7 many new locales are supported by default. It can be tricky to support both old locales and new locales correctly in some cases; here I will discuss one I happen to be aware of: Chinese.
Basic background:
Chinese is written in two different scripts: Simplified and Traditional Each Chinese-speaking region generally uses just one script While ideally one would localize for each region, we will assume here that we have just one resource set for each script.
Prior to Android 7, the following Chinese locales were available:
zh-CN (Simplified)
zh-TW (Traditional)
In some cases:
zh-SG (Simplified)
zh-HK (Traditional)
zh-MO (Traditional)
A common resource layout scheme to support the above locales while minimizing resource duplication would be:
values-zh: Traditional
values-zh-rCN: Simplified
values-zh-rSG: Simplified
In other words Traditional resources are put at the root, and zh-TW, zh-HK, and zh-MO are covered by fallback.
In Android 7, the older language-region locales are gone, replaced by the following:
zh-Hans-CN
zh-Hans-MO
zh-Hans-HK
zh-Hans-SG
zh-Hant-TW
zh-Hant-HK
zh-Hant-MO
Note:
The script and region are specified separately There are now default locales specifying Simplified script in traditionally Traditional regions: zh-Hans-MO and zh-Hans-HK. Problems using the old scheme in Android 7:
Thus the minimal correct resource layout is now:
values-zh: Simplified
values-zh-rTW: Traditional
values-zh-rHK: Traditional
values-zh-rMO: Traditional
values-b+zh+Hans+HK: Simplified
values-b+zh+Hans+MO: Simplified
With this we get the desired behavior:
On Android 6 and earlier:
On Android 7:
You can see detail from this post Link
Upvotes: 7