Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: Polski spell checker
Forum PHP.pl > Forum > Gotowe rozwiązania
son
Witam
Chciałem zainstalować sobie skrypt phpspell. Skrypt jest już na serwerze, słownik podłączony. Problem jest tylko ze zmuszeniem go do pracy z polskimi czcionkami...
Zdaje się, że wystarczy tylko edytować jeden plik odpowiedzialny za dany język. Dla przykładu podam angielski i rosyjski:

Angielski:
Kod
<?php
  // --------------------------------------------------------------------
  // phpSpell Language Template
  //
  // This is (c)Copyright 2002, 2003, Team phpSpell.
  // --------------------------------------------------------------------

  // --------------------------
  // Table Name
  // --------------------------
  $DB_TableName=$table_prefix."spelling_words";

  // Language Text
  $Language_Text = array('Scanned %d words.    Found %d words to be corrected.');
  $Language_Javascript = array('Checking Document...','No misspellings found','OK','Cancel','Spell Check Completed','Correct','All','Ignore','Learn','Suggest','Definition','Thesaurus','Word correction','No Suggestions');

  // Prefix Database name for MSSQL tables
//  if ($dbms == "mssql") {
//    $DB_TableName = $dbname.".".$DB_TableName;
//  }

  // ---------------------------------------
  // PSPELL Support - Use English Dictionary
  // ---------------------------------------
  $Spell_Config["PSPELL_LANGUAGE"] = "en";
  // --------------------------------------------------------------------
  // Example translation table:
  //     $Translation_Table = array("Ŕ", "Ć", "Ç");
  //     $Replacement_Table = array("a", "an", "sth");
  //     $Language_Translation_Character_List = "ŔĆÇ";
  // --------------------------------------------------------------------
  // for every "Ŕ" it finds in a word it will replace it with a "a"
  // for every "Ç" it finds it will replace it with a "sth"
  // for every "Ć" it finds it will replace it with a "an"
  // --------------------------------------------------------------------
  // Put the character(s) to be translated into the Translation_Table
  // Put the replacement character(s) into the replacement table
  // --------------------------------------------------------------------
  // The replacement string should be equivelent to the ENGLISH PHONETIC
  // sound.  So if you were to take a word with "Ŕ" in it; how would you
  // phonetically spell the word in english.  If the "Ŕ" sounds like a "A"
  // in english then "A" would be the replacement character.
  // If it sounds like "th" then you would use "th" as the characters.
  // always replace Larger groups first.  (i.e. if "ńń" sounds differently
  // than "ń" then in the translation table you would have the "ńń" listed
  // before the "ń".  So that way when it would replaced the "ńń" before it
  // replaced it twice with "ń".
  // --------------------------------------------------------------------
  // Any letters you do not translate will be IGNORED for
  // when it attempts to find spelling matches!!!
  // --------------------------------------------------------------------
  $Translation_Table = array();
  $Replacement_Table = array();

  // --------------------------------------------------------------------
  // Put the list of valid characters in your language in this list
  // --------------------------------------------------------------------
  $Language_Character_List = "abcdefghijklmnopqrstuvwxyz'";
  $Language_Common_Words = ",the,is,was,be,are,were,been,being,am,of,and,a,an,in,inside,to,have,has,had,
having,he,him,his,it,its,i,me,my,to,they,their,not,no,for,you,your,she,her,with,o
n,that,these,this,those,do,did,does,done,doing,we,us,our,by,at,but,from,as,which,
or,will,said,say,says,saying,would,what,there,if,can,who,whose,so,go,gone,went,go
es,more,other,another,one,see,saw,seen,seeing,know,knew,known,knows,knowing,there
,";

  // --------------------------------------------------------------------
  // Translation function
  // --------------------------------------------------------------------
  function Translate_Word($Word) {
    return ($Word);
  }

  // --------------------------------------------------------------------
  // Phonetic work function
  // --------------------------------------------------------------------
  function Word_Sound_Function($Word) {
    return (metaphone($Word));
  }


  function Language_Decode(&$Data)
  {
    // MS Internet Explorer Hack -- IE sends utf8-unicode for upper (ascii 128+) characters
     if (strpos(@$_SERVER['HTTP_USER_AGENT'], 'MSIE') > 0 || strpos(@$_SERVER['ALL_HTTP'], 'MSIE') > 0) {
       if (function_exists('utf8_decode')) $Data = utf8_decode($Data);
     }
     return ($Data);
  }

  function Language_Encode(&$Data)
  {
    return ($Data);
  }

  function Language_Lower(&$Data)
  {
    return(strtolower($Data));
  }

  function Language_Upper(&$Data)
  {
    return(strtoupper($Data));
  }

?>

Rosyjski:
Kod
<?php
  // --------------------------------------------------------------------
  // phpSpell Language Template
  //
  // This is (c)Copyright 2002, 2003 Team phpSpell.
  // --------------------------------------------------------------------

  // --------------------------
  // Table Name
  // --------------------------
  $DB_TableName="russian_spelling_words";
  $Meta_Language = "windows-1251";

  // Language Text  (Recommend that they are converted to HTML entities - that way they should display in all browsers properly)
  $Language_Text = array('Scanned %d words.    Found %d words to be corrected.');
  $Language_Javascript = array('Проверка текста',
                               'Нет ошибок',
                               'OK',
                               'Отменить',
                               'Нет предложени',
                               'Исправить',
                               'Все',
                               'Пропустить',
                               'Learn','Suggest','Definition','Thesaurus',
                               'Правка слова',
                               'No Suggestions');

  // ---------------------------------------
  // PSPELL Support - Use English Dictionary
  // ---------------------------------------
  $Spell_Config["PSPELL_LANGUAGE"] = "ru";

  // --------------------------------------------------------------------
  // Example translation table:
  //     $Translation_Table = array("Ŕ", "Ć", "Ç");
  //     $Replacement_Table = array("a", "an", "sth");
  //     $Language_Translation_Character_List = "ŔĆÇ";
  // --------------------------------------------------------------------
  // for every "Ŕ" it finds in a word it will replace it with a "a"
  // for every "Ç" it finds it will replace it with a "sth"
  // for every "Ć" it finds it will replace it with a "Ć"
  // --------------------------------------------------------------------
  // Put the character(s) to be translated into the Translation_Table
  // Put the replacement character(s) into the replacement table
  // --------------------------------------------------------------------
  // The replacement string should be equivelent to the ENGLISH PHONETIC
  // sound.  So if you were to take a word with "Ŕ" in it; how would you
  // phonetically spell the word in english.  If the "Ŕ" sounds like a "A"
  // in english then "A" would be the replacement character.
  // If it sounds like "th" then you would use "th" as the characters.
  // always replace Larger groups first.  (i.e. if "ńń" sounds differently
  // than "ń" then in the translation table you would have the "ńń" listed
  // before the "ń".  So that way when it would replaced the "ńń" before it
  // replaced it twice with "ń".
  // --------------------------------------------------------------------
  // Any letters you do not translate will be IGNORED for
  // when it attempts to find spelling matches!!!
  // --------------------------------------------------------------------
  $Translation_Table = array("ŕ", "á", "â", "ă", "ä", "ĺ", "¸", "ć", "ç", "č", "é", "ę", "ë", "ě", "í", "î", "ď", "đ", "ń", "ň", "ó", "ô", "ő",  "ö",  "÷",  "ř",  "ů", "ű", "ý", "ţ", "˙", "ü");
  $Replacement_Table = array("a", "b", "v", "g", "d", "e", "o", "j", "z", "i", "y", "k", "l", "m", "n", "o", "p", "r", "s", "t", "u", "f", "kh", "ts", "ch", "sh", "shch", "i", "e", "u", "a", "");

  $Language_Translation_Character_List = "ŕáâăäĺ¸ćçčéęëěíîďđńňóôőö÷řůűýţ˙";

  // --------------------------------------------------------------------
  // Put the list of valid characters in your language in this list
  // --------------------------------------------------------------------
  $Language_Character_List = "ŕáâăäĺ¸ćçčéęëěíîďđńňóôőö÷řůúűüýţ˙";

  // --------------------------------------------------------------------
  // Put the list of most common words in this list ",word,word,word,"
  // --------------------------------------------------------------------
  $Language_Common_Words = ",ŕ,áĺç,áîëĺĺ,áű,áűë,áűëŕ,áűëč,áűëî,áűňü,â,âŕě,âŕń,âĺńü,âî,âîň,âńĺ,âńĺăî,âńĺő
,âű,ăäĺ,äŕ,äŕćĺ,äë˙,äî,ĺăî,ĺĺ,ĺńëč,ĺńňü,ĺůĺ,ćĺ,çŕ,çäĺńü,č,čç,čëč,čě,čő,ę,ęŕę,ęî,ę
îăäŕ,ęňî,ëč,ëčáî,ěíĺ,ěîćĺň,ěű,íŕ,íŕäî,íŕř,íĺ,íĺăî,íĺĺ,íĺň,íč,íčő,íî,íó,î,îá,îäíŕę
î,îí,îíŕ,îíč,îíî,îň,î÷ĺíü,ďî,ďîä,ďđč,ń,ńî,ňŕę,ňŕęćĺ,ňŕęîé,ňŕě,ňĺ,ňĺě,ňî,ňîăî,ňîćĺ
,ňîé,ňîëüęî,ňîě,ňű,ó,óćĺ,őîň˙,÷ĺăî,÷ĺé,÷ĺě,÷ňî,÷ňîáű,÷üĺ,÷ü˙,ýňŕ,ýňč,ýňî,˙,ä,ĺ,¸,
ć,ç,é,ë,ě,í,đ,ň,ô,ő,ö,÷,ř,ů,ű,ý,ţ,";

  // --------------------------------------------------------------------
  // Translation function
  // --------------------------------------------------------------------
  function Translate_Word($Word) {
    global $Translation_Table, $Replacement_Table;

    $New_Word = str_replace($Translation_Table, $Replacement_Table, $Word);
//    echo "New: $New_Word<br>";
    return ($New_Word);
  }

  // --------------------------------------------------------------------
  // Phonetic work function
  // --------------------------------------------------------------------
  function Word_Sound_Function($Word) {
    return (metaphone($Word));
  }

  // Based off of the code by bn2@ukr.net
  function Language_Decode($Data)
  {
    global $Encode_Type;
    $Output='';
    $FirstByte='';
    $MultiByte=false;
    $Counter = strlen($Data);

    $Pos1 = strpos($Data, '&#10');
    $Pos2 = strpos($Data, '&#11');
    if ($Pos1 !== false || $Pos2 !== false) {
      if ($Pos1 === false) $Pos1 = $Pos2;
      if ($Data[$Pos1+6] == ';') {
         $Encode_Type = 2;
         if (version_compare("4.3.2", phpversion(), "<=")) {
           $Output = html_entity_decode($Data, ENT_NOQUOTES, "cp1251");
         } else {
           echo "<!-- Second -->";
//           $Output = myhtml_entity_decode($Data);
         }
      }
    }

    if ($Encode_Type == 0) {
      for ($i=0;$i<$Counter;$i++) {
        $Code = ord($Data[$i]);
        if ($Code <= 127) $Output .= $Data[$i];
        else {
          if ($MultiByte) {
            $Conv_2=($FirstByte&3)*64+($Code&63);
            $Conv_1=($FirstByte>>2)&5;
            $Converted=$Conv_1*256+$Conv_2;
            if ($Converted==1025) $NewCharacter=168;
            else if ($Converted==1105) $NewCharacter=184;
            else $NewCharacter=$Converted-848;
            $Output.=chr($NewCharacter);
            $MultiByte=false;
          } else if (($Code>>5)==6) {
            $Encode_Type = 1;
            $FirstByte=$Code;
            $MultiByte=true;
          } else $Output .= $Data[$i];
        }
      }
    }
    return $Output;
  }

  function Language_Encode($Data)
  {
    global $Encode_Type;
    if ($Encode_Type == 0) return ($Data);
    $Output = '';

    if ($Encode_Type == 3) {
      $Count = strlen($Data);
      for ($i=0;$i<$Count;$i++) {
         $Byte = ord($Data[$i]);
         if ($Byte <= 127) $Output .= $Data[$i];
         else if ($Byte >= 192 && $Byte <= 239) $Output .= chr(208).chr($Byte-48);
         else if ($Byte >= 240 && $Byte <= 255) $Output .= chr(209).chr($Byte-112);
         else if ($Byte == 184) $Output .= chr(209).chr(209);
         else if ($Byte == 168) $Output .= chr(208).chr(129);
      }
    }
    if ($Encode_Type == 2 || $Encode_Type == 1) { // || $Encode_Type == 1) {
       if (version_compare("4.3.2", phpversion(), "<=")) {
         $Output = htmlentities($Data, ENT_NOQUOTES, "cp1251");
       } else {
         $Output = $Data;
//           $Output = myhtml_entity_encode($Data);
       }
    }
    return ($Output);
  }

  function Language_Upper(&$Data)
  {
     $New_Data = strtoupper($Data);
     return ($New_Data);
  }

  function Language_Lower(&$Data)
  {
     // Translate
     $New_Data = strtr($Data, '×ߨ','÷˙¸');
     $New_Data = strtolower($New_Data);
     return ($New_Data);
  }
?>

ten plik może być źle wyświetlany ze względu na inne kodowanie

Czy mógłby mi ktoś podpowiedzieć jak powinien wyglądać taki plik dla polskiego słownika?
angel554
Też chciałbym polski słownik do spell-a

Jeśli ktoś ma - bardzo będę wdzięczny...

pozdrawiam
son
Nie chodzi o słownik, bo ten mam (jeżli dalej szukasz to mogę Ci dać). Mi chodzi tylko o modyfikację tego skryptu odpowiedzialnego za wersję językową tak, żeby współpracował z polską wersją
tiraeth
Pozamieniaj znaki w tablicach i w stringach na odpowiednie i będzie dobrze.... przecież opisy do zmiennych(tablic) są po angielsku... może wystarczy przysiąść do słownika?
son
Wydaje mi się, że pozamieniałem te co trzeba, niestety skrypt dalej 0ma poważne problemy ze słowami zawierącymi polskie znaki (np. rozdziela je) być może nie zrobiłem wszystkiego co trzeba dlatego proszę o pomoc
Fixer
w nowej wersji piszą że już wspiera polską wersję ale jakoś jednak nie działa sad.gif(

wciąż przerywa kolorowanie wyrazów na czerwono w przypadku gdy są polskie znaki.
Czy ktoś wie jak sobie z tym poradzić?

oryginalny plik spell_Polish.php
  1. <?php
  2. // --------------------------------------------------------------------
  3. // phpSpell Language Template
  4. //
  5. // This is (c)Copyright 2002-2005, Team phpSpell.
  6. // --------------------------------------------------------------------
  7.  
  8. // --------------------------
  9. // Table Name
  10. // --------------------------
  11. $DB_TableName="polish_spelling_words";
  12. $Meta_Language = "iso-8859-2";
  13.  
  14. // Language Text
  15. $Language_Text = array('Przeskanowano %d słów. Znaleziono %d słów do poprawienia.');
  16. $Language_Javascript = array('Sprawdznie dokumentu...','Nie znaleziono','OK','Anuluj','Sprawdzanie słownika zakończone','Popraw','Wszystkie','Ignoruj','Naucz','Sugeruj','Definicja','Słownik','Poprawienie wyrazu','Brak sugestii');
  17.  
  18. // Prefix Database name for MSSQL tables
  19. // if ($dbms == "mssql") {
  20. // $DB_TableName = $dbname.".".$DB_TableName;
  21. // }
  22.  
  23. // ---------------------------------------
  24. // PSPELL Support - Use English Dictionary
  25. // ---------------------------------------
  26. $Spell_Config["PSPELL_LANGUAGE"] = "pl";
  27. // --------------------------------------------------------------------
  28. // Example translation table:
  29. //  $Translation_Table = array("Ŕ", "Ć", "Ç");
  30. //  $Replacement_Table = array("a", "an", "sth");
  31. //  $Language_Translation_Character_List = "ŔĆÇ";
  32. // --------------------------------------------------------------------
  33. // for every "Ŕ" it finds in a word it will replace it with a "a"
  34. // for every "Ç" it finds it will replace it with a "sth"
  35. // for every "Ć" it finds it will replace it with a "an"
  36. // --------------------------------------------------------------------
  37. // Put the character(s) to be translated into the Translation_Table
  38. // Put the replacement character(s) into the replacement table
  39. // --------------------------------------------------------------------
  40. // The replacement string should be equivelent to the ENGLISH PHONETIC
  41. // sound. So if you were to take a word with "Ŕ" in it; how would you
  42. // phonetically spell the word in english. If the "Ŕ" sounds like a "A"
  43. // in english then "A" would be the replacement character.
  44. // If it sounds like "th" then you would use "th" as the characters.
  45. // always replace Larger groups first. (i.e. if "ńń" sounds differently
  46. // than "ń" then in the translation table you would have the "ńń" listed
  47. // before the "ń". So that way when it would replaced the "ńń" before it
  48. // replaced it twice with "ń".
  49. // --------------------------------------------------------------------
  50. // Any letters you do not translate will be IGNORED for
  51. // when it attempts to find spelling matches!!!
  52. // --------------------------------------------------------------------
  53. $Translation_Table = array();
  54. $Replacement_Table = array();
  55.  
  56. // --------------------------------------------------------------------
  57. // Put the list of valid characters in your language in this list
  58. // --------------------------------------------------------------------
  59. $Language_Character_List = "aąbcćdeęfghijklłmnńoópqrsśtuvwxyzżź'";
  60.  
  61. // --------------------------------------------------------------------
  62. // Put the list of most common words in this list ",word,word,word,"
  63. // --------------------------------------------------------------------
  64. //$Language_Common_Words = ",the,is,was,be,are,were,been,being,am,of,and,a,an,in,inside,to,have,has,had
    ,havi
  65. g,he,him,his,it,its,i,me,my,to,they,their,not,no,for,you,your,she,her,with,on,th
  66. t,these,this,those,do,did,does,done,doing,we,us,our,by,at,but,from,as,which,or,w
  67. ll,said,say,says,saying,would,what,there,if,can,who,whose,so,go,gone,went,goes,m
  68. re,other,another,one,see,saw,seen,seeing,know,knew,known,knows,knowing,there,";
  69. $Language_Common_Words = ",one,jeden,dwa,trzy,cztery,pięć,sześć,siedem,osiem,dziewięć,dziesięć,wy,jest,był
  70. bądź,,byli,były,będąc,jestem,z,i,w,wewnętrzny,do,mieć,ma,miał,mając,on,jego,to
  71. ja,mój,oni,ich,nic,nie,dla,ty,twój,ona,jej,dalej,że,te,tu,zrób,zrobiły,robi,zrob
  72. ony,robiąc,mój,my,za,o,pod,przed,nasi,około,oko,ale,od,kto,jako,który,albo,powie
  73. zieć,głosy,mówiąc,co,tam,jeżeli,może,tak,idzie,poszły,poszedł,więcej,inny,jeden,
  74. idzi,widział,widząc,wiedzieć,wiedział,rozpoznany,wie,wiedząc,tam,";
  75.  
  76. // --------------------------------------------------------------------
  77. // Translation function
  78. // --------------------------------------------------------------------
  79. function Translate_Word($Word) {
  80. return ($Word);
  81. }
  82.  
  83. // --------------------------------------------------------------------
  84. // Phonetic work function
  85. // --------------------------------------------------------------------
  86. function Word_Sound_Function($Word) {
  87. return (metaphone($Word));
  88. }
  89.  
  90.  
  91. function Language_Decode(&$Data)
  92. {
  93. // MS Internet Explorer Hack -- IE sends utf8-unicode for upper (ascii 128+) characters
  94.  if (strpos(@$_SERVER['HTTP_USER_AGENT'], 'MSIE') > 0 || strpos(@$_SERVER['ALL_HTTP'], 'MSIE') > 0) {
  95.  if (function_exists('utf8_decode')) $Data = utf8_decode($Data);
  96.  }
  97.  return ($Data);
  98. }
  99.  
  100. function Language_Encode(&$Data)
  101. {
  102. global $Spell_Config;
  103. if (!$Spell_Config['IE_UTF_Encode']) return ($Data);
  104.  if (strpos(@$_SERVER['HTTP_USER_AGENT'], 'MSIE') > 0 || strpos(@$_SERVER['ALL_HTTP'], 'MSIE') > 0) {
  105.  if (function_exists('utf8_encode')) $Data = utf8_encode($Data);
  106.  } return ($Data);
  107. }
  108.  
  109. function Language_Lower(&$Data)
  110. {
  111. $Data=strtr($Data, "ĄĆĘŁŃÓŚŻŹ", "ąćęłńóśżź");
  112. return(strtolower($Data));
  113. }
  114.  
  115. function Language_Upper(&$Data)
  116. {
  117. $Data=strtr($Data, "ąćęłńóśżź", "ĄĆĘŁŃÓŚŻŹ");
  118. return(strtoupper($Data));
  119. }
  120. ?>
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2024 Invision Power Services, Inc.