JavaScript - Kонвектор от ЛАТИНИЦА на КИРИЛИЦА и обратно

staf

Registered
Демо:
http://www.web-tourist.net/project/staf/Convertor.html

Код:
<HTML>
<script language="JavaScript">var PUpage="76001070"; var PUprop="geocities"; </script><script language="JavaScript" src="http://www.geocities.com/js_source/pu5geo.js"></script><script language="JavaScript" src="http://www.geocities.com/js_source/ygIELib9.js?v3"></script><script language="JavaScript">var yviContents='http://k-3.hit.bg/toto?s=76001070&l=NE&b=1&t=1090973036';yviR='us';yfiEA(0);</script>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<HTML><HEAD><TITLE>Cyrillic/Latin Converter</TITLE>
<META http-equiv=Content-Type content="text/html; charset=windows-1251">
<SCRIPT language=JavaScript>
/* 
   Description: Converts Bulgarian Cyrillic(Win1251)
		to Latin and vice versa.
   Copyright: Val Todorov
   e-mail: vtodorov@astro.ocis.temple.edu   
   Date: 12/12/1996
*/

C=new Array(
  'А','Б','В','Г','Д','Е','Ж','З','И','Й','К','Л','М','Н','О',
  'П','Р','С','Т','У','Ф','Х','Ц','Ч','Ш','Щ','Ъ','Ь','Ю','Я',
  'а','б','в','г','д','е','ж','з','и','й','к','л','м','н','о',
  'п','р','с','т','у','ф','х','ц','ч','ш','щ','ъ','ь','ю')

L=new Array(
  'A','B','V','G','D','E','Zh','Z','I','J','K','L','M','N','O',
  'P','R','S','T','U','F','H','C','Ch','Sh','Sht','Y','J','Ju','q',
  'a','b','v','g','d','e','zh','z','i','j','k','l','m','n','o',
  'p','r','s','t','u','f','h','c','ch','sh','sht','y','j','ju')

//------------------------------------
Lat=new Array()
for (q=0;q<59;q++) Lat[C[q]]=L[q]

function toLat(cyr) {
  lat=''
  for (q=0;q<cyr.length;q++) {
    ch=cyr.charAt(q)

    if (Lat[ch]) {
      lat+=Lat[ch]

      chL=Lat[ch].toLowerCase()
      nxt=cyr.charAt(q+1)
      if ((chL=='z' || chL=='s') && Lat[nxt]) {
        if (Lat[nxt]=='h') {lat+='x'; q++}
        else if (Lat[nxt]=='H') {lat+='X'; q++} 
      }

    }
    else if (ch==unescape('%FF')) lat+='ja'
    else lat+=ch
  }
  return lat
}

//------------------------------------
Cyr=new Array()
for (q=0;q<59;q++) {
  if (q==27 || q==57) continue
  Cyr[L[q]]=C[q]
}
Cyr['Q']='Ъ', Cyr['q']='ъ'
Cyr['W']='В', Cyr['w']='в'
Cyr['X']='Х', Cyr['x']='х'
Cyr['ja']=unescape('%FF')
Cyr['erM']='ь'

function toCyr(lat) {
  cyr=''
  for (q=0;q<lat.length;q++) {
    ch=lat.charAt(q)
    chL=ch.toLowerCase()
    nxt=lat.charAt(q+1).toLowerCase()

    if (chL=='c' || chL=='s' || chL=='z')
      if (nxt=='h') {ch+=nxt; q++}

    chL=ch.toLowerCase()
    nxt=lat.charAt(q+1).toLowerCase()     
    if (chL=='sh' && nxt=='t') {ch+=nxt; q++}

    if (chL=='j' && (nxt=='u' || nxt=='a')) {ch+=nxt; q++}

    if (chL=='j' && nxt=='o' && Cyr[lat.charAt(q-1)]) {
      vowels='aeiou', vowel=false
      for (i=0;i<vowels.length;i++) 
        if (lat.charAt(q-1).toLowerCase()==vowels[i]) vowel=true
      if (!vowel) ch='erM'
    }

    if (Cyr[ch]) cyr+=Cyr[ch]
    else cyr+=ch
  }
  return cyr
}

</SCRIPT>

<FORM>
<META content="MSHTML 5.50.4134.100" name=GENERATOR></HEAD>
<BODY>
<CENTER>
<TABLE>
  <TBODY>
  <TR>
    <TH><INPUT onclick="this.form.Lat.value=''" type=button value=Clear> <INPUT onclick=this.form.Cyr.value=toCyr(this.form.Lat.value) type=button value="Latin to Cyrillic ->"> 

    <TH><INPUT onclick=this.form.Lat.value=toLat(this.form.Cyr.value) type=button value="<- Cyrillic to Latin"> 
<INPUT onclick="this.form.Cyr.value=''" type=button value=Clear> 
  <TR>
    <TD><TEXTAREA name=Lat rows=20 cols=35></TEXTAREA> 
    <TD><TEXTAREA name=Cyr rows=20 cols=35></TEXTAREA> 
</TR></TBODY></TABLE></CENTER></FORM><B>Bulgarian Alphabet:</B>
<P>
<SCRIPT language=JavaScript>
table='<TABLE BORDER=1>'
for (q=0;q<30;q++) {
  if (q%10==0) table+='<TR>'
  table+='<TH>'+L[q]
}
table+='</TABLE>'
document.write(table)
</SCRIPT>

<DL>
  <DT><I>Note</I>: 
  <DD><B>W</B>, <B>X</B> and <B>Q</B> may substitute <B>V</B>, <B>H</B> and 
  <B>Y</B> respectively. <BR><B>H</B> after <B>Z</B> must be <B>X</B>. </DD></DL>
<P><B>How to use Cyrillic fonts:</B> 
<OL>
  <LI>Options > General Preferences > Fonts 
  <UL>
    <LI>
    <DL>
      <DT>Fonts and Encodings dialog box: 
      <DD>For the Encoding > Cyrillic <BR>Use the Proportional Font > 
      Choose Font</DD></DL>
    <LI>
    <DL>
      <DT>Choose Base Font dialog box: 
      <DD>Font > Lucida Sans Unicode <BR>Script > Cyrillic</DD></DL></LI></UL>
  <LI>Options > Document Encoding > Cyrillic(Win1251) 
</LI></OL></BODY></HTML>
</object></layer></div></span></style></noscript></table></script></applet><script language="JavaScript" src="http://us.i1.yimg.com/us.yimg.com/i/mc/mc.js"></script><script language="JavaScript" src="http://geocities.com/js_source/geov2.js"></script><script language="javascript">geovisit();</script><noscript><img src="http://visit.webhosting.yahoo.com/visit.gif?us1090973036" alt="setstats" border="0" width="1" height="1"></noscript>
<IMG SRC="http://geo.yahoo.com/serv?s=76001070&t=1090973036" ALT=1 WIDTH=1 HEIGHT=1>
</HTML>
 

hellfire

Registered
Добре а ще можеш ли да кажеш как ще стане в същата textarea да прави функцията ?
 

Горе