Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Multi-Language support in my game  (Read 2773 times)

0 Members and 3 Guests are viewing this topic.

santiaboy

  • Full Member
  • ***
  • Posts: 118
    • View Profile
Multi-Language support in my game
« 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
 

FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: Multi-Language support in my game
« Reply #1 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.
« Last Edit: March 22, 2013, 08:17:24 pm by FRex »
Back to C++ gamedev with SFML in May 2023

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Multi-Language support in my game
« Reply #2 on: March 22, 2013, 08:28:00 pm »
There are tools to ease this process, the most famous is gettext.
Laurent Gomila - SFML developer

tom64

  • Jr. Member
  • **
  • Posts: 57
    • View Profile
Re: Multi-Language support in my game
« Reply #3 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.
« Last Edit: March 23, 2013, 12:31:12 pm by tom64 »
Newbie to C++ and SFML

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11033
    • View Profile
    • development blog
    • Email
Re: Multi-Language support in my game
« Reply #4 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>.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

santiaboy

  • Full Member
  • ***
  • Posts: 118
    • View Profile
Re: Multi-Language support in my game
« Reply #5 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.