Multi-language GUI setup with a string array
I am working on the Keil uv4 IDE with an ARM Cortex-M3 in a bare metal C
application. I have a GUI that I created that is currently in English, but
I would like to give the user the ability to go between other languages
like you can on a cell phone.
I have created a structure with all the words that are used called
string_table_t.
struct string_table_t
{
char *word1;
char *word2;
char *word3;
};
My thought process was to have plain text files for the different
languages and the list of words used contained in each one. Then I would
do a load function that would link the pointers of the string table with
the actual word.
Now, my initial menu is created statically by defining it like so. It is
based off of Altium software platform.
// Test structure
struct string_table_t string_table = {"Main Menu","test1","test2"};
form_t mainmenu_form =
{
.obj.x = 0,
.obj.y = 0,
.obj.width = 240,
.obj.height = 320,
.obj.draw = form_draw,
.obj.handler = mainmenu_form_handler,
.obj.parent = NULL,
.obj.agui_index = 0,
.obj.visible = __TRUE,
.obj.enabled = __TRUE,
.caption.x = 0,
.caption.y = 0,
.caption.text = "Main Menu",
.caption.font = &helveticaneueltstdltext18_2BPP,
.caption.color = RGB(230,230,230),
.caption_line_color = RGB(241,101,33),
.caption.fontstyle = FS_NONE,
.caption.align = ALIGN_CENTRE,
.captionbarcolor = RGB(88,89,91),
.children = mainmenu_children,
.n_children = 4,
.relief = RELIEF_NONE,
.color = RGB(65,64,66),
};
What I want to do is replace the "Main Menu" of the caption.text with
string_table.word1. Therefore, if I load a different language set, the
menu will automatically be pointing to the correct char array. Doing this
currently results in a error expression must have a constant value.
Now, I can get this to work by leaving the text null in the menu component
and adding:
mainmenu_form.caption.text = string_table.Main_menu_text;
This will compile and work, but I would rather not have to have 100 or so
of these statements. Is there a more optimal way of doing this?
No comments:
Post a Comment