C#中如何区分简体中文和繁体中文?

发布于 2024-12-19 12:31:23 字数 725 浏览 2 评论 0原文

我的应用程序已被翻译成多种语言,包括法语、繁体中文和简体中文。现在,当应用程序首次启动时,我想根据用户区域设置自动选择正确的翻译。

对于法语,评估 InstalledUiCultureTwoLettersIsoLanguageName 属性效果很好,但对于中文 ISO 代码还不够。我想过求助于 Name 属性,它将 zh-Hanszh-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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

墨小沫ゞ 2024-12-26 12:31:23

似乎 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文