Skip to content

Instantly share code, notes, and snippets.

@r37r0m0d3l
Created September 12, 2012 12:16
Show Gist options
  • Save r37r0m0d3l/3706242 to your computer and use it in GitHub Desktop.
Save r37r0m0d3l/3706242 to your computer and use it in GitHub Desktop.
Translit
var ru2en =
{
ru_str : "АБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯабвгдеёжзийклмнопрстуфхцчшщъыьэюя",
en_str : ['A','B','V','G','D','E','JO','ZH','Z','I','J','K','L','M','N','O','P','R','S','T',
'U','F','H','C','Ch','Sh','Shh',String.fromCharCode(35),'I',String.fromCharCode(39),'Je','Ju',
'Ja','a','b','v','g','d','e','jo','zh','z','i','j','k','l','m','n','o','p','r','s','t','u','f',
'h','c','ch','sh','shh',String.fromCharCode(35),'i',String.fromCharCode(39),'je','ju','ja'],
translit : function(org_str)
{
var tmp_str = "";
for(var i = 0, l = org_str.length; i < l; i++)
{
var s = org_str.charAt(i), n = this.ru_str.indexOf(s);
tmp_str += n >= 0 ? this.en_str[n] : s;
}
return tmp_str;
},
}
ru2en.translit('name');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment