.resx文件,用于使用托管C ++进行本地化 [英] .resx files for localization with managed C++

查看:121
本文介绍了.resx文件,用于使用托管C ++进行本地化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用.resx文件在带有VS2013的托管C ++ CLR项目中进行字符串本地化.在我的项目Resources Files文件夹中,右键单击> Add Item> .resx文件,并将其命名为AppLocalization.resx.我再做一次,并创建AppLocalization.fr.resx.然后,我向每个字符串添加一个具有相同名称的不同字符串.如果我运行我的应用程序,则以下代码将从AppLocalization.resx文件中获取正确的字符串:

I'm trying to use .resx files for string localization in a managed C++ CLR project with VS2013. In my projects Resources Files folder I right click > Add Item > .resx file and name it AppLocalization.resx. I do it again and create AppLocalization.fr.resx. Then I add a different string with the same name to each. If I run my application the following code gets the correct string from the AppLocalization.resx file:

ResourceManager ^rm1 = gcnew ResourceManager(L"My_App.AppLocalization", Assembly::GetExecutingAssembly());
this->Text = rm1->GetString(L"My String Name");

现在,我想测试.fr法语翻译,这是我遇到麻烦的地方.这两种方法都无法从.fr.resx文件获取字符串,而是从AppLocalization.resx文件返回字符串:

Now I want to test the .fr French translation and this is where I'm having trouble. Both of these fail to get the string from the .fr.resx file and instead return the string from the AppLocalization.resx file:

this->Text = rm1->GetString(L"My String Name", gcnew System::Globalization::CultureInfo("fr"));

System::Threading::Thread::CurrentThread->CurrentCulture = gcnew System::Globalization::CultureInfo("fr-FR");
System::Threading::Thread::CurrentThread->CurrentUICulture = gcnew System::Globalization::CultureInfo("fr-FR");
this->Text = rm1->GetString(L"My String Name");

毫无疑问,这很简单,我做错了或没有设置,但是经过大量搜索后,我找不到解决方案.我已经尝试在调试模式和发布模式下进行测试.我已经验证了\ fr \ My_App.resources.dll文件是在Debug和Release文件夹中创建的,但是我尝试执行的任何操作都没有在运行时使用.

No doubt its going to be something simple I'm doing wrong or haven't set, but after much searching I can't find the solution. I've tried testing in both debug mode and release mode. I have verified the file \fr\My_App.resources.dll is being created in the Debug and Release folders, but whatever I try it isn't used at run time.

推荐答案

问题是.....我的项目属性将公共语言运行时支持"设置为"/clr:safe".一旦将其更改为"/clr:pure,一切都将正常运行.

And the problem was.....my project properties had "Common Language Runtime Support" set to "/clr:safe". Once I changed it to "/clr:pure everything worked perfectly.

这篇关于.resx文件,用于使用托管C ++进行本地化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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