How to write text from Right to Left?

Hello,

I am trying to write text in Hebrew, But there is a problem. Unity allows me to write text in direction from Left to Right, But I can’t write from Right to Left. And I can’t to do something good with the code, Because I think It is impossible.

I’m talking about the Text Component which located in the Canvas game object (The new UI which released in Unity 4.6).

I can’t finish my Project ):

Any ideas?

http://feedback.unity3d.com/suggestions/feature-to-change-direction-of-the-text-unity-ui

The bad news is that right-to-left languages are not currently supported by our text system. This is definitely something to want to support, however, and it is on our roadmap, but I can’t make any predictions or guarantees when it will be available.

Using @cjdev 's string reversing code, I have come up with this script. See if it can help you. :slight_smile:

using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using System;
using System.Linq;
using Syst![52718-output.png|213x194](upload://5kbQ74wn6gLxMNdnhnRRgTJfJ89.png)em.Collections.Generic;


public class flipfont : MonoBehaviour {

	Text myText; //You can also make this public and attach your UI text here.

	string individualLine = ""; //Control individual line in the multi-line text component.

	int numberOfAlphabetsInSingleLine = 20;
	
	string sampleString = "I am trying to write text in Hebrew," +
						  "But there is a problem. Unity allows me to write text in direction from Left to Right, " +
						  "But I can't write from Right to Left. And I can't to do something good with the code, " +
						  "Because I think It is impossible.";

	void Awake(){
		myText = GetComponent<Text>();
	}

	void Start(){

		List<string> listofWords = sampleString.Split(' ').ToList(); //Extract words from the sentence

		foreach(string s in listofWords){

			if(individualLine.Length >= numberOfAlphabetsInSingleLine){
				myText.text +=Reverse(individualLine)+"

"; //Add a new line feed at the end, since we cannot accomodate more characters here.
individualLine = “”; //Reset this string for new line.
}

			individualLine +=s+" ";

		}

	}

	public static string Reverse(string s)
	{
		char[] charArray = s.ToCharArray();
		Array.Reverse(charArray);
		return new string(charArray);
	}

}

What I am doing is limiting the number of characters that are to be shown in a single line.
Hope this helps and saves your day. :slight_smile:

52713-flipfont.png

You could use a function to reverse a string like this one:

public static string Reverse(string s)
{
    char[] charArray = s.ToCharArray();
    Array.Reverse(charArray);
    return new string(charArray);
}

shameless plug

I have made an asset that inherits from InputField and allows for RTL editing.
I’m still fleshing out the editing and integrations, but the core functionality is there (and does the job)

https://forum.unity3d.com/threads/released-native-rtl-input-field.471403/

@Ben35852