Kupu spellchecker in Plone

Blog

9 steps to install spellchecker for Kupu editor in Plone CMS in Windows. But this should be also helpfull for Unix-based system users.

Configuration

I’ve used Windows XP, Zope 2.8.8, Plone 2.1.4. I’ve replaced default kupu product (1.3.8) with the latest version 1.4 beta5. I’ve changed kupu’s code in two places (steps: 6 and 7) but hopefully it won’t be necessary in the future when all my changes would be added to official source code.

1. Install kupu 1.4

Download Kupu 1.4 or later version from Plone Products website. Currently (25.04.2007) latest version is 1.4 beta 5. Unpack tar.gz file and copy to your /Products directory.

2. Install Cygwin and aspell

For spell checking we need aspell. To learn more about this tool visit aspell.net. This is easy to install on Linux but hopefully we can manage it also on Windows. Linux users please skip to the section 5.

The easiest way is to install Cygwin. Installation is pretty straightforward and in case of problems you can read extensive Setup manual. During installation don’t forget to check aspell and your language files.

3. Update system path

After installation we must provide that aspell.exe can be executed from anywhere in the system. That is why we need to edit system PATH variable. Go to Control Panel -> System -> Advanced (tab). Press button Environemnt Variables and modify Path variable. At the end of its string add ; /bin. You can also add here path to your python binary so it will be easier to test it. After doing that restart computer so the new Path value would be used. Attached images should explain everything.

4. Change aspell configuration

I don’t know why but now we cannot use aspell yet because it doesn’t see installed language files. You can change aspell configuration file – which I didn’t do. But I’ve copied files from /lib/aspell to /usr/lib/aspell and that’s it.

5. Test aspell

Now lets test if our istallation is correct. Go to /Products/kupu/python and run

Type existing word – you should see empty dictionary or okay word. On my Windows machine I’ve always got empty dictionary when the word was fine. Then type misspelled word and you will see distionary of possible correct values.

6. Enable spellchecker javascript

Another strange thing – javascript for spellchecker (kupuspellchecker.js) is not added to plone_javascript resource registry during Kupu installation. It is impossible then to use Spellchecker button in editor’s toolbar. The problem is that this file is not mentioned in head.kupu file, which is used in Install.py script to recognize what files should be installed. So we have to add one entry to that configuration:

7. Update KupuLibraryTool

After all that changes I’ve finally got this error Error loading data, status 404. Quick look to error_log shows me that there is missing method spellcheck inside KupuLibraryTool class. But there was a CGI method with the same name here /Products/kupu/common/spellcheck.cgi. I’ve copied this method and after few changes it look like this:

from Products.kupu.python.spellcheck import SpellChecker, format_result

def spellcheck (self, REQUEST):
data = REQUEST[ “text” ]
c = SpellChecker()
result = c.check(data)
if result == None :
result = “”
else :
result = format_result(result)
REQUEST.RESPONSE.setHeader( “Content-Type” , “text/xml, charset=utf-8” )
REQUEST.RESPONSE.setHeader( “Content-Length” ,str( len (result)))
return result

8. Enable spellcheck button

Restart Zope or refresh kupu product. Uninstall editor in portal_quickinstaller and install again. Then go to preferences -> Kupu visual editor -> toolbar (tab). Select checkbox spellchecker to enable button.

9. Enable popups in browser

I didn’t know what to expect because I’ve never seen spellchecker working. After first test nothing happened. Then I saw a message in my Firefox that pop-ups are disabled. So I’ve enabled them for my test instance and finally it has worked. Text appeared in new window with highlighted error. After click on misspelled word we can see all possibilities in javascript alert window.

Rate article
llakomy.com
Add a comment