Multi-language support

I’m thinking about supporting multiple languages on my application. So far I think I would use ofParameter and load different files depending on the language chosen.

I would like to know if anybody has tried any other method/library that could be helpful.

Thank you!

oops sorry didn’t see this thread:

Hey Jordi,
¿Cómo estás? Espero que bien. :slight_smile:

I´ve done this recently for an android/iOS app I was working on by simply using xml files. One xml per language.
It is quite straightforwards. store everything in an std::map object.

	map<string,string> lang;
if(xml.load("lang.xml")){
	for (int i = 0; i < xml.getNumChildren(); i++) {
		xml.setToChild(i);
		string key = xml.getName();
		string value = xml.getValue();
		if (lang.count(key) == 0 ) {
			lang[key] = value;
		}
		xml.setToParent();
	}
	for (auto& l: lang) {//this is for the lazy ones
		cout << "static string  " << l.first << " = \"" << l.second<<"\";" << endl;
	}
}

for the lazy ones:
copy what is printed to the console and paste into a languageKeys.h file in your project.
This way, include the languageKeys.h file and just start typing the name of the key and your ide’s code sense should suggest you the rest of the string. This way you also avoid typing the wrong string; if you do such there will be no error from the std::map as when you try to access a non existing object it simply creates a new one for that key.

remember to put the root element in the xml file like

<Language>
<string0>blablabla</string0>
<string1>blablabla</string1>
<string2>blablabla</string2>
</Language>

All the best!

1 Like

Thank you very much! I will give it a shot :slight_smile: