George Welder
George Welder

Reputation: 4055

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

Upvotes: 7

Views: 2606

Answers (3)

Abdulla Saeed
Abdulla Saeed

Reputation: 69

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

Upvotes: 1

Said Pc
Said Pc

Reputation: 655

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.

Upvotes: 1

Deckerz
Deckerz

Reputation: 2604

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(""));

Upvotes: 1

Related Questions