DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
Translit
// Transliteration (or Translit for short).
// Converts Russian characters into Latin on-the-fly.
// Save the code as UTF-8.
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Translit</title>
<script type="text/javascript">
/* Javascript functions */
function JSfunc()
{
/* Making transliteration! */
this.strTranslit = function(el)
{
new_el = document.getElementById('out');
A = new Array();
A["Ð"]="YO";A["Й"]="I";A["Ц"]="TS";A["У"]="U";A["К"]="K";A["Е"]="E";A["Ð"]="N";A["Г"]="G";A["Ш"]="SH";A["Щ"]="SCH";A["З"]="Z";A["Ð¥"]="H";A["Ъ"]="'";
A["ё"]="yo";A["й"]="i";A["ц"]="ts";A["у"]="u";A["к"]="k";A["е"]="e";A["н"]="n";A["г"]="g";A["ш"]="sh";A["щ"]="sch";A["з"]="z";A["х"]="h";A["ъ"]="'";
A["Ф"]="F";A["Ы"]="I";A["Ð’"]="V";A["Ð"]="A";A["П"]="P";A["Ð "]="R";A["О"]="O";A["Л"]="L";A["Д"]="D";A["Ж"]="ZH";A["Ð"]="E";
A["Ñ„"]="f";A["Ñ‹"]="i";A["в"]="v";A["а"]="a";A["п"]="p";A["Ñ€"]="r";A["о"]="o";A["л"]="l";A["д"]="d";A["ж"]="zh";A["Ñ"]="e";
A["Я"]="YA";A["Ч"]="CH";A["С"]="S";A["М"]="M";A["И"]="I";A["Т"]="T";A["Ь"]="'";A["Б"]="B";A["Ю"]="YU";
A["Ñ"]="ya";A["ч"]="ch";A["Ñ"]="s";A["м"]="m";A["и"]="i";A["Ñ‚"]="t";A["ÑŒ"]="'";A["б"]="b";A["ÑŽ"]="yu";
new_el.value = el.value.replace(/([\u0410-\u0451])/g,
function (str,p1,offset,s) {
if (A[str] != 'undefined'){return A[str];}
}
);
}
/* Normalizes a string, eÑŽ => eyu */
this.strNormalize = function(el)
{
if (!el) { return; }
this.strTranslit(el);
}
}
var oJS = new JSfunc();
</script>
</head>
<body>
<p>введите текÑÑ‚:</p>
<textarea onkeyup="oJS.strNormalize(this)" style="height:10em;width:100%" id="in"></textarea>
<p>результат:</p>
<textarea style="height:10em;width:100%" id="out"></textarea>
</body>
</html>






Comments
Snippets Manager replied on Fri, 2007/08/10 - 5:24pm