transliterate

Transliteration engine
git clone git://lumidify.org/transliterate.git
Log | Files | Refs | README | LICENSE

commit 9420d98d90eabd8ad718a74e7e66bde7f5d221c6
parent 9bece82fb8385f9b72a49e7c2b98a9b4f2006182
Author: lumidify <nobody@lumidify.org>
Date:   Wed,  8 Apr 2020 08:56:53 +0200

Fix comment option; add 'ignore whole line' to GUI

Diffstat:
Mtransliterate.pl | 31+++++++++++++++++++++++++++----
1 file changed, 27 insertions(+), 4 deletions(-)

diff --git a/transliterate.pl b/transliterate.pl @@ -158,6 +158,13 @@ sub prompt_unknown_word { $window->destroy; }, $window); $hbox->pack_start($button, FALSE, FALSE, 0); + $button = Gtk2::Button->new("Whole line"); + $button->signal_connect( + clicked => sub { + $action = ["ignore", "wholeline"]; + $window->destroy; + }, $window); + $hbox->pack_start($button, FALSE, FALSE, 0); $vbox->pack_start($hbox, FALSE, FALSE, 0); # AHHHH! IT BURNS!!! THE CODE IS SO HORRIBLE! @@ -897,9 +904,12 @@ sub load_config { # 0 - nothing needs to be done # 1 - the current line needs to be re-transliterated with the new config # 2 - an error occurred while reloading the config +# 3 - stop asking for unknown words on this line sub handle_unknown_word_action { my ($action, $config, $args) = @_; if ($action->[0] eq "ignore") { + # yeah, this is a bit messy and inconsistent + return 3 if $action->[1] eq "wholeline"; $config->{"ignore_words"}->{$action->[2]} = ""; if ($action->[1] eq "permanent") { my $fh; @@ -1249,6 +1259,7 @@ sub get_unknown_words { $word->[1], $contextr, $contextr_orig, $config, "$cur_lineno" ); + # if $ret == 3, just return here # if $ret == 2, config could not be loaded # if $ret == 1, line must be redone with new config my $ret = handle_unknown_word_action($action, $config, $args); @@ -1260,6 +1271,7 @@ sub get_unknown_words { $config, "$cur_lineno", 1); $ret = handle_unknown_word_action($action, $config, $args); } + last if $ret == 3; # re-transliterate the line with the new config return 1 if $ret == 1; } @@ -1276,8 +1288,10 @@ sub replace { my ($config, $args, $total_lines, $inputfh, $outputfh) = @_; while (my $line = <$inputfh>) { next if $. < $args->{"start"}; + my $comment; if (exists $config->{"comment"}) { - $line =~ s/\Q$config->{comment}\E.*$//; + $line =~ s/\Q$config->{comment}\E(.*)\z//s; + $comment = $1; } my $nfd_line = NFD($line); my $substrings = replace_line($config, $nfd_line); @@ -1308,6 +1322,7 @@ sub replace { foreach (@$substrings) { print $outputfh $_->[1]; } + print $outputfh $comment if $comment; } } @@ -1546,7 +1561,12 @@ The possible actions are: "This run" only ignores the word until the program exist, while "Permanently" saves the word in the ignore file specified in the -configuration. +configuration. "Whole file" stops asking for unknown words on +this line and prints the line out as is. Note that this still +leaves all replacements intact that have already been done. +If any words were replaced with multiple choices already, those +will also still cause the L<word choice window|/"WORD CHOICE WINDOW"> +to appear. =item Retry without <display name> @@ -1772,10 +1792,13 @@ B<Default:> C<$> =item B<comment> <string> If enabled, anything after C<< <string> >> will be ignored on all lines in -the input file. +the input file. This will not be displayed in the +L<unknown word window|/"UNKNOWN WORD WINDOW"> or L<word choice window|/"WORD CHOICE WINDOW"> +but will still be printed in the end, with the comment character removed +(that seems to be the most sensible thing to do). Note that this is really just a "dumb replacement", so there's no way to -prevent a line with the comment character from being replaced. Just try +prevent a line with the comment character from being ignored. Just try to always set this to a character that does not occur anywhere in the text (or don't use the option at all).