Spell ckecker release 2 Now multiple dictionaries allowed

Spell ckecker release 2 Now multiple dictionaries allowed

by Ludo (Marc Alier) -
Number of replies: 29

Hello,

here is the new version of the spell checker patch.

Setup instructions: now the directory "speller" must be copied into the "lib" subdirectory.

The file weblib.php must be copied into the "lib" directory.

The config.php file provided shows the usage of three new configuration atributes used to set up the speller feature:

// This setting will activate the Spell checking utility for the HTML Editor
# TODO: Change the aspellpath variable to point to the aspell executable file
# in your system
# is VERY IMPORTANT that you leave the double cuotes insithe the simple ones
# like this $aspellpath = '"c:\usr\Aspell\bin\aspell.exe"';
$CFG->aspellpath='"c:\usr\Aspell\bin\aspell.exe"';
// now add the codes of the language dictionaries that are installed
// to the CFG->aspell_langs array example
//  $CFG->aspell_langs= array("en", "es", "ca"); to work with english, spanish
// and catalan dictionaries
$CFG->aspell_langs= array("en", "es", "ca");
$CFG->aspell_default_lang = "en"; // if the current language does not match
// any of the installed then aspell_default_lang will be used
// if is undefined "en" language will be used instead

So that's it good luck,

Marc

ps.Note for code lovers guiño:

A few ninor changes have been added to the file weblib.php. The main change is that now the speller specific code is placed in a function in the speller/lib.php file so the code in weblib.php is cleaner.

function use_html_editor($name="") {

/// Sets up the HTML editor on textareas in the current page.
/// If a field name is provided, then it will only be
/// applied to that field - otherwise it will be used
/// on every textarea in the page.
///
/// In most cases no arguments need to be supplied

// Modification by Ludo ( Marc Alier to provide Spell Checking to the
// html editor. August 2004
<font face="courier new,courier,monospace" size="2">malier@lsi.upc.es
/// START LUDO
    global $CFG;
    if(!empty($CFG->aspellpath)) {
        echo "<script src=\"".$CFG->
wwwroot."/lib/speller/spellChecker.js\"></script>";
    }
/// END LUDO
    echo "<script language=\"javascript\" type=\"text/javascript\" defer=\"1\">\n";
    if (empty($name)) {
        echo "HTMLArea.replaceAll();\n";
    } else {

      //START LUDO
           echo "var config = new HTMLArea.Config();\n";  // object used to
                   // store configuation modifications
            if(!empty($CFG->aspellpath)) {
               speller_print_add_speller_button();
            }


        echo "HTMLArea.replace('$name', config);\n";
        // END LUDO */

 // ORIGINAL       echo "HTMLArea.replace('$name');\n";
    }
    echo "</script>\n";
}  

If somebody wants to add another modification on the HTMLeditor configuration
can modify this function and the variable "config" before tha HTMLarea.replace method is called.

Average of ratings: -
In reply to Ludo (Marc Alier)

Re: Spell ckecker release 2 Now multiple dictionaries allowed

by Janne Mikkonen -
Picture of Core developers
Hi Ludo.

I surely hope that I don't sound like completely corn..le when I write this wink, but if I do smack me hard big grin

Ok, few observations:

use_html_editor -function still lacks flexibility and backward compatility. If $name is set but the $CFG->aspellpath is not, HTMLArea.replace('$name') should be called. The config file for editor should be somewhere where it can be easily edited (there might be an user interface someday to make configs for the editor smile).
Spellchecking is using shell_exec system call and on some server configurations system calls (exec, shell_exec, passthru etc) might be prohibited. So there have to be a way to completely shut it off.
I'm not so sure about requiring speller lib at the start of weblib.php (Mr. Burns might have a cow about that big grin).

I hope my pointers doesn't sound too harsh.

I really, really appreciate your contribution and work, spellchecking is one of the most wanted feature to have on this editor and I really hope it can be squeezed in release 1.4 final.

Cheers,
Janne
In reply to Janne Mikkonen

Re: Spell ckecker release 2 Now multiple dictionaries allowed

by W Page -
Hi Ludo and Janne,

Uploaded Patch 2. The HTML Edior disappeared and only a text box with HTML code was present.

