Hi everyone:
I was wondering, if I call CString::LoadString() method to load a string from resources how do I know which language did that method use?
Printable View
Hi everyone:
I was wondering, if I call CString::LoadString() method to load a string from resources how do I know which language did that method use?
Have you looked through the MFC sources to find out?
I don't understand the question.
Hi,
There's no obvious way to do it. You can specify the language you want to be used as the 3rd parameter. However, there's no way to check that MFC was actually able to find the string in that language in your resource DLL.
Alan
CString::LoadString does not have any "3rd parameter". It has one and only one:If the module (exe or dll) contains resources in more than one language then the only way to obtain the ones for the specific language rather than the default one is using resource APIs with Ex suffix:Quote:
BOOL LoadString( UINT nID );
FindResourceEx -> LoadResource -> LockResource
See How To Use LoadResource to Load Strings from a String Table
Yes. What happens on the inside is that the resource string is id'ed with a call to this Win32 API:Quote:
Originally Posted by Arjay
But that doesn't help me much.Code:::FindResource( hInstance, MAKEINTRESOURCE( ((id>>4)+1) ), RT_STRING );
I agree, that seems to be the case.Quote:
Originally Posted by alanjhd08
That is exactly the reason why I needed to know which version of a string resource was loaded. The reason being, in my application strings were processed a bit differently depending on the language.Quote:
Originally Posted by alanjhd08
That is not true. Or at least in the last versions of MFC. There's also this method:Quote:
Originally Posted by VictorN
But I would prefer not to use it and let the language be determined automatically. My reasoning behind it is that this whole language question is quite a complex subject that I may not completely understand at this stage (especially with custom locales in Vista, etc.) thus I'd prefer to let a Windows API handle the language selection.Quote:
Originally Posted by msdn
But, fellas, I was able to find an easy workaround. By adding a simple language ID string into the resource (that is always in your predefined language, English, in my case) I can easily tell which language was actually loaded.
Code:IDS_STRING_COUNTRY_ID "en_us"
Well, I cannot say I understand the solution.
OK, say you have three string resources for English, French and German. You add the following string into each:
//For US resource
IDS_STRING_COUNTRY_ID "en_us"
//For French resource
IDS_STRING_COUNTRY_ID "fr_french"
//German resource
IDS_STRING_COUNTRY_ID "ge_german"
And then when the resource is loaded you check that ID to get the language of the resource loaded.
Could you demo the corresponding fragment from .rc file?
:) Igor, you're killing me.... Take a look at the resource file snippet:
Code://///////////////////////////////////////////////////////////////////////////
//
// String Table
//
STRINGTABLE
BEGIN
IDS_STRING_COUNTRY_ID "en_us"
IDS_STRING_HELLO_WORLD "Hello World!"
IDS_STRING_GOODBYE_WORLD "Goodbye World!"
END
/////////////////////////////////////////////////////////////////////////////
// French (France) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_FRA)
#ifdef _WIN32
LANGUAGE LANG_FRENCH, SUBLANG_FRENCH
#pragma code_page(1252)
#endif //_WIN32
/////////////////////////////////////////////////////////////////////////////
//
// String Table
//
STRINGTABLE
BEGIN
IDS_STRING_COUNTRY_ID "fr_france"
IDS_STRING_HELLO_WORLD "Bonjour tout le monde!"
IDS_STRING_GOODBYE_WORLD "Adieu le monde!"
END
#endif // French (France) resources
/////////////////////////////////////////////////////////////////////////////
// German (Germany) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_DEU)
#ifdef _WIN32
LANGUAGE LANG_GERMAN, SUBLANG_GERMAN
#pragma code_page(1252)
#endif //_WIN32
/////////////////////////////////////////////////////////////////////////////
//
// String Table
//
STRINGTABLE
BEGIN
IDS_STRING_COUNTRY_ID "ge_german"
IDS_STRING_HELLO_WORLD "Hallo Welt!"
IDS_STRING_GOODBYE_WORLD "Goodbye Welt!"
END
#endif // German (Germany) resources
Thank you. :) You might be surprised, but I never did multilanguage support this way. It's always was a per-language resource dll.
The same applies to a resource DLL, doesn't it?