Sujet : How to add the second (or other) languages
De : pozzugno (at) *nospam* gmail.com (pozz)
Groupes : comp.arch.embeddedDate : 12. Feb 2025, 17:26:26
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <voii3i$28jmm$1@dont-email.me>
User-Agent : Mozilla Thunderbird
I have an embedded project that runs on a platform without a fully OS (bare metal). The application can interact with humans with italian messages. These messages are displayed on a touch screen, sent in the payload of SMS or push notifications.
I used a very stupid approach: sprintf() with hard-coded constant strings. For example:
void
display_event(Event *ev)
{
if (ev->type == EVENT_TYPE_ON) {
display_printf("Evento %d: accensione", ev->idx);
} else ...
...
}
Now I want to add a new language.
I could create a new build that replaces the constant strings at preprocessor time:
#if LANGUAGE_ITALIAN
# define STRING123 "Evento %d: accensione"
#elif LANGUAGE_ENGLISH
# define STRING123 "Event %d: power up"
#endif
void
display_event(Event *ev)
{
if (ev->type == EVENT_TYPE_ON) {
display_printf(STRING123, ev->idx);
} else ...
...
}
This way I can save some space in memory, but I will have two completely different production binary for the two languages.
Another approach is giving the user the possibility to change the language at runtime, maybe with an option on the display. In some cases, I have enough memory to store all the strings in all languages.
I know there are many possible solutions, but I'd like to know some suggestions from you. For example, it could be nice if there was some tool that automatically extracts all the strings used in the source code and helps managing more languages.