I do not know if the above is because I am not properly installing it, Is this correct,

moodle
moodle/config.php (with adjustments)
moodle/lib/speller
moodle/lib/weblib.php

I could not determine what subdirectory you wanted the "speller" directory placed into.

Also, I understand that "Drupal" uses a module to connect to the Aspell Spellcheaker.
"Drupal" is OSS. Maybe this might be a better route. Possibly less core code integration??? smile .

WP1
In reply to W Page

Re: Spell ckecker release 2 Now multiple dictionaries allowed

by Janne Mikkonen -
Picture of Core developers
If you're using Mozilla, could you check are there any errormessages in your Javascript console.

"Drupal" uses a module
The main idea to move speller directory under /moodle/lib is to provide access to all moodle modules (so you do not need to use editor and we're able to make it available for those who never uses editor).
In reply to Janne Mikkonen

Re: Spell ckecker release 2 Now multiple dictionaries allowed

by W Page -
Hi Janne,

I am picking up bits and pieces of the PHP stuff. It is slowly beginning to geal together. Now I understand why placing the changes in "lib" code would be better than using a module like Drupal. Makes a lot of sense.

Ok, now I know this will sound like a "baby" question, but, how do I get to the "JavaScript" console to see what is going on. I see it is referred to all the time but I have never really searched it out. I am running FireFox v0.9.2 with WebDeveloper installed.  I also have IE6 on the computer? Where do I look and what do I look for?

BTW, do I have the files in the proper location as noted above.

This is how I completed the significant area in the "config.php" file. Is this completed properly (lines in bold print).
// Turning this on will make Moodle use a https connection just for the
// login page (providing a secure login), and then afterwards revert
// back to the normal http URL. Requires https to be enabled on the
// web server.
// $CFG->loginhttps = true;
//
// This setting will activate the Spell checking utility for the HTML Editor
# TODO: Change the aspellpath variable to point to the aspell executable file
# in your system
# is VERY IMPORTANT that you leave the double cuotes insithe the simple ones
# like this $aspellpath = '"c:\usr\Aspell\bin\aspell.exe"';
$CFG->aspellpath='"/homepages/22/d12345999/htdocs/aspell/bin/aspell.exe"';
// now add the codes of the language dictionaries that are installed
// to the CFG->aspell_langs array example
// $CFG->aspell_langs= array("en", "es", "ca"); to work with english, spanish
// and catalan dictionaries
$CFG->aspell_langs= array("en");
$CFG->aspell_default_lang = "en"; // if the current language does not match
// any of the installed then aspell_default_lang will be used
// if is undefined "en" language will be used instead

Thanks in advance,

WP1

In reply to W Page

Re: Spell ckecker release 2 Now multiple dictionaries allowed

by Janne Mikkonen -
Picture of Core developers
On FireFox you can find Javascript console from Tools -> Javascript Console smile

Your aspell path is wrong! Seem to me that your using *nix box, but you're trying to call windows executable? You can't run windows programs in *nix like that wink .

If you have a shell access to that machine (ssh or telnet) you can find if there is aspell already installed on that machine with command whereis aspell or which aspell. You just simply write the command and hit enter. Either way if aspell is installed you'll get the path to aspell program as result (usually /usr/bin/aspell). And on *nix boxes you MUST NOT use double quotes inside single quotes when specifying the path ('/usr/local/aspell' is the right form when using *nix)

- Janne -
In reply to Janne Mikkonen

Re: Spell ckecker release 2 Now multiple dictionaries allowed

by W Page -
Hi Janne,

I have removed the double quotes.

I had to install Aspell on the server.  Apparently 1and1 does not already have it installed.

The path to Aspell looks something like this,
/homepages/22/d12345999/htdocs/aspell

how should I place it in the "config.php" file.

The aspell directory  does contain a bin directory, but there is no aspell.exe inside of it.

I found the JavaScript Console.  Right in front of my face. blush blush

This is what I saw relating to the "editor".

Error:  syntax error
Source File:  http://s12345678.onlinehome.us/moodle/lib/editor/htmlarea.php?id=1          Line 4
<br />

Error:  syntax error
Source File:  http://s12345678.onlinehome.us/moodle/lib/editor/lang/en.php          Line 4
<br />

WP1

In reply to W Page

Re: Spell ckecker release 2 Now multiple dictionaries allowed

by Janne Mikkonen -
Picture of Core developers
Is there a file called "aspell" in your /homepages/22/d12345999/htdocs/aspell/bin -directory? If there is then your path is /homepages/22/d123459999/htdocs/aspell/bin/aspell

- Janne -
In reply to Janne Mikkonen

Re: Spell ckecker release 2 Now multiple dictionaries allowed

by Ludo (Marc Alier) -

Hi Janne,

thank you for your observations. Let's talk about it:

> use_html_editor -function still lacks flexibility and backward compatility

Ok, I'll recode it i a way that if teh aspellpath variable is not setted then the usual generate
call will be issued.

>The config file for editor should be somewhere where it can be easily edited (there might be an user interface someday to make configs for the editor smile).

I think the same abot this, do you have any suggestion abot how to place  it?

> Spellchecking is using shell_exec system call and on some server configurations system calls (exec, shell_exec, passthru etc) might be prohibited. So there have to be a way to completely shut it off.

You're completely rigth. I've been thinking about it. There are some alternatives. We can use the C or Java Aspell API to call the spell cheching routine. This would need some hard coding (and heavy testing) but its not impossible. But I have doubts about if it migth be usefull. Usually when a sysadmin forbids the use of "exec" commands usually forbid also the use of  C scripts, and usually they dont like to install side aplications and librarys like aspell. so in most cases we would be back to trhe start point. triste

So i believe that would be interesting to know if it migth be usefull before coding.

Another alternative woul be to use an external server for spell checking.

Well that's it. I'll send soon an update solving the issues in weblib.php.

Cheers

Marc

In reply to Ludo (Marc Alier)

Re: Spell ckecker release 2 Now multiple dictionaries allowed

by Janne Mikkonen -
Picture of Core developers
Hi Ludo.

>The config file for editor should be somewhere where it can be easily edited (there might be an user interface someday to make configs for the editor smile).

>I think the same abot this, do you have any suggestion abot how to place  it?

I was thinking about something like $CFG->dataroot/editor/config.txt? If we put it in there we'll also need a user interface to edit it.

> Spellchecking is using shell_exec system call and on some server configurations system calls (exec, shell_exec, passthru etc) might be prohibited. So there have to be a way to completely shut it off.

>You're completely rigth. I've been thinking about it...

I think better alternative would be pspell thoughtful. Downside is that we need to check php version and is pspell functions available.

I also made a check_language -function in spellchecker.php (attachment). This will get rid of $CFG->aspell_langs and $CFG->aspell_default_lang settings. It'll always return "english" as a default language if it can't find users language dictionary installed in the system.

- Janne -
In reply to Janne Mikkonen

Re: Spell ckecker release 2 Now multiple dictionaries allowed

by W Page -
Hi Janne and Ludo,

Yes "aspell" is inside of the "bin" directory. As indicated above, I removed the double quotes and replaced the path as "/homepages/22/d12345999/htdocs/aspell/bin/aspell". However the editor still does not display properly. Only HTML code inside of the editor and the tool bar is still missing as well.

It is great to watch the thought processes that go into developing this speller feature and the workings of collaboration.

While reading your interchanges, as pimarily still a "user" vs. a "programmer". I began to wonder about the following,

1. "$CFG->dataroot/editor/config.txt" appears to be a good move as it would make configuration of the speller [not also the editor?] easier.

2. What about considering a seperate configuration link in the Admin panel for the editor [Turn speller on or off for the site, toggle to allow speller on or off per each site, determine default speller language, list of other languages installed and enabled, toggle to allow/disallow HTML editor for the site and per course, ability to determine - default text style, text size, text color - for the site and per course, ability to allow for the editor to be allowed for the entire site or the individual courses. etc. etc.]. This would mean removing the HTML features from the "Variables" page [Which I think is becoming a bit long]. I think however, the concentration of the HTML editor on one page would help people think a bit before making choices since it would be removed from all the non-HTML choices on the "Variables" page.

3. Having the best is always good. However, I think "choice" is always preferred because it allows for different configurations of the speller based on different systems. This helps those who cannot afford costly webhosting and therefore may face limited hosting features. So I think including the choice in using aspell through C++ as well as through PHP (pspell) would be good.

Just some thoughts of a seriously "novice" programmer. wink smile

WP1

In reply to W Page

Re: Spell ckecker release 2 Now multiple dictionaries allowed

by Janne Mikkonen -
Picture of Core developers
Hi WP1 smile

1. $CFG->dataroot/editor/config.txt, idea is actually for the editor only not for the speller it self

2. Your on right track smile . There might be a user interface to configure editor settings and it will be in admin panel, what options it'll have is still very much open:
  1. Should it be site wide or per course?
  2. Do we have only one configuration file or several configuration files (load basic buttons, load fullpage functionality etc.)
3. Running system commands through script has always its downsides, I don't know does c++ api or java api make things any safer or easier (and I think it would still be accessed through system command?). Downside of pspell is that it need to be compiled as a part of php (on windows you just install aspell and copy aspell-15.dll into %systemroot%\system32, needs php version 4.3.3 or newer)

So there are lots of things to consider before its actually ready wink

- Janne -
In reply to W Page

Re: Spell ckecker release 2 Now multiple dictionaries allowed

by Ludo (Marc Alier) -

Hello WP1,

I've just aplied the speller patch to a raw moodle installation ( current stable version ) replacing the config.php and weblib.php files and copying the speller directory. And in my configuration works (win xp SP1 , apache 1.3 and mysql with php 4.3). I browse it with MS IE (this is important due to diferences in the implementation of javascript ). So, I can't reproduce your bug. I suggest you to go back to a previous version where the HTML editor works ok and then locate step by step when appears the bug.

Cheers

Marc

In reply to Janne Mikkonen

Re: Spell ckecker release 2 Now multiple dictionaries allowed

by Ludo (Marc Alier) -

Hi Janne and WP1,

I've been reading the check_language function. And I've got some questions and considerations:

1. How do I access to the resutlts of the error_handler calls? Maybe in the logfiles ? ( I'm not a PHP programmer, I just use it   guiño, but I see much skill in your code )

2. We can use this function assuming that we'll keep on using the system excec calls or adapt it to the pspell routines at due time.

3. We could use together this function and the CFG->aspell_langs like this:

If CFG->aspell_langs is empty then en language is used

IF CFG->aspell_langs contains the"auto" key then check_language is called

else we use current_language() if is IN CFG->aspell_langs AND if is returned by check_language()

If check_language is used like is now, the moodle admin can't control wich dictionaries will be used and a user will be able to use ANY dictionarie installed in the system.

The next move should be to "move" the aspell_dictionaries variable to the "course" environment. The course responsable will be able to enable the use of any dict, to restrict it to a number of languages, or to forbid the using of dictonariy.

I don't know enougth the moodle architecture to suggest how should the course information can be altered.

Any insigths ?

Cheers

Marc

 

In reply to Ludo (Marc Alier)

Re: Spell ckecker release 2 Now multiple dictionaries allowed

by Janne Mikkonen -
Picture of Core developers
Hi Marc

  1. error_handler function is also in spellchecker.php file. You can't access it's results though they're visual errormessages.
  2. Yes. We'll use system exec calls until someone writes that pspell alternative version smile
  3. Thinking, thinking... There is also $CFG->langlist property that could be used, when moodle is setup as a multilanguage environment.
The next move should be to "move"...
One way would be write a function in weblib.php called print_spell_button smile

- Janne -
In reply to Ludo (Marc Alier)

Re: Spell ckecker release 2 Now multiple dictionaries allowed

by W Page -
Hi Ludo and Janne,

I installing the spellchecker on v1.3.4

The HTML editor works with the original "weblib.php" file.  It does not work with the "weblib.php" file that is in the zip file.

Just for my own clarity let me ask these three questions.

QUESTION 1

Is this the proper path for the following files and folders?

moodle/config.php (with adjustments)
moodle/lib/speller [directory]
moodle/lib/weblib.php (In Zip file)

QUESTION 2

This is how I completed the significant area in the "config.php" file.
I placed these below "$CFG->loginhttps = true;" in the "config.php" file.
I have only installed one language "en"

Is this completed properly??

$CFG->aspellpath='/homepages/22/d12345999/htdocs/aspell/bin/aspell';
$CFG->aspell_langs= array("en");
$CFG->aspell_default_lang = "en";

QUESTION 3

Will this work in v1.4 Dev?

WP1
In reply to Ludo (Marc Alier)

Re: Spell ckecker release 2 Now multiple dictionaries allowed

by Al Williams -
No joy for me. I would really like to add spell checking. I set everything up as prescribed. Got the spell check button. Apparently my version of aspell is out of date since it didn't like the utf-8 setting. I removed that option from the spellchecker.php file. However, after that, the header() call on line 10 was unhappy because it says that line 4 (the language include) has already emitted headers. I commented out the header() call, and got a spell check in progress, followed by an empty spell check window. Sigh. Put it back the way it was. Maybe I should upgrade aspell. UPDATE: Upgraded to the latest aspell and had all the same problems. Also, I noticed that an IMG was broken while I had the new weblib.php installed, but it came back when I replaced the original weblib.php!
In reply to Al Williams

Re: Spell ckecker release 2 Now multiple dictionaries allowed

by N Hansen -
I haven't been following the spell checker discussion closely, so forgive me if this has been answered before. But will it be possible to configure the spell checker so only teachers and admins can use it?

Obviously it needs a little work still though-"ckeck" out  the subject of this thread. tongueout
In reply to N Hansen

Re: Spell ckecker release 2 Now multiple dictionaries allowed

by Ludo (Marc Alier) -

Hi,

this week I am so busy and I can't work in the spell check patch. On next week I'll go back to the work.
By the way:
The spell check pack has been tested in this environment:

Moodle 1.3 release without any modification. Maybe some of the bugs reported are because you use an early version of moodle 1.4 ?
Apache 1.3 PHP 4.3 and MySQL (whatever version)
All running under Windows XP SP1 (Shame on me)
The aspell version I use is the 5.0 and I successfully tested it with the "en" "es" "ca" languages.

Next week I'll test the spell patch in a linux environment and with previous and newer versions on moodle.
Anyone has any idea of how to make possible to configure the spell checker so only teachers and admins can use it, in every course? I think that I'll have to hack in the course settings. Any tips ?

Cheers

Marc

 

In reply to Ludo (Marc Alier)

Re: Spell ckecker release 2 Now multiple dictionaries allowed

by Will Muenchow -
I think I read that spell checker comes with 1.4 - Can't seem to find it? Any help??
In reply to Will Muenchow

Re: Spell ckecker release 2 Now multiple dictionaries allowed

by Janne Mikkonen -
Picture of Core developers
Yes it comes wink and huge amount of credits and thanks to that goes to Ludo (Marc Alier). Without his work we'd still be without spellchecking .

Do you have aspell installed? If so, you'll have to edit your config.php file,
add $CFG->aspellpath = '/path/to/aspell' into it (see config-dist.php).

After that you'll have to enable it from editor settings page (admin -> editor settings). Then you'll have a new button in your editor's toolbar...

It's this way since this feature is quite new (under heavy surveillance).
In reply to Janne Mikkonen

Re: Spell ckecker release 2 Now multiple dictionaries allowed

by W Page -
Hi Janne,

Did not realize Ludo got it to work with Unix.  That is just great.

As you know I already went through the pains of installing Aspell [with your help] so this is not going to be too musch of a big deal to "hook up".

Thanks Ludo and Janne.

WP1
In reply to Janne Mikkonen

Re: Spell ckecker release 2 Now multiple dictionaries allowed

by W Page -
Hi Janne & Ludo,

Everything went fine as far as the Admin/Editor page.  But a few problems after that.  I had enabled it on two v1.5 Dev installations.

In v1.5 Dev / 2004082600
When I loaded a HTML Editor in a forum.  No Speller Icon or area displayed.

In v1.5 Dev / 2004083000
When I loaded a HTML Editor in a Forum. 
  • The editor displayed but the area that the Speller Icon should be is blank.  See image below.
  • The "popup" window [really neat] indicated initially  "Spellchecking in progress"  then it gave the message
    "error = 'No suitable dictionary found installed on your server!';".

I thought I had installed the english dictionary.  I will check again.

Suggest placing the "Speller" button between the "elements" and "<>" buttons with a separator on each side.  To me it kinda doen't look right so far to the end of the panel.

If you want to check it out the v1.5 Dev / 2004083000 installation is located at,
http://s94988317.onlinehome.us/moodlegrade/
[Login:  teacher1010/teacher1010]

WP1
In reply to W Page

Re: Spell ckecker release 2 Now multiple dictionaries allowed

by W Page -
OOPS!!
Attachment speller_prob_01.gif
In reply to W Page

Re: Spell ckecker release 2 Now multiple dictionaries allowed

by Janne Mikkonen -
Picture of Core developers
The spell-check button seems not to found it's way to cvs in main trunk from my hard-drive, do'h...

The popup window's error message takes place when it can't find users current language nor english dictionaries installed on your server.
In reply to W Page

Re: Spell ckecker release 2 Now multiple dictionaries allowed

by W Page -
Hi!

I am using the english language dictionary files.  This is how the path to the language dictionary files look,

/aspell/bin/aspell
/aspell/bin/aspell-import
/aspell/bin/pspell-config
/aspell/bin/run-with-aspell
/aspell/bin/word-list-compress

  • Is this not correct?? 
  • If it is, why do I keep getting an error message indicating no language dictionary is installed.

WP1

In reply to W Page

Re: Spell ckecker release 2 Now multiple dictionaries allowed

by Janne Mikkonen -
Picture of Core developers
If you have console access (like ssh) you can check what dictionaries are installed on your system with command: aspell dump dicts

The paths you provide seems to be ok, if this is the path where aspell is installed (find it out with command: whereis aspell).

- Janne -
In reply to Janne Mikkonen

Re: Spell ckecker release 2 Now multiple dictionaries allowed

by W Page -
Hi Janne

When Ludo initially added the multiple language feature he had added the following to the "config.php" file,

$CFG->aspell_langs= array("en", "es", "ca");
$CFG->aspell_default_lang = "en"; 
  • $CFG->aspell_langs= array("en", "es", "ca"); adds the codes of the language dictionaries that are installed to the CFG->aspell_langs array to work with english, spanish and catalan dictionaries
  • $CFG->aspell_default_lang = "en"; if the current language does not match any of the installed then the aspell_default_lang will be used. 
I tried these and still did not get the "english" dictionary recognized.  I only have the "english" dictioary installed presently.  [aspell5-en-6.0-0.tar.bz2]

$CFG->aspell_langs= array("en");
$CFG->aspell_default_lang = "en"; 

When I used the command, "whereis aspell"  I got back the proper path.  When I used the command, "aspell dump dicts"  I got back
"bash: ./aspell: is a directory".


From the above post, it appears the "english" dictionary is installed.

Is there anything else I can do to get this resolved?

WP1
In reply to W Page

Re: Spell ckecker release 2 Now multiple dictionaries allowed

by Ludo (Marc Alier) -

Hi, I'm finally back!

I've just downloaded the 1.4 version and I still have to take a look at the final version of the spellcheck patch that Jane squeezed (I had to look in a dictionary to learn this new word, I love it "squeeze" sounds gread ... squeeze risa) in the CVS for the 1.4  version. 

The last version that I tested was designed to use the user's current language using a Jane's function that checked if the language was present. So I don't know if the $CFG->aspell_langs variable is still needed.

I think that would be usefull to write a mini setup manual for the spell checking feature. I'll try to have it ready for tomorrow. 

Cheers

Ludo (Marc)

In reply to Ludo (Marc Alier)

Re: Spell ckecker release 2 Now multiple dictionaries allowed

by Janne Mikkonen -
Picture of Core developers
Hi WP1 and Ludo.

Ludo, if you think that I'm "missy" or  a "girlieman" atleast call me Susan ( joke wink ), not Jane...

At the moment there aren't any langlist variable, but the idea is not too bad as I mention before, or did I ?!? There is a lang list configuration variable in main configuration page that could be used to control available languages???

Now it checks if user language is installed, and if not it tries to find if english is installed and if it can't find english dictionary then the error is returned.

Further development isn't restricted wink

- Janne -