Solved

String table

Posted on 2002-04-17
8
290 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 100 total points
ID: 6947962
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
ID: 6948098
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
ID: 6948272
>>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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 4

Author Comment

by:IainHere
ID: 6948306
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
 
LVL 86

Expert Comment

by:jkr
ID: 6948319
>>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
ID: 6949326
>>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
ID: 6952404
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
ID: 6963215
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
C++ to C# code conversion issue 4 121
Error C2678: binary '!=': no operator found... 4 65
Indy 10 not Receiving UDP broadcast 3 43
why doesn't assert terminate here? 2 11
Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

730 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