Skip to content

Instantly share code, notes, and snippets.

@MohamedAmrMahdy
Last active September 30, 2018 21:52
Show Gist options
  • Save MohamedAmrMahdy/d76840f86f0106754988302d6a77f74b to your computer and use it in GitHub Desktop.
Save MohamedAmrMahdy/d76840f86f0106754988302d6a77f74b to your computer and use it in GitHub Desktop.
Convert Arabic words from LTR to RTL
function arabicFixerRTL(inputString){
let words = inputString.split(" ");
let final = "";
for (var i = 0; i < words.length ; i++) {
if(words[i].charCodeAt(0) > 1535 && words[i].charCodeAt(0) < 1792){
final += words[i].split("").reverse().join("") + " ";
}else{
final += words[i] + " ";
}
}
return final.split(" ").reverse().join(" ");
}
function arabicFixerRTL(inputString){
let words = inputString.split(" ");
let final = "";
for (var i = 0; i < words.length ; i++) {
if(words[i].charCodeAt(0) > 1535 && words[i].charCodeAt(0) < 1792){
final += Reshaper.reshape(words[i]).split("").reverse().join("") + " ";
}else{
final += words[i] + " ";
}
}
return final.split(" ").reverse().join(" ");
}
https://github.com/mapmeld/js-arabic-reshaper
https://github.com/louy/Javascript-Arabic-Reshaper
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment