Search Unity

Bug Localization doesn't work on Scene Change

Discussion in 'Localization Tools' started by aqsanadeem82, Sep 5, 2022.

  1. aqsanadeem82

    aqsanadeem82

    Joined:
    Sep 15, 2018
    Posts:
    76
    I have the settings to select the language in the main menu it works fine in the main menu when I change the language from English to Portuguese, but when I change the scene the language reverts back to English(default), even though The selected language shown above in the Editor is Portuguese.

    Another Problem is Sometimes When I show 2 Text boxes one after another when Portuguese is selected, The first one appears in Portuguese but the second one appears in English even though again The selected language shown above in the Editor is Portuguese.


    upload_2022-9-5_15-54-21.png
    upload_2022-9-5_15-55-7.png
     
  2. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,293
    How are these text boxes being localized? Are you using a LocalizedStringEvent or a custom script?
    When you switch language through the language bar do they update or always stay in English?
     
  3. aqsanadeem82

    aqsanadeem82

    Joined:
    Sep 15, 2018
    Posts:
    76
    I am using localized string events, They do update when I change the language in main menu but as soon as I change the scene they switch back to english. upload_2022-9-5_16-4-6.png
     
  4. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,293
    Are you able to share the project so I can take a look at what's going wrong?
     
  5. aqsanadeem82

    aqsanadeem82

    Joined:
    Sep 15, 2018
    Posts:
    76
  6. aqsanadeem82

    aqsanadeem82

    Joined:
    Sep 15, 2018
    Posts:
    76
    And these are my settings
    upload_2022-9-5_16-18-33.png
     
  7. aqsanadeem82

    aqsanadeem82

    Joined:
    Sep 15, 2018
    Posts:
    76
    And the table upload_2022-9-5_16-19-18.png
     
  8. aqsanadeem82

    aqsanadeem82

    Joined:
    Sep 15, 2018
    Posts:
    76
    Can't share the project At the moment but these are the settings, you need to see anything else I can show you.
     
  9. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,293
    Nothing stands out from the screenshots.
    Can you show a screenshot of the Text components and its LocalizeStringEvent inspector when its showing the wrong language?

    Are you able to reproduce it in a new project?
     
  10. aqsanadeem82

    aqsanadeem82

    Joined:
    Sep 15, 2018
    Posts:
    76
  11. aqsanadeem82

    aqsanadeem82

    Joined:
    Sep 15, 2018
    Posts:
    76
    Here is the script that I am using



    Code (CSharp):
    1.  public static LocalizationScript Instance;
    2.     public Locale english,estonian,finnish,french,german,indonesian,norwegian,portugese,russian,spanish,turkish;
    3.     LocalizationSettings settings;
    4.     bool selectLanguage = false;
    5.     public GameObject LanguageSelection;
    6.     public int languageindex;
    7.     // Start is called before the first frame update
    8.     void Awake()
    9.     {
    10.         DontDestroyOnLoad(this.gameObject);
    11.         Instance = this;
    12.         settings = LocalizationSettings.Instance;
    13.     }
    14.  
    15.     // Update is called once per frame
    16.     void Update()
    17.     {
    18.         if (!selectLanguage && LocalizationSettings.InitializationOperation.IsDone)
    19.         {
    20.              SelectLanguage(PlayerPrefs.GetInt("Language"));
    21.         }
    22.     }
    23.     public void SelectLanguage(int index)
    24.     {
    25.  
    26.      
    27.         if (index == 0)
    28.             ChangeLanguage(0, "en", english);
    29.         if (index == 1)
    30.             ChangeLanguage(1, "et", estonian);
    31.         if (index == 2)
    32.             ChangeLanguage(2, "fi", finnish);
    33.         if (index == 3)
    34.             ChangeLanguage(3, "fr", french);
    35.         if (index == 4)
    36.             ChangeLanguage(4, "de", german);
    37.         if (index == 5)
    38.             ChangeLanguage(5, "id", indonesian);
    39.         if (index == 6)
    40.             ChangeLanguage(6, "no", norwegian);
    41.         if (index == 7)
    42.             ChangeLanguage(7, "pt", portugese);
    43.         if (index == 8)
    44.             ChangeLanguage(8, "ru", russian);
    45.         if (index == 9)
    46.             ChangeLanguage(9, "es", spanish);
    47.         if (index == 10)
    48.             ChangeLanguage(10, "tr", turkish);
    49.     }
    50.     void ChangeLanguage(int index, string language,Locale localeName)
    51.     {
    52.         languageindex = index;
    53.         settings.SetSelectedLocale(localeName);
    54.         LocalizationSettings.SelectedLocale = LocalizationSettings.AvailableLocales.Locales[index];
    55.         PlayerPrefs.SetInt("Language", index);
    56.         LanguageSelected();  
    57.     }
    58.  
    59.  
    60.     void LanguageSelected()
    61.     {
    62.         selectLanguage = true;
    63.       //  LanguageSelection.gameObject.SetActive(false);
    64.     }
     
    Last edited: Sep 5, 2022
  12. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,293
    There's a problem with your language changer script. Don't hold public references to Locales in script. It will create duplicates in the build.
    Instead use the LocaleIdentifier struct.
    Also don't use player prefs, instead add the Player pref selector to the localization settings locale selectors. Move it to the top of the list.

    Also try disabling WaitForCompletion on the localized string event for the object that is not working. See if that makes a difference.
     
  13. aqsanadeem82

    aqsanadeem82

    Joined:
    Sep 15, 2018
    Posts:
    76
    Okay, I will try. But this script only works once in the main menu, which shows correct language, when I change the scene the script does not destroy on load and there is no change made, but there the text does not show correctly, but I will try what you just said.
     
  14. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,293
    The language menu problems are unlikely to be the cause of the original issue but they will create new problems once you start building the game.

    WaitForCompletion could be the issue though.
     
  15. aqsanadeem82

    aqsanadeem82

    Joined:
    Sep 15, 2018
    Posts:
    76
    Okay I did try to disable WaitForCompletion but it did not work, one more thing when I try to change the language back to English and then again Portuguese while in the level scene then I can see the language being changed on the text component.
     
  16. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,293
    I'm afraid I'm out of ideas. We will need a bug report with a reproduction project that shows this issue so we can debug and understand what's going on.
     
  17. aqsanadeem82

    aqsanadeem82

    Joined:
    Sep 15, 2018
    Posts:
    76
    There is another thing I have noticed, there is a text called Level, its value is changing in the new scene because it's an Active component when the scene is started. But the dialogues are inactive at the start of the scene, they are made active after a few seconds. Only dialogue text is not changing.
     
  18. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,293
    I don't believe this would make a difference.
    Do you have any errors or warnings in the log?
     
  19. aqsanadeem82

    aqsanadeem82

    Joined:
    Sep 15, 2018
    Posts:
    76
  20. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,293
    Is that the default text being shown? The text that is set in the Tmp component?