Committer: amyshkin
LJSV-2090: Spell check is flagging almost all words and is not providing correctionsU trunk/cgi-bin/LJ/SpellCheck.pm U trunk/cgi-bin/LJ/Talk/Post.pm U trunk/htdocs/editjournal.bml U trunk/htdocs/update.bml
Modified: trunk/cgi-bin/LJ/SpellCheck.pm =================================================================== --- trunk/cgi-bin/LJ/SpellCheck.pm 2012-06-22 13:20:44 UTC (rev 22312) +++ trunk/cgi-bin/LJ/SpellCheck.pm 2012-06-22 13:35:50 UTC (rev 22313) @@ -33,6 +33,7 @@ 'en_lj' => 'en', # lower case of 'en_LJ' 'en_gb' => 'en_GB', 'de' => 'de', + 'en_LJ' => 'en', }; sub new { @@ -40,8 +41,9 @@ my $self = {}; bless $self, ref $class || $class; - $self->{command} = $args->{spellcommand} || [ @DEFAULT_COMMAND ]; - $self->{color} = $args->{color} || "#FF0000"; + $self->{'command'} = $args->{'spellcommand'} || [ @DEFAULT_COMMAND ]; + $self->{'color'} = $args->{'color'} || "#FF0000"; + $self->{'lang'} = $args->{'lang'} || $LJ::DEFAULT_LANG; return $self; } @@ -57,6 +59,7 @@ $opts = {} unless defined($opts) && ref($opts) eq 'HASH'; my $command = $opts->{command}; + if ($command) { if (ref($command) ne 'ARRAY') { die "Invalid parameter 'command' - need arrayref"; @@ -64,6 +67,7 @@ } else { $command = [ @DEFAULT_COMMAND ]; + if (my $language = $opts->{language}) { $language = $LANGUAGES->{lc($language)}; return (0, 'unsupported_language') unless $language; @@ -77,7 +81,7 @@ { my ($in, $out, $err); - + ## ! = turn terse mode on (don't write correct words to output) ## ^ = escape each line (i.e. each line is text, not control command for aspell) $in = "!\n" . join("\n", map { "^$_" } @in_lines); @@ -98,7 +102,7 @@ INPUT_LINE: foreach my $input_line (@in_lines) { my $text_pos = 0; - ASPELL_LINE: + ASPELL_LINE: while (my $aspell_line = shift @out_lines) { my ($word, $offset, $suggestions_str); @@ -124,7 +128,7 @@ $handler_text->(substr($input_line, $text_pos, length($input_line) - $text_pos) . "\n") if $handler_text && $text_pos < length($input_line); } - + return (1, 'ok'); } @@ -201,7 +205,7 @@ $output .= $text; }; - my ($result, $status) = run_aspell($text_ref, {language => 'ru'}, $handler_misspelled, $handler_text); + my ($result, $status) = run_aspell($text_ref, {language => $self->{'lang'}}, $handler_misspelled, $handler_text); return '' unless $result; Modified: trunk/cgi-bin/LJ/Talk/Post.pm =================================================================== --- trunk/cgi-bin/LJ/Talk/Post.pm 2012-06-22 13:20:44 UTC (rev 22312) +++ trunk/cgi-bin/LJ/Talk/Post.pm 2012-06-22 13:35:50 UTC (rev 22313) @@ -850,9 +850,14 @@ # clean first; if the cleaner finds it invalid, don't spellcheck, so that we # can show the user the error. my $cleanok = LJ::CleanHTML::clean_comment(\$event, $form->{'prop_opt_preformatted'}); + my $remote = LJ::get_remote(); + if (defined($cleanok) && $LJ::SPELLER && $form->{'do_spellcheck'}) { - my $s = new LJ::SpellCheck { 'spellcommand' => $LJ::SPELLER, - 'color' => '#ff0000', }; + my $s = LJ::SpellCheck->new({ + 'spellcommand' => $LJ::SPELLER, + 'color' => '#ff0000', + 'lang' => $remote ? $remote->prop('browselang') : $LJ::DEFAULT_LANG, + }); $spellcheck_html = $s->check_html(\$event); } Modified: trunk/htdocs/editjournal.bml =================================================================== --- trunk/htdocs/editjournal.bml 2012-06-22 13:20:44 UTC (rev 22312) +++ trunk/htdocs/editjournal.bml 2012-06-22 13:35:50 UTC (rev 22313) @@ -337,10 +337,14 @@ # are we spellchecking before we post? my $spellcheck_html; my $did_spellcheck; + if ($LJ::SPELLER && $POST{'action:spellcheck'}) { $did_spellcheck++; - my $s = new LJ::SpellCheck { 'spellcommand' => $LJ::SPELLER, - 'color' => '<?hotcolor?>', }; + my $s = LJ::SpellCheck->new({ + 'spellcommand' => $LJ::SPELLER, + 'color' => '<?hotcolor?>', + 'lang' => $remote ? $remote->prop('browselang') : $LJ::DEFAULT_LANG, + }); my $event = LJ::ehtml($POST{'event'}); $spellcheck_html = $s->check_html(\$event); $spellcheck_html = "<?inerr $ML{'entryform.spellcheck.noerrors'} inerr?>" unless $spellcheck_html ne ""; Modified: trunk/htdocs/update.bml =================================================================== --- trunk/htdocs/update.bml 2012-06-22 13:20:44 UTC (rev 22312) +++ trunk/htdocs/update.bml 2012-06-22 13:35:50 UTC (rev 22313) @@ -262,8 +262,11 @@ if ($LJ::SPELLER && $POST{'action:spellcheck'}) { $did_spellcheck++; - my $s = new LJ::SpellCheck { 'spellcommand' => $LJ::SPELLER, - 'color' => '<?hotcolor?>', }; + my $s = LJ::SpellCheck->new({ + 'spellcommand' => $LJ::SPELLER, + 'color' => '<?hotcolor?>', + 'lang' => $remote ? $remote->prop('browselang') : $LJ::DEFAULT_LANG, + }); $spellcheck_html = $s->check_html(\$event); $spellcheck_html = "<?inerr $ML{'entryform.spellcheck.noerrors'} inerr?>" unless $spellcheck_html ne "";