.resx files for localization with managed C++

亡梦爱人 提交于 2019-12-11 22:05:44

问题


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");

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");

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.


回答1:


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.



来源:https://stackoverflow.com/questions/28070451/resx-files-for-localization-with-managed-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!