I have to print some text to printer. I needed to translate that text in Urdu language also. For that I used google translation API and all was set. But I am facing problem in order of output.

 // this is the code which is giving my desired output
 String text = "Honda head light large size"
 String translatedText = GoogleTranslate.translate("ur", text);
 String myString = "Saboor"

  String printString = String.format("%-15s %-15s 
  %-10s",text,translatedText,myString);

   graphics.drawString(printString,x,y)

  //Above code is giving me correct output as following

  Honda head light large size     urdu translation        Saboor

  // Now pasting the code which create problem:

   String text = "Honda head light large size"
   String translatedText = GoogleTranslate.translate("ur", text);
   int val = 10

   String printString = String.format("%-15s %-15s 
   %-10s",text,translatedText,val);

   graphics.drawString(printString,x,y);

  // now the output of this code is following(which i don't want):

 Honda head light large size   10       udru translation

// but i need following output:

  Honda head light large size     urdu translation     10

This question may already have an answer here:

How can I create table using ASCII in a console? 8 answers
I have to print some text to printer. I needed to translate that text in Urdu language also. For that I used google translation API and all was set. But I am facing problem in order of output.

// this is the code which is giving my desired output
String text = "Honda head light large size"
String translatedText = GoogleTranslate.translate("ur", text);
String myString = "Saboor"

String printString = String.format("%-15s %-15s
%-10s",text,translatedText,myString);

graphics.drawString(printString,x,y)

//Above code is giving me correct output as following

Honda head light large size urdu translation Saboor

// Now pasting the code which create problem:

String text = "Honda head light large size"
String translatedText = GoogleTranslate.translate("ur", text);
int val = 10

String printString = String.format("%-15s %-15s
%-10s",text,translatedText,val);

graphics.drawString(printString,x,y);

// now the output of this code is following(which i don't want):

Honda head light large size 10 udru translation

// but i need following output:

Honda head light large size urdu translation 10

As you see in case of code(correct output), after printing translated text, when i print a String , it prints correctly.

But after printing translated text,when i print a decimal or float number , alignment or order goes wrong. Please guide me, why is this happening?

Note: Urdu language has right to left direction.

Congratulations on a really interesting question!

maybe what’s going on is in the String.format you process a l-r string, then a r-l and after that the direction is still r-l when the third argument is processed.

There are Unicode chars to override the direction, but more than that I don’t know. They are

left-to-right mark: 0x200e
right-to-left mark: 0x200f

I think you insert them in the string, but I don’t know where exactly. Maybe that’s enough info for you to find more details?

Cheers
JC

commented: Yea this is one I've never seen before +11