Localisation (switching languages)

If you have managed to muddle through making an app and getting it up on the Google console you may have noticed the tips and sections on adding different languages for store listings.

This should be possible by adding a localisation Manager and supporting scripts to your project.

Unity have a very good Tutorial on this and it is relatively straight forward.  I found a tutorial on this area via DFT Games YouTube Channel.

The video goes on to show the concept of Localisation and how it is applied to websites.  What we want is the core code to execute the language change.

Download the project from the link in the video description or from here.

The part we want to use is the “Localisation” which is in => UnityLocalization-master\Assets\DFT Games\Localization. (you will have to forgive the spelling as I had to stop myself from changing the “z” to an “s” !).

Extract the folder and import it (drag and drop) to your Unity Project.

Cap2

I opened his “Demo” scene and copied the “MenuManager” object into my “MenuScreen” scene (changing the object name to “LocalisationManager”).  Then opened the script attached to the “LocalisationMangaer” and tailored it like so:

using UnityEngine;
using DFTGames.Localization;
using UnityEngine.SceneManagement;

public class MenuManager : MonoBehaviour
{
#region Language Selections

public void SetEnglish()
{
Localize.SetCurrentLanguage(SystemLanguage.English);
SceneManager.LoadScene(“MenuScreen”);
}

public void SetGerman()
{
Localize.SetCurrentLanguage(SystemLanguage.German);
SceneManager.LoadScene(“MenuScreen”);
}

public void SetFrench()
{
Localize.SetCurrentLanguage(SystemLanguage.French);
SceneManager.LoadScene(“MenuScreen”);
}

public void SetSpanish()
{
Localize.SetCurrentLanguage(SystemLanguage.Spanish);
SceneManager.LoadScene(“MenuScreen”);
}

public void SetItalian()
{
Localize.SetCurrentLanguage(SystemLanguage.Italian);
SceneManager.LoadScene(“MenuScreen”);
}

public void SetPolish()
{
Localize.SetCurrentLanguage(SystemLanguage.Polish);
SceneManager.LoadScene(“MenuScreen”);
}

public void SetKorean()
{
Localize.SetCurrentLanguage(SystemLanguage.Korean);
SceneManager.LoadScene(“MenuScreen”);
}

public void SetJapan()
{
Localize.SetCurrentLanguage(SystemLanguage.Japanese);
SceneManager.LoadScene(“MenuScreen”);
}
#endregion Language Selections
}

In the original script you would find an extra line for switching images on language change. I did not need this so removed all the references.  Replacing it with my “SceneManager.LoadScene(“MenuScreen”);”

To note: I also removed the script which handles the Image switching – LocalizeImage.cs from the folder too.

I created the .txt documents inside the => Assets\Localization\Resources\Localisation folder. Naming them => English, French, German etc, etc.

Cap3

Example of text inside file:

start=Start
gameover=Game\nOver
yourscore=Your Score
restart=Restart
resume=Resume\nGame

*(\n = newline/return)*

My dictionary would be the same for every language, so for the German.txt file it would be:

start=Anfang
gameover=Spiel\nist aus
yourscore=Ihr Ergebnis
restart=Neustart
resume=Spiel\nfortsetzen

I next made sure the buttons for different languages i.e. Deutsche (German) had an On-Click event/Button component added to it. Then taking the LocalisationManager object – dropped this into the run-time inspector field.  Select the MenuManager script from the dropdown and select the corresponding Language i.e. “SetGerman”.

Once this groundwork/prep has been done, you can now simply add the “Localize.cs” script to any text object.

The component will then display a field labelled – “Localized Key” in here you would put the first value on the left side of the equals sign from your Dictionary, i.e. “start” or “gameover” and so on and so forth.

Cap1

Make sure to put the key exactly as you have created inside the .txt file/s.  This relates to all the different language text files you have created.

Then if you have it setup as I have, the click of the button will then take you to the MenuScreen and show you correct language associated with the key value.

If you have any issues with the above – as always, please get in-touch!

Regards,

SillyDev

 

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s