How do we access the string database in the Editor

I’m trying to scrape the existing string database for all keys, as I’m trying to check if we have any stranded keys. So any that aren’t used in a scene, prefab or scriptable object.

I’m trying to implement a menu method that does so, and I’m struggling getting the string database to work in the static method.

    private static async Task<Dictionary<long, string>> GetDBLocIds()
    {
        Dictionary<long, string> used = new Dictionary<long, string>();
        /*
        var selectTask = LocalizationSettings.Instance.GetSelectedLocaleAsync();
        await selectTask.Task;

        var locales = LocalizationSettings.Instance.GetAvailableLocales();

        if (locales.Locales.Count == 0)
        {
            Debug.LogError("no locales found");
            return used;
        }
        */

        var async = LocalizationSettings.StringDatabase.GetTableAsync(LocalizationSettings.StringDatabase.DefaultTable);

        while (!async.IsDone)
            await async.Task;

        foreach (StringTableEntry entry in async.Task.Result.Values)
            used.Add(entry.KeyId, entry.LocalizedValue);

        return used;
    }

When this runs, the result of getting the table is null, and I’m not sure why.

Is this for an editor script?
You can use LocalizationEditorSettings. It will give you table collections which you can work with.
You won’t need to do any async stuff, it’s all immediate in editor.
If you do make a change to a table then be sure to mark the table as dirty and the shared table data as they are assets and changes won’t be saved otherwise.Class LocalizationEditorSettings | Localization | 0.9.0-preview

Thanks, that worked perfectly

2 Likes