Forum rules - please read before posting.

L2Localization integration

Hi
Is there a way to integrate I2 Localization with AC? All text lines now made with AC but Would be great to use that plugin for localization. Maybe you can give some advice where we should look at first.
Thanks

Comments

  • A lot of game text is not just stored in Managers and Inspectors, but in ActionLists as well.  The Speech Manager is able to go through your game and record anything translatable - so I think relying on this to gather up your text is the best approach, even if you use something else to handle the actual localisation.

    All runtime translations are retrieved in the RuntimeLanguage script's GetTranslation method, which you could modify to return strings from another asset.  If that's a good approach, I'll consider adding an override system similar to the way inputs can be overridden (see the "Remapping inputs" chapter of the Manual) so that it can be done non-invasively.

    This method has parameters for both the original text, the current language index number, and the text's "Line ID" which is generated by the Speech Manager when "Gather text" is clicked.
  • edited November 2022

    Bringing this back to life after some time...
    I'm using Dialogue System and I2 Localization, what is handled by AC for now is just Hotspots Names and Inventory Names (dialogues, menu and UI are all handled either through DS or I2), and I'd prefer having the hotspots and inventory items handled by I2 Localization as well for having a single CSV file with everything.
    What's the best practice to achieve this?

    For the hotspots I thought to use a simple script like this, to attach to each of them, defining which entry to look on the i2 table:

    using UnityEngine;
    using AC;
    using I2.Loc;
    
    public class HotspotLocalizator : MonoBehaviour
    {
        public string i2Entry;
    
        private void Start()
        {
            Hotspot h = GetComponent<Hotspot>();
            h.SetName(LocalizationManager.GetTermTranslation(i2Entry), 0);
        }
    }
    

    And it seems to work, but not sure if it's the best way.

    But how about the Inventory Items? Also, I've some actions that shows the inventory item based on its name. For instance, when the player pick up an item, I've a custom action called "Show Inventory Popup" that shows an UI in foreground with the item just picked, which relies on the item name (KickStarter.inventoryManager.GetItem()), if that's translated, will my custom action return null? Therefore shall I change it to use the item ID rather than item Name? Or can I find a method to translate the label of the inventory item when I'm over it, without changing its internal name for scripts and such?

    Any help is very appreciated.
    Thanks

    UPDATE:
    For the inventory items I wrote this script, attached to the Persistent Engine. Using "AltLabel" it shouldn't create issues for the ShowInventoryPopUp script I was mentioning above.

    using UnityEngine;
    using AC;
    using I2.Loc;
    
    public class InventoryLocalizator : MonoBehaviour
    {
        void Start()
        {
            LocalizeInventoryItems();
        }
    
        //This is out of Start to be called also from the Options Menu when a language is changed.
        public void LocalizeInventoryItems()
        {
            var _items = KickStarter.inventoryManager.items;
    
            for (int i = 0; i < _items.Count; i++)
            {
                KickStarter.runtimeInventory.GetItem(i).altLabel = LocalizationManager.GetTermTranslation("inv" + i);
                //The i2 CSV shall contain entries for the each inventory item, labeled "inv"+ item ID, (i.e. inv2, inv17, etc.)
            }
        }
    }
    

    As for the one for Hotspots scripts, it seems to work, but I'm not sure if it's the best practice. Any guidance is very welcome.

  • As for the one for Hotspots scripts, it seems to work, but I'm not sure if it's the best practice. Any guidance is very welcome.

    The script relies on Unity's Start function, meaning it'll update the name once the scene is opened. If you changed the language mid-scene, the names wouldn't be updated to reflect this.

    If you're still using AC's Language option to change the language, you can have your script hook into the OnChangeLanguage custom event, which will run at the point the language is changed (and pass in the language index value):

    using UnityEngine;
    using AC;
    using I2.Loc;
    
    public class HotspotLocalizator : MonoBehaviour
    {
    
        public string i2Entry;
    
        private void OnEnable ()
        {
            EventManager.OnInitialiseScene += OnInitialiseScene;
            EventManager.OnChangeLanguage += OnChangeLanguage;
        }
    
        private void OnDisable ()
        {
            EventManager.OnInitialiseScene += OnInitialiseScene;
            EventManager.OnChangeLanguage += OnChangeLanguage;
        }
    
        void OnInitialiseScene ()
        {
            UpdateHotspot (Options.GetLanguage ());
        }
    
        void OnChangeLanguage (int language)
        {
            UpdateHotspot (language);
        }
    
        private void UpdateHotspot (int index)
        {
            Hotspot h = GetComponent<Hotspot>();
            h.SetName(LocalizationManager.GetTermTranslation(i2Entry), index);
        }
    
    }
    

    Otherwise, you'd need to have your own callback that runs when the language is set without the use of AC.

  • Hi @chaosmonger , really curious about your solution as I'm also interested in using L2 for dialogues, menu and UI localization. Could you share a bit more about the solution you came up with?

  • edited July 2023

    Hello @juanelo_dev
    I've wrote my own scripts to translate Inventory and Hotspots, but they aren't very elegant. They are the ones I posted initially, but I paste them here again with some more explanation. For instance, for the hotspots I do something like this:

    using UnityEngine;
    using AC;
    using I2.Loc;
    
    public class HotspotLocalizator : MonoBehaviour
    {
        public string i2Entry;
    
        private void Start()
        {
            LocalizeHotspot();
            LocalizationManager.OnLocalizeEvent += LocalizeHotspot;
        }
    
        public void LocalizeHotspot()
        {
            Hotspot h = GetComponent<Hotspot>();
            h.SetName(LocalizationManager.GetTermTranslation(i2Entry), 0);
        }
    }
    

    And attach this script to each of my hotspots, then manually entry the string which will be the i2Loc entry (for instance "hotspot00", "hotspot01", etc.). Then on the i2Loc table, I've as a key "hotspot00" with translations, i.e. English "Door", Italian "Porta", etc. (if you prefer you can set the i2Loc entry by getting the hotspot label, but then you must be sure to assign a label for each hotspot).

    The inventory works in a similar way, but I get automatically the number ID of the inventory, and change the iLoc entry to "inv"+ID, so for instance my first inventory item in AC will have an i2Loc entry of "inv0". This affects the AltLabel (not the label which will stay the same).

    using UnityEngine;
    using AC;
    using I2.Loc;
    
    public class InventoryLocalizator : MonoBehaviour
    {
        void Start()
        {
            LocalizeInventoryItems();
            LocalizationManager.OnLocalizeEvent += LocalizeInventoryItems;
        }
    
        public void LocalizeInventoryItems()
        {
            var _items = KickStarter.inventoryManager.items;
    
            for (int i = 0; i < _items.Count; i++)
            {
                KickStarter.inventoryManager.GetItem(i).altLabel = LocalizationManager.GetTermTranslation("inv" + i);
            }
        }
    }
    

    These are the only two I'm using. For all the other UIs, I'm using Unity prefabs which have already entries on text (I don't rely on AC labels at all for those). While for the dialogues I'm using Pixel Crushers Dialogue System (not AC).

    Let me know if it's more clear now.
    Regards

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.