Search Unity

Resolved Change String of LocalizationTable vía C#

Discussion in 'Localization Tools' started by diegosobrinoutad, Jan 25, 2024.

  1. diegosobrinoutad

    diegosobrinoutad

    Joined:
    Aug 23, 2021
    Posts:
    10
    Hi,

    I want to modify an existing String Table.I'm referning the Locale in the editor, but when I execute the script this error shows:

    Exception: Can not add new table. The same LocaleIdentifier is already in use.


    upload_2024-1-25_13-30-56.png

    Code (CSharp):
    1.  // Get the collection
    2.             var collection = LocalizationEditorSettings.GetStringTableCollection("TestTable");
    3.  
    4.             // Add a new table
    5.             var newTable = collection.AddNewTable(locale.Identifier) as StringTable;
    6.  
    7.             // Add a new entry to the table
    8.             var entry = newTable.AddEntry("Hello", "Hola");
    9.  
    10.             // Add some metadata
    11.             entry.AddMetadata(new Comment { CommentText = "This is a comment" });
    12.  
    13.             // We need to mark the table and shared table data entry as we have made changes
    14.             EditorUtility.SetDirty(newTable);
    15.             EditorUtility.SetDirty(newTable.SharedData);

    How can we modify an existing StringTable? The only way is to create an asset of the String Table each time you want to modify a new Entry?

    Thanks in advice,
    Diego
     
  2. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,277
    You need to call GetTable, not AddTable.
     
  3. diegosobrinoutad

    diegosobrinoutad

    Joined:
    Aug 23, 2021
    Posts:
    10
    That was straight, great system!
    Thanks.
     
    karl_jones likes this.