Skip to content

Instantly share code, notes, and snippets.

@alisahanyalcin
Created April 24, 2023 09:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alisahanyalcin/c9512807d6d418019ca87c8454938110 to your computer and use it in GitHub Desktop.
Save alisahanyalcin/c9512807d6d418019ca87c8454938110 to your computer and use it in GitHub Desktop.
Unity Localize Dropdown Component
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Localization;
using UnityEngine.Localization.Settings;
using TMPro;
using UnityEditor;
public class LocalizeDropdown : MonoBehaviour
{
[SerializeField] private List<LocalizedString> dropdownOptions;
private TMP_Dropdown _tmpDropdown;
private void Awake()
{
if (_tmpDropdown == null)
_tmpDropdown = GetComponent<TMP_Dropdown>();
LocalizationSettings.SelectedLocaleChanged += ChangedLocale;
}
private void ChangedLocale(Locale newLocale)
{
List<TMP_Dropdown.OptionData> tmpDropdownOptions = new List<TMP_Dropdown.OptionData>();
foreach (var dropdownOption in dropdownOptions)
{
tmpDropdownOptions.Add(new TMP_Dropdown.OptionData(dropdownOption.GetLocalizedString()));
}
_tmpDropdown.options = tmpDropdownOptions;
}
}
public abstract class AddLocalizeDropdown
{
[MenuItem("CONTEXT/TMP_Dropdown/Localize", false, 1)]
private static void AddLocalizeComponent()
{
// add localize dropdown component to selected gameobject
GameObject selected = Selection.activeGameObject;
if (selected != null)
{
selected.AddComponent<LocalizeDropdown>();
}
}
}
@alisahanyalcin
Copy link
Author

alisahanyalcin commented Apr 24, 2023

How To

  • Right-click on the Dropdown Component and select the "Localize" option at the bottom
    image

  • Add localize options
    image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment