I need suggestions on creating a language file for my project. My project is multi language and i want to output all texts in the selected language.
I was thinking about creating a language.h file with some sort of object for all outputs per language but i don't know exactly what the best approach is.
Is it better to create a language.h file with all language variables or multiple files (like en.h, nl.h etc)?
I would like to have a global setting (selectedLanguage), and with that value i can select the text in the right language.
localisation can be complex where word orders or variable positions don't work the same way depending on the language. (currency symbol location ➜ 5€ versus $5 for example or Friday, August 31st versus Vendredi 31 août, ...)
so more than the text, it might impact the way things get printed out
how sophisticated does it need to be? what type or arduino do you plan to run this on? (memory footprint can become large)
It won't be a lot of text, just some day names and error messages
I can create different classes (class per language) but than i don't know what the easiest way is to select the right language. Preferably i would set a language at some point, and the variable is taken from the right object or class
Thanks, but i don't like the fact that i cannot use a key (string instead of an index) to get the value. I am sure at some point i will get a mess with selecting the right key and none of the texts are right.
of just have the chosen language a global variable and always use the array indirection whenever you want to print and may be an enum list that matches the array's order to make the code more readable
In file included from src/main.cpp:4:
src/language.h:27:9: error: flexible array member 'Language::en' not at end of 'class Language'
};
^
src/language.h:27:9: error: initializer for flexible array member 'const char* const Language::en []'
src/language.h:36:9: error: initializer for flexible array member 'const char* const Language::nl []'
};
^
you don't need the size to define the array, the compiler will calculate it
see in this code, I did not have to specify I had 2 entries
what's the question exactly ?
would you want something to magically generate the enum keywords based on the array? (really hard may be impossible esp. if you have long text and not just words in the array ➜ probably better to maintain the words in XML on the side and have a pre-processor phase generating a .h for you from all your languages )