Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only. On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live. Read our full announcement for more information and let us know if you have any questions.

Feature Request Improve string entry ID generation

Discussion in 'Localization Tools' started by Peter77, Sep 10, 2023.

  1. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,650
    @karl_jones Please allow me to explain our workflow in order to illustrate the issue we are facing with the current ID generation system. It is a slightly complex process, so I will strive to be as precise as possible. I apologize in advance for the lengthy explanation.


    Problem description

    In our localization process, we utilize a Google Sheet. We add fresh keys and corresponding text to this Google Sheet, which is then imported into the Unity project through the Google Sheets Extension.

    The problem arises when two or more individuals work on separate branches, each adding new text locations to the Google Sheet, and later intend to merge their changes. The issue lies in the fact that the Google Sheets importer generates differing IDs for the same keys.

    Let me provide you with an example:
    1. You create a Git branch named "karl" from the "develop" branch.
    2. You add a new localized text with the key "karl" to the Google Sheet.
    3. You update the localization in the project by pulling the modified Google Sheet using the Google Sheets Extension.
    4. You add the "karl" key to a LocalizedString in an already existing prefab called "hello".

    1. I'm creating a new Git branch named "peter" from the "develop" branch.
    2. Next, I'm adding a new localized text with the key "peter" to the Google Sheet.
    3. Then, I'm pulling the updated Google Sheet to update the localization in the project using the Google Sheets Extension.
    4. Now, my project includes the "peter" key, but it also includes the "karl" key from the Google Sheets document that was pulled in.
    5. I'm adding the key "peter" to a LocalizedString in an existing prefab named "world".
    6. Finally, I'm merging my changes into develop.


    Now you want to merge your changes into the develop branch. However, since develop has new changes, you need to pull them into your branch first. Now you encounter several merge conflicts because we both made changes to the text localization files.

    However, this isn't a problem because we make text localization in Google Sheets, so nothing has been lost. You can discard your changes to the localization files, proceed with the git-merge, and then simply pull the Google Sheet to integrate your changes as well as any other modifications.

    Now everything has been successfully merged, but the LocalizedString in the "hello" prefab is referring to a missing text. It should point to "karl", but it doesn't. The reason for this discrepancy is that the Localization tool generated different IDs for the "karl" loca-key in both of our branches, and I merged my changes first. The project currently contains the ID for the "karl" text that was generated when I pulled the Google Sheet.


    Proposal to solve the problem
    Instead of generating a random ID when importing a Google Sheet, the ID should be a hash of the provided loca-key. Consequently, we will have a stable ID for imported loca-keys, and collaborating with multiple individuals on the same project will no longer lead to asset issues where LocalizedStrings are involved.
     
  2. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,570
    Hi,
    By default our keys use this method
    https://docs.unity3d.com/Packages/com.unity.localization@1.4/manual/TableEntryKeys.html

    It's designed to prevent conflicts between users editing the same project on different machines, the keys should be unique to the machine.
    We considered a hash of the keys but it was found to be unreliable and handling conflicts could be tricky. The hash would also have to be based on the initial name which is always the same at the moment (New Entry). You can however change the default method used to generate keys by assigning a different key generator to the shared table data.
    https://docs.unity3d.com/Packages/c...Engine.Localization.Tables.IKeyGenerator.html
    This method doesn't have the key Info to generate a hash though, we would probably improve that.

    You can also change the I'd of a key at any time by calling RemapId on the shared table data. This won't update any references you may have in scenes and assets though.

    Also worth mentioning for your use case, you can manually assign an id value in Google sheets by adding a comment to the Key column with the I'd value.
     
    Last edited: Sep 10, 2023