Skip to content

Instantly share code, notes, and snippets.

@tenphi
Created January 29, 2019 08:35
Show Gist options
  • Save tenphi/e6d7b6c71631c64eb5ef68edeb8873ae to your computer and use it in GitHub Desktop.
Save tenphi/e6d7b6c71631c64eb5ef68edeb8873ae to your computer and use it in GitHub Desktop.
Transliteration
TRANSLITE_DICT = {"Ё":"YO","Й":"I","Ц":"TS","У":"U","К":"K","Е":"E","Н":"N","Г":"G","Ш":"SH","Щ":"SCH","З":"Z","Х":"H","Ъ":"","ё":"yo","й":"i","ц":"ts","у":"u","к":"k","е":"e","н":"n","г":"g","ш":"sh","щ":"sch","з":"z","х":"h","ъ":"","Ф":"F","Ы":"I","В":"V","А":"a","П":"P","Р":"R","О":"O","Л":"L","Д":"D","Ж":"ZH","Э":"E","ф":"f","ы":"i","в":"v","а":"a","п":"p","р":"r","о":"o","л":"l","д":"d","ж":"zh","э":"e","Я":"Ya","Ч":"CH","С":"S","М":"M","И":"I","Т":"T","Ь":"","Б":"B","Ю":"YU","я":"ya","ч":"ch","с":"s","м":"m","и":"i","т":"t","ь":"","б":"b","ю":"yu"};
transliterate = function(word){
return word.split('').map(function(char){
return typeof TRANSLITE_DICT[char] !== 'undefined' ? TRANSLITE_DICT[char] : char;
}).join("").replace(/\s/g, '-').toLowerCase().replace(/[^\w^-]/gi, '');
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment