Using WinZO’s SDK

Localisation for Static Text:

Static text means the text that does not change at runtime. Eg. Time, score, points, menu etc. In this approach, WinZO’s SDK will handle the localisation part for your game. You just need to follow some simple predefined steps.

Steps:

  1. Wherever you are using a Text or TextMeshPro component in your game UI, you need to add the “LocalizedText” component via Inspector or script in the Awake() method of your script also and need to define a key for the same. This key must be unique for all of your text. This “LocalizedText” script is present in the WinZO’s sample SDK. You do not need to include “LocalizedText” script in your Unity package when you are exporting the package to be submitted.

For Example: Assign a key if you are adding “LocalizedText” component via script.

public Text pleaseWait;
 startPlaying.GetOrAddComponent<LocalizedText>().key =
 "please_wait";
  1. Add Key and its translated value in that particular json file. For Hindi and Portuguese, localizedText_hi.json and localizedText_po.json are already present in the sample project. Note: (i) Key must be the same in all languages and must be the same as you assign in LocalisedText during adding the component to your Text. (ii) This key must be in this format: "gamename_key" where gamename should be same as your game name and key can be any string. For Example: For Hindi Language: Add key and value in below file

For Portuguese Language: Add key and value in below file

Run Time Localisation

Run Time Localisation of a text means the value of the text will change at runtime.

  1. Create a (GameName+Strings.cs) class within your namespace and add all the Text strings of your game along with their key. Eg. MetroSurferStrings.cs For Example:

    The first parameter is the Original English translation string and the second is the key.

public static StringPair Points = new StringPair("Points",
 "please_wait");

If you are playing the game in English language and have not set up the text value in Game UI then we fill the text from this variable using this key. In English language it will take the value from this key and if we are using other languages then it will take the key from here and search the value of that key in its perspective json file.

2. We have 2 json files (LocalizedText_hi.json and LocalizedText_po.json). Add a key value pair in this file, remember to use the same key and write its value in the specific language.

Example: In LocalizedText_hi.json

{
"k": "sp_points",
"v": "अंक"
}#

In LocalizedText_po.json

{
"k" : "sp_points",
"v" :"Pontos"
}
  1. You have set up the localisation of your game now lets see how you can use this in your game. Go to your script where you are using the text. Get the localized value by using the above key and assign that value to your text.

 void SetupLocalization()
 {
    var textNumber =
    LocalizationManager.instance.GetLocalizedValue(Strings.sp_points);
    dummyTxt.GetOrAddComponent<LocalizedText>().key =
    Strings.sp_points.key;
    dummyTxt.text = textNumber;
    dummyTxt.GetOrAddComponent<LocalizedText>().LocalizeText();
 }

Note: If you want to localize the text and append a number to the text, you can use the format only option available in LocalizedText script.

Example:

void SetupLocalization2()
{
  var count = 2;
  var textnumber; Text dummyTxt; textnumber =
  LocalizationManager.instance.GetLocalizedValue(Strings.sp_points);
  dummyTxt.GetOrAddComponent<LocalizedText>().formatOnly = true;
  dummyTxt.GetOrAddComponent<LocalizedText>().key = 
  Strings.sp_points.key;
  dummyTxt.text = textnumber + $"({count})";
  dummyTxt.GetOrAddComponent<LocalizedText>().LocalizeText();
}

Last updated