Last active
October 26, 2023 21:00
-
-
Save mlshv/295fefcc04fdf1b6ce2acfa677d6812a to your computer and use it in GitHub Desktop.
Двусторонний транслит (перевод с транслита на русский и наоборот)
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
// Чуть-чуть поменял код отсюда: https://javascript.ru/forum/misc/27347-nadezhnyjj-dvukhstoronnijj-translit.html#post168115 | |
var transliterate = ( | |
function() { | |
var rus = "щ ш ч ц ю я ё ж з ъ ы э а б в г д е з и й к л м н о п р с т у ф х ь".split(/ +/g); | |
var eng = "shh sh ch cz yu ya yo zh th `` y' e` a b v g d e z i j k l m n o p r s t u f h `".split(/ +/g); | |
return function(text, engToRus) { | |
for (var x = 0; x < rus.length; x++) { | |
text = text.split(engToRus ? eng[x] : rus[x]).join(engToRus ? rus[x] : eng[x]); | |
text = text.split(engToRus ? eng[x].toUpperCase() : rus[x].toUpperCase()).join(engToRus ? rus[x].toUpperCase() : eng[x].toUpperCase()); | |
} | |
return text; | |
} | |
} | |
)(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment