User:ZxxZxxZ/arTranslit.js

/* */ function arTranslit{ var arLetters = "ءاآأإؤئبپتثجچحخدذرزژسشصضطظعغفڤڥقڨڧكگلمنوهية"; var c = document.getElementById('wpTextbox1').value; c = c.replace(/‌/g, '-'); // ZWNJ c = c.replace(/[‍ـ]/g, ''); // remove ZWJ, tatweel c = c.replace(/ًا?/g, 'an'); c = c.replace(/ٍ/g, 'in'); c = c.replace(/ٌ/g, 'un'); c = c.replace(/^[اٱ]َ?ل/g, 'al-'); c = c.replace(new RegExp('([^' + arLetters + '\\w])[اٱ]َ?ل', 'g'), '$1al-'); c = c.replace(/[أؤئء]/g, 'ʾ'); c = c.replace(/إِ?/g, 'ʾi'); c = c.replace(/و(ّ?َ?ة)/g, 'w$1'); c = c.replace(/ي(ّ?َ?ة)/g, 'y$1'); c = c.replace(/^و/g, 'w'); c = c.replace(/^ي/g, 'y'); c = c.replace(new RegExp('([^' + arLetters + '\\w])وَ?([أإآ])', 'g'), '$1wa-$2'); c = c.replace(new RegExp('([^' + arLetters + '\\w])و', 'g'), '$1w'); c = c.replace(new RegExp('([^' + arLetters + '\\w])ي', 'g'), '$1y'); c = c.replace(/وا/g, 'wā'); c = c.replace(/يا/g, 'yā'); c = c.replace(/و([ًٌٍَُِّْ])/g, 'w'); c = c.replace(/ي([ًٌٍَُِّْ])/g, 'y'); c = c.replace(/^ا/g, 'ʾ'); c = c.replace(new RegExp('([^' + arLetters + '\\w])ا', 'g'), '$1ʾ'); c = c.replace(/[اٰى]/g, 'ā'); c = c.replace(/ٱ/g, ''); c = c.replace(/آ/g, 'ʾā'); c = c.replace(/(.)ّ/g, '$1$1'); c = c.replace(/([َُ])ي/g, '$1y'); c = c.replace(/([َِ])و/g, '$1w'); c = c.replace(/َ/g, 'a'); c = c.replace(/ِ/g, 'i'); c = c.replace(/ُ/g, 'u'); c = c.replace(/ْ/g, ''); c = c.replace(/ب/g, 'b'); c = c.replace(/پ/g, 'p'); // used in some dialects c = c.replace(/ت/g, 't'); c = c.replace(/ث/g, 'ṯ'); c = c.replace(/ج/g, 'j'); c = c.replace(/چ/g, 'č/ž/g'); // used in some dialects, e.g. Khuzestani (č), Egyption (ž), and Israeli Arabic (g) c = c.replace(/ح/g, 'ḥ'); c = c.replace(/خ/g, 'x'); c = c.replace(/د/g, 'd'); c = c.replace(/ذ/g, 'ḏ'); c = c.replace(/ر/g, 'r'); c = c.replace(/ز/g, 'z'); c = c.replace(/س/g, 's'); c = c.replace(/ش/g, 'š'); c = c.replace(/ص/g, 'ṣ'); c = c.replace(/ض/g, 'ḍ'); c = c.replace(/ط/g, 'ṭ'); c = c.replace(/ظ/g, 'ẓ'); c = c.replace(/ع/g, 'ʿ'); c = c.replace(/غ/g, 'ġ'); c = c.replace(/ف/g, 'f'); c = c.replace(/[ڤڥ]/g, 'v'); // used in some dialects, e.g. Egyptian (ڤ) and Maghrebi Arabic (ڥ) c = c.replace(/ق/g, 'q'); c = c.replace(/ڧ/g, 'q'); // Maghrebi Arabic c = c.replace(/ڨ/g, 'g'); // used in some dialects, e.g. Maghrebi Arabic c = c.replace(/ك/g, 'k'); c = c.replace(/گ/g, 'g'); // rarely used c = c.replace(/ل/g, 'l'); c = c.replace(/م/g, 'm'); c = c.replace(/ن/g, 'n'); c = c.replace(/و/g, 'w/ū'); c = c.replace(/ه/g, 'h'); c = c.replace(/ي/g, 'y/ī'); c = c.replace(/َ?ة/g, 'a(t)'); c = c.replace(/aā/g, 'ā'); c = c.replace(/،/g, ','); c = c.replace(/؛/g, ';'); c = c.replace(/[«»]/g, '"');   c = c.replace(/؟/g, '?');    c = c.replace(/٫/g, '.');    c = c.replace(/٬/g, ',');    c = c.replace(/٭/g, '*');    c = c.replace(/٪/g, '%');    nums = ['٠', '١', '٢', '٣', '٤', '٥', '٦', '٧', '٨', '٩'];    for (var i = 0; i < 10; i++) {        c = c.replace(new RegExp(nums[i], 'g'), i);    }    alert(c); } $(function {    var cp = document.getElementById('editpage-copywarn');    var wpSave = document.getElementById('wpSave');    if (!cp || !wpSave) return    var ins = ' arTranslit';    cp.innerHTML += ins;    var warningDone = false; }) /* */