Localising your text in Unity once the previous steps are done, is even easier than the last post.
Where ever you have text to localise, simply replace:
//C# public GUIText myText; myText.text = "This is my text to localise"; //UnityScript var myText : GUIText; myText.text = "This is my text to localise";
with……
public String textID; public String defaultText; myText.text = EtceteraBinding.getLocalizedString( textID, defaultText );
Where…
- textID is the stringID that you have in Column B of your Data Entry tab in the Localisation Register
- defaultText is the text that should appear should your string reference not work – makes it easy for you to see during QAing. e.g. put in here “NOSTRING” as an example.
And that’s it!
We have made a little script that we literally throw onto any GUIText instances in the scene for quick localisation. It exposes the above textID and defaultText, so that’s all we need to enter in the Inspector once it’s attached:
UnityScript Version
#pragma strict var textLabel : String; var defaultText : String; var thisObject : GUIText; function Start () { LocaliseStrings(); } function OnEnable () { LocaliseStrings(); } function LocaliseStrings() { thisObject.text = EtceteraBinding.getLocalizedString( textLabel, defaultText ); }
C# Version
using UnityEngine; using System.Collections; public class LocaliseMe : MonoBehaviour { public string textLabel; public string defaultText; public GUIText thisObject; void Start() { LocaliseStrings(); } void OnEnable() { LocaliseStrings(); } void LocaliseStrings() { thisObject.text = EtceteraBinding.getLocalizedString( textLabel, defaultText ); } }
When you’ve added strings for all text, simply make an APPEND BUILD (Command/Control B) and your App is localised.
You can also “localise” images, as well, by using getCurrentLanguage(); to grab the language and load an image accordingly.
So that’s all there is folks! Localisation is so easy when you have the right tools.
In the word’s of Google Translate, “Viel Glück!”