使用正确的".resx"根据文化信息归档 [英] Using the correct ".resx" file according to the culture info

查看:60
本文介绍了使用正确的".resx"根据文化信息归档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在项目中使用本地化,所以我使用的是".resx"文件.

I want to use localization in my project so I'm using ".resx" files.

我有两个文件"StringRes.resx"和"StringRes.fr.resx".如您所料,我希望我的应用程序的所有消息都根据用户的CultureInfo进行更改.

I have two files "StringRes.resx" and "StringRes.fr.resx". As you can guess, I want that all the messages of my app change according to the CultureInfo of the user.

但是当我这样做时:

public MainWindow()
{
     Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("fr");
     InitializeComponent();
}

当我这样做时,它什么都没有改变:

It doesn't change anything when I do :

Console.WriteLine(StringRes.FirstName);

实际上,显示的始终是StringRes中的字符串,而不是StringRes.fr中的字符串

Indeed, it's always the string in StringRes which is displayed and not the string from StringRes.fr

两者都在同一个命名空间中.

The both are in the same namespace.

谢谢您的帮助.

推荐答案

我创建了自己的测试项目,并计划将"fr-FR" 用作区域性标签.可以在我的skydrive 上找到测试项目.

I have created my own test projected an I used "fr-FR" as a culture tag. The test project can be found on my skydrive.

完美.

简而言之:

我将项目的属性"中的区域性设置为"en-US",因为这就是我想要的 Resource.resx .

I set the culture in the Properties of the project to be en-US as that is what I would want my Resource.resx to be.

然后我创建了 Resource.resx Resource.fr-FR.resx Resource.nl-NL.resx .

我用 TestData 字符串填充了它们.并创建了一个包含3个按钮的窗口,其中包含事件.在我创建的文本块的按钮旁边,该文本块被绑定到文本字符串"字段.

I filled them with the TestData string. And the created a window with 3 buttons with events hooked to them. Next to the buttons I created a textblock, the textblock is binded to a Text string field.

在按钮事件中,我更改区域性和 Text 字段.然后您可以看到更改发生了.

In the button events I change the culture and the Text field. And you can then see the change happen.

您首先需要创建 Resource.resx ,然后在同一文件夹中创建 Resource.fr-FR.resx .Resource.resx将获得一个代码隐藏文件,而不是所有文化资源文件.如果您的Resource.fr-FR.resx确实有一个区域性文件,则您做错了什么,最好删除该资源文件并重新创建,以免丢失其代码后缀.

You first need to create your Resource.resx then in the same folder you need to create Resource.fr-FR.resx. The Resource.resx will get a codebehind file, all the cultured resource files should not. If your Resource.fr-FR.resx does have a culture file you did something wrong and it is best to delete that resources file and recreate it so it loses it's codebehind.

这篇关于使用正确的".resx"根据文化信息归档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