version 1.1090, 2012/08/07 10:52:17
|
version 1.1091, 2012/08/14 10:22:25
|
Line 70 use Apache::lonclonecourse();
|
Line 70 use Apache::lonclonecourse();
|
use LONCAPA qw(:DEFAULT :match); |
use LONCAPA qw(:DEFAULT :match); |
use DateTime::TimeZone; |
use DateTime::TimeZone; |
use DateTime::Locale::Catalog; |
use DateTime::Locale::Catalog; |
|
use Text::Aspell; |
|
|
# ---------------------------------------------- Designs |
# ---------------------------------------------- Designs |
use vars qw(%defaultdesign); |
use vars qw(%defaultdesign); |
Line 3063 Note: This sub assumes that aspell is in
|
Line 3064 Note: This sub assumes that aspell is in
|
|
|
sub check_spelling { |
sub check_spelling { |
my ($wordlist, $language) = @_; |
my ($wordlist, $language) = @_; |
|
my @misspellings; |
|
|
|
# Generate the speller and set the langauge. |
|
# if explicitly selected: |
|
|
# Format the command. If $language is null then |
my $speller = Text::Aspell->new; |
# don't request a language - Note that's dangerous |
|
# because there's no assurance the server is running the intended default |
|
# language. |
|
|
|
my $langswitch = ''; |
|
if ($language) { |
if ($language) { |
$langswitch = "--lang=$language"; |
$speller->set_option('lang', $language); |
} |
} |
|
|
my $aspell_command = "aspell -a $language"; |
# Turn the word list into an array of words by splittingon whitespace |
my $full_command = "echo $wordlist | $aspell_command"; |
|
|
|
my $ispell_result = `$full_command`; |
|
|
|
# The result is several lines of text. |
my @words = split(/\s+/, $wordlist); |
# 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 @misspellings; |
foreach my $word (@words) { |
my @lines = split(/\n/, $ispell_result); |
if(! $speller->check($word)) { |
my $heading = shift(@lines); # header |
push(@misspellings, $word); |
if ($heading =~ /^\@\(#\) /) { |
|
foreach my $word (split(/\s+/, $wordlist)) { |
|
my $spellok = pop(@lines); |
|
if (!($spellok =~ /^\*/)) { |
|
push(@misspellings, $word); |
|
} |
|
} |
} |
return join(' ', (@misspellings)); # empty if all words ok. |
|
} else { |
|
return ""; |
|
} |
} |
|
return join(' ', @misspellings); |
|
|
} |
} |
|
|
# -------------------------------------------------------------- Plaintext name |
# -------------------------------------------------------------- Plaintext name |