Tuesday, December 10, 2013

Javascript ile Türkçe heceleme uygulaması

Eğer sayfalarınızdaki metinlerde Türkçe heceleme uygulaması ihtiyacınız varsa bu kod ile, düz metinlere heceleme karakteri eklemeniz mümkün.

// Hecleme
function Hecele(Sozcuk)
{
 var Sozcukler = Sozcuk.split(" ");
 
 for (var i2 = 0; i2 < Sozcukler.length; i2++) 
 {
  var i=-1;
  while (i < Sozcukler[i2].length)
  {
   i++;

   if ((Sozcukler[i2].charAt(i) == "a") || (Sozcukler[i2].charAt(i) == "ı") || (Sozcukler[i2].charAt(i) == "o") || (Sozcukler[i2].charAt(i) == "u") || (Sozcukler[i2].charAt(i) == "e") || (Sozcukler[i2].charAt(i) == "i") || (Sozcukler[i2].charAt(i) == "ö") || (Sozcukler[i2].charAt(i) == "ü"))
   {
    SonucVar = false;
    //sağ tarafındaki ilk harf sesli mi
    if (i < (Sozcukler[i2].length-1))
    {
     if ((Sozcukler[i2].charAt(i+1) == "a") || (Sozcukler[i2].charAt(i+1) == "ı") || (Sozcukler[i2].charAt(i+1) == "o") || (Sozcukler[i2].charAt(i+1) == "u") || (Sozcukler[i2].charAt(i+1) == "e") || (Sozcukler[i2].charAt(i+1) == "i") || (Sozcukler[i2].charAt(i+1) == "ö") || (Sozcukler[i2].charAt(i+1) == "ü"))
     {
      i++;
      Sozcukler[i2] = [Sozcukler[i2].slice(0, i), "-", Sozcukler[i2].slice(i)].join('');
      SonucVar = true;
     }
    }

    //sağ tarafındaki ikinci harf sesli mi
    if ( (i < (Sozcukler[i2].length-2)) && (!SonucVar) )
    {
     if ((Sozcukler[i2].charAt(i+2) == "a") || (Sozcukler[i2].charAt(i+2) == "ı") || (Sozcukler[i2].charAt(i+2) == "o") || (Sozcukler[i2].charAt(i+2) == "u") || (Sozcukler[i2].charAt(i+2) == "e") || (Sozcukler[i2].charAt(i+2) == "i") || (Sozcukler[i2].charAt(i+2) == "ö") || (Sozcukler[i2].charAt(i+2) == "ü"))
     {
      i++;
      Sozcukler[i2] = [Sozcukler[i2].slice(0, i), "-", Sozcukler[i2].slice(i)].join('');
      SonucVar = true;
     }
    }

    //sağ tarafındaki üçüncü harf sesli mi
    if ( (i < (Sozcukler[i2].length-3)) && (!SonucVar) )
    {
     if ((Sozcukler[i2].charAt(i+3) == "a") || (Sozcukler[i2].charAt(i+3) == "ı") || (Sozcukler[i2].charAt(i+3) == "o") || (Sozcukler[i2].charAt(i+3) == "u") || (Sozcukler[i2].charAt(i+3) == "e") || (Sozcukler[i2].charAt(i+3) == "i") || (Sozcukler[i2].charAt(i+3) == "ö") || (Sozcukler[i2].charAt(i+3) == "ü"))
     {
      i++;
      i++;
      Sozcukler[i2] = [Sozcukler[i2].slice(0, i), "-", Sozcukler[i2].slice(i)].join('');
      SonucVar = true;
     }
    }

   }
  }
 }

 var Sonuc = "";
 for (var i2 = 0; i2 < Sozcukler.length; i2++) 
 {
  Sonuc += Sozcukler[i2];
  if ( i2 < Sozcukler.length-1 ) { Sonuc += " "; }
 }
 
 return Sonuc;
}

4 comments:

  1. çalışmıyor bu. İstanbul kelimesini İstan-bul diye heceledi.

    ReplyDelete
  2. evet bence de çalımıyor. Türkçe kelimesini heceleyemedi.

    ReplyDelete
  3. Adafruit presents a enjoyable and thrilling stickers to rejoice achievement for electronics, science and engineering. We believe everyone ought to be able to|be succesful of|have the power to} be rewarded for studying a helpful talent, a sticker is just one of the many ways level out|to indicate} and share. This is the "I realized method to|tips on how to} 3D print" badge for use with educators, lecture rooms, workshops, Maker... Adafruit presents a enjoyable and thrilling "badges" of achievement for electronics, science and engineering. We believe everyone ought to be able to|be succesful of|have the power to} be rewarded for studying a helpful talent, toilet handle a badge is just one of the many ways level out|to indicate} and share. This is the "I realized method to|tips on how to} 3D print" badge to be used with educators, lecture rooms, workshops, Maker Faires,...

    ReplyDelete
  4. Guests can surf the 코인카지노 web utilizing the complimentary wireless Internet access. Business-friendly amenities include telephones along with free native calls . There's a restaurant on website, properly as|in addition to} a espresso shop/cafe and a snack bar/deli.

    ReplyDelete