Search Unity

Localize local changing Strings

Discussion in 'Localization Tools' started by camouflaged_penguin, Apr 11, 2022.

  1. camouflaged_penguin

    camouflaged_penguin

    Joined:
    Jun 1, 2021
    Posts:
    22
    Hey there

    Overall The Localization Tool works fine for me but i have some exceptional cases where i would like to know if there is a solution with the Localization Tool do it easy and fast.

    So for Example in the game are serveral Players with different Names and Teams. This Teams and Names are changing on runtime or locally so i can't use the table with fixed entries to solve this cases.

    There is also a button which changes between Dash and Tackle like this:

    Code (CSharp):
    1. tackleButton.SetText(hasBall ? "Dash" : "Tackle");
    As you can see ingame the Text changes from Dash to Tackle if hasBall is True.

    But is there a way to localize Dash & Tackle with the localization tool?
     
  2. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,299
  3. camouflaged_penguin

    camouflaged_penguin

    Joined:
    Jun 1, 2021
    Posts:
    22
    hey there,
    It still looks easier to make an own table for that case because for dash/tackle alone we need to use additional code like this, to check which state we are in. Is there an easier solution with smart strings?
    Code (CSharp):
    1. {connection_state : choose (Disconnected|JoiningLobby|InLobby|JoiningGame|InGame) : {disconnected}|{joiningLobby}|{inLobby}|{joiningGame}|{inGame}}
    2.   - supply local variables for nested LocalStrings disconnected joiningLobby inLobby joiningGame inGame
    3.   - supply local variable for Source connection_state [System.Serializable] public class ConnectionStateSource :
    4.  ISource {     public string selector = "connection_state";
    5.      public bool TryEvaluateSelector(ISelectorInfo selectorInfo)     {         if (selectorInfo.SelectorText != selector)             return false;          
    6. selectorInfo.Result = NetworkManager.State.ToString()         return true;     } }
    7. Does this update on statechange?
    8.  
     
  4. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,299
    It looks like it's getting a little more complicated now. A translator will have a harder time with something that complex and it will be harder to add/remove items. I would place each state into its own String Table Entry and then use a script to switch to the correct item.
    You can do this without a Smart String.

    Code (csharp):
    1. public string GetStateString(ConnectionState state)
    2. {
    3.     return LocalizationSettings.StringDatabase.GetLocalizedString("My Table", state.ToString());
    4. }
    The table then has entries like this

    upload_2022-4-13_11-34-40.png


    This keeps it nice and simple, easier to maintain and translate.
     
  5. camouflaged_penguin

    camouflaged_penguin

    Joined:
    Jun 1, 2021
    Posts:
    22
    yes thanks. i think that is the better way then.
     
    karl_jones likes this.