Skip to content

Instantly share code, notes, and snippets.

@meysampg
Created April 19, 2016 09:10
Show Gist options
  • Save meysampg/41bdc155511a7e03090b7922a6ca50f9 to your computer and use it in GitHub Desktop.
Save meysampg/41bdc155511a7e03090b7922a6ca50f9 to your computer and use it in GitHub Desktop.
Convert a mis-layouted persian string to readable one
var msg = 'hdk d; k,aji thvsd hsj';
var engPerLet = {
' ': ' ',
'a': 'ش',
's': 'س',
'd': 'ی',
'f': 'ب',
'g': 'ل',
'h': 'ا',
'j': 'ت',
'k': 'ن',
'l': 'م',
';': 'ک',
'q': 'ض',
'w': 'ص',
'e': 'ث',
'r': 'ق',
't': 'ف',
'y': 'غ',
'u': 'ع',
'i': 'ه',
'o': 'خ',
'p': 'ح',
'[': 'ج',
']': 'چ',
'z': 'ظ',
'x': 'ط',
'c': 'ز',
'v': 'ر',
'b': 'ذ',
'n': 'د',
'm': 'پ',
',': 'و',
'.': '.',
'M': 'ء'
};
str = '';
for (i = 0; i < msg.length; ++i) {
str += engPerLet[msg[i]];
}
alert(str);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment