Forum rules - please read before posting.

ITranslatable and Scriptable Objects

edited July 26 in Technical Q&A

Hi

Should strings inside scriptable objects be gathered properly for translations?

Test case:

  • The SO implements ITranslatable and has a single string variable to test.
  • The string in the SO is set to some text (not empty)
  • The player prefab has a reference to the SO
  • To be safe, I've placed an instance of the prefab in the scene and saved
  • Filters set to include everything (Type = Custom/All, Scene: Any, Text: All)
  • This exact copy paste code works fine in a mono behaviour (string is listed under custom).

When gathering text the string isnt listed after Gathering text (reset didnt help) with Custom filter (or any filter for that matter).

            [SerializeField]
            private string parameterText = "My Test String";
            private int parameterLineID = -1;

            public string GetTranslatableString(int index)
            {
                return parameterText;
            }

            public int GetTranslationID(int index)
            {
                return parameterLineID;
            }

    #if UNITY_EDITOR

            public void UpdateTranslatableString(int index, string updatedText)
            {
                parameterText = updatedText;
            }

            public int GetNumTranslatables()
            {
                return 1;
            }

            public bool CanTranslate(int index)
            {
                return !string.IsNullOrEmpty(parameterText);
            }

            public bool HasExistingTranslation(int index)
            {
                return (parameterLineID >= 0);
            }

            public void SetTranslationID(int index, int lineID)
            {
                parameterLineID = lineID;
            }

            public string GetOwner(int index)
            {
                return string.Empty;
            }

            public bool OwnerIsPlayer(int index)
            {
                return false;
            }

            public AC_TextType GetTranslationType(int index)
            {
                return AC_TextType.Custom;
            }
    #endif

Comments

  • How are the Player and the SO linked?

    Custom ITranslatable implementations currently need to be a MonoBehaviour inside a scene, or an Action, for them to be automatically detected.

    What you could do is have a separate ITranslatable script in the scene that passes its implmemtation values to the SO's, i.e:

    public void SetTranslationID(int index, int lineID)
    {
        mySO.parameterLineID = lineID;
    }
    

    I will, however, see if an ITranslatableReferencer or some such is possible, to allow for ITranslatables to be detected elsewhere.

  • edited July 27
    The player has a direct private reference to the SO.
    It's marked with the Serialize field attribute.

    I can easily look to see how the speech manager gathers references, I just didn't go down that rabbit hole.

    Tbh - while I love AC as a whole - I do find code/script localization to be cumbersome at first glance (granted I haven't looked tonight into it). Implementing an interface with multiple methods to essentially do a lookup for one string is alot.

    I'm nearly all games I've worked on strings come from a CSV that has KVPs of string Id and value. There is a csv per language.vslues can contain escape sequences for substitution. Ie

    $HumanRaceID, Human

    Lookups are done at runtime to convert string Id to localized value, ie

    cout << Localization.Translate("$HumanRaceID);// Human if English language

    I understand you need to make AC non programmer friendly, though.

    I think I might just have a second CSV lookup for script strings that aren't directly used by AC and hoo into its language changed evens as needed.
  • Noted, thank you.

    I will introduce ITranslatableReferencer in the next update. It'll be a simple one-function interface that you can implement in your Player script to inform AC of the link to the ITranslatable field:

    public ITranslatable[] GetTranslatables()
    {
        return new ITranslatable[] { myTranslatable };
    }
    
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.