Search Unity

Question Editor Script : modifying a LocalizedString permanently

Discussion in 'Localization Tools' started by AnAngelineer, Mar 5, 2023.

  1. AnAngelineer

    AnAngelineer

    Joined:
    Nov 4, 2015
    Posts:
    34
    I am working on editor scripts with the "Odin Serializer" asset. My end goal is to obfuscate the whole "localization tables" thing from the people who are going to input the data. They are not very computer-savvy and would be very confused by all this. So my role is to make it more obvious, with simple "Text in english" or "title in French" labeled textfields.

    I managed to automate the creation of entries into the LocalizedStringTable for when a new asset is created, and have them displayed in the inspector like I want : in text fields that can be edited. This will be much more convenient for my intended users.

    But now the problem comes of transferring the changes done in those fields to the tables themselves. As the fields are just editor-only string attributes that have nothing to do with the tables.

    The asset I manipulate uses a LocalizedString attribute as a basis to fill the text fields. So when the values in those is modified, rhere are the two things I would need to do to complete my goal :
    • Use the LocalizedString as a strarting point to find the entries that I need to update in the table (one per locale)
    • Update the table through code, preferably without doing a "destroy/recreate" thing.

    If this is not clear enough and you want me to send the code, I can do so. Thanks.
     
  2. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,291
  3. AnAngelineer

    AnAngelineer

    Joined:
    Nov 4, 2015
    Posts:
    34
    Sorry, but I can't figure it out staring from this page... I managed to find this example in the documentation which seems to carry the general idea :

    Code (CSharp):
    1. var newCollection = LocalizationEditorSettings.CreateStringTableCollection("My Strings", "Assets/String Tables");
    2.  
    3.     var table = newCollection.GetTable("en") as StringTable;
    4.     table.AddEntry("START_MENU", "Start Game");
    5.     table.AddEntry("OPTIONS_MENU", "Options");
    6.     table.AddEntry("EXIT_MENU", "Quit");
    But there is only "addEntry" and "removeEntry". To update, should i just "add" with the same key, then?
     
  4. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,291
    You can use GetEntry and then update the returned value. You can also use AddEntry which will update the value if an entry already exists. Just make sure to mark the table dirty so the changes you make are not lost.
     
  5. AnAngelineer

    AnAngelineer

    Joined:
    Nov 4, 2015
    Posts:
    34
    Okay! I managed to make it work! Had to extrapolate what you said a bit with the documentation, but you definitely set me up on the right track. Thanks a lot for the help!
     
    karl_jones likes this.