Best Practice for Multiple Languages?

Hello,

I’m starting to develop an interactive application that has a lot of content, images and texts (interactive story basically).

I would like to know what the best practice is to support multiple languages within the app (I’m not referring to code - I mean human written words).

The app will be using a lot of 3D Text Meshes, so my first thought would be to attach a script onto all the 3D Text Meshes.

This script will consist of a Text Field for English, German, Spanish, etc … And whatever the language the user has selected, the scripts will simply swap in and out the requested language within the TextMesh.text.

The only problem with is, is that I may start to lose track of all my 3D Text Meshes throughout the App as there may be loads between different windows, and scenes (Dialog Boxes, Prompts, Buttons, Static Text, etc…).

I would like to know if anyone has a preferable method to overcome this? Thanks.

A common method for doing this is to wrap every string in a function call. The function uses the passed in string as a key to look up the translated string based on the current language.

For example:

field.text = Translate("How are you?");

The function would return How are you? for English, but Hur mår du? for Swedish. Once you deal with all of your strings that way it’s a matter of building up your translation dictionaries. There are tools and APIs available - you can probably find something in the app store or even a more general C# library.

Edit: There is a common GNU interface for doing translations. The Unity Wiki has some code that will read the dictionary files for a language and allow using them for translating.

Time has moved on and Unity now provides a localization package. So just check the package manager more often :wink:

Why not use some scripts like:

public class Texts {

		public static string Language = "en";
		public const string Russian = "ru";
		public const string English = "en";
		public const string Deutsch = "de";
		public const string Portugal = "pt";
		public const string Turkish = "tr";

		public static string STRING_001 { get { 
				switch (LocalTexts.Language) {
				case LocalTexts.Russian:
					return "из";
				case LocalTexts.English:
					return "off";
				case LocalTexts.Deutsch:
					return "von";
				case LocalTexts.Portugal:
					return "de";
				case LocalTexts.Turkish:
					return "/";
				default:
					return "of";
				} return ""; } }
}

Then in any scripts (at start point) do this

void Awake() {
		switch (Application.systemLanguage) {
		case SystemLanguage.Russian:
			Texts.Language = Texts.Russian;
			break;
		case SystemLanguage.German:
			Texts.Language = Texts.Deutsch;
			break;
		case SystemLanguage.Portuguese:
			Texts.Language = Texts.Portugal;
			break;
		case SystemLanguage.Turkish:
			Texts.Language = Texts.Turkish;
			break;
		default:
			Texts.Language = Texts.English;
			break;
		}
}

Then in at any script use it like that

void Awake() {
	Text textField = gameObject.GetComponent<Text>();
	textField.text = LocalTexts.STRING_001;
}

checkout this thread:

https://forum.unity.com/threads/add-multiple-language-support-to-your-unity-projects.206271/

the used method uses XML file for language translations

also check sGlorz reply for C# class:
https://forum.unity.com/threads/add-multiple-language-support-to-your-unity-projects.206271/#post-1909679

I use a script attached to the Ui Text, string will write down every time you use the UiText, if the system is in portuguese, it will use the text in the variable textPort string.
The application will validate the system language and write down int the empty string.
I found this very easy for me.

public string  text1Port = "";
public string text2Eng = "";
public string text3French = "";

public Text textTXT;


public void Update()
{
  
    switch (Application.systemLanguage)
    {
        case SystemLanguage.Portuguese:
            {
                textTXT.text = text1Port.ToString();
                Debug.Log(text1Port);
                break;
            }

        case SystemLanguage.English:
            {
                textTXT.text = text2Eng.ToString();
                Debug.Log("This system is in English. ");
                break;
            }
      

        case SystemLanguage.French:
            {
                textTXT.text = text3French.ToString();
                Debug.Log("This system is in French. ");
                break;
            }
   
    }
}

Make a scriptableobject that contains a dictionary, and for every Language you make a scriptableobject, key is refference text and key is translated text.