Search Unity

Feature Request Create Table from JSON

Discussion in 'Localization Tools' started by EduardDraude, Apr 15, 2020.

  1. EduardDraude

    EduardDraude

    Joined:
    Mar 8, 2019
    Posts:
    60
    Hello!
    Firstly I want to to shout out a huge comliment! I really like this localization approach and editor tool! Great job!
    I would also love a feature to parse a JSON and convert it to a string table.
    Or is there an api to create string table data from script?

    Thx and cheers
     
  2. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,297
    Hi,
    This is not supported at the moment but it is planned for the future. You may have some luck with the JsonUtility class now.
     
  3. EduardDraude

    EduardDraude

    Joined:
    Mar 8, 2019
    Posts:
    60
    What function is called when pressing "New Table Entry" in a string table? I would like to write an editor script which first reads a json and then just add the entries with the same function as the new entry butto :)
     
  4. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,297
    We call TableCollection.SharedData.AddKey();
    This will only add the key to the Shared Table data, it won't create an entry in the table.
    You probably want StringTable.AddEntry. This will create a new key if one does not exist and set the localised text value for that table.
     
    EduardDraude likes this.
  5. EduardDraude

    EduardDraude

    Joined:
    Mar 8, 2019
    Posts:
    60
    Hey @karl_jones!
    Thanks for your advise! That worked already and I could parse a json to a string table. But somehow the data is not saved and lost after I reopen Unity. I use
    Undo.RecordObject(tableName, "...")
    before each operation on the table and also at the very end:
    AssetDatabase.SaveAssets();
    AssetDatabase.Refresh();

    Do I need to call something else?
    The data is visible in the Table Editor, before I restart Unity. And when I manually add an entry it also saves my stuff applied by my editorscript., but not if I just use the script..

    Do you have an idea how to solve this issue?

    Thx and cheers!
     
  6. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,297
    Hey.
    You need to also record changes to the SharedTableData asset.
    Code (csharp):
    1. Undo.RecordObject(tableName.SharedTableData, ...)
    Thats the asset that stores the actual keys
     
    EduardDraude likes this.
  7. EduardDraude

    EduardDraude

    Joined:
    Mar 8, 2019
    Posts:
    60
    karl_jones likes this.