Difference between revisions of "Multi language C embedded"
From Teknologisk videncenter
m (added Category:C using HotCat) |
m (→Design goals) |
||
Line 13: | Line 13: | ||
"The format received is inconsistent with RFC 1024", | "The format received is inconsistent with RFC 1024", | ||
}; | }; | ||
+ | </source> | ||
== Example == | == Example == | ||
+ | In this small example both languages are in the same file. In a project, you should have a file called english.h where all your multi language messages should reside. When the project is internationalized send a copy of english.h to the translator with a new name. For example german.h | ||
<source lang=c> | <source lang=c> |
Revision as of 14:43, 16 October 2016
Different approaches of implementing multi language support in embedded C projects. (See links below).
Design goals
- Should only exist in flash. (No copying to memory)
- Logical for translators to translate from english to other language.
- Easy to change language on-the-fly
- No padding of strings to max length in arrays
- In the example below the text strings yes and no use the same amount of memory as the long message.
char txt[3][] = {
"Yes",
"No",
"The format received is inconsistent with RFC 1024",
};
Example
In this small example both languages are in the same file. In a project, you should have a file called english.h where all your multi language messages should reside. When the project is internationalized send a copy of english.h to the translator with a new name. For example german.h
char const * const danish[] = {
"FEJL: Kommando eksisterer ikke: %s",
"FEJL: Dato %s ugyldig",
"Advarsel: Der er kun %u%% batteri tilbage!"
};
char const * const english[] = {
"ERROR: Non-existing command: %s",
"ERROR: Invalid Date %s",
"Warning: Only %u%% battery left!"
};
void example(void) {
char **textmes;
textmes = (char **) &danish; // Set danish language
printf( textmes[2], 17); // Outputs: Advarsel: Der er kun 17% batteri tilbage!
textmes = (char **) &english; // Set english language
printf( textmes[2], 17); // Outputs: Warning: Only 17% battery left!
}