Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

GetLocalizedStringAsync not work

Discussion in 'Localization Tools' started by SinedDV, Sep 23, 2020.

  1. SinedDV

    SinedDV

    Joined:
    Sep 23, 2020
    Posts:
    9
    Hi, All!
    Simple code:
    Code (CSharp):
    1.  
    2. public class Test : MonoBehaviour
    3. {
    4.     LocalizationSettings Instance;
    5.  
    6.     public string GetKeyTitle(KeyCode keyCode)
    7.     {
    8.         string reference = "F1";//keyCode.ToString();
    9.  
    10.         //print(reference);
    11.  
    12.         var loadAsync = Instance.GetStringDatabase().GetLocalizedStringAsync(reference); //"Keys",
    13.         while (!loadAsync.IsDone) continue;
    14.         return loadAsync.Result;
    15.     }
    16.  
    17.     IEnumerator Start()
    18.     {
    19.         // Wait for the localization system to initialize, loading Locales, preloading etc.
    20.         yield return LocalizationSettings.InitializationOperation;
    21.  
    22.         Instance = LocalizationSettings.InitializationOperation.Result;
    23.  
    24.         print("Ready");
    25.     }
    26.  
    27.     // Update is called once per frame
    28.     void Update()
    29.     {
    30.         if (Input.GetKeyDown(KeyCode.F1))
    31.         {
    32.             print("Input.GetKeyDown(KeyCode.F1)");
    33.  
    34.             print(GetKeyTitle(KeyCode.F1));
    35.         }
    36.     }
    37. }
    With errors. Key "F1" exist. Need Help...
     

    Attached Files:

  2. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,410
    When you only pass in a key then it will use the default table, it looks like you have not assigned a default table. Check the Localisation settings under string database
     
    SinedDV likes this.
  3. SinedDV

    SinedDV

    Joined:
    Sep 23, 2020
    Posts:
    9
    Thanks a lot for the quick response! It helped.
    Found another way :)
    Your package is great!

    Code (CSharp):
    1. public class Test : MonoBehaviour
    2. {
    3.     LocalizedStringTable m_StringTable = new LocalizedStringTable { TableReference = "Keys" };
    4.  
    5.     StringTable table_Keys = default;
    6.  
    7.     public string GetKeyTitle(KeyCode keyCode)
    8.     {
    9.         string reference = "F1";//keyCode.ToString();
    10.  
    11.         var entry = table_Keys.GetEntry(reference);
    12.         return entry.GetLocalizedString();
    13.     }
    14.  
    15.     void Start()
    16.     {
    17.         m_StringTable.TableChanged += Ready;
    18.     }
    19.  
    20.     private void Ready(StringTable value)
    21.     {
    22.         table_Keys = value;
    23.  
    24.         print("Ready");
    25.     }
    26.  
    27.     // Update is called once per frame
    28.     void Update()
    29.     {
    30.         if (Input.GetKeyDown(KeyCode.F1))
    31.         {
    32.             print("Input.GetKeyDown(KeyCode.F1)");
    33.  
    34.             print(GetKeyTitle(KeyCode.F1));
    35.         }
    36.     }
    37. }
    38.  
     
    C0b0ll and karl_jones like this.