Advertisement
prog

Untitled

Mar 15th, 2009
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function toArabic(text)
  2. {
  3.   var t = "_" + text.replace(/ /g, "_") + "_";
  4.  
  5.   t = t.replace(//ig,   "e");
  6.   t = t.replace(//ig,   "e");
  7.   t = t.replace(//ig,   "e");
  8.  
  9.   t = t.replace(/oo/ig,  "w");
  10.   t = t.replace(/ee/ig,  "y");
  11.   t = t.replace(/ea/ig,  "y");
  12.   t = t.replace(/ie/ig,  "y");
  13.   t = t.replace(/ou/ig,  "w");
  14.   t = t.replace(/kh/ig,  "5");
  15.   t = t.replace(/sh/ig,  "H");
  16.   t = t.replace(/ch/ig,  "H");
  17.   t = t.replace(/gh/ig,  "R");
  18.   t = t.replace(/gu/ig,  "k");
  19.   t = t.replace(/gn/ig,  "ny");
  20.   t = t.replace(/gn/ig,  "ny");
  21.   t = t.replace(/ph/ig,  "f");
  22.   t = t.replace(/qu/ig,  "k");
  23.   t = t.replace(/tion/ig, "ssywn");
  24.   t = t.replace(/sion/ig, "sywn");
  25.  
  26.   t = t.replace(/an_/ig, "A_");
  27.   t = t.replace(/in_/ig, "_");
  28.   t = t.replace(/on_/ig, "_");
  29.   t = t.replace(/a_/ig,  "A_");
  30.   t = t.replace(/i_/ig,  "y_");
  31.   t = t.replace(/o_/ig,  "w_");
  32.  
  33.   t = t.replace(/_x/ig,  "_Aks");
  34.   t = t.replace(/_a/ig,  "_A");
  35.   t = t.replace(/_e/ig,  "_A");
  36.   t = t.replace(/_al/ig, "_Al");
  37.   t = t.replace(/_i/ig,  "_A");
  38.   t = t.replace(/_o/ig,  "_A");
  39.   t = t.replace(/_l/ig,  "_Al");
  40.  
  41.   t = t.replace(/i/ig,   "y");
  42.   t = t.replace(/g/ig,   "k");
  43.   t = t.replace(/v/ig,   "f");
  44.  
  45.   t = t.replace(/'/g,    "");
  46.   t = t.replace(/e/ig,   "-");
  47.   t = t.replace(/i/ig,   "-");
  48.   t = t.replace(/a/g,   "|");
  49.   t = t.replace(/o/ig,   "|");
  50.  
  51.   var r = "";
  52.   var i = 0;
  53.   var lc = "";
  54.   while (i < t.length)
  55.   {
  56.     var c = t.charAt(i);
  57.     if ("AHORST".indexOf(c) < 0)
  58.     {
  59.       c = c.toLowerCase();
  60.     }
  61.     if (c == lc && c != "l")
  62.     {
  63.       i++;
  64.       continue;
  65.     }
  66.     lc = c;
  67.     if (c == "A") c = "ا";       //alef bela hamza
  68. //  else if (c == "A") c = "أ";  //alef be hameza fo9
  69.     else if (c == "b") c = "ب";  //ba
  70.     else if (c == "c") { if ("-y".indexOf(t.charAt(i + 1)) >= 0) c = "س"; else c = "ك"; }
  71.     else if (c == "d") c = "د";  //dal
  72.     else if (c == "D") c = "ض";  //dad
  73. //  else if (c == "e") c = "ك";
  74.     else if (c == "f") c = "ف";
  75. //  else if (c == "g") c = "ك";
  76.     else if (c == "h") c = "ه";
  77.     else if (c == "H") c = "ش";  //ch
  78. //  else if (c == "i") c = "ئ"; //hamza 3la ya
  79. //    else if (c == "I") c = "إ"; //alef be hamza ta7t
  80.     else if (c == "j") c = "ج";
  81.     else if (c == "k") c = "ك";
  82.     else if (c == "l") c = "ل";
  83.     else if (c == "m") c = "م";
  84.     else if (c == "n") c = "ن";
  85.     else if (c == "O") c = "ٶ";  //hamza 3la waw
  86.     else if (c == "p") c = "پ";
  87. //  else if (c == "q") c = "ك";
  88.     else if (c == "r") c = "ر";
  89.     else if (c == "R") c = "غ";  //gh
  90.     else if (c == "s") { if ("-|ywA".indexOf(t.charAt(i - 1)) >= 0 && "-|ywA".indexOf(t.charAt(i + 1)) >= 0) c = "ز"; else c = "س"; }
  91.     else if (c == "S") c = "ص";  //sad
  92.     else if (c == "t") c = "ت";
  93.     else if (c == "T") c = "ط";
  94.     else if (c == "u") c = "و";  //wa
  95. //  else if (c == "v") c = "ك";
  96.     else if (c == "w") c = "و";  //wa
  97.     else if (c == "x") c = "كس";
  98.     else if (c == "y") c = "ي";
  99.     else if (c == "Y") c = "ى";  //alf m9sora
  100.     else if (c == "z") c = "ز";
  101.     else if (c == "1") c = "ك";
  102.     else if (c == "2") c = "ك";
  103.     else if (c == "3") c = "ع";
  104.     else if (c == "4") c = "ك";
  105.     else if (c == "5") c = "خ";
  106.     else if (c == "6") c = "ط";
  107.     else if (c == "7") c = "ح";
  108.     else if (c == "8") c = "ك";
  109.     else if (c == "9") c = "ق";
  110.     else if (c == "0") c = "ة";
  111.     else if (c == "?") c = "؟";
  112.  
  113.     r += c;
  114.     i++;
  115.   }
  116.   return r.replace(/\|/g, "").replace(/\-/g, "").replace(/_/g, " ");
  117. }
  118.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement