Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
335 views
in Technique[技术] by (71.8m points)

android - Simplified and Traditional Chinese vs Regions

In the process of implementing traditional and simplified chinese support in my Android application and I confused on how this is supposed to work.

So from reading the documentation as well as some discussions like this and this I have put simplified chinese into

  • values-zh
  • values-zh-rCN
  • values-zh-rSG

and traditional chinese into

  • values-zh-rTW
  • values-zh-rHK

That all works fine but somehow does not make sense to me (sorry if I dont understand enough about chinese simplified vs traditional usage).

From what I understand from checking the locale setting dialog in the emulator as well as on a rooted phone a user can change the locale to Simplified Chinese or Traditional Chinese.

Now here is the question. How does the system know where to get the simplified or traditional chinese strings.xml. Is there some sort of assumption baked in that says if I am supposed to display simplified chinese get it from values-zh and get traditional from values-zh-rTW?

But what if a user is located in HK and set his device up to display simplified chinese? Or what if an emigrant somewhere else in the world sets his device to traditional chinese but his region is e.g. US or CA?

What do I have to do to allow my users to set their locale and have my app appear with the right locale?

Update:

From further investigation I believe that a Android phone user can not set the country separately from the language. They can only set what is called the locale in the UI. It consists of language and country, but the list is limited so many combinations are not possible.

E.g. a Chinese person living in the US that wants to use Traditional Chinese could set the language to traditional chinese (at least on a rooted phone) and would then have a locale of zh-rTW. He could in no way set his country separately to be US. In a similar manner any sort of emigrant can not set their native language with the country they currently live in..

Basically that means that only a bunch of combinations of language and country are supported. Now the questions is how to find out which ones they are?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

So I think after further investigation and with Marks answer I am going to provide an answer myself. Here is goes:

Out of the box Android only has the two locales zh_rCN, which is simplified chinese and zh_rTW, which is traditional chinese. As you can see from the Settings app these are the only supplied locales:

https://android.googlesource.com/platform/packages/apps/Settings/+/master/res/

However any other creator of an Android system e.g. for a phone sold in China or so could change what they add. The overall theoretically supported set can be found by looking at the list of locales found in the icu4c app:

https://android.googlesource.com/platform/external/icu4c.git/+/master/data/locales/ As you can see for Chinese there are

  • zh.txt
  • zh_CN.txt
  • zh_HK.txt
  • zh_Hans.txt
  • zh_Hans_CN.txt
  • zh_Hans_HK.txt
  • zh_Hans_MO.txt
  • zh_Hans_SG.txt
  • zh_Hant.txt
  • zh_Hant_HK.txt
  • zh_Hant_MO.txt
  • zh_Hant_TW.txt
  • zh_MO.txt
  • zh_SG.txt
  • zh_TW.txt

Hant is the ISO code for traditional and Hans for simplified chinese. So theoretically this would mean we could have

  • simplified chinese in China, HongKong, Macau and Singapore
  • traditional chinese in HongKong, Macau and Taiwan

However keep in mind that the Settings app would have to be modified to have the different selections of locale. So at this stage simplified chinese translates to zh_rCN and traditional zh_rTW and you should be apart for users that have such a modified Android image that supports other locales.

In any case to be on the save side you can use the Configuration class to get the locale e.g. in your Application class with getResources().getConfiguration().locale.

You could e.g. log that and send the data to your tracking system (whatever you use) or you could check for supported ones and throw an exception with the locale setting in the message and that would then show up in your market interface... it would however mean a minimum of one crash of your app (if you are on the ball you can publish and update a few minutes later ..)

So to recap .. the minimum setup would be mirroring what is done in the settings app (only have zh-rCN and zh-rTW), but if you want to provide for default locales for Singapore, HongKong, Macau supplying traditional chinese as default you can do that too and it should work. I have however no evidence that such a configuration is used anywhere..

Hope that helps.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...