2
votes

Background
We have an older webforms application, and we're not using any custom language/globalization code that I'm aware of. We're using resx files for culture specific resources. For Chinese, we currently have 4 resx files: zh, zh-cn, zh-hans, and zh-hant. I am hoping to pair down to just 2 for simplicity's sake: zh-hans and zh-hant. We don't intend to support any locale-specific variations; just generic Simplified Chinese and generic Traditional Chinese.

Question(s)

  1. My main question is this: Are there any situations where I would need to have more than zh-hans or zh-hant files for Chinese? *Outside of a need to support any locale-specific variations.

    Basically, I need to guarantee that if a user browses to our site using zh, zh-cn, zh-sg language codes, they will get resources from the zh-hans file, and if they browse using zh-tw, zh-hk, or zh-mo, they get resources from the zh-hant file. These are the only Chinese codes I know of, but if there are others, they should be included here as well - basically a Chinese speaking user with their browser set to any Chinese language, should see the appropriate Simplified or Traditional Chinese - and definitely never see English.

    So far my testing seems to indicate that yes, .NET resolves them correctly, but I want to be sure there are no hidden or rare scenarios I am missing.

  2. I am aware that the zh-hans and zh-hant codes are a little newer - and are considered "parent" cultures. I am also aware that the old generic, parent codes were zh-chs and zh-cht. Are there old browsers out there that allow these zh-chs/zh-cht codes to be selected, and if so, will .NET still resolve them appropriately?

  3. I am not entirely sure how .NET resolves the correct resource files, so if someone could point me in the right direction, such as what classes/namespaces are involved, that would also be great.


Resources
Language codes for simplified Chinese and traditional Chinese?
IETF Language Tags

1

1 Answers

2
votes

The answer was no - you can't have only zh-hans/zh-hant. Because, if you do, and you pass the base zh code with your browser, it will NOT automatically resolve to the zh-hans or zh-hant resx files.

The reason is due to something called the “Resource Fallback Process”.

Basically, .NET resolves resources through a hierarchy. It will start with the culture code requested, and if a resx for that specific culture code doesn’t exist, it will then begin to travel up the hierarchy, searching for the next culture code that does have a resx. But, it never travels down, only up.


Here is an example of the hierarchy for zh-sg [Singapore]:

  1. Invariant
  2. zh
  3. zh-Hans
  4. zh-chs (legacy generic code)
  5. zh-sg (locale-specific codes)

So first it looks for zh-sg. If there is no resource file for zh-sg, it looks for zh-chs. If there is no resource file for zh-chs, it looks for zh-Hans. And so forth.

Having just zh-Hans and zh-Hant would work for all the locale-specific codes, such as zh-sg, zh-tw, etc. Some browsers allow you to select Generic Simplified (zh-Hans) or Generic Traditional (zh-Hant), and obviously it'd work in those scenarios as well. The only scenario it wouldn't work for is when base Chinese zh was selected and passed in the request. In that scenario, if zh doesn't exist, the next place it looks is the Invariant culture - in this case, that returns English text - which is obviously not what we want.

My solution, then, was to pair down to having base zh, and zh-Hant for my 2 codes. Base zh then is my file containing Simplified text, and zh-Hant of course is my file containing Traditional text. I could've done it the other way around (made zh contain Traditional text and used zh-Hans for Simplified) but really, there are no guidelines out there I can find, about what the base zh should represent. Should it be Simplified, or should it be Traditional? I suspect it's largely a matter of preference. A quick search of several popular websites revealed that in most cases, a request for base zh produces text which Google Translate recognizes as Simplified. In a few cases it did produce Traditional. But, I went with what the majority seemed to be doing.