简体中文与繁体中文对地域

在我的 Android 应用程序中实现传统和简体中文支持的过程中,我对这个应该如何工作感到困惑。

因此,从阅读 < a href = “ http://developer.android.com/resources/Tutorials/location/index.html”rel = “ norefrer”> 文档中可以看出 以及一些像 这个这个这样的讨论,我已经投入了简体中文

  • 值 -zh
  • Value-zh-rCN
  • 值 -zh-rSG

中国传统文化

  • 值 -zh-rTW
  • Value-zh-rHK

这一切工作正常,但不知何故没有意义对我来说(抱歉,如果我不理解足够的中国简体与传统用法)。

根据我在模拟器和植入式手机上检查区域设置对话框的理解,用户可以将区域设置更改为简体中文或繁体中文。

现在问题来了。系统如何知道从哪里获得简化的或传统的中文 strings.xml。是否存在某种假设,假设我应该显示简体中文,从值 zh 中得到它,从值 zh-rtW 中得到传统值?

但是,如果用户位于香港,并将他的设备设置为显示简体中文,该怎么办呢?或者,如果一个移民在世界其他地方设置他的设备传统中文,但他的地区是如美国或加利福尼亚州?

我需要做些什么来允许我的用户设置他们的语言环境,并让我的应用程序以正确的语言环境出现?

更新:

根据进一步的调查,我认为 Android 手机用户不能将国家与语言分开。它们只能在 UI 中设置所谓的区域设置。它由语言和国家组成,但列表是有限的,因此许多组合是不可能的。

例如,一个生活在美国的中国人如果想使用繁体中文,可以将该语言设置为繁体中文(至少在一个固定的电话上) ,然后就会有一个 zh-rTW 的地区。他决不能把自己的国家单独设定为国家。以同样的方式,任何移民都不能将他们的母语与他们目前居住的国家联系起来。.

基本上,这意味着只支持一系列语言和国家的组合。现在的问题是如何找出它们是哪些?

60409 次浏览

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.

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.

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 +

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