C#中如何区分简体中文和繁体中文?
我的应用程序已被翻译成多种语言,包括法语、繁体中文和简体中文。现在,当应用程序首次启动时,我想根据用户区域设置自动选择正确的翻译。
对于法语,评估 InstalledUiCulture
的 TwoLettersIsoLanguageName
属性效果很好,但对于中文 ISO 代码还不够。我想过求助于 Name
属性,它将 zh-Hans
和 zh-Hant
分开,但这会破坏法语,因为它给出了fr-FR,在其他系统上则为
fr-CA
。
有没有一种简单的方法可以获取当前文化的两个字母语言代码(如果它不是中文),否则获取 zh-Hans
/zh-Hant
?
我正在寻找一个优雅的解决方案;我当然考虑过解析文化的 Name
属性并为中文制作一个特例,但这并不是很漂亮:/
简而言之,我想我正在寻找一种方法从当前区域性中检索“中性”区域性:从 fr-Fr
获取 fr
,从 zh-TW
获取 zh-Hant
,以及来自zh-CN
获取 zh-Hans
。有想法吗?
谢谢!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
似乎 Parent 属性 CultureInfo 类就是您要寻找的。
看来从一开始就支持了。
顺便提一句。如果需要翻译,您应该使用 CurrentUICulture而不是 CurrentCulture (后者用于格式化)或InstalledUiCulture,这是操作系统语言版本,不是必需的用户首选项。
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.