Best way to apply different languages in your game?

Hi all,

i would like to ask if anyone of you could explain to me ( and to others in our forum ) , the most efficient way to apply multiple languages in the game? Kinda like, you pickup a language at the start menu, the language is then identified as a number or something in globalDict . then in every scene, this value will turn every text so the phrases you have written and saved somewhere.

I think this would work with if clause… but if the script, which contains your function and text, is already long, i dont think its the best way.

thank you in advance

The way I would recommend is to have every single string you want to be able to translate in an external file. Assign a unique label to each string in the file. For example for the main menu, you might have something like this:

menuStart = Start Game
menuTutorial = Tutorial
menuOptions = Options
...

You can use something like Python’s configparser module to help you read the file if you want. Then when you need to use the strings in game, just fetch them from the Configparser or whatever you used to read the strings from the file. For example:

startButtonText['Text'] = myStringParser.get_string('menuStart')

You could use a text properties for each text and replace the according to the saved language using some of the save methods aviable. Just make a property language, put it in globalDict and make all the texts recieve it and set theirselves basing on it- this is the simplies method I can imagine. You can also use replace mesh if you use rendered texts(images).

What I do is this, I have come cfg files:
spanish.cfg
english.cfg

Every one contain data like this:


[english]
menuStart = Start
menuExit = Exit

In another one (configuration file) I save which lenguaje the game is using, for example: english.

So, in the first frame, I use configparser to get the data of the lenguaje by the one that is set in the configuration file, the end result is this:
{“menuStart” : “Start”, “menuExit”: “Exit”}

And I save it in: logic.lenguaje.

Later, for example if I have a text, I put a property named: textID, and set it to “menuStart”.
And a script change it text corresponding to the data saved in logic.leguaje.

Somenthing like this:


textID = owner["textID"]

if textID in logic.lenguaje:
    owner["Text"] = logic.lenguaje["textID"]
else:
    owner["Text"] = textID

thanks everyone.

I think the methodes Movious and Carlo679 posted are great for complex and long translations. I also found out a simple way to make it, do you think it is a good solution?

import bge

vm=logic.globalDict
trans = vm["language"]


word= {}


word[0]=["One","Two"] #English
word[1]=["Eins","Zwei"] #German
word[2]=['UNO',"Due"] #Italian


C_1,C_2 = word[trans]



Can you please t ell me how i can save every of these values into globalDict (C_1 and C_2), using 1 code line?

C_1,C_2 = word[trans]

I created animplementation to use .properties files as it is used by Java applications quite a while ago. I’m not sure if it still works, but the principles are still valid.

If you want mutlilanguages separate resources are the way to go. Otherwise it is nearly impossible to maintain the texts, or add new languages. Be aware translating/writing texts has nothing to do with programming.