GetLocalizedStringAsync not work

Hi, All!
Simple code:

public class Test : MonoBehaviour
{
    LocalizationSettings Instance;

    public string GetKeyTitle(KeyCode keyCode)
    {
        string reference = "F1";//keyCode.ToString();

        //print(reference);

        var loadAsync = Instance.GetStringDatabase().GetLocalizedStringAsync(reference); //"Keys",
        while (!loadAsync.IsDone) continue;
        return loadAsync.Result;
    }

    IEnumerator Start()
    {
        // Wait for the localization system to initialize, loading Locales, preloading etc.
        yield return LocalizationSettings.InitializationOperation;

        Instance = LocalizationSettings.InitializationOperation.Result;

        print("Ready");
    }

    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.F1))
        {
            print("Input.GetKeyDown(KeyCode.F1)");

            print(GetKeyTitle(KeyCode.F1));
        }
    }
}

With errors. Key β€œF1” exist. Need Help…


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

1 Like

Thanks a lot for the quick response! It helped.
Found another way :slight_smile:
Your package is great!

public class Test : MonoBehaviour
{
    LocalizedStringTable m_StringTable = new LocalizedStringTable { TableReference = "Keys" };

    StringTable table_Keys = default;

    public string GetKeyTitle(KeyCode keyCode)
    {
        string reference = "F1";//keyCode.ToString();

        var entry = table_Keys.GetEntry(reference);
        return entry.GetLocalizedString();
    }

    void Start()
    {
        m_StringTable.TableChanged += Ready;
    }

    private void Ready(StringTable value)
    {
        table_Keys = value;

        print("Ready");
    }

    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.F1))
        {
            print("Input.GetKeyDown(KeyCode.F1)");

            print(GetKeyTitle(KeyCode.F1));
        }
    }
}
2 Likes