Text Changed Updated event

hello, is there any event or place that i can use to add extra line of code when Text get the localized new string?

Hi,
You want to append text to the Localized string or you want to do something when the value changes?
How are you localizing the strings, are you using a script or using the LocalizedStringEvent component we provide?

we have problem to localize RTL languages like Arabic, so after i grab the Text from table i need to fix it since unity dosent suppoer RTL until now, so i need to know when the string ready after i get it from table, then i will change it and back it to the Text field.
edit: and yes i used the Event provided in 0.8+.

Ok. You could change the target of the Update String event to a script or you could write a script to do everything in 1.
Take a look at the Samples we include with the package(In the package manager window).

Try the sample **LocalizedStringWithChangeHandlerExample** under the LoadingStrings category.
In UpdateString modify the translated value and then set it to the text component.

Here is an example

using UnityEngine;
using UnityEngine.Localization;
using UnityEngine.UI;

namespace UnityEditor.Localization.Samples
{
    public class LocalizedStringWithChangeHandlerExample : MonoBehaviour
    {
        public Text text;

        public LocalizedString stringRef = new LocalizedString() { TableReference = "My String Table", TableEntryReference = "Hello World" };
        string m_TranslatedString;

        void OnEnable()
        {
            stringRef.StringChanged += UpdateString;
        }

        void OnDisable()
        {
            stringRef.StringChanged -= UpdateString;
        }

        void UpdateString(string translatedValue)
        {
            m_TranslatedString = translatedValue;

            // Do something here

            text.text = m_TranslatedString;
        }
    }
}

I would also be interested in what your RTL fix is, maybe its something we could incorporate.

1 Like

Thank you for the example,
Arabic Localization is a pain for Us, since Unity does not support RTL as i mention before, so our community start doing open source support, the problem is:

  • Arabic language start from Right to left
  • Arabic characters has different form when came between 2 char like this : ب if it come between 2 letters it will be like ـبـ and if it came at the end its form like ـب .

there fore right now there is Core support for the issue above, here the source code:

but this has another problem, because its flip all characters, so index of first character will equal to index of last character, and if you have statement in only 1 line will be fine, but when it come to mutlilines it show first line below the 2nd line, here come the 2nd tool thats fix the multiline issue:
https://github.com/AbdullahAlimam/Arabic-Support-for-Unity-UI/blob/master/Assets/Abdullah%20Al-Imam/Arabic%20Support%20UI/Script/ArabicText.cs

the previous 2 tools, does not support TextMesh Pro, thats enforce me to do that, just updated some lines and make it support normal text and TMP text , inputfield , and TMP inputfield.

                case whichType.TMPText:
                    tmpTextComponent.text = "";

                    for (int lineIndex = 0; lineIndex < rtlParagraph.Length; lineIndex++)
                    {
                        string[] words = rtlParagraph[lineIndex].Split(' ');
                        System.Array.Reverse(words);
                        tmpTextComponent.text = string.Join(" ", words);
                        Canvas.ForceUpdateCanvases();
                        for (int i = 0; i < tmpTextComponent.textInfo.lineCount; i++)
                        {
                            int startIndex = tmpTextComponent.textInfo.lineInfo[i].firstCharacterIndex;
                            int endIndex = (i == tmpTextComponent.textInfo.lineCount - 1) ? tmpTextComponent.text.Length
                                : tmpTextComponent.textInfo.lineInfo[i+1].firstCharacterIndex;
                            int length = endIndex - startIndex;
                            string[] lineWords = tmpTextComponent.text.Substring(startIndex, length).Split(' ');
                            System.Array.Reverse(lineWords);
                            finalText = finalText + string.Join(" ", lineWords).Trim() + "\n";
                        }
                    }

all files attached.
if you can help us with this it will be great. and if you need more information, i am happy to help.

6388227–712017–ArabicFixer.cs (12 KB)
6388227–712020–ArabicFixerEditor.cs (545 Bytes)
6388227–712023–ArabicSupport.cs (37.9 KB)

1 Like

Thanks!
Arabic is an issue we are aware of and its certainly something we plan to address in the future.
Ill record what you said so we can look further into it when we begin the work adding suport to the Localization package.

1 Like