Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Resolved Get localized string during editor runtime from LocalizedString

Discussion in 'Localization Tools' started by d_grass, Nov 6, 2020.

  1. d_grass

    d_grass

    Joined:
    Mar 6, 2018
    Posts:
    45
    Short for those who also search because I haven't found a Solution in the Forum to retrive the value of a entry:

    Code (CSharp):
    1. public static class LocalizedStringExtension{
    2.     public static string GetValue(this LocalizedString ls, LocaleIdentifier localeIdentifier){
    3.         var collection = LocalizationEditorSettings.GetStringTableCollection(ls.TableReference);
    4.         return (collection.GetTable(localeIdentifier) as StringTable).GetEntryFromReference(ls.TableEntryReference).Value;
    5.     }
    6. }
    Example how to use:
    Code (CSharp):
    1. [SerializeField]
    2. public LocaleIdentifier localeIdentifier;
    3. [SerializeField]
    4. public LocalizedString localizedString;
    5. string result = localizedString.GetValue(localeIdentifier);
     
    karl_jones likes this.
  2. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    7,787
    What's your use case here? Is this something for an Editor only thing?
     
  3. d_grass

    d_grass

    Joined:
    Mar 6, 2018
    Posts:
    45
    Hi Karl Jones,
    thanks for your interest.
    Yes, in my current use case it is for editor only.
    In my case or from our company the editor user selects which string should be used and which language and then triggers a setup of different gameobjects, these will then be setup with the choosen language settings.

    So yes it is editor only and the results should currently not switch dynamic the language but should have the selected one which it initial had.
     
    karl_jones likes this.
  4. JesseSTG

    JesseSTG

    Joined:
    Jan 10, 2019
    Posts:
    236
    I can add a use case, too. I'm sequencing a text-typing animation with Unity Timeline, and I need to write a custom PlayableBehaviour; as part of this process, I need to be able to preview the animation in the editor.
     
  5. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    7,787
    We have editor support on the way. Probably 0.11.0
     
  6. JesseSTG

    JesseSTG

    Joined:
    Jan 10, 2019
    Posts:
    236
    Neat, thanks! Loving the package so far.
     
    karl_jones likes this.