Simplified and Traditional Chinese vs Regions
Asked Answered
C

4

78

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?

Charnel answered 15/11, 2010 at 23:29 Comment(1)
I know I could try to figure this out by reading the source .. and I probably will if nobody helps me out..Charnel
C
60

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..

Charnel answered 22/11, 2010 at 21:7 Comment(6)
Since Android 7.0, if a user select zh-rSG, it will look for zh-rSG, if it can't find it, it will instead look for zh-rCN or any other locale with the simplified script. – The same goes if a user select sv-rFI, it will look for, in order: sv-rFI, sv, sv-rSEJosphinejoss
The current repository does provide values-zh-rHK.Ossifrage
values-zh-rCN will not compile. It says invalid resource directory name.Mayenne
values-zh is simplified and values-zh-rTW is traditional or what?Schecter
should I add values-zh-rCN if I already put simplified Chinese to just values-zh?Schecter
or should we put simplified to values-zh but traditional to both values-zh-rCN and values-zh-rTW?Schecter
S
11

Updated answer

The question and previous answers are pretty old. It is hard to tell how correct they still are. This answer is for other people coming here who just want to support both Traditional and Simplified Chinese in their app, but are not overly concerned about the details of locality.

Add string.xml files for Traditional and Simplified Chinese

In Android Studio right click the res folder and choose New > Android resource file. Type in strings for the File name and choose Locale from the list.

enter image description here

Scroll down to zh for the language. Add one strings file for CN: China (simplified) and one for TW: Taiwan (traditional). If you are only using one then just choose Any Region.

As I understand the documentation, lookup will first check if there is an exact match for language and region (Example: Chinese-Traditional-Taiwan). Then it will fall back to broader checks. (This system is as of Android 7.0.)

1. zh-Hant-TW   // Chinese - Traditional - Taiwan
2. zh-Hant      // Chinese - Traditional
3. zh           // Chinese

I'm not completely sure about how all this works so please read this and this documentation.

Following this method in my own app, switching the system settings between Traditional and Simplified changed the app display also.

Converting between Traditional and Simplified

If you already have one translation in either Traditional or Simplified, you can auto convert the text online. Start with Google Translate to convert to the other (just paste in your strings.xml file). It does a fairly good job already. Then do it again several times using one of the many online converters. Use a text comparing tool or site (text-compare.com is good) to compare the result of the conversions. That will help you catch any mistakes that Google made.

Stubbs answered 23/11, 2017 at 5:50 Comment(4)
zh-Hant-TW zh-Hant what is that? there are values-zh-rCN and values-zh-rTWSchecter
should I add values-zh-rCN if I already put simplified Chinese to just values-zh? or should we put simplified to values-zh but traditional to both values-zh-rCN and values-zh-rTW?Schecter
@user924, It's been a while since I've done this so I don't know if there have been some updates to the naming. However, assuming the names you have are correct, then I don't think you need to specify values-zh-rCN if you already set the default to simplified with values-zh. Definitely don't set values-zh-rCN to traditional since CN means mainland China and they use simplified characters there.Stubbs
Test all of this by changing the system language (and locale to if that's possible) in your device settings to make sure that it updates your app language correctly.Stubbs
S
9

https://developer.android.com/guide/topics/resources/providing-resources.html#AlternativeResources

Android 7.0 (API level 24) introduced support for BCP 47 language tags, which you can use to qualify language- and region-specific resources. A language tag is composed from a sequence of one or more subtags, each of which refines or narrows the range of language identified by the overall tag.

you can now define traditional or simplified using the BCP 47 tags. (To use a BCP 47 language tag, concatenate b+ and a two-letter ISO 639-1 language code, optionally followed by additional subtags separated by +.)

more specifically: -

Simplified:

values-b+zh (defaults to simplified) 
values-b+zh+Hans or
values-b+zh+Hans+CN (if you want to include regions)

Traditional:

values-b+zh+Hant or
values-b+zh+TW (defaults to traditional)
values-b+zh+Hant+TW (if you want to include regions)

you can look at https://tools.ietf.org/html/bcp47 for other interesting combinations. including: -

  zh-cmn-Hans-CN (Chinese, Mandarin, Simplified script, as used in
  China)

  cmn-Hans-CN (Mandarin Chinese, Simplified script, as used in
  China)

  zh-yue-HK (Chinese, Cantonese, as used in Hong Kong SAR)

  yue-HK (Cantonese Chinese, as used in Hong Kong SAR)

  zh-nan-TW (min nan Chinese, as used in Taiwan)

  zh-hak-CN (Chinese, Hakka, China).

remember to add -b and replace the - in each tag with +

Senzer answered 12/4, 2019 at 2:56 Comment(1)
This should be the correct answer, especially when you want to provide only 2 translations: Hans and Hant for all regions. Hans is used in Mainland China and Singapore, and Hant is used in Hong Kong and Taiwan. And if you want to provide audio content through text to speech, the 2nd part of this answer may be good.Deportment
S
1

I have created this table, hope it helps someone.

CODE LANG FORM REGION
zh Chinese - -
zh_Hans Chinese Han Simplified -
zh_Hans_CN Chinese Han Simplified China
zh_Hans_HK Chinese Han Simplified Hong Kong SAR China
zh_Hans_MO Chinese Han Simplified Macau SAR China
zh_Hans_SG Chinese Han Simplified Singapore
zh_Hant Chinese Han Traditional -
zh_Hant_HK Chinese Han Traditional Hong Kong SAR China
zh_Hant_MO Chinese Han Traditional Macau SAR China
zh_Hant_TW Chinese Han Traditional Taiwan
Severable answered 20/2, 2022 at 20:47 Comment(1)
those codes are not for Android strings.xml locale....Schecter

© 2022 - 2024 — McMap. All rights reserved.