While all the online English to Urdu translators that I have seen don’t really work that well (read suck), if we make use the overlapping vocabulary and grammar of Hindi and Urdu along with using Google’s translation API, things come out pretty decent (as mentioned in my previous post). Here’s a small 15 min first cut script which just uses English to Hindi translation and then transliterates from Hindi to Urdu. Feel free to use the code and do ping me if you improve something. This works as a Hindi to Urdu transliterator as well.
google.load(“language”, “1”);var conv=[]; conv[‘ऀ’]=’’;//‘ऀ’; conv[‘ँ’]=‘ن’; conv[‘ं’]=‘ن’; conv[‘ः’]=‘ہ’; conv[‘ऄ’]=’’;//‘ऄ’; conv[‘अ’]=‘اَ’; conv[‘आ’]=‘آ’; conv[‘इ’]=‘اِ’; conv[‘ई’]=‘اِی’; conv[‘उ’]=‘اُ’; conv[‘ऊ’]=‘اُو’; conv[‘ऋ’]=’’;//‘ऋ’; conv[‘ऌ’]=’’;//‘ऌ’; conv[‘ऍ’]=‘ای’; conv[‘ऎ’]=‘ऎ’; conv[‘ए’]=’’;//‘ِ’; conv[‘ऐ’]=‘ائے’; conv[‘ऑ’]=’’;//‘ऑ’; conv[‘ऒ’]=‘ؤ’; conv[‘ओ’]=‘او’; conv[‘औ’]=‘اؤ’; conv[‘क’]=‘ک’; conv[‘ख’]=‘کھ’; conv[‘ग’]=‘گ’; conv[‘घ’]=‘گھ’; conv[‘ङ’]=‘ن’; conv[‘च’]=‘چ’; conv[‘छ’]=‘چھ’; conv[‘ज’]=‘ج’; conv[‘झ’]=‘جھ’; conv[‘ञ’]=‘ن’; conv[‘ट’]=‘ٹ’; conv[‘ठ’]=‘ٹھ’; conv[‘ड’]=‘ڈ’; conv[‘ढ’]=‘ڈھ’; conv[‘ण’]=‘ن’; conv[‘त’]=‘ت’; conv[‘थ’]=‘تھ’; conv[‘द’]=‘د’; conv[‘ध’]=‘دھ’; conv[‘न’]=‘ن’; conv[‘ऩ’]=’’;//‘ऩ’; conv[‘प’]=‘پ’; conv[‘फ’]=‘پھ’; conv[‘ब’]=‘ب’; conv[‘भ’]=‘بھ’; conv[‘म’]=‘م’; //conv[‘य’]=‘ے’; conv[‘य’]=‘ی’; conv[‘र’]=‘ر’; conv[‘ऱ’]=‘ऱ’; conv[‘ल’]=‘ل’; conv[‘ळ’]=’’;//ळ’; conv[‘ऴ’]=’’;//‘ऴ’; conv[‘व’]=‘و’; conv[‘श’]=‘ش’; conv[‘ष’]=‘ش’; conv[‘स’]=‘س’; conv[‘ह’]=‘ہ’; conv[‘ऺ’]=’’;//‘ऺ’; conv[‘ऻ’]=’’;//‘ऻ’; conv[‘़’]=’’;//‘़’; conv[‘ऽ’]=’’;//‘ऽ’; conv[‘ा’]=‘ا’; conv[‘ि’]=‘ِ’; conv[‘ी’]=‘ی’; conv[‘ु’]=‘ُ’; conv[‘ू’]=‘وُ’; conv[‘ृ’]=‘ر’; conv[‘ॄ’]=’’;//‘ॄ’; conv[‘ॅ’]=‘ی’; conv[‘ॆ’]=‘ء’; conv[‘ै’]=‘ی’; //conv[‘े’]=‘ے’; conv[‘े’]=‘ی’; conv[‘ॉ’]=’’//‘ا’; conv[‘ॊ’]=’’;//‘ॊ’; conv[‘ो’]=‘و’; conv[‘ौ’]=‘و’; conv[‘्’]=’’; conv[‘ॎ’]=’’;//‘ॎ’; conv[‘ॏ’]=’’;//‘ॏ’; conv[‘ॐ’]=’’;//‘ॐ’; conv[‘॑’]=‘॑’; conv[‘॒’]=‘॒’; conv[‘॓’]=‘॓’; conv[‘॔’]=‘॔’; conv[‘ॕ’]=’’;//‘ॕ’; conv[‘ॖ’]=’’;//‘ॖ’; conv[‘ॗ’]=’’;//‘ॗ’; conv[‘क़’]=‘ق’; conv[‘ख़’]=‘خ’; conv[‘ग़’]=‘غ’; conv[‘ज़’]=‘ز’; conv[‘ड़’]=‘ڑ’; conv[‘ढ़’]=‘ڑھ’; conv[‘फ़’]=‘ف’; conv[‘य़’]=’’;//य़’; conv[‘ॠ’]=’’;//‘ॠ’; conv[‘ॡ’]=’’;//‘ॡ’; conv[‘ॢ’]=’’;//‘ॢ’; conv[‘ॣ’]=’’;//‘ॣ’; conv[’।’]=’۔’; conv[’॥’]=’’;//’॥’; conv[‘0’]=‘۰’; conv[‘1’]=‘۱’; conv[‘2’]=‘۲’; conv[‘3’]=‘۳’; conv[‘4’]=‘۴’; conv[‘5’]=‘۵’; conv[‘6’]=‘۶’; conv[‘7’]=‘۷’; conv[‘8’]=‘۸’; conv[‘9’]=‘۹’; conv[’॰’]=’॰’ conv[‘ॱ’]=’’;//‘ॱ’; conv[‘ॲ’]=’’;//‘ॲ’; conv[‘ॳ’]=’’;//‘ॳ’; conv[‘ॴ’]=’’;//‘ॴ’; conv[‘ॵ’]=’’;//‘ॵ’; conv[‘ॶ’]=’’;//‘ॶ’; conv[‘ॷ’]=’’;//‘ॷ’; conv[‘ॸ’]=’’;//‘ॸ’; conv[‘ॹ’]=’’;//‘ॹ’; conv[‘ॺ’]=’’;//‘ॺ’; conv[‘ॻ’]=’’;//‘ॻ’; conv[‘ॼ’]=’’;//‘ॼ’; conv[‘ॽ’]=’’;//‘ॽ’; conv[‘ॾ’]=’’;//‘ॾ’; conv[‘ॿ’]=’’;//‘ॿ’; conv[’?’]=’؟’; conv[’.’]=’۔’; function xliterate() { src = document.getElementById(‘src’).value; google.language.translate(src, “en”, “hi”, function(result) { if (!result.error) { mid = result.translation; dest=’’; for(i=0; i<mid.length;i++) { dest=dest+ ((conv[mid[i]]!=undefined) ? conv[mid[i]] : mid[i]); } document.getElementById(‘dest’).value=dest; } else { alert(result.error); } }); }
How are you? آپ کیسی ہیں؟
(Thanks to عزت مآب جناب آغا علی رضا قزلباش رحمتہ اللہ علیہ who graciously sent me his term report on Hindi to Urdu transliteration, from where I’ve copied (and modified) the character mapping.)