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 Requesting more detailed guide for CustomTableProvider

Discussion in 'Localization Tools' started by TimedragonX, Aug 4, 2023.

  1. TimedragonX

    TimedragonX

    Joined:
    Nov 3, 2017
    Posts:
    9
    I don't know if I'm just overlooking something, but I couldn't find any more details in the documentation and samples.

    I have all of my translations in a JSON file and I want to load them into a string table when the game starts. From the documentation I could infer, that you can use the ITableProvider interface to write a custom table provider (as seen here: https://docs.unity3d.com/Packages/com.unity.localization@1.4/manual/Scripting.html). However, I have trouble understanding the entire setup process from just the provided code samples alone.

    For example, when triggering AssignCustomTableProviderExample with the menu item, nothing seems to happen. I also don't see any "My Custom Table" file anywhere with those created example entries. I tried only creating the table itself, but that didn't seem to do anything either. Do I maybe need to create some Bootstrap script that calls ProvideTableAsync? Do I have to do some additional setup somewhere else? How do I assign the translations to my text objects with LocalizeStringEvent? Is that even possible? I couldn't find answers to those questions anywhere.

    As such, I would be very happy if someone could provide more detailed steps on how to set all of this up, because merely adding the example classes doesn't seem to get me anywhere and there are no tutorials that cover this.
     
  2. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    7,820
    Nothing will happen when you assign the provider, the system will however use your provider when subsequent calls are made for tables that have not yet been loaded. You need to assign the table provider before you do anything with localization or it will be too late. This is why in the example we do it with a menu item so that it is saved into the asset and will be serialized. This means you only need to assign the providers once and they will now be part of the asset. Now when you request a table it will be called.

    The system does not support table providers in the editor. You can assign the values via a script, either in the editor or at runtime.

    E.G

    Code (csharp):
    1.  
    2. public class Example : MonoBehaviour
    3. {
    4.     // This can be set and will be saved in the scene however you wont be able to change it in the inspector and it will report a missing table when viewed in the inspector.
    5.     public LocalizedString myLocalizedString = new LocalizedString("My Custom Table", "My Entry");
    6.  
    7.     void Start()
    8.     {
    9.         //  This will trigger the string to be loaded from your custom table
    10.         myLocalizedString.StringChanged += ValueChanged;
    11.     }
    12.  
    13.     void ValueChanged(string value)
    14.     {
    15.         Debug.Log("Value changed to: " + value);
    16.     }
    17. }
    You could create a custom editor for your component and provide a way to select the table and entry from your custom JSON, this can then be applied to the serialized value "myLocalizedString"