سؤال

My app has been translated to a number of languages, including French, Traditional Chinese, and Simplified Chinese. Now, when the app first launches, I'd like to automatically select the correct translation based on the user locale.

For French, evaluating the TwoLettersIsoLanguageName property of the InstalledUiCulture worked well, but for Chinese ISO codes are not sufficient. I thought of resorting to the Name property, which separates zh-Hans and zh-Hant, but that breaks French, since it gives fr-FR on certain systems, and fr-CA on others, for example.

Is there a simple way to get the current culture's two-letter language code if it's not chinese, and otherwise get zh-Hans/zh-Hant?

I'm searching for an elegant solution ; I've of course thought of parsing the culture's Name property and making a special case for chinese, but that's not really pretty :/

In short, I think I'm searching for a way to retrieve a "neutral" culture from the current culture: from fr-Fr get fr, from zh-TW get zh-Hant, and from zh-CN get zh-Hans. Ideas?

Thanks!

هل كانت مفيدة؟

المحلول

It seems that Parent property of CultureInfo class is what you are looking for.
It seems it was supported from the very beginning.

BTW. In case of translations, you should use CurrentUICulture rather than CurrentCulture (the latter is meant for formatting) or InstalledUiCulture, which is Operating System language version and not necessary user preference.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top