Path: csiph.com!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail From: pozz Newsgroups: comp.arch.embedded Subject: How to add the second (or other) languages Date: Wed, 12 Feb 2025 17:26:26 +0100 Organization: A noiseless patient Spider Lines: 49 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Wed, 12 Feb 2025 17:26:26 +0100 (CET) Injection-Info: dont-email.me; posting-host="d4be9f6570d57c59541f345d52e3081c"; logging-data="2379478"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19O0OWZah3wR3fHtKU/1KvVJN2SF0GdIss=" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:8fZeXfRhLmZH/GyjmdocoqxjQNE= Content-Language: it Xref: csiph.com comp.arch.embedded:32331 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.