Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Feature Request Be able to get/set a TableEntry's string Key

Discussion in 'Localization Tools' started by rowanwaring, Oct 6, 2020.

  1. rowanwaring

    rowanwaring

    Joined:
    Mar 6, 2018
    Posts:
    6
    Hello there,

    I find it curious that one isn't able to access an entry's Key string (not the Id long). I find myself running into situations where I might want to change the Key string programmatically (say, through a custom editor that interfaces between the Loc system with other systems), or even simply access it's value if nothing else.

    If string keys are unique within their given collection (which is how I currently understand it), this doesn't seem like something that should too hard to support, but I'm not sure.
     
  2. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,396
    Hey,
    We do support this.
    Keys are handled through the SharedTableData which can be accessed through the collection or table. Make sure you set the asset dirty if you make changes.

    You have 2 types of entries, table entries which just contain the id and localized value and shared entries which contain the Key and Id. To get to the shared entries use SharedTableData.

    Code (csharp):
    1.  
    2. var collection = LocalizationEditorSettings.GetStringTableCollection("My Strings");
    3.  
    4. // Change the name
    5. collection.SharedData.RenameKey("My Entry", "My New Entry");
    6.  
    7. // Change the id
    8. collection.SharedData.RemapId(123, 321);
    9.  
    10. // Get the entry with the Key, Id and shared metadata
    11. var entry = collection.SharedData.GetEntry("My New Entry");
    12.  
    13. EditorUtility.SetDirty(collection.SharedData);
    14.  
     
  3. rowanwaring

    rowanwaring

    Joined:
    Mar 6, 2018
    Posts:
    6
    Oh! Nice, I didn't know about that - I think that is exactly what I'm looking for.

    Quick followup question: do Id's need to be remapped if a key is renamed? Is there anytime within an entry's potential lifetime that an Id will change without an explicit call?
     
  4. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,396
    No you don't need to change the id to change the Key. The Id should never change unless you call that API.