Created
March 4, 2015 12:03
-
-
Save osv/8d62e3ea5f0539c6f821 to your computer and use it in GitHub Desktop.
ua-ru translate js, translate miss ru keyboard
This file contains hidden or 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
var transliterate = ( | |
function() { | |
var | |
rus = "щ ш ч ц ю я ё ж ъ ы э а б в г д е з и й к л м н о п р с т у ф х ь і ї є ґ".split(/ +/g), | |
eng = "shh sh ch cz yu ya yo zh ' y e a b v g d e z i j k l m n o p r s t u f x ` i yi e g".split(/ +/g); | |
return function(text, engToRus) { | |
if (!text) | |
return ""; | |
var x; | |
for(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; | |
}; | |
} | |
)(); | |
// Эта функция вернет кирилицу если расскладка была английская | |
var translateMissKbd = ( | |
function() { | |
var | |
eng = "o i x w . z ` ; m s ' f , d u l t p b q r k v y j g h c n e a [ m s ] \\".split(/ +/g), | |
rus = "щ ш ч ц ю я ё ж ъ ы э а б в г д е з и й к л м н о п р с т у ф х ь і ї ґ ".split(/ +/g); | |
return function(text, engToRus) { | |
if (!text) | |
return ""; | |
var x; | |
for(x = 0; x < eng.length; x++) { | |
text = text.split(eng[x]).join(rus[x]); | |
} | |
return text; | |
}; | |
} | |
)(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
translateMissKbd - вернет текст на русском если ошибочная раскладка клавиатуры была