Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NodeJS : Right-To-Left Language Console Log (Arabic)

I have the following tiny nodejs script which just console logs an arabic verb:

var verb = "كتب";
console.log(verb);

However, the console log gives me: output: بتك - which is the verb, but inverted. (So instead of getting abc I get cba).

I guess that this is because nodejs does not know that I am using a right-to-left language, such as Arabic. However, I was not able to find anything online, on how to fix this? Is there some setting I don't know of?

PS: What's interesting is also, that while the letters are inverted, their their form is basically correct - so the first letter, although displayed at the end, still has the correct form of a first letter in Arabic (in Arabic, letters take on different forms, depending on the position in the word)

enter image description here

like image 988
George Welder Avatar asked Nov 13 '17 15:11

George Welder


3 Answers

Although i am not sure why it is doing that (i cant reproduce it in chrome console).

You could try reverse the string before output like so:

var verb = "كتب";
console.log(verb.split("").reverse().join(""));
like image 127
Deckerz Avatar answered Sep 30 '22 14:09

Deckerz


Bro it's just because of the console , your word will still conserved as it is if you try to send it in the response object for testing.

like image 39
Said Pc Avatar answered Sep 30 '22 12:09

Said Pc


There's a package on npm for displaying the Arabic text correctly on consoles/terminals that don't support it.

https://www.npmjs.com/package/rtl-arabic

like image 26
Abdulla Saeed Avatar answered Sep 30 '22 13:09

Abdulla Saeed