Forum Discussion
JavaScript Text Direction
I have a challenge with text direction. I usually use Persian/Arabic language which is Right to Left direction.I also used JavaScript code in it and wrote something in Persian/Arabic language in parts of it. But in the output, due to the use of Persian language, it shows the numbers in reverse. For example, the number 1234 is represented by 4321, or the word "null" is represented by "llun". Please tell me a solution to my problem.
- MathNotermans-9Community Member
Basically i added a function to reverse any part of your text to it.
As you can see the first line both the number and my name are RTL... As i am not 100% sure if that was correct...i added a function to get parts of your string and revert those.function reverse(s){
return s.split("").reverse().join("");
}
This is the function that does that. In the Storyline added i commented a lot, just to see if it works. And i pass the name and score to a separate array... that might not be necessarry... you have to test that. Only thing thats really needed is converting any value sending to reverse function into a string ( toString() ) Either directly, or in the function itself.
Just tried that by changing the function to this:function reverse(s){
s = s.toString();
return s.split("").reverse().join("");
}
Works fine. - PhilMayorSuper Hero
I presume that in Arabic text is RTL and number are LTR is that right? Could you inverse the numbers before you send them?
- MahdiMalekanCommunity Member
Yes, you are correct.but Reversing the numbers doesn't solve the problem because the same thing happens with words
Actually, I translated some English words in the codes into Farsi.
I will send the code link below for you to take a look.
https://stackoverflow.com/questions/73748948/text-direction-issue-in-javascript
- MathNotermans-9Community Member
If you share a sample im sure domeone ( if not me:)) will help. Noticing your code is mostly javascript, so please share your Storyline and we get it fixed.
- MahdiMalekanCommunity Member
sorry for late reply. I did not have access to the Internet due to issues in my country
Ok, I will send you the project...
This project works like this:
You enter the user's name and the user's score and then press the blue button. The box below shows the user's rank based on his score.
The javascript code is in the blue button and the data is stored in a google sheet.
- MathNotermans-9Community Member
Just tested it... and i guess the font you use causes it. Because opening the file i miss 0 Koodak Bold... and like this my result shows...and it seems to me that that is correct.
Or am i wrong and should the numbers be visible as 1234567... - MahdiMalekanCommunity Member
Hi Again Math
Wow!! , it seems that you have found the solution! It was really amazing.
But since I am not familiar with the JavaScript language, I could not understand the codes.
The user score is now working correctly but with many attempts I could not reverse the date and time like you.
I hope you can help me in this matter too, dear Math. - MathNotermans-9Community Member
Offcourse. Do sent me what needs to be fixed and i get it done. Do make it crystalclear to me what needs to be reversed... as i donot speak Arabic ;-) You can sent it to m.notermans@tilburguniversity.edu
Kind regards,
Math