How to access the localization from the scripts

There are several API functions available, these are the most used ones.

// Get the translation of MyKey into the Current Language

string text1 = I2.Loc.ScriptLocalization.Get("MyKEY");                      // Term in the Default (empty) category

string text2 = I2.Loc.ScriptLocalization.Get("Tutorial/MyKEY");          // Term in the Tutorial category

string text2 = I2.Loc.ScriptLocalization.Get("Tutorial/Tips/MyKEY");   // Nested Categories

Safer way to access the translations

However, given that accessing a term using a string can lead to typos or missing terms that are hard to find without doing lot of QA, the plugin supports another way of accessing the Translations.

By using the Scripts Tool, you can generate a script containing variables that directly accesses the terms. That removes the need to type names yourself and avoids typos. Furthermore, if any term changes or get deleted, Unity will generate a Compile Error that will alert you of the missing term.

// The previous examples could be rewritten in this way for safer access:

string text1 = I2.Loc.ScriptLocalization.MyKEY;                      // MyKey is a generated property

string text2 = I2.Loc.ScriptLocalization.Tutorial.MyKEY;          // MyKey is a property inside the Tutorial structure

string text2 = I2.Loc.ScriptLocalization.Tutorial.Tips.MyKEY;

Notice, that for this to work, you first need to run the Scripts Tool and select which Terms should be baked into the Scripts.

Created with the Personal Edition of HelpNDoc: Free EPub and documentation generator