Localization Support

Default ListViewIcons and TreeView

ListViewIcons and TreeView items have LocalizedName field, and you can use it for localization support.

using UnityEngine;
using System.Collections;
using UIWidgets;

[RequireComponent(typeof(ListViewIcons))]
public class ListViewIconsLocalization : MonoBehaviour
{
   ListViewIcons targetListView;

   public ListViewIcons TargetListView;
   {
      get
      {
         if (targetListView==null)
         {
            targetListView = GetComponent<ListViewIcons>();
         }

         return targetListView;
      }
   }

   void Start()
   {
      LocalizationSystem.OnLanguageChanged += Localization;
      Localization();
   }

   void OnDestroy()
   {
      LocalizationSystem.OnLanguageChanged -= Localization;
   }

   public void Localization()
   {
      TargetListView.DataSource.BeginUpdate();
      TargetListView.DataSource.ForEach(x => x.LocalizedName = LocalizationSystem.getLocalizedString(x.Name));
      TargetListView.DataSource.EndUpdate();
   }
}

Generated ListView, TreeView, TileView

You can change component class to add localization support.

public class SomeItemComponent : ListViewItem, IViewData<SomeItem>
{
   SomeItem item;

   void Start()
   {
      LocalizationSystem.OnLanguageChanged += Localization;
   }

   void OnDestroy()
   {
      LocalizationSystem.OnLanguageChanged -= Localization;
   }

   public virtual void SetData(SomeItem newItem)
   {
      item = newItem;
      Localization();
   }

   public virtual void Localization()
   {
      Text.text = item.LocalizedField ?? item.OriginalField;

      Description.text = LocalizationSystem.getLocalizedString(item.Description);
   }
}

If you need sorting for some fields, you can add special fields for localization. For other fields, you can apply localization in Component.SetData() function.

Comparison<SomeItem> ItemsComparison = (x, y) => (x.LocalizedField ?? x.OriginalField).CompareTo(y.LocalizedField ?? y.OriginalField);
ListView.DataSource.Comparison = ItemsComparison;

Tabs

Use derived class from TabButtonComponent for Tabs with overridden SetButtonData method or TabIconActiveButton and TabIconDefaultButton for TabsIcons with overridden SetData method.

public class TabButtonComponentLocalized : TabButtonComponent
{
   public override void SetButtonData(Tab tab)
   {
      Name.text = LocalizationSystem.getLocalizedString(tab.Name);
   }
}

public class TabIconActiveButtonLocalized : TabIconActiveButton
{
   public override void SetData(TabIcons tab)
   {
      base.SetData(tab);
      Name.text = LocalizationSystem.getLocalizedString(tab.Name);
   }
}