Apologies if this is super obvious, but I couldn’t figure out how to do it in the documentation.
If I have a string table named “UI Text” like in the quick start example, what’s the easiest way to just do something like
public SomeSortOfSharedStringTable myTable;
myTable.GetLocalizedString(stringKeyName);
Where I can just pull up a value by key name and automatically get the string for the current locale?
Is there some global way to do something else like
Localization.GetLocalizedStringTableEntry("UI Text", "START_GAME");
Yes it’s LocalizationSettings.StringDatabase.GetLocalizedString
1 Like
Ahhh, thanks! I had seen that, but when I saw that it took TableEntryReference
s I didn’t realize that those were just structs that could be implicitly generated from strings. Thought they were specific existing references or something. Not sure if it’s worth changing, but just seeing the autocomplete for that function pop up with a string input as an explicit overload would have helped in the learning through discovery process for me, even though it’s obviously not necessary mechanically speaking given the implicit string to TableEntryReference that exists.
Also totally aside, this feels like an extremely common use case to me, but it feels like it’s quite deeply nested in terms of namespacing and layering, which made it harder to discover. All in all, you have to dig quite a bit (though obviously this is cut down with the right using directive): UnityEngine.Localization.Settings.LocalizationSettings.StringDatabase.GetLocalizedStringAsync("My Key");
Yes it is deep if you use the full namespace.
The TableEntry and TableEntryReference exist so we don’t need to have multiple versions of each function. 1 table string, 1 table guid, 1 key name, 1 key I’d, then arguments and locale etc. It creates a lot of overloads. So those structs help to reduce it although I can see how they may be confusing at first.