Click here to Skip to main content
15,885,309 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I'm having a dialog based app written in VC++ using Visual Studio 6. It's a simple app with very few texts, but now those needs to support multiple languages. As it's not many texts, the plan is to add all the different languages into just one string table with a unique identifier. So now a sample string table looks like this,
XML
STRINGTABLE
BEGIN
    IDS_STRING_OK_BUTTON_ENG "OK"    //English text
    IDS_STRING_EXIT_BUTTON_ENG "Exit"   //English text
    IDS_STRING_OK_BUTTON_FRA "D'accord"   //French text
    IDS_STRING_EXIT_BUTTON_FRA "Sortie"   //French text
END


Now i have a function that will return a string based on the OS language setting.

C++
CString strLang = "";
    //Retrieves the system default locale identifier
    LCID lcid = GetSystemDefaultLCID();

    //Determine the language identifier from the locale identifier
    LANGID langid = LANGIDFROMLCID(lcid);

    //Does many processing here........
    //.................................
    //.................................
    // So if English is the OS language then this function will return "_ENG".


What I have tried:

Now in another part of the code, this unique language ID is concatenated with another string to find the language specific text.

C++
CString okButton = "IDS_STRING_OK_BUTTON" + m_strLanguageIndex; //Here m_strLanguageIndex for example will be "_ENG"


The final string will be
IDS_STRING_OK_BUTTON_ENG


So this way, i can have just one string table with all different languages and then use the above method to create a unique resource ID.

But now the challenge is, the resource IDs in resource.h file are integers. So the above CString is of no use to find the corresponding text.

So am not sure whether this is going to work. Am just throwing it out to see whether anyone has better ideas or have any suggestion to make the above method work.

I don't want to create multiple DLLs for every language as this is a simple dialog based app.
Posted
Updated 8-May-18 22:15pm
v2

Resource DLLs is the recommended way to do this, but if you have reasons to not want to use those, constructing the resource IDs in code is not impossible.

The ID's in resource.h are integers, and refering to them as e.g. IDS_STRING_OK_BUTTON_ENG can only be done at compile time. However you could do something like this.

resource.h:
#define IDS_STRING_OK_BUTTON_ENG	100
#define IDS_STRING_EXIT_BUTTON_ENG 	101
#define IDS_STRING_OK_BUTTON_FRA	200
#define IDS_STRING_EXIT_BUTTON_FRA 	201


.rc file:
STRINGTABLE
BEGIN
    IDS_STRING_OK_BUTTON_ENG "OK"    //English text
    IDS_STRING_EXIT_BUTTON_ENG "Exit"   //English text
    IDS_STRING_OK_BUTTON_FRA "D'accord"   //French text
    IDS_STRING_EXIT_BUTTON_FRA "Sortie"   //French text
END

And then refer to the ID's as the English ID + a language dependent offset. In this example the offset for French would be 100.
 
Share this answer
 
Why try to re-invent the wheel, when Windows already provides the ability to have multi-language resources? See Multiple-Language Resources[^].
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900