Author Topic: Key not being found bug  (Read 2643 times)

apple741

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 17
    • View Profile
Key not being found bug
« on: May 17, 2014, 09:34:01 AM »
Hello,

I think I have found a bug, I check if my localisation key exists, the if statement below reports false but the debug still prints the correct value?

  1.  
  2. if (Localization.Exists(testString)
  3.                         {
  4.                                 myLabel.text = Localization.Get(testString);
  5.                         }
  6. else
  7.                         {
  8.                                
  9.                                 Debug.Log(Localization.Get(testString);
  10.                         }
  11.  
  12.  
  13.  

Any thoughts on what could be going wrong?
« Last Edit: May 17, 2014, 12:45:21 PM by apple741 »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Key not being found bug
« Reply #1 on: May 17, 2014, 06:42:40 PM »
I'm guessing the localization hasn't been loaded yet? Try replacing Localization.Exists with the following:
  1.         static public bool Exists (string key)
  2.         {
  3.                 // Ensure we have a language to work with
  4.                 if (!localizationHasBeenSet) language = PlayerPrefs.GetString("Language", "English");
  5.  
  6. #if UNITY_IPHONE || UNITY_ANDROID
  7.                 string mobKey = key + " Mobile";
  8.                 if (mDictionary.ContainsKey(mobKey)) return true;
  9.                 else if (mOldDictionary.ContainsKey(mobKey)) return true;
  10. #endif
  11.                 return mDictionary.ContainsKey(key) || mOldDictionary.ContainsKey(key);
  12.         }