Click or drag to resize

LocalizationLoaderLoadItemsInModule Method

Localizes the PartModule items.

Namespace:  KSPDev.GUIUtils
Assembly:  KSPDev_Utils.2.3 (in KSPDev_Utils.2.3.dll) Version: 2.3 for KSP v1
Syntax
C#
public static void LoadItemsInModule(
	PartModule module
)
Request Example View Source

Parameters

module
Type: (Default Namespace)PartModule
The module instance to localize.
Remarks

The localizable items must be declared as non-static public or protected members. The following items are supported:

  • KSPField. This type may have multiple localization items: for guiName (spec=null) and for guiUnits (spec=Units).
  • KSPEvent.
  • KSPAction.

The original KSP attributes don't need to specify guiName field since it will be overwritten anyway. However, it's a good idea to give a default value just in case.

This method can be called at any time during the module's life. However, the LocalizeModule method looks the most appropriate.

Examples
public class LocalizationLoaderDemo1 : PartModule {
  public class OtherModule : PartModule {
    [KSPField(guiName = "just-in-case text", guiActive = true)]
    [LocalizableItem(tag = "#tag1")]
    public string field1 = "";
  }

  public void AddCustomModule() {
    var newModule = gameObject.AddComponent<OtherModule>();
    LocalizationLoader.LoadItemsInModule(newModule);
  }
}
Examples
public class LocalizationLoaderDemo2 : PartModule, IsLocalizableModule {
  [KSPField(guiActive = true)]
  [LocalizableItem(tag = "#tag1", defaultTemplate = "Field1")]
  [LocalizableItem(tag = "#tag2", defaultTemplate = "units",
                   spec = StdSpecTags.Units)]
  public string field1 = "";

-  #region IsLocalizableModule implementation
   public void LocalizeModule() {
     LocalizationLoader.LoadItemsInModule(this);
   }
   #endregion

  public override void OnAwake() {
    base.OnAwake();
    LocalizeModule();
  }
}
See Also