var ru = { 'а':'a', 'б':'b', 'в':'v', 'г':'g', 'д':'d', 'е':'e', 'ё':'yo', 'ж':'zh', 'з':'z', 'и':'i', 'й':'y', 'к':'k', 'л':'l', 'м':'m', 'н':'n', 'о':'o', 'п':'p', 'р':'r', 'с':'s', 'т':'t', 'у':'u', 'ф':'f', 'х':'h', 'ц':'ts', 'ч':'ch', 'ш':'sh', 'щ':'sch', 'ъ':'', 'ы':'y', 'ь':'', 'э':'e', 'ю':'yu', 'я':'ya', 'А':'A', 'Б':'B', 'В':'V', 'Г':'G', 'Д':'D', 'Е':'E', 'Ё':'Yo', 'Ж':'Zh', 'З':'Z', 'И':'I', 'Й':'J', 'К':'K', 'Л':'L', 'М':'M', 'Н':'N', 'О':'O', 'П':'P', 'Р':'R', 'С':'S', 'Т':'T', 'У':'U', 'Ф':'F', 'Х':'H', 'Ц':'Ts', 'Ч':'Ch', 'Ш':'Sh', 'Щ':'Sch', 'Ъ':'', 'Ы':'Y', 'Ь':'', 'Э':'E', 'Ю':'Yu', 'Я':'Ya' } var ALL_DOWNCODE_MAPS=new Array() ALL_DOWNCODE_MAPS[0] = ru var Downcoder = new Object(); Downcoder.Initialize = function() { if (Downcoder.map) // already made return ; Downcoder.map ={} Downcoder.chars = '' ; for(var i in ALL_DOWNCODE_MAPS) { var lookup = ALL_DOWNCODE_MAPS[i] for (var c in lookup) { Downcoder.map[c] = lookup[c] ; Downcoder.chars += c ; } } Downcoder.regex = new RegExp('[' + Downcoder.chars + ']|[^' + Downcoder.chars + ']+','g') ; } downcode= function( slug ) { Downcoder.Initialize() ; var downcoded ="" var pieces = slug.match(Downcoder.regex); if(pieces) { for (var i = 0 ; i < pieces.length ; i++) { if (pieces[i].length == 1) { var mapped = Downcoder.map[pieces[i]] ; if (mapped != null) { downcoded+=mapped; continue ; } } downcoded+=pieces[i]; } } else { downcoded = slug; } return downcoded; } function URLify(s, num_chars) { // changes, e.g., "Petty theft" to "petty_theft" // remove all these words from the string before urlifying s = downcode(s); s = s.replace(/[^-\w\s]/g, '-'); // remove unneeded chars s = s.replace(/^\s+|\s+$/g, ''); // trim leading/trailing spaces s = s.replace(/[-\s]+/g, '-'); // convert spaces to hyphens s = s.toLowerCase(); // convert to lowercase return s.substring(0, num_chars);// trim to first num_chars chars }