Hi there! im using unity’s localization system and im trying to have content from modders be dynamically imported into the localization tables.
The problem im currently encountering is that ImportInto and LocalizationEditorSettings are within UnityEditor, thus not being added into the build.
Whats the alternative or suggested approach to dynamically add/replace content from the localization tables at runtime?
foreach (var asset in hostAssets) {
var modLocalization = asset.AssetObject as TextAsset;
// the following belongs to UnityEditor.Localization
var collection = LocalizationEditorSettings.GetStringTableCollection("GameUI");
using(TextReader sr = new StringReader(modLocalization.ToString()))
{
// the following belongs to UnityEditor.Localization.Plugins.CSV
Csv.ImportInto(sr, collection);
}
}
As you say CSV is editor only at the moment.
You can patch a table when the game starts, something like this: PatchTableContents.cs · GitHub
This way you just can read a text file and update the table with new data. We do have some features to further support this coming in the next release in a couple of months.
Ah it won’t be anything like that in the next release, just improvements so you can provide a custom table and patch the contents. Support for other formats in the player is not anything planned in the short term.
Oh, that’s sad. So what would be the suggested way to have modders add/modify content to different tables?
Patching them up with individual strings like in the code you shared?
Yes using the patching method to add new strings from a file the modder added. You could use CSV with your own parser or JSON and the JSON utility class.
Hi Karl!
We have been trying to implement the solution you shared with me and we run into the following:
While getting the table using LocalizationSettings.StringDatabase.GetTable(tableName);
we found out that it is just bringing the current locale, instead of the full table:
Do you know what method we should be using to get the full table instead of the current locale one? we would like to have modders populate more than one locale with their content.
Cheers
By default, we only load the table for the selected locale. If you want the other ones you can force them to be loaded by calling LocalizationSettings.StringDatabase.GetTable(tableName, locale) and passing in the locale of the table you want.
To be safe I would use GetTableAsync and call Addressables.Aquire on the returned operation, this will make sure it doesn’t get unloaded when you switch language.
Perfect! thanks. Im headed that way using json instead of csv to expedite things.
Ive got another question tho:
Do you have any method to convert from a string code to a locale?
i want to get Locale (to use the method you exposed) by providing the code “en” or “es” etc