T
Tim
I'm looking to implement a function of the form:
const char *get_string(enum string_id id);
so I can move all my static strings into a separate library that will
be easily editted for localization. The strings will be of widely
varying length so I don't want to put them in a fixed dimension array.
I think the code below does roughly what I want. Is there a more
direct way to get this same result? Or, a way to macro-ize it to
isolate the string data for a translator, and have only 1 list of
(enum name,string) to maintain.
const char s1[] = "string1";
const char s2[] = "string2";
enum string_id {
id1 = 0,
id2
}
const char *sa[2];
void init()
{
sa[id1] = s1;
sa[id2] = s2;
}
const char *get_string(enum string_id id)
{
return sa[id];
}
const char *get_string(enum string_id id);
so I can move all my static strings into a separate library that will
be easily editted for localization. The strings will be of widely
varying length so I don't want to put them in a fixed dimension array.
I think the code below does roughly what I want. Is there a more
direct way to get this same result? Or, a way to macro-ize it to
isolate the string data for a translator, and have only 1 list of
(enum name,string) to maintain.
const char s1[] = "string1";
const char s2[] = "string2";
enum string_id {
id1 = 0,
id2
}
const char *sa[2];
void init()
{
sa[id1] = s1;
sa[id2] = s2;
}
const char *get_string(enum string_id id)
{
return sa[id];
}