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

Question Is there a way to detect when a localized string's english value is modified?

Discussion in 'Localization Tools' started by sourenpapazian, Aug 30, 2023.

  1. sourenpapazian

    sourenpapazian

    Joined:
    Aug 15, 2020
    Posts:
    5
    When someone changes the english value of a string, we want to remove all of the existing translations for that string because they are no longer up to date.
    Any ideas on how this can be implemented?
     
  2. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    7,845
    It depends how they make the change. If it's done through the table editor or the localized string property drawer then you should be able to use the TableEntryModified event.
    https://docs.unity3d.com/Packages/c...or.Localization.LocalizationEditorEvents.html

    E.g
    Code (csharp):
    1. LocalizationEditorSettings.EditorEvents.TableEntryModified += // event callback
    This is an editor only feature. You could set up a script that uses InitializeOnLoad to add a subscriber to monitor. Then when a change occurs you can invalidate the table collection. Maybe add some metadata to the entry to say that it needs checking.
     
    sourenpapazian likes this.
  3. sourenpapazian

    sourenpapazian

    Joined:
    Aug 15, 2020
    Posts:
    5
    Thank you for the timely and helpful response :)
     
    karl_jones likes this.
  4. tina_gifts5

    tina_gifts5

    Joined:
    Jul 5, 2022
    Posts:
    2
    You can use Unity localization package + Crowdin to manage translation changes. It would be easy to see which source strings (english) changed and whether translations should be updated as well. Here's a bit more on how Unity localization would work if you use a localization tool.
     
  5. sourenpapazian

    sourenpapazian

    Joined:
    Aug 15, 2020
    Posts:
    5
    @Karl-jones I have three follow-up questions:

    1. Is there a way to add metadata per table entry? As in metadata per locale for a string entry. I want to detect if the Spanish string for an entry was modified and only tag that one with metadata.
    2. If the answer to 1 is yes, then I think I would need an EditorEvent for TableEntryModified that gives a
    `StringTableEntry` as a parameter rather than a `SharedTableEntry`.
    3. In the callback for TableEntryModified I have a SharedTableEntry. Is there an efficient way to get the collection that the SharedTableEntry belongs too? Currently i have to iterate through all the collections in my project and check if it contains that key.
     
  6. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    7,845
    1. Yes, we have metadata per entry.
    2. Unfortunately, we don't have an event that will tell you what locale was changed for the entry though. I'll add a task for us to add that.
    3. Ah looks like we need to improve that callback as well.

    Thanks for the feedback, we will look at improving these callbacks.

    For now, as a workaround one thing you can try is to use the Undo post process callback. You should be able to identify what table has changed and the entry using the asset and path info.
    https://docs.unity3d.com/ScriptReference/Undo-postprocessModifications.html