Programmatically Create/Add new Locales

EDIT 2: This seems to be an issue with serialization - if there are more available Locales than a collection currently contains, LocalizationString won’t serialize properly. If I had ‘en’ ‘fr’ and ‘es’ supported, but the collection only has ‘en’ and ‘fr’ tables, then this issue pops up. One can create the table for the collection via the Missing Tables section in the inspector, and the serialization works again.

Hi there, I’ve been poking at the Localization package’s API, and I’m currently trying to (correctly) programmatically create a new Locale and then add it to the Localization system seamlessly (ideally all at edit time for now).

Right now my test code looks like this:

Locale newLocale = Locale.CreateLocale(SystemLanguage.Spanish);
AssetDatabase.CreateAsset(newLocale, "Assets/Localization/" + newLocale.name + " (" + newLocale.Identifier.Code + ").asset");
LocalizationEditorSettings.AddLocale(newLocale);

AssetDatabase.SaveAssets();

I simply want to create and add and have it persist, right. Anyways, when I run this, it seems to create the asset and it’s all showing up properly more or less in the Localization Tables and whatnot - except I’m bombarded with a handful of Null ref exceptions related to some PropertyDrawer things:

Which leads me to believe I’m likely doing something wrong here.

Any wisdom to be shed?

Thank you!

EDIT: This is in 2020.1.6f1 - using Localization v0.8.1

I think this was caused by having a component visible in the inspector that’s presenting a serialized LocalizedString - maybe it’s having trouble responding to changes? When I run this method (via the Context Menu currently), that Serialized field disappears from the inspector and the errors arrive. I have some code that Removes the Locale, and when ran (also from the Context Menu on this component) it works as well as restores that serialized LocalizedString.

HI,
Yes this is a known bug with the LocalizedString property drawer. We will have a fix in the next release.