Project

General

Profile

Feature #7388

Using hunspell as back end in spellchecker.php

Added by Torkil Zachariassen over 4 years ago. Updated over 4 years ago.

Status:
Feature implemented
Priority:
Normal
Assignee:
Category:
Global / Others / Misc
Target version:
Start date:
11/11/2014
Due date:
% Done:

100%

Estimated time:
Spent time:
Complexity:
Normal
SCRUM pts - complexity:
?

Description

spellchecker.php supports aspell which supports a limited number of languages on our system.
The system provides hunspell which supports quite a number of languages.
Thus we tried to configure spellchecking.php to use hunspell.
This turned out to be quite easy and a patch is attached for reference.
Adaption to other languages can be made by configuring the $lang variable, using the list of supported languages in hunspell, e.g. 'hunspell -D'

Now our users can engage the spell checking against three languages.

Tested on CentOS7 with chamilo-1.9.8.2 and hunspell and hunspell-{en-GB,en-US,fo,-da} installed.

This could be included in an upcoming version of Chamilo or fckeditor


Files

spellchecker.php.patch.txt (908 Bytes) spellchecker.php.patch.txt Change backend in spellchecker.php to use hunspell as back end engine Torkil Zachariassen, 11/11/2014 16:25

Associated revisions

Revision 3587db21 (diff)
Added by Julio Montoya over 4 years ago

Adding aspell settings see #7388

Revision 14072214 (diff)
Added by Yannick Warnier over 4 years ago

Remove unnecessary aspell_lang setting and default to en_US - refs #7388

History

#1

Updated by Torkil Zachariassen over 4 years ago

Pardon - the patch file was misformatted somehow. This should do the trick:

--- spellchecker.php.000    2014-11-11 12:45:14.118874378 +0000
+++ spellchecker.php    2014-11-11 14:08:17.410110124 +0000
@@ -3,11 +3,17 @@

 // The following variables values must reflect your installation needs.

-$aspell_prog    = '"C:\Program Files\Aspell\bin\aspell.exe"';    // by FredCK (for Windows)
+//$aspell_prog    = '"C:\Program Files\Aspell\bin\aspell.exe"';    // by FredCK (for Windows)
 //$aspell_prog    = 'aspell';                                        // by FredCK (for Linux)
+//$aspell_prog    ='/usr/bin/aspell';
+$aspell_prog    ='/usr/bin/hunspell';  // torkil for hunspell

-$lang            = 'en_US';
-$aspell_opts    = "-a --lang=$lang --encoding=utf-8 -H --rem-sgml-check=alt";        // by FredCK
+//$lang            = 'en_US';
+
+$lang                   = 'fo_FO,da_DK,en_GB'; // torkil for hunspell
+
+//$aspell_opts    = "-a --lang=$lang --encoding=utf-8 -H --rem-sgml-check=alt";        // by FredCK
+$aspell_opts    = "-a  -d $lang    -i utf-8         -H                     ";   // torkil for hunspell

 $tempfiledir    = "./";

#2

Updated by Julio Montoya over 4 years ago

  • Status changed from New to Needs testing

I just added those options as a configurations settings in configuration.php:
For example:

$_configuration['aspell_bin'] = '/usr/bin/hunspell';
$_configuration['aspell_lang'] = 'en_US';
$_configuration['aspell_opts'] = '-a --lang=$lang --encoding=utf-8 -H --rem-sgml-check=alt';
$_configuration['aspell_temp_dir'] = './';

See:

https://github.com/chamilo/chamilo-lms/commit/3587db2180ba30b30834f0dda51f443fa067051d

#3

Updated by Yannick Warnier over 4 years ago

  • % Done changed from 100 to 90

torkil, please try it locally (from Github repository) and let us know if that works for you, as we cannot close it until someone can approve it (and you are in a nice position to approve it)

#4

Updated by Torkil Zachariassen over 4 years ago

Yannick, while using the solution from GitHub the errorlog trows the following error. It seems like we are missing the function 'api_get_configuration_value()' here.

==> /var/log/httpd/error_log <== [Thu Nov 20 19:10:14.645206 2014] [:error] [pid 6853] [client 94.18.254.195:48992] PHP Fatal error: Call to undefined function api_get_configuration_value() in /var/www/chamilo-1.9.8.2/main/inc/lib/fckeditor/editor/dialog/fck_spellerpages/spellerpages/server-scripts/spellchecker.php on line 8, referer: http://svar.fo/main/inc/lib/fckeditor/editor/dialog/fck_spellerpages/spellerpages/spellchecker.html
#5

Updated by Yannick Warnier over 4 years ago

Hi Torkil,

Sadly, we cannot (easily) fix that for your test, as this means there is a dependency on a function that was created after 1.9.8.2 and before 1.9.10. That's why you don't have it.

If you want, you can temporarily add the function at the end of your main/inc/lib/main_api.lib.php file. It's quite short:

/**
 * @param string $variable
 * @return bool|mixed
 */
function api_get_configuration_value($variable)
{
    global $_configuration;
    if (isset($_configuration[$variable])) {
        return $_configuration[$variable];
    }
    return false;
}

Then reload the page where the error appears. It should be fixed and let you test the integration with hunspell

#6

Updated by Torkil Zachariassen over 4 years ago

Appended the missing function to main_api.lib.php, and installed spellchecker.php from github.
As hunspell does not understand long options the configuration (aspell_opts) has to change a bit.
The lang option works in aspell only.
Here is what works for me using three languages simultaneously

/**
 * Aspell Settings for hunspell
 */
$_configuration['aspell_bin'] = '/usr/bin/hunspell';
$_configuration['aspell_lang'] = 'en_US';                   // aspell option only
//$_configuration['aspell_opts'] = '-a --lang=$lang --encoding=utf-8 -H --rem-sgml-check=alt'; // aspell options
$_configuration['aspell_opts'] = '-a -d fo_FO,da_DK,en_GB -H -i utf-8'; // hunspell options
$_configuration['aspell_temp_dir'] = './';

#7

Updated by Yannick Warnier over 4 years ago

  • Assignee set to Julio Montoya
#8

Updated by Julio Montoya over 4 years ago

  • Assignee deleted (Julio Montoya)
#9

Updated by Torkil Zachariassen over 4 years ago

As language is selected in the '-d' option to hunspell, you might want to remove

  $_configuration['aspell_lang'] = 'en_US';

The rest works for me.

#10

Updated by Yannick Warnier over 4 years ago

  • Status changed from Needs testing to Feature implemented
  • Assignee set to Julio Montoya
  • % Done changed from 90 to 100

Setting removed and defaulted to en_US.
Thanks!

#11

Updated by Torkil Zachariassen over 4 years ago

Thank you.

Also available in: Atom PDF