Writing RTL in input field

I’m trying to write Persian in unity input fields. Persian is right to left language and it’s alphabet is similar to Arabic.

I’ve found a library that converts and corrects the text. It’s works just fine. When I’m showing the converted text into Debug.Log() everything is perfect but the problem is when I’m going to put corrected text into input field it would be reversed! I’ve tried to reversed the input field text but nothing happened!

Here’s my code

public InputField empName;
    
PersianMaker pm;
string tempStr = "";
    
private void Start()
{
    pm = new PersianMaker();
}
    
void OnGUI()
{
    tempStr = "";
    
    if (!string.IsNullOrEmpty(empName.text))
    {
        tempStr = pm.ToPersian(empName.text);
        tempStr = Regex.Replace(tempStr, @"\s+", " ");
        tempStr = tempStr.Trim();
        //empName.text = ReverseString(empName.text);
        //empName.text = tempStr;
        Debug.Log(tempStr);
    }
}
    
private string ReverseString(string s)
{
    char[] arr = s.ToCharArray();
    Array.Reverse(arr);
    return new string(arr);
}

Any suggestion?

@masoudarvishian

Sorry for too late Response but I hope my asset will help you

it supports both Arabic & Persian for Text, Input Field, Toggle and Button UIs

this is the GitHub 1

First and best solution is using Textmesh pro. Now it has TextMeshProGUI component which is the best choice for Arabic and Persian and RTL languages for UI and you can use it in canvas. having mesh in this component name Don’t let mislead you. It can be used in canvas and UI and is even better than default Text ui text component of unity. It has no any margin problem or multi line problem.


If you want a very quick solution you can use this package as simple as

yourText.faConvert ();

for multi-line support you should set line spacing to -1.


Next solution is using the package you refer to or a better version can be found here. the only problem with this packages is some margin problems. but you should change all the text component with RTLText component so when TextMeshPro is available there is no any reason to use it anymore.


The last solution is to use this localization asset which has some auto fix for RTL languages. For multi line support you can set line spacing to -1 or it has a simple solution to break line on a constant length.