Force re-initialization / Refresh LocalStringEvents after patching string tables.

Hi

I have a simple code for patching StringTables from local CSV-files. CSV is imported and we replace matching keys/strings in the table when the app starts (SubsystemRegistration).

The patching works, LocalizationTable editor window shows the patched strings, but nothing is updated on screen before changing languages.

What I want is to have all LocalizedStringEvents update their string when the patching is done.

I've searched a bit on the forums, but I haven't found a working solution for my case. LocalizationSettings.InitializationOperation doesn't seem to do anything.

I've even tried getting all LocalizedStringEvents and refreshing them, but then I get a nullref exception in the DetailedLocalizationTable.cs at

   /// <summary>
        /// Returns true if any tag metadata of type TShared contains this entry.
        /// </summary>
        /// <typeparam name="TShared"></typeparam>
        /// <returns></returns>
        public bool HasTagMetadata<TShared>() where TShared : SharedTableEntryMetadata
        {
            var tag = Table.GetMetadata<TShared>();
            return tag?.IsRegistered(this) == true;
        }

Note: Currently I'm not copying over the KeyID (just the key).KeyID is 0 in patched entrees.

Anyone that some tips or experience to share? Thanks in advance.

Are you using the ITablePostProcessor to do the patching? This is designed for this purpose and will apply the patch before any data is used.
See the example here
https://docs.unity3d.com/Packages/com.unity.localization@1.4/manual/Scripting.html

1 Like

ITableProcessor did the trick. I modified my code to fit with the post processor logic, and registered it on SubsystemRegistration. Thanks for swift reply @karl_jones !

1 Like

That’s great. It’s actually a serialized field so you should be able to register it in the editor and not have to do it in the player, although if it’s working as is then no problem :slight_smile:

1 Like

I'll keep that in mind if I bump into issues when I try to build

I think its better do it in code like this, instead of some unseen reference, since there's no Editor UI showing what post processors are assigned.

1 Like

That’s a good point, we should add a UI for it. I’ll add it to our tasks.

1 Like

For sure. After doing some refactoring, Unity still has a reference to an older table processor.
9377279--1311494--upload_2023-9-29_12-42-38.png

I tried fixing it by by:

    [MenuItem("Tools/Localization/Clear PostProcessors")]
    public static void ClearPostProcessors()
    {
        var settings = LocalizationEditorSettings.ActiveLocalizationSettings;
        settings.GetStringDatabase().TablePostprocessor = null;
        settings.GetAssetDatabase().TablePostprocessor = null;

        // Set dirty so the changes are saved.
        EditorUtility.SetDirty(settings);
    }

but the warning won’t go away.

  • How should we clear PostProcessors?
  • Also: if we set “Preload All Locales”, will that mean that my Processor/Patcher will run on all tables and locales on initialization? Trying to figure out how to carry out the patching once at startup.

9377279--1311494--upload_2023-9-29_12-42-38.png

Try setting the localization settings dirty after making a change. EditorUtility.SetDirty(LocalizationSettings
instance)

Preload all locales will load them all and let you do all tables but I would not recommend it. Your table post processor will always be run after loading a table so it should be safe to just patch the tables as they are loaded.

Thanks for the swift reply. That yielded some result, but now I’m getting these errors:
9377618--1311524--upload_2023-9-29_14-28-7.png

Restarting Editor did not help. I’m guessing this is an Editor-only error, but still a little annoying. Any ideas?

I'm not familiar with those errors. Can you share the editor log file? Does it happen all the time?
What does the code look like?

Sure.

Log: https://pastebin.com/2bJK6N4G

The errors came after I did this:

        var settings = LocalizationEditorSettings.ActiveLocalizationSettings;
        settings.GetStringDatabase().TablePostprocessor = null;
        settings.GetAssetDatabase().TablePostprocessor = null;

        // Set dirty so the changes are saved.
        EditorUtility.SetDirty(LocalizationSettings.Instance);

I think the GC error came after my previous attempt which I posted above; same, but with different param for the SetDirty.

So I made a new project and copied the scripts over. Same errors appeared even before pressing play, so I guess there’s something else going on. Unity 2022.3.10f1