Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Bug I'm not able to create a Drop Down menu with the languages

Discussion in 'Localization Tools' started by djovercome, Aug 8, 2022.

  1. djovercome

    djovercome

    Joined:
    Jun 4, 2022
    Posts:
    3
    This is my code:

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.Localization;
    using UnityEngine.UI;


    public class LocaleDropdown : MonoBehaviour
    {
    public Dropdown dropdown;

    IEnumerator Start()
    {
    // Wait for the localization system to initialize, loading Locales, preloading etc.
    yield return LocalizationSettings.InitializationOperation;

    // Generate list of available Locales
    var options = new List<Dropdown.OptionData>();
    int selected = 0;
    for(int i = 0; i < LocalizationSettings.AvailableLocales.Locales.Count; ++i)
    {
    var locale = LocalizationSettings.AvailableLocales.Locales;
    if (LocalizationSettings.SelectedLocale == locale)
    selected = i;
    options.Add(new Dropdown.OptionData(locale.name));
    }
    dropdown.options = options;

    dropdown.value = selected;
    dropdown.onValueChanged.AddListener(LocaleSelected);
    }

    static void LocaleSelected(int index)
    {
    LocalizationSettings.SelectedLocale = LocalizationSettings.AvailableLocales.Locales[index];
    }
    }


    my error:
    Assets\Scripts\Globals\LocaleDropdown.cs(34,47): error CS0103: The name 'LocalizationSettings' does not exist in the current context
     

    Attached Files:

  2. salman_unity26

    salman_unity26

    Joined:
    Jul 30, 2022
    Posts:
    1
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.Localization.Settings;
    using UnityEngine.UI;

    public class LocaleDropdown : MonoBehaviour
    {
    public Dropdown dropdown;

    IEnumerator Start()
    {
    // Wait for the localization system to initialize, loading Locales, preloading etc.
    yield return LocalizationSettings.InitializationOperation;

    // Generate list of available Locales
    var options = new List<Dropdown.OptionData>();
    int selected = 0;
    for (int i = 0; i < LocalizationSettings.AvailableLocales.Locales.Count; ++i)
    {
    var locale = LocalizationSettings.AvailableLocales.Locales;
    if (LocalizationSettings.SelectedLocale == locale)
    selected = i;
    options.Add(new Dropdown.OptionData(locale.name));
    }
    dropdown.options = options;

    dropdown.value = selected;
    dropdown.onValueChanged.AddListener(LocaleSelected);
    }

    static void LocaleSelected(int index)
    {
    LocalizationSettings.SelectedLocale = LocalizationSettings.AvailableLocales.Locales[index];

    }
    }