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

Bug Locales are not equal

Discussion in 'Localization Tools' started by denis_bogdanov, Jul 23, 2022.

  1. denis_bogdanov

    denis_bogdanov

    Joined:
    Apr 20, 2015
    Posts:
    135
    Hello!

    If I compare locales in the editor, everything is fine (code below), but if on android, it shows they are not equal. Am I doing something wrong?

    Code (CSharp):
    1. public class TestWordTarget: Monobehaviour{
    2.  
    3.     public List<LanguageSearch> languageSearch;
    4.     public Locale testLocale;
    5.  
    6.         public string GetWordId()
    7.     {
    8.         var targetLocale = testLocale == null ? LocalizationSettings.SelectedLocale : testLocale;
    9.         var obj = languageSearch.Find(q => q.locale == targetLocale);
    10.  
    11.         if (obj != null)
    12.         {
    13.             GameLog.Print("Current:", targetLocale, obj.wordId);
    14.             return obj.wordId;
    15.         }
    16.  
    17.         GameLog.Print("Current:", targetLocale, null, "en");
    18.  
    19.         return "en";
    20.     }
    21.    
    22.   public void Print()
    23.     {      
    24.             var selectedLocale = LocalizationSettings.SelectedLocale;
    25.  
    26.             for (int i = 0; i < languageSearch.Count; i++)
    27.             {
    28.                 GameLog.Print(
    29.                             languageSearch[i].wordId,
    30.                             languageSearch[i].locale,
    31.                             languageSearch[i].locale == selectedLocale
    32.                     );
    33.             }
    34.     }
    35.  
    36. }
    37.  
    38.  
    39. [System.Serializable]
    40. public class LanguageSearch
    41. {
    42.     public string wordId;
    43.     public Locale locale;
    44. }
    45.  
    index.jpg
     
  2. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    7,845
    Locales should not be referenced like that. When you build the addressables it will pack the locales Into asset bundles, referencing them via a script will create duplicates.
    Try using the LocaleIdentifier to reference them.
     
    denis_bogdanov likes this.
  3. denis_bogdanov

    denis_bogdanov

    Joined:
    Apr 20, 2015
    Posts:
    135
    Thank you, it works!
     
    karl_jones likes this.