Unity3D Tutorial - Localisation of text and graphics in C#

Hi all, I have just completed the first couple of tutorials in my new series and thought I would share them with you here. This one is around localisation and takes a simple approach to making localisation easy in your games. I really hope it is of some help to someone out there :slight_smile:

Merry christmas and a happy new year to you all :slight_smile:

That’s a very wet code you wrote there, You basically have these lines:

string dialogString = dialogLoaded.ToString();
            dialogLines = dialogString.Split("\n"[0]);

            string interfaceString = interfaceLoaded.ToString();
            interfaceLines = interfaceString.Split("\n"[0]);

            string messageString = messagesLoaded.ToString();
            messagesLines = messageString.Split("\n"[0]);

            string levelString = levelsLoaded.ToString();
            levelLines = levelString.Split("\n"[0]);

repeated for each language in your code, you should solve that, then if you’re already there, you could use some trickery, to get rid of the whole thing, eg. like this:

if language is english then
    curDialog = englishDialog
    curInterface = englishInterface
    ...
else if language is spanish then
    ...

The you can just simply change every Resouces.Load(“Languages/” + englishInterface) to (“Languages/” + curInteface)

Same with texture loading

1 Like

Now that you point it out, its so obvious :slight_smile: thank you, thats a really helpful suggestion and I shall change it to reflect that :smile:
Thanks for taking the time to read it and comment!

It would be even better, if you would do something like this:
variables:
public string dialogPrefix, levelPrefix, etc; // = “Dialog”, “Level”

Then you give the enums base value:
enum Languages {
English = “English”,
French = “French”,
etc…
}

then you can simply get the correct file with:
Resources.Load(dialogPrefix + “_” + (string)language)

1 Like

Thanks! Thats super helpful, and I have now just removed a block of totally unecessary code from the game :slight_smile: Every day is a school day :slight_smile: I’ll now update my tutorial :smile:

1 Like