Supporting Chinese localization in UWP apps

Xamarin WinUI

5 years ago

I have recently come across this challenging question on Stack Overflow. The OP, my friend Touseef, tried to add Chinese translation to his UWP app via a RESW file but unfortunately failed. The system didn't even recognize the app as supporting Chinese culture and even the built-in texts like Settings in the NavigationView stayed in English even when the rest of UWP apps displayed in Chinese and the primary language was set accordingly.

Language settings

Language settings
On the surface, the setup looked perfectly valid. He properly set up a `Strings` folder in the root of his UWP project and created subfolders for each supported language using the language-neutral two-letter code, *en* for English, *es* for Spanish and *zh* for Chinese. Here is a screenshot of the folder structure:

Resource files

Resource files

Even weirder, the other languages worked as expected - both English and Spanish. After quite some time of investigation, I stumbled across the following in the CultureInfo class documentation:

A neutral culture is specified by only the two-letter lowercase language code. For example, fr specifies the neutral culture for French, and de specifies the neutral culture for German.

There are two culture names that contradict this rule. The cultures Chinese (Simplified), named zh-Hans, and Chinese (Traditional), named zh-Hant, are neutral cultures. The culture names represent the current standard and should be used unless you have a reason for using the older names zh-CHS and zh-CHT.

The very important takeaway from this note is that zh is by itself not sufficient as a neutral language code. Instead you must name the folder either zh-Hans for Chinese simplified or zh-Hant for Chinese traditional. The choice really depends on how your resources are translated, but you need to be specific in this distinction as zh on its own is not enough.

This resolved the problem and app now was properly showing the Chinese resources. Mission accomplished!