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. Dismiss Notice

Localize Texture Empty Table Reference

Discussion in 'Localization Tools' started by satchell, Jan 5, 2020.

  1. SDX_2012

    SDX_2012

    Joined:
    Jul 31, 2019
    Posts:
    6
    Yes, game detects phone language and if it matches one of the availables it assigns it. Otherwise default language is selected.
    This is done in a coroutine when the first scene calls start()

    Code (CSharp):
    1. string activeLocale = LANGUAGE_ENGLISH; //Default
    2. if (Application.systemLanguage == SystemLanguage.Spanish)
    3.     activeLocale = LANGUAGE_SPANISH;
    4.  
    5. activeLocaleIndex = 0;
    6. for (int i = 0; i < LocalizationSettings.AvailableLocales.Locales.Count; ++i)
    7. {
    8.     var locale = LocalizationSettings.AvailableLocales.Locales[i];
    9.     if (locale.Identifier.Code.Equals(activeLocale))
    10.     {
    11.         activeLocaleIndex = i;
    12.         break;
    13.     }
    14. }
    15. LocalizationSettings.SelectedLocale = LocalizationSettings.AvailableLocales.Locales[activeLocaleIndex];
    16. localeInitialized = true;
    maybe localization was called before coroutine finishes?
    I should assign default value even before coroutine starts right?
    thanks
     
  2. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    7,845
    Yes thats whats wrong.
    Ok you should be able to move this code into a custom LocaleSelector, thats what it's for ;)

    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using UnityEngine.Localization;
    4. using UnityEngine.Localization.Settings;
    5.  
    6. [System.Serializable]
    7. public class MyLocaleSelector : IStartupLocaleSelector
    8. {
    9.     public LocaleIdentifier activeLocale;
    10.  
    11.     public Locale GetStartupLocale(ILocalesProvider availableLocales)
    12.     {
    13.         if (Application.systemLanguage == SystemLanguage.Spanish)
    14.             return availableLocales.GetLocale("es");
    15.  
    16.         for (int i = 0; i < availableLocales.Locales.Count; ++i)
    17.         {
    18.             var locale = availableLocales.Locales[i];
    19.             if (locale.Identifier.Code.Equals(activeLocale))
    20.             {
    21.                 return locale;
    22.             }
    23.         }
    24.         Debug.LogError("Could not set locale");
    25.         return null;
    26.     }
    27. }
    28.  
    29.  
    This will now be called during initialization.
    Just click on the LocalizationSettings and click the + button under Locale Selectors to add it. You can remove all the others if you dont need them.

    upload_2020-6-10_14-27-38.png
     
    Last edited: Jun 10, 2020
    tealm likes this.
  3. SDX_2012

    SDX_2012

    Joined:
    Jul 31, 2019
    Posts:
    6
    Thanks a lot for the detailed explanation! I'll change it!
     
    karl_jones likes this.