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

Question How to change locale language via script?

Discussion in 'Localization Tools' started by GPaduanoImmerxive, Sep 26, 2022.

  1. GPaduanoImmerxive

    GPaduanoImmerxive

    Joined:
    Jan 19, 2022
    Posts:
    14
    Hi, I'm trying to change via script the selected Locale by pressing a button.

    Is there a specific way to do this?

    By searching on internet I found following solution but it doesn't work:

    Code (CSharp):
    1. LocalizationSettings.SelectedLocale.Identifier = languageIdentifier;
    I've tried also to change directly the SelectedLocale but nothing...

    Code (CSharp):
    1. LocalizationSettings.SelectedLocale = newLocale;
    Can you help me please? Thank you :)
     
  2. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    7,876
  3. GPaduanoImmerxive

    GPaduanoImmerxive

    Joined:
    Jan 19, 2022
    Posts:
    14
    Hi, thank you so much for the answer, as always :).

    I don't know why, Unity was "stuck" and, restarting it, it started to work right again.

    The following code represents my simple solution and it works great for my purpose.

    Code (CSharp):
    1. public void SetNewLocale()
    2. {
    3.     switch (language)
    4.     {
    5.         case "en":
    6.             LocalizationSettings.SelectedLocale = LocalizationSettings.AvailableLocales.Locales[0];
    7.             break;
    8.         case "fr":
    9.             LocalizationSettings.SelectedLocale = LocalizationSettings.AvailableLocales.Locales[1];
    10.             break;
    11.         case "it":
    12.             LocalizationSettings.SelectedLocale = LocalizationSettings.AvailableLocales.Locales[2];
    13.             break;
    14.         case "es":
    15.             LocalizationSettings.SelectedLocale = LocalizationSettings.AvailableLocales.Locales[3];
    16.             break;
    17.         default:
    18.             break;
    19.     }
    20. }
     
    grams and karl_jones like this.