public void UpdateLocalization() { var dropdown = GetComponent <Dropdown>(); var dOptions = dropdown.options; if (options != null) { for (var i = 0; i < options.Count; i++) { var option = options[i]; var dOption = default(Dropdown.OptionData); if (dOptions.Count == i) { dOption = new Dropdown.OptionData(); dOptions.Add(dOption); } else { dOption = dOptions[i]; } var stringTranslation = LeanLocalization.GetTranslation(option.StringTranslationName); // Use translation? if (stringTranslation != null && stringTranslation.Data is string) { dOption.text = LeanTranslation.FormatText((string)stringTranslation.Data, dOption.text, this); } // Use fallback? else { dOption.text = LeanTranslation.FormatText(option.FallbackText, dOption.text, this); } var spriteTranslation = LeanLocalization.GetTranslation(option.StringTranslationName); // Use translation? if (spriteTranslation != null && spriteTranslation.Data is Sprite) { dOption.image = (Sprite)spriteTranslation.Data; } // Use fallback? else { dOption.image = option.FallbackSprite; } } } else { dOptions.Clear(); } dropdown.options = dOptions; }
// Call this to force the behaviour to get updated public void UpdateLocalization() { UpdateTranslation(LeanLocalization.GetTranslation(phraseName)); }