Search Unity

  1. Unity 2020.1 has been released.
    Dismiss Notice
  2. We are looking for feedback on the experimental Unity Safe Mode which is aiming to help you resolve compilation errors faster during project startup.
    Dismiss Notice
  3. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Simple Get String from table via script?

Discussion in 'Localisation Tools Previews' started by Bogdenz, Jul 25, 2020.

  1. Bogdenz

    Bogdenz

    Joined:
    Oct 17, 2019
    Posts:
    4
    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

    Code (CSharp):
    1. public SomeSortOfSharedStringTable myTable;
    2.  
    3. 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
    Code (CSharp):
    1. Localization.GetLocalizedStringTableEntry("UI Text", "START_GAME");
     
  2. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    4,094
    Yes it's LocalizationSettings.StringDatabase.GetLocalizedString
     
    Bogdenz likes this.
  3. Bogdenz

    Bogdenz

    Joined:
    Oct 17, 2019
    Posts:
    4
    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):
    Code (CSharp):
    1. UnityEngine.Localization.Settings.LocalizationSettings.StringDatabase.GetLocalizedStringAsync("My Key");
     
    Last edited: Jul 28, 2020
  4. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    4,094
    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.
     
unityunity