Localisation using SpreadSheets

Note: Tutorial implementation can be found under GD_ExampleLocalization example scene

Let’s create a simple localization script using the spreadsheet as a data source. As an example data source will use the Localisation worksheet from the Google Doc Connector Example doc.



Instead of the first two tutorials, here we are going to use the Scripting API instead of editor implementation. The implementation can be found in.

Create LocalizationFromDocExample script and attach it to any Game object on the scene.

We will need to create a Dictionary where we will store our localization data and List of available languages.

private List<string> LangCodes;
private Dictionary<string, Dictionary<string, string>> languages =  new Dictionary<string, Dictionary<string, string>>();

//Also letâââ‰â¢s define constant values
private const string DOC_NAME = "Google Doc Connector Example";
private const string LOCALIZATION_WORK_SHEET_NAME = "Localization";


Now on Awake function we can retrieve all data for our localization Dictionary. Code example below.

//Getting avaliable languages codes:
GDCellRange range = new GDCellRange("B1");
LangCodes = GoogleDocAPI.GetList<string>(DOC_NAME, range, LOCALIZATION_WORK_SHEET_NAME);

//creating range of keys (tcokens);
GDCellRange keysRange = new GDCellRange("A2", GDRanageDirection.Collumn);

foreach(string lang in LangCodes) {
//creating dictionary range for current language
//the row shift is 0
//the coll shoft is lang index in LangCodes list
GDCellDictionaryRange dict = new GDCellDictionaryRange(keysRange, LangCodes.IndexOf(lang) + 1, 0);
//filling languages dictionary
languages.Add(lang, GoogleDocAPI.GetDictionary<string, string>(DOC_NAME, dict, LOCALIZATION_WORK_SHEET_NAME));


//Setting defult language code and retriving all avaliables tockens
//this section is only for demo GUI redner
tokens = GoogleDocAPI.GetList<string>(DOC_NAME, keysRange, LOCALIZATION_WORK_SHEET_NAME);
currentLangCode = LangCodes[0];

//Function that will return localized string by the token
private string GetLocalizedString(string langCode, string tocken) {
       if(languages.ContainsKey(langCode)) {
           if(languages[langCode].ContainsKey(tocken)) {
               return languages[langCode][tocken];
       return string.Empty;


Now the only thing left to do is  to print our localized strings and implement the ability to switch between available languages. We will use Unity native GUI for this function.

private List<string> tokens;
private string currentLangCode;
void OnGUI() {
  int x = 10;
  int y = 10;
  foreach(string lang in LangCodes) {
    if(GUI.Button( new Rect(x, y, 140, 60), lang)) {
      currentLangCode = lang;
    x += 170;

  x = 10;
  y = 100;

  foreach(string token in tokens) {
      GUI.Label(new Rect(x, y, 140, 20),"Token: " + token, GUITextStyle);
      GUI.Label(new Rect(x + 300, y, 140, 20),"Localized String: " + GetLocalizedString(currentLangCode, token), GUITextStyle);
  y += 25;


As an example, we will have a GUI with printed localization and ability to switch between languages: