Forum rules - please read before posting.

Localization of use syntax

I am researching the localization options when it comes to languages that support articles like French, Spanish, German, Greek and so on. In those languages, you must perform noun declining in order for the constructed phrase to make sense: For example while in English we can just say "Use pen on paper" (maybe even "Use the pen on the paper") for:

  • French: "Utilisez le stylo sur le papier"
  • Spanish: "Usa el bolígrafo sobre el papel"
  • German: "Verwenden Sie den Stift auf dem Papier"
  • Greek: "Χρησιμοποίησε το στυλό στο χαρτί"

There are several things to note here: For example genders are not consistent from one language to another, or in some languages (like Greek) the "on" word equivalent gets merged with the article ("στο") of the item.

As far as I can understand there's no support for such smart formatting when it comes to Adventure Creator even if I choose to use the Unity Localization package as the GetHotspotPrefixLabel(...) method will not perform any string formatting when it comes to 'smart strings'.

Is my assumption correct or is there a way to make the 'Use syntax' aware of those localization "quirks"?

Comments

  • A custom script is necessary to handle the formatting based on language-specific conditions, but it's possible to override the default "Hotspot label" when e.g. a Hotspot is hovered-over while an Inventory item is selected:

    using AC;
    using UnityEngine;
    
    public class CustomHotspotLabel : MonoBehaviour
    {
    
        public string menuName = "Hotspot";
        public string elementName = "HotspotLabel";
        private MenuLabel hotspotLabel;
    
        void Start()
        {
            hotspotLabel = PlayerMenus.GetElementWithName(menuName, elementName) as MenuLabel;
        }
    
        void Update()
        {
            if (KickStarter.playerInteraction.GetActiveHotspot() && InvInstance.IsValid(KickStarter.runtimeInventory.SelectedInstance))
            {
                var languageIndex = Options.GetLanguage();
                string overrideText = ""; // Set this
                hotspotLabel.OverrideLabel(overrideText);
            }
            else
            {
                hotspotLabel.OverrideLabel(string.Empty);
            }
        }
    
    }
    
  • My concern here is how I can link certain entities (e.g. the Adventure Creator inventory item for 'Paper') with titles that allow noun declension while also making use of Adventure Creator's localization logic.

    I was thinking of a Scriptable Object that could link those two together, that also conforms to ITranslatable. Does that make sense?

  • If the script is able to update sentences correctly using AC's provided Item and Hotspot names, along with separators such as "the" etc that the script provides, then those individual separators could be sent to the Speech Manager via ITranslatable.

    I'd recommend putting the ITranslatable aspect to one side for the moment, while the construction logic is still being worked out, however.

    How you link Items with Hotspots in the code can be done a few ways, but a custom class could refer to them by e.g. name, along with some variable (such as an integer, for a very basic example), to denote the "rule" between them:

    [System.Serializable]
    public class ItemHotspotPair
    {
    
        public string itemName;
        public string hotspotName;
        public int ruleType; // For example
    
    }
    

    Your main script can then have an array of this that is then used to work out which rule to apply:

    using AC;
    using UnityEngine;
    
    public class CustomHotspotLabel : MonoBehaviour
    {
    
        public string menuName = "Hotspot";
        public string elementName = "HotspotLabel";
        private MenuLabel hotspotLabel;
        public ItemHotspotPair[] pairs;
    
        void Start()
        {
            hotspotLabel = PlayerMenus.GetElementWithName(menuName, elementName) as MenuLabel;
        }
    
        void Update()
        {
            if (KickStarter.playerInteraction.GetActiveHotspot() && InvInstance.IsValid(KickStarter.runtimeInventory.SelectedInstance))
            {
                var languageIndex = Options.GetLanguage();
                var pair = GetPair (KickStarter.runtimeInventory.SelectedInstance, KickStarter.playerInteraction.GetActiveHotspot());
                if (pair != null)
                {
                    var ruleType = pair.ruleType;
                    string overrideText = ""; // Set this
                    hotspotLabel.OverrideLabel(overrideText);
                }
            }
            else
            {
                hotspotLabel.OverrideLabel(string.Empty);
            }
        }
    
        ItemHotspotPair GetPair(InvInstance item, Hotspot hotspot)
        {
            foreach (var pair in pairs)
            {
                if (item.InvItem.label == pair.itemName && hotspot.name == pair.hotspotName)
                {
                    return pair;
                }
            }
            return null;
        }
    
    }
    
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.