Unity Localize Dropdown Component

We cannot localize the dropdown component using com.unity.localization library, so I created a simple dropdown localize component for this purpose. Its usage is as follows:

I assume that you have created a Localization Table and set up contents.

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

  • In the newly added Localize Dropdown Component, we add items corresponding to the Dropdown options, and the final result will be as follows:

Localize Dropdown Component Code;

using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Localization;
using UnityEngine.Localization.Settings;
using TMPro;
using UnityEditor;

public class LocalizeDropdown : MonoBehaviour
{
    [SerializeField] private List dropdownOptions;
    private TMP_Dropdown _tmpDropdown;
 
    private void Awake()
    {
        if (_tmpDropdown == null)
            _tmpDropdown = GetComponent();
        
        LocalizationSettings.SelectedLocaleChanged += ChangedLocale;
    }
 
    private void ChangedLocale(Locale newLocale)
    {
        List tmpDropdownOptions = new List();
        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();
        }
    }
}

Translation is being performed between lines 8 and 30, and a Localize Dropdown Component is being added between lines 32 and 44.