Solved

String table

Posted on 2002-04-17
8
256 Views
Last Modified: 2008-03-17
I want to hold all visible strings for my project in a table, probably in a series of header files.  The aim is to replace IDC_MEMORY_ERROR with "You are out of memory".  How should I do this?  I would rather use something other than #define, but if that's the best way, then I can live with it.

It must work on any platform (so no VC++ resources etc.)
0
Comment
Question by:IainHere
8 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 100 total points
Comment Utility
Well, the simplest way would be to load your text resources at runtime from a text file into an array and have IDC_MEMORY_ERROR as an index into that array. If you want it to be bullet-proof, use a map that maps the integer constant to a string...
0
 
LVL 4

Author Comment

by:IainHere
Comment Utility
With that method, I'd have to keep the strings in the same order, otherwise I'd have to recode the section that reads in the strings.  Is there a way for me to avoid it, or am I missing something?

Also, using #define will fix the strings at compile time - is there a special advantage/disadvantage to this?

My ideal would be to have a text file that read

IDC_MEMORY_ERROR    "you're outta memory"
IDC_BORED_ERROR     "you're too bored"
etc

and refer to the IDC_ in the program.  Thanks for your help.
0
 
LVL 86

Expert Comment

by:jkr
Comment Utility
>>Also, using #define will fix the strings at compile
>>time - is there a special advantage/disadvantage
>>to this?

Well, there's a disadvantage: You'll have to supply a seperate binary for each language...
0
 
LVL 4

Author Comment

by:IainHere
Comment Utility
Oh yeah - I forgot about that whole section in the install process "choose language".  As you might guess, this is my first go at multi-language support.

So, discounting that option, if I use the map solution, my file will look like

10001   "Error String"

and code will look like:
const int IDC_STRING_ERROR = 10001;

And I implement a method of equating the two.  Is this right?

How would you normally store strings for different languages?  Is it acceptable to put the strings in an unencoded file on the end user's machine?

Increasing points to 100.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 86

Expert Comment

by:jkr
Comment Utility
>>Is it acceptable to put the strings in an unencoded file on the end user's machine?

I've seen that with several commercial products - just don't name them '*.txt', so the users don't tamper with them :o)

BTW, regarding the solution you mentioned - this is ideal for using a map, as a map also allows "gaps", IOW, doesn't require consecutive numbering...
0
 
LVL 2

Expert Comment

by:gandalf79
Comment Utility
>>Is it acceptable to put the strings in an unencoded file on the end user's machine?

anouther opption i have seen is placing your error codes in a dll resorce. you could write a function you pass an error code to and have it return the error string. all that would be required then would be a new dll for each language.

if you want to do something like this a map would be ideal for you.

and if you want to go that rought you could move all your text resorces to that file and worry about transltion later.
0
 
LVL 4

Expert Comment

by:mblat
Comment Utility
Actually we've implemented something like this.  We are parsing .rc files and all string resources into binary with it' numeric ids.  Then file translated (using small tool) it into several languages.  Then application reads file user specifies and automatically translate all text into that language.

To hold data in memory I've used vector, that hold user defined type, something like this:

class LanguageToken
{
UINT     m_nResourceId;
CString  m_csResourceString;
};

STL map or any other map can be used also, like it was mentioned before it is very convinient to associate resource id with resource text .

It works pretty well, we just have couple issues - like not all items in menus have ID.  So menu's have to translated by position, or contracted on a fly from string in the string table.  One other thing that all labels on all dialogs are placed with IDC_STATIC. ( or -1).  So you have to make sure that all labels you want to translate have to have own unique id.

Small probem with the way you want it implemented

IDC_BORED_ERROR     "you're too bored"

is that I don;t see the way how you going to find out wich control/text has IDC_BORED_ERROR associated with.  I couldn;t figure it out - so I resorted to storing it's numeric value.  That of cause forced me to parse resource.h file :-(.  

Of cause if all you want to do is just simplify translation process it is not an issue for you.

Hope it helps a little.
0
 
LVL 4

Author Comment

by:IainHere
Comment Utility
Thanks jkr.

mblat - good info.  I've dropped some points off for you at http://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=cplusprog&qid=20292724

:-)
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now