使用资源文件进行本地化无法正常工作 [英] Localization using resources file not working

查看:169
本文介绍了使用资源文件进行本地化无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我添加了新的Rosource文件UserNotification.resx.然后,我添加了两个文件进行本地化,并将其命名为UserNotification.hr-HR.resx和UserNotification.sl-SI.resx. (以下主题:如何在C#中使用本地化)

I added new Rosource file UserNotification.resx. Then I added two files for localization and named it UserNotification.hr-HR.resx and UserNotification.sl-SI.resx. (followed thread: How to use localization in C#)

然后,我将Windows语言的语言更改为"si".如果我使用System.Globalization.CultureInfo.CurrentCulture.ToString()打印当前区域性,则输出si sl-SI

Then I changed Windows language's to "si". If i print current culture using System.Globalization.CultureInfo.CurrentCulture.ToString() the output si sl-SI

但是,我总是从UserNotification.resx获得一个字符串.接缝它无法识别本地化资源文件.

But, I allways get a string from UserNotification.resx. Seams it doesn't recognizes the localization resource files.

推荐答案

如果使用多线程,.NET本地化中的问题是,您需要为产生的每个线程手动设置区域性(以防与Windows区域性不同) ,以防用户可以选择所需的语言).它不是从主线程继承的.

The problem in .NET localization if you use multithreading is that you need to set culture manualy for every thread that you spawn (in case it is different than windows culture, in case when user can choose desired language). It is not inherited from the main thread.

创建新线程之后,在启动新线程之前,应将其文化设置为主线程的文化(通常使用Windows的默认文化).

After you create new thread and before you start it you should set it's Culture to the Culture of main thread (which normaly uses the default culture of the windows).

因此,系统显示出良好的CurrentCulture.但是当前线程怎么说?也许由于某种原因,应用程序以不同的文化启动,这就是为什么它加载默认资源文件的原因?无论如何,没有理由不应该手动设置当前的文化.通常,当您想为用户提供更改应用程序语言的选项时,需要这样做.

So, system shows good CurrentCulture. But what does current thread says? Maybe application is started with different culture for some reason so that's why it loads default resources file? Anyway, there is no reason why you shouldn't manualy set current culture. Mostly you need to do that when you want to give user the option to change application's language.

这篇关于使用资源文件进行本地化无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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