Search Unity

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

Discussion in 'Localization Tools' started by John_Leorid, Feb 15, 2021.

  1. John_Leorid

    John_Leorid

    Joined:
    Nov 5, 2012
    Posts:
    651
    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:
    8,282
    You want to get the data in editor? You can use LocalizationEditorSettings.
     
  3. John_Leorid

    John_Leorid

    Joined:
    Nov 5, 2012
    Posts:
    651
    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:
    8,282
    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. John_Leorid

    John_Leorid

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