I2 Localization allows accessing the translations from scripts by calling


string text1 = I2.Loc.LocalizationManager.GetTranslation("Tutorial/MyKEY");


However this could lead to typos or wrong names that are really hard to track. For instance, you could accidentally be asking for ("Tutorial/MyKEy", or "Tutoria/MyKEY") which will fail.


To help write safer scripts, the plugin allows avoiding typing the name of the term your self and instead, a script can be generated with properties that do the access for you.



Just open the Tools Tab and then select the Script Tool.

Then select the terms you are going to access from your code and click Bake.


That will generate a class similar to this one:


public static class ScriptLocalization

{

       public static string MyKey { get{ return LocalizationManager.GetTranslation ("MyKey"); } }


       public static class Tutorial

       {

               public static string MyKey { get{ return LocalizationManager.GetTranslation ("Tutorial/MyKey"); } }

       }

}


public static class ScriptTerms

{

       public const string MyKey = "MyKey";


       public static class Tutorial

       {

               public const string MyKey = "Tutorial/MyKey";

       }

}


ScriptLocalization will allow you to access the translations without using strings. All terms are now properties that return the translation to the current language. This way, there is no way to add Typos or wrong string without having the compiler warning you about it.

Also, ScriptTerms return the Key name in case you need to call LocalizationManager.GetTranslation directly. This is useful if you need custom parameters when calling GetTranslation to control RTL, modifiers, parameters, etc.



string text1 = I2.Loc.ScriptLocalization.MyKEY;                      // instead of I2.Loc.ScriptLocalization("MyKEY")

string text2 = I2.Loc.ScriptLocalization.Tutorial.MyKEY;          // instead of I2.Loc.ScriptLocalization("Tutorial/MyKEY")

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


string text3 = I2.Loc.LocalizationManager.GetTranslation( ScriptTerms.Tutorial ); // instead of I2.Loc.ScriptLocalization("Tutorial/MyKEY")



Created with the Personal Edition of HelpNDoc: Full-featured Help generator