LocalizationUI with Recoined (for Rewired)

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
User avatar
Haytam95
Posts: 23
Joined: Sun Mar 15, 2020 5:56 pm

LocalizationUI with Recoined (for Rewired)

Post by Haytam95 »

Hi!

I'm using Dialogue System table to make my game multilanguage. It works great!

Now I installed Rewired, and Reiconed because I wanted to make my game gamepad friendly, but when updating the texts I found out that some of them broke. I think that is because the "LocalizeUI" script reads the whole string, and Reiconed replaces it with the correct icon.

Image

Is there another way to make the LocalizeUI work? (I'm thinking maybe with a linear scan of the caracters and then when match, replace only that portion of the string)

That could work?

Thanks!!
User avatar
Tony Li
Posts: 22144
Joined: Thu Jul 18, 2013 1:27 pm

Re: LocalizationUI with Recoined (for Rewired)

Post by Tony Li »

Hi,

The LocalizeUI script's GetLocalizedText() method is virtual. You can make a subclass that overrides GetLocalizedText() to do what you describe.
User avatar
Haytam95
Posts: 23
Joined: Sun Mar 15, 2020 5:56 pm

Re: LocalizationUI with Recoined (for Rewired)

Post by Haytam95 »

Really? I'll give it a shot and come back to you!

Thank you!
User avatar
Tony Li
Posts: 22144
Joined: Thu Jul 18, 2013 1:27 pm

Re: LocalizationUI with Recoined (for Rewired)

Post by Tony Li »

Glad to help! If you get stuck, let me know. You can use Regex.Replace to extract the strings between {...} and replace them with their translations.
User avatar
Haytam95
Posts: 23
Joined: Sun Mar 15, 2020 5:56 pm

Re: LocalizationUI with Recoined (for Rewired)

Post by Haytam95 »

I couldn't find a nice way to make them work along.

I tried overriding the class, but the method wasn't being called. The trouble was, that if LocalizedUI doesn't find the field in the table, it just won't call GetLocalizedText method. (I think it's because I'm using an old version of Dialogue System)

Image

I really hate to touch source code, but I gave it a shot and got it working.

New LocalizedUIExtended:

Code: Select all

protected override string GetLocalizedText(string fieldName) {

        var localizedText = fieldName;
        foreach (var field in textTable.GetFieldNames()) {
            if (localizedText.Contains(field)) {
                localizedText = localizedText.Replace(field, textTable.GetFieldText(field));
            }
        }
        return localizedText;
    }
The next trouble, is that Reiconed uses the "Update" hook in order to update the icons, so the localized text would be overriden by it. Alright, so I extended reiconed and make it invoke an event when the icon changed, so the new Localize UI can translate again the text.

Image

That didn't work neither, because LocalizeUI then would override the icon (I'm not completly sure why, I think it's related to the way reiconed parses the string in order to choose the correct sprite. Anyway, it just blink for a second and then the icon disapears). Also after that, reiconed loses reference to the {action} text (that uses to setup the icon).

It just become a little messy, so, the cleaner the better. I will just use two text components :oops: , one will display the button and the other will display the localized text

Unless there is a better way to make it work, I think I can live with that :lol:
User avatar
Tony Li
Posts: 22144
Joined: Thu Jul 18, 2013 1:27 pm

Re: LocalizationUI with Recoined (for Rewired)

Post by Tony Li »

Good point; you'd want to override LocalizeUI.UpdateText(), not GetLocalizedText(). If the text contains a ReIconed {tag}, parse it and replace each part around the tags. If it doesn't contain a ReIconed tag, you can just call base.UpdateText().
Post Reply