How to add the second (or other) languages

Liste des GroupesRevenir à ca embedded 
Sujet : How to add the second (or other) languages
De : pozzugno (at) *nospam* gmail.com (pozz)
Groupes : comp.arch.embedded
Date : 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.

Date Sujet#  Auteur
12 Feb 25 * How to add the second (or other) languages13pozz
12 Feb 25 +* Re: How to add the second (or other) languages11Stefan Reuther
12 Feb 25 i+* Re: How to add the second (or other) languages7David Brown
16 Feb 25 ii+* Re: How to add the second (or other) languages4pozz
17 Feb 25 iii`* Re: How to add the second (or other) languages3David Brown
17 Feb 25 iii `* Re: How to add the second (or other) languages2pozz
17 Feb 25 iii  `- Re: How to add the second (or other) languages1David Brown
16 Feb 25 ii`* Re: How to add the second (or other) languages2pozz
17 Feb 25 ii `- Re: How to add the second (or other) languages1David Brown
16 Feb 25 i`* Re: How to add the second (or other) languages3pozz
17 Feb 25 i +- Re: How to add the second (or other) languages1David Brown
17 Feb 25 i `- Re: How to add the second (or other) languages1Stefan Reuther
13 Feb 25 `- Re: How to add the second (or other) languages1Niocláiſín Cóilín de Ġloſtéir

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal