如何在 Windows Phone 中使用中性语言

发布于 2024-12-21 22:10:47 字数 799 浏览 5 评论 0原文

我面临以下问题:

  • 我已使用 resx 文件将我的应用程序翻译成不同的语言。我也想在其他应用程序中使用相同的 resx 文件。
  • 对于不同的应用程序,我应该能够更改默认语言(某些应用程序仅提供西班牙语版本,其他应用程序仅提供英语版本,还有一些应用程序为多语言版本)

我想我可以只命名资源 LanguageStrings.es.resx 和 LanguageStrings.en。 resx,并使用 NeutralResourcesLanguageAttribute 设置应用程序的默认语言。

但是,当应用程序中没有 LanguageStrings.resx(不变文件)时,应用程序似乎会崩溃 (MissingManifestResourceException)。我认为资源管理器应该使用 NeutralResourcesLanguageAttribute 中的设置来查找正确的资源(例如;回退到西班牙语),而不是寻找中性文件。

我的假设正确吗?我是否遇到了平台错误?我注意到 ResourceManager.GetNeutralResourcesLanguage 未返回使用定义的语言NeutralResourcesLanguageAttribute,但不变的区域性

I am facing the following issue:

  • I have translated my application into different languages using resx files. I want to use the same resx files in other apps as well.
  • For different apps, I should be able to change the default language (some apps will only be available in Spanish, others only in English, and others multilingual)

I figured I could just name the resources LanguageStrings.es.resx and LanguageStrings.en.resx, and use NeutralResourcesLanguageAttribute to set the default language of the app.

However, when there is no LanguageStrings.resx (invariant file) in the app, the application seems to break (MissingManifestResourceException). I thought the Resource Manager should use the setting in NeutralResourcesLanguageAttribute to find the correct resource (for example; fall back to Spanish) instead of looking for a neutral file.

Is my assumption correct and am I running into a platform bug? I have noticed that ResourceManager.GetNeutralResourcesLanguage doesn't returned the language defined using NeutralResourcesLanguageAttribute, but invariant culture instead

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

源来凯始玺欢你 2024-12-28 22:10:47

如果没有不变的资源文件 (LanguageStrings.resx),编译器将不会选择它。您应该让英文资源文件(当前为LanguageStrings.en.resx)为不变文件,即。文件名中不包含 .en,然后设置

[ assembly: NeutralResourcesLanguage("en")]

所有 .NET 应用程序都以这种方式工作。这并不是 Windows Phone 独有的“问题”。

Without a invariant resource file (LanguageStrings.resx), the compiler won't pick it up. You should let the English resource file (Currently LanguageStrings.en.resx) be the invariant file, ie. without .en in the filename, and then set

[assembly: NeutralResourcesLanguage("en")]

All .NET applications work this way. It's not a unique "issue" to Windows Phone.

小巷里的女流氓 2024-12-28 22:10:47

我相信,如果您在 csproj 的元素中指定支持的语言 - 您需要拥有您尝试在受支持的区域性中使用的 resx。如果您使用据称受支持的语言,但 resx 不存在 - 您将收到 MissingManifestResourceException。如果当前语言不受支持,则会选择中性语言。

I believe if you specify your language as supported in the element in your csproj - you need to have the resx that you are trying to use in the supported culture. If you use the language that is supposedly supported and the resx is not there - you will get a MissingManifestResourceException. Neutral language will be picked up if the current language is not supported.

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