Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

LocalizedString get Entry Name

Discussion in 'Localization Tools' started by unknowndevice, Jun 3, 2021.

  1. unknowndevice

    unknowndevice

    Joined:
    Sep 13, 2016
    Posts:
    86
    Hi, I'm just wondering if there's a way of getting the Entry Name field from LocalizedString that's displayed in the inspector. Right now I'm getting the table and passing it the localized string entry reference. I'm just wondering if that field value is stored somewhere so I can avoid doing this.


    Code (CSharp):
    1. // What I'm doing now.
    2. LocalizedString localizedString;
    3. var table = LocalizationSettings.StringDatabase.GetTableAsync(localizedString.TableReference).Result;
    4. var entryName = table.SharedData.GetEntryFromReference(localizedString.TableEntryReference).Key;
     
    Last edited: Jun 3, 2021
  2. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    7,846
    Hi,
    No the value is only stored in the SharedTableData and its not possible for us to automatically resolve this as we dont store any table collection information in the TableEntryReference struct.
    It is possible to store the Key instead of the Key Id in the TableEntryReference however when setting the value via the inspector we always use the Key Id at the moment, maybe we can make this a preference in the future.

    Code (csharp):
    1.  
    2. public LocalizedString usingNames = new LocalizedString("My String Table", "My Game Text");
    3.  
    4. public LocalizedString usingTableNameAndEntryId = new LocalizedString("My String Table", 4324324541);
    5.  
    6. public LocalizedString usingTableGuidAndEntryId = new LocalizedString(new System.Guid("6e79ded14bc9e0a4d9bf2b8aac246bfe"), 323453434);
    7.  
    8. public LocalizedString usingTableGuidAndEntryName = new LocalizedString(new System.Guid("6e79ded14bc9e0a4d9bf2b8aac246bfe"), "Start Game");
    When you have the SharedTableData you can use ResolveKeyName which basically does the same thing you are already doing.
     
    unknowndevice likes this.
  3. unknowndevice

    unknowndevice

    Joined:
    Sep 13, 2016
    Posts:
    86
    Thanks @karl_jones! Totally understand the reasoning behind using using the key id, especially if the key name gets changed you'll potentially lose your reference. Thanks for the ResolveKeyName suggestion. I'll use that!
     
    karl_jones likes this.
  4. PlaycorpStudios

    PlaycorpStudios

    Joined:
    Aug 2, 2016
    Posts:
    47
    What is the best way to get the SharedTableEntry from LocalizedString in runtime?

    I intend to use that to resolve a key in runtime.
     
  5. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    7,846
    You can do:
    Code (csharp):
    1. var tableOp = LocalizationSettings.StringDatabase.GetTableAsync(localizedString.TableReference);
    2. yield return tableOp;
    3. tableOp.Result.SharedData;
     
    PlaycorpStudios likes this.
  6. PlaycorpStudios

    PlaycorpStudios

    Joined:
    Aug 2, 2016
    Posts:
    47
    Cheers Karl, I appreciate your quick response.
     
    karl_jones likes this.