Get a list of locales that you've created
- Windows 11
- Unity Editor
- Input System (Unity Technologies)
- Localization (Unity Technologies)
Prerequisites for this tip
The following settings have been made in advance as a premise for the description of this tip.
Goals of our tips
Displays a list of corresponding locales in the drop-down UI and toggles the display text to match the locale selected by the user.
Prerequisite knowledge and preparation
This tip assumes localization of the following text: First, please refer to the following tips to prepare to display localized text.
- Switching the text of a text object to match the environment in which the text is multilingually supported
Locale change drop-down placement
Provides a drop-down to display a list of locales. You only need to be able to display and select, so make sure that the UI parameters are set appropriately.
Get a list of locales
You can get a list of locales
LocalizationSettings.AvailableLocales.Locales created in .
If you use this and set it to the drop-down at the start of the scene, you are OK.
However, initialization may not have completed when
Localization you start the game, so you may need to wait for it to complete.
First, create a script.
DropDownEvent Leave the name as .
The script looks like this:
public class DropDownEvent : MonoBehaviour
async void Start()
// Localization の初期化が完了するまで待機します
// 処理対象の Dropdown コンポーネントを取得します
var dropdownLocale = GetComponent<Dropdown>();
// LocalizationSettings.AvailableLocales.Locales からロケール一覧を取得してオプションを追加します
foreach (var locale in LocalizationSettings.AvailableLocales.Locales)
dropdownLocale.value = LocalizationSettings.AvailableLocales.Locales.IndexOf(LocalizationSettings.SelectedLocale);
LocalizationSettings.SelectedLocale = LocalizationSettings.AvailableLocales.Locales[index];
Start The method performs processing at the start of the scene, but at this point
Localization , the initialization of may not have been completed.
await LocalizationSettings.InitializationOperation.Task Wait for initialization to complete.
await , so
Start please add it to the
LocalizationSettings.AvailableLocales.Locales Next, contains a list of locales that you created, so
foreach process as many locales as you want.
Dropdown the locale name to and add it to .
Dropdown.value the current locale in the drop-down, search for the target locale in the property and set the index.
This is the end of creating the list, but I also want to include a process that changes the locale when the drop-down item is selected.
onValueChanged Adds locale switching to the event. This is the same as the previous tip.
Attach the script you created to the dropdown.
Run and verify
Try running the game to check it out.
There is a time when the locale list is not set immediately after the game starts,
Localization because is not initialized.
After a little time, you should be able to see the list of locales registered in the dropdown. If you try switching items, you should be able to see that the content of the text changes.