--- loncom/interface/loncommon.pm 2012/08/07 10:52:17 1.1090 +++ loncom/interface/loncommon.pm 2012/08/14 10:22:25 1.1091 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # a pile of common routines # -# $Id: loncommon.pm,v 1.1090 2012/08/07 10:52:17 foxr Exp $ +# $Id: loncommon.pm,v 1.1091 2012/08/14 10:22:25 foxr Exp $ # # Copyright Michigan State University Board of Trustees # @@ -70,6 +70,7 @@ use Apache::lonclonecourse(); use LONCAPA qw(:DEFAULT :match); use DateTime::TimeZone; use DateTime::Locale::Catalog; +use Text::Aspell; # ---------------------------------------------- Designs use vars qw(%defaultdesign); @@ -3063,41 +3064,27 @@ Note: This sub assumes that aspell is in sub check_spelling { my ($wordlist, $language) = @_; + my @misspellings; + + # Generate the speller and set the langauge. + # if explicitly selected: - # Format the command. If $language is null then - # don't request a language - Note that's dangerous - # because there's no assurance the server is running the intended default - # language. - - my $langswitch = ''; + my $speller = Text::Aspell->new; if ($language) { - $langswitch = "--lang=$language"; + $speller->set_option('lang', $language); } - my $aspell_command = "aspell -a $language"; - my $full_command = "echo $wordlist | $aspell_command"; - - my $ispell_result = `$full_command`; + # Turn the word list into an array of words by splittingon whitespace - # The result is several lines of text. - # the first line will start with @(#). Other wise - # There's an error. With an error our fallback is to declare - # all the words are correctly spelled (return empty string). + my @words = split(/\s+/, $wordlist); - my @misspellings; - my @lines = split(/\n/, $ispell_result); - my $heading = shift(@lines); # header - if ($heading =~ /^\@\(#\) /) { - foreach my $word (split(/\s+/, $wordlist)) { - my $spellok = pop(@lines); - if (!($spellok =~ /^\*/)) { - push(@misspellings, $word); - } + foreach my $word (@words) { + if(! $speller->check($word)) { + push(@misspellings, $word); } - return join(' ', (@misspellings)); # empty if all words ok. - } else { - return ""; } + return join(' ', @misspellings); + } # -------------------------------------------------------------- Plaintext name