SFML community forums

Help => General => Topic started by: santiaboy on March 22, 2013, 08:02:11 pm

Title: Multi-Language support in my game
Post by: santiaboy on March 22, 2013, 08:02:11 pm
Hey guys, I've been making a really simple platformer and I wanted to upload it to the SFML projects section, but I realized I made it all in Spanish.
My question would be how do you do multi-language support on videogames?
Do you have something like this for every string there is in the game?
//code
sf::String myString;
if(languageIsEnglish){
   myString.setString("Hi");
}
else if(languageIsSpanish){
   myString.setString("Hola");
}
//more code
 
Title: Re: Multi-Language support in my game
Post by: FRex on March 22, 2013, 08:15:50 pm
I think(and seen it in some games, Thief Metal Age for example) it'd be better to have languages folder with folders for each language and have same named files everywhere in them so you just then load "langs/"+languagefoldername+filepath and read it's content. But of course that depends on how much text you are managing and if you want it to be switchable or do you want to compile it once for every language. For last one you could use C preprocessor.
Title: Re: Multi-Language support in my game
Post by: Laurent on March 22, 2013, 08:28:00 pm
There are tools to ease this process, the most famous is gettext (https://en.wikipedia.org/wiki/Gettext).
Title: Re: Multi-Language support in my game
Post by: tom64 on March 23, 2013, 12:25:09 pm
I think the easiest way is to store all the strings in a separate text/ini file and name the file what ever language it is (eg. 'English.ini' etc.)

Have the user select which language they want, then get the strings from that file.

eg.

then when show a message, just do something like:
message("Hello")

the message function would look for a key in the ini called "Hello" and find the corresponding word (which in english will still be hello), and display the corresponding string.

The ini file would look like this for english:

Hello=Hello
What is your name=What is your name

the Italian ini file would look like:

Hello=Ciao
What is your name=Vive name el solo
----

Otherwise instead of constantly reading from the file, you could store all of the strings in memory, maybe use a struct, stored in an array?

string myString
string translatedString

And then when use message("Hello") function, the function will look through all of your structs for "Hello" in myString, and return what ever the translatedString is.

Sorry I'm still a novice at C++, so I don't know if my advice is any good.
Title: Re: Multi-Language support in my game
Post by: eXpl0it3r on March 23, 2013, 01:54:39 pm
As said before, there are many libraries for multi-language support. Just google a bit or use gettext.
Also the usual principle has been mentioned, use external files which have the same id-key but the different values for each language and then simply load the file, that matches the wanted language.

Otherwise instead of constantly reading from the file, you could store all of the strings in memory, maybe use a struct, stored in an array?
Most definitely!
Reading from the disk is slow and unnecessarily uses OS resources. You can load the wanted language file once into memory and if the user switches the language, you can just reload it.
As mentioned with the principle, you get a unique id and a language-specifc value. This literary screams for a datastructure such as std::map<std::string, std::string> or std::unordered_map<std::string, std::string>.
Title: Re: Multi-Language support in my game
Post by: santiaboy on March 23, 2013, 05:46:59 pm
Thanks for the replies!

I'm currently making a map, and a loader.  Hopefully I'll finish that and the language change by tomorrow.