Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Question Programmatically Create/Add new Locales

Discussion in 'Localization Tools' started by rowanwaring, Sep 30, 2020.

  1. rowanwaring

    rowanwaring

    Joined:
    Mar 6, 2018
    Posts:
    6
    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:

    Code (CSharp):
    1. Locale newLocale = Locale.CreateLocale(SystemLanguage.Spanish);
    2. AssetDatabase.CreateAsset(newLocale, "Assets/Localization/" + newLocale.name + " (" + newLocale.Identifier.Code + ").asset");
    3. LocalizationEditorSettings.AddLocale(newLocale);
    4.  
    5. 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
     
    Last edited: Sep 30, 2020
  2. rowanwaring

    rowanwaring

    Joined:
    Mar 6, 2018
    Posts:
    6
    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.
     
  3. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,422
    HI,
    Yes this is a known bug with the LocalizedString property drawer. We will have a fix in the next release.