问题描述
我正在尝试在Windows应用程序(控制台应用程序)中实现字符串本地化。
为实现这一点,我已经完成了以下工作。
我在项目名称中添加了两个资源文件。 English.rc和Germany.rc
English.rc
我添加了一个字符串表。它的语言设置为英语(美国)
在Germany.rc
我添加了一个字符串表。它的语言设置为德国(德国)
在两个字符串表中我都添加了一个字符串资源条目
For English.rc
Hi,
I am trying to implement string localization in the windows application (Console app ).
To achieve this i have done following.
I have added two resource files in the project namele. English.rc and Germany.rc
In English.rc
I have added a string table. Its language is set to English(United States)
In Germany.rc
I have added a string table. Its language is set to Germany(Germany)
In both string tables i have adde a string resource entry
For English.rc
ID = IDS_STRING_Title
Value = 101
Caption = EnglishCaption
适用于German.rc
For German.rc
ID = IDS_STRING_Title
Value = 101
Caption = GermanCaption
我将两个rc文件中字符串资源的值保持为101.
我试图将此字符串用于代码中,如下所示。
I have kept the value of the string resources in both rc files to 101.
I am trying to consume this string into the code as follows.
#include "stdafx.h"
#include "windows.h"
#include "atlstr.h"
#include "resource1.h"
#include "resource.h"
int _tmain(int argc, _TCHAR* argv[])
{
CString str( MAKEINTRESOURCE( IDS_STRING_Title ) ) ;
return 0;
}
当我调试上述应用程序时, str总是加载EnglishCaption文本。 \
当我更改区域设置以将系统区域设置更改为德语(德语)或更改系统的显示语言时,它始终仅显示EnglishCaption文本。
为什么会这样。当我将系统区域设置设置为德语(德国)时,为什么应用程序不会使用德语(德语)语言从字符串表中获取字符串。 ???
我错过了什么?
When i debug above application, str gets always loaded with the "EnglishCaption" text. \
When i change the regional settings to change the system locale to German(German) or change Display language of the system, it always shows "EnglishCaption" text only.
Why this happens. Why application does not pick up the string from the string table with German(Germany) language when i set the system locale to German(Germany). ???
Am I missing something ??
推荐答案
::SetThreadLocale(MAKELCID(MAKELANGID(m_iLangID, SUBLANG_DEFAULT), SORT_DEFAULT));
然后拨打所有电话
then all your calls to
CString::LoadString()
将加载正确的语言
这篇关于Windows exe的字符串本地化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!