Search Unity

  1. Get the latest news, tutorials and offers directly to your inbox with our newsletters. Sign up now.
    Dismiss Notice

How to get the value of one or all LocalizedStrings in Editor?

Discussion in 'Localisation Tools Previews' started by Hannibal_Leo, Feb 15, 2021.

  1. Hannibal_Leo

    Hannibal_Leo

    Joined:
    Nov 5, 2012
    Posts:
    291
    The strings are there, I know it, I've written them and they work fine in the game as well as the build.
    BUT I need some kind of validation, I know it's on the roadmap ... but there has to be some way to access the strings within the editor right now and maybe even compare them to the LocalizedString.TableEntryReference?

    Haven't found anything on the previos posts of the last 3 sites and nothing in the quick start guide / docs.
    It's possible to export CSV, so it has to be possible to get the strings somehow.

    But how?
     
  2. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    4,896
    You want to get the data in editor? You can use LocalizationEditorSettings.
     
  3. Hannibal_Leo

    Hannibal_Leo

    Joined:
    Nov 5, 2012
    Posts:
    291
    Code (CSharp):
    1.  
    2. void DoValidate()
    3. {
    4. #if UNITY_EDITOR
    5.     var collection = UnityEditor.Localization.
    6.             LocalizationEditorSettings.GetStringTableCollection(text.TableReference);
    7.     if (collection == null) return;
    8.     var entry = collection.SharedData.GetEntryFromReference(text.TableEntryReference);
    9.     if (entry == null) return;
    10.     Debug.Log("Entry is: " + entry);
    11.     // entry.value ???
    12. #endif
    13. }
    14.  
    I've come this far
    (and ignore the #if UNITY_EDITOR line, it's because I am using the Odin Asset to quickly make Buttons without creating a CustomInspector)
     
  4. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    4,896
    If you want a value for a particular locale:
    Code (csharp):
    1. vat st = collection.GetTable("en") as StringTable;
    2. var entry = st.GetEntryFromReference(reference);
    3. Debug.Log(entry.LocalizedValue)
     
  5. Hannibal_Leo

    Hannibal_Leo

    Joined:
    Nov 5, 2012
    Posts:
    291
    Yes it worked :D
    Awesome! Thanks a lot :D
     
    karl_jones likes this.
unityunity