Created
July 2, 2012 11:46
-
-
Save b1/3032843 to your computer and use it in GitHub Desktop.
javascript transliteration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String.prototype.translit = (function(){ | |
var L = { | |
'А':'A','а':'a','Б':'B','б':'b','В':'V','в':'v','Г':'G','г':'g', | |
'Д':'D','д':'d','Е':'E','е':'e','Ё':'Yo','ё':'yo','Ж':'Zh','ж':'zh', | |
'З':'Z','з':'z','И':'I','и':'i','Й':'Y','й':'y','К':'K','к':'k', | |
'Л':'L','л':'l','М':'M','м':'m','Н':'N','н':'n','О':'O','о':'o', | |
'П':'P','п':'p','Р':'R','р':'r','С':'S','с':'s','Т':'T','т':'t', | |
'У':'U','у':'u','Ф':'F','ф':'f','Х':'Kh','х':'kh','Ц':'Ts','ц':'ts', | |
'Ч':'Ch','ч':'ch','Ш':'Sh','ш':'sh','Щ':'Sch','щ':'sch','Ъ':'"','ъ':'"', | |
'Ы':'Y','ы':'y','Ь':"'",'ь':"'",'Э':'E','э':'e','Ю':'Yu','ю':'yu', | |
'Я':'Ya','я':'ya' | |
}, | |
r = '', | |
k; | |
for (k in L) r += k; | |
r = new RegExp('[' + r + ']', 'g'); | |
k = function(a){ | |
return a in L ? L[a] : ''; | |
}; | |
return function(){ | |
return this.replace(r, k); | |
}; | |
})(); | |
alert('нужна функция перевода слова из кириллицы в транслит'.translit()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment