Silverlight 无法正确读取我的资源文件

发布于 2024-12-20 21:44:44 字数 532 浏览 5 评论 0原文

我为英语 (MyResourcesFile1.resx) 和法语 (MyResourcesFile1.fr.resx) 创建了 .resx 文件。两者都有公共的访问修饰符,并且都是嵌入式资源

在 app.xaml.cs 中,甚至 Application_Startup 包含:

  var languageInfo = new CultureInfo("fr");
  Thread.CurrentThread.CurrentCulture = languageInfo;
  Thread.CurrentThread.CurrentUICulture = languageInfo;

在 Silverlight 代码的许多地方,我使用 Visual Studio 提供的生成属性。

 string myString = MyResourcesFile1.MyPropertyValue;

不幸的是,它只从英文文件中获取本地化的字符串。为什么?

I have .resx file created for english (MyResourcesFile1.resx) and french (MyResourcesFile1.fr.resx). Both have the Access Modifier to Public and they are both Embedded Resource.

In the app.xaml.cs the even Application_Startup contain :

  var languageInfo = new CultureInfo("fr");
  Thread.CurrentThread.CurrentCulture = languageInfo;
  Thread.CurrentThread.CurrentUICulture = languageInfo;

In many place in the Silverlight code I use the generated property that Visual Studio has provide.

 string myString = MyResourcesFile1.MyPropertyValue;

Unfortunately, it only takes the localized string from the english file. Why?

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

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

发布评论

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

评论(2

秋千易 2024-12-27 21:44:44

我通过阅读大量的微软文档最终让它工作起来。

Visual Studio 2010 还没有用于添加 Silverlight 项目支持的语言的菜单。为了让您的应用程序能够使用所有资源文件,需要对其进行修改。第一步是使用记事本打开项目解决方案。完成后,搜索SupportedCultures。在括号内您可以添加所需的语言(无需添加默认语言)。所以我的现在看起来像这样:

<SupportedCultures>fr
</SupportedCultures>

重新加载项目并编译。如果您像我在应用程序启动中所做的那样设置线程,则资源将正确加载并显示。我认为它不能动态更改,但对我来说没有必要。

I make it works finally by reading a lot of Microsoft Documentation.

Visual Studio 2010 doesn't have (yet) a menu to add the supported language for Silverlight project. To have your application working with all your resources files, it needs to be modified. The first step is to open the project solution with NotePad. Once it's done, search for SupportedCultures. Inside the bracket you can add the desired language (no need to add the default one). So mine looks like that now:

<SupportedCultures>fr
</SupportedCultures>

Reload the project and compile. If you set the thread like I were doing in the Application Startup, the resource is correctly loaded and displayed. I think it cannot be dynamically changed but it wasn't necessary for me.

唱一曲作罢 2024-12-27 21:44:44

其中一个选项是在 App.xaml.cs 中设置文化,您可以在其中设置对象标记。

<object ...>
     ...
     <param name="culture" value="de-de" />
     <param name="uiculture" value="de-de" />
    ...
</object>

One of the options is insted of settings culture in App.xaml.cs, you can set in it the object tag.

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