This project is read-only.

Distinguish "zh-CN" and "zh-TW"

Dec 27, 2011 at 1:21 PM

I want to localize the dialog, and have a new problem now.

The Chinese language's Alpha-2 code is "zh" in ISO 639-1. In fact the Chinese language has several code in CultureInfo class,such as "zh-CN","zh-TW","zh-Hans","zh-Hant"...

I want to distinguish "zh-CN" and "zh-TW". What should I do?


Dec 27, 2011 at 3:20 PM

OK,I find a method to resolve this problem.


In LocalizationHelper.cs:

//var language = culture.TwoLetterISOLanguageName;               

var language = culture.Name;


Use the culture.Name to replace culture.TwoLetterISOLanguageName. It works,but you must change the name of the "Data.zh.xml" to "Data.zh-CN.xml" or "Data.zh-TW.xml".

Thanks.I think you can use this method to adapt more demands. 8-)

Dec 27, 2011 at 10:04 PM
Edited Dec 27, 2011 at 10:04 PM

Hi! I'm glad you found a solution that works for you. Creating a better mechanism for that is actually already on my list. The complete logic that'll be implemented shortly will be:

  • Look for the current full country/region code (for example de-DE or zh-CN etc.) - this is what you do now.
  • If no localization based on the country/region is found, look for the current language code only (e.g. de or zh) - this is how it works at the moment.
  • If no localization based on the language is found too, use the invariant culture.

The reason I want both alternatives (country/region and only language based) is that this allows you to both create a single file per language (e.g. .de) if the differences between countries are only very subtle or non-existent (de-AT, de-DE etc.), and to branch out for those cases where differentiation is required (e.g. zh-CN, zh-TW).

Thank you, and happy coding :)

Dec 28, 2011 at 1:31 AM

Thanks a lot! Look forward to your updates! 8-)

Jan 11, 2012 at 12:32 AM

Hi again. The discussed change is now part of YLAD, starting with version 1.3. I've tested it with different cultures and countries/regions, and it should work as expected. The new version is also on NuGet.

Jan 11, 2012 at 2:59 AM

Cool!  I'll try it right now. Thank you!