transliterate

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

commit 95b442d44108af5e6bb79061e5a82805b35792a0
parent 70012257f6d6eb86532f71538529aa74627cc31c
Author: lumidify <nobody@lumidify.org>
Date:   Wed,  8 Apr 2020 13:49:15 +0200

Add 'Reset text' button; modify retrywithout

Diffstat:
Mtransliterate.pl | 74++++++++++++++++++++++++++++++++++++++++++++++++--------------------------
1 file changed, 48 insertions(+), 26 deletions(-)

diff --git a/transliterate.pl b/transliterate.pl @@ -136,6 +136,13 @@ sub prompt_unknown_word { $vbox->pack_start($hbox, FALSE, FALSE, 0); $hbox = Gtk2::HBox->new(FALSE, 5); $hbox->pack_start($button, FALSE, FALSE, 0); + my $complete_text = $ctxtl . $word . $ctxtr; + $button = Gtk2::Button->new("Reset text"); + $button->signal_connect( + clicked => sub { + $buffer->set_text($complete_text); + }, $window); + $hbox->pack_start($button, FALSE, FALSE, 0); $vbox->pack_start($hbox, FALSE, FALSE, 0); }; $make_context_box->($contextl, $contextr, "Context: "); @@ -188,21 +195,27 @@ sub prompt_unknown_word { $hbox->pack_start($replace_entry, TRUE, TRUE, 0); $vbox->pack_start($hbox, FALSE, FALSE, 0); - $hbox = Gtk2::HBox->new(FALSE, 5); - foreach my $without (@{$config->{"retrywithout"}}) { - $button = Gtk2::Button->new("Retry without $without->[0]"); - $button->signal_connect( - clicked => sub { - my @chars = @{$without}[1..$#$without]; - my $stripped = replace_strip_chars($config, \@chars, $word); - # recombine substrings - my $repl_text = ""; - $repl_text .= $_->[1] foreach @$stripped; - $replace_entry->set_text($repl_text); - }, $window); - $hbox->pack_start($button, FALSE, FALSE, 0); + if (exists $config->{"retrywithout"}) { + $hbox = Gtk2::HBox->new(FALSE, 5); + $label = Gtk2::Label->new("Retry without: "); + $hbox->pack_start($label, FALSE, FALSE, 0); + foreach my $without (@{$config->{"retrywithout"}}) { + $button = Gtk2::Button->new("$without->[0]"); + $button->signal_connect( + clicked => sub { + my @chars = @{$without}[1..$#$without]; + my $stripped = replace_strip_chars($config, \@chars, $word); + # recombine substrings + my $repl_text = ""; + $repl_text .= $_->[1] foreach @$stripped; + $replace_entry->set_text($repl_text); + }, $window); + $hbox->pack_start($button, FALSE, FALSE, 0); + } + $vbox->pack_start($hbox, FALSE, FALSE, 0); } + $hbox = Gtk2::HBox->new(FALSE, 0); $button = Gtk2::Button->new("Add replacement"); $button->signal_connect( clicked => sub { @@ -688,7 +701,6 @@ sub interpret_config { # a list of "replacement configs", which specify the type and any # other arguments (this is given to replace_match, etc. $config{"replacements"} = []; - $config{"retrywithout"} = []; # these are temporary mappings used while loading the config my %path_to_table; my %table_id_to_path; @@ -707,7 +719,7 @@ sub interpret_config { "comment" => [$STRING], "group" => [], "endgroup" => [], - "retrywithout" => [$STRING, $STRING], + "retrywithout" => [$STRING], "targetdiacritics" => [$STRING] ); my $in_group = 0; @@ -832,6 +844,9 @@ sub interpret_config { my $override = $#$cmd >= 2 && $cmd->[2]->{"value"} eq "override"; add_to_trie($table, $trie_root, $tables{$table}, $args, \%config, $override); } elsif ($cmd_name eq "retrywithout") { + if (!exists $config{"retrywithout"}) { + $config{"retrywithout"} = []; + } # first value is the display name my @values = map {$_->{"value"}} @{$cmd}[1..$#$cmd]; push @{$config{"retrywithout"}}, \@values; @@ -1544,7 +1559,9 @@ Both the context from the original script and the context from the transliterated version (so far) is shown. If a part of the text is selected in one of the text boxes and "Use selection as word" is pressed for the appropriate box, the selected text is used for the -action that is taken subsequently. +action that is taken subsequently. "Reset text" resets the text in +the text box to its original state (except for the highlight because +I'm too lazy to do that). The possible actions are: @@ -1578,12 +1595,12 @@ characters have been removed). Note that the selection can still be modified after this, before pressing "Add to list". This could potentially be useful if a word -is in a table that is expanded using "noroot" because "Retry without -diacritics" would only work with the full word (with the ending), -but only the stem should be added to the list. If that is the case, -"Retry without diacritics" could be pressed with the whole word -selected, but the ending could be removed before actually pressing -"Add to list". +is in a table that is expanded using "noroot" because for instance +"Retry without diacritics" would only work with the full word (with +the ending), but only the stem should be added to the list. If that +is the case, "Retry without diacritics" could be pressed with the +whole word selected, but the ending could be removed before actually +pressing "Add to list". A separate button is shown for every B<retrywithout> statement in the config. @@ -1916,13 +1933,13 @@ Note that a table must have been loaded before being used in a B<replace> statem End a replacement group. -=item B<retrywithout> <display name> <character> [...] +=item B<retrywithout> <display name> [character] [...] Adds a button to the L<unknown word window|/"UNKNOWN WORD WINDOW"> to retry the replacements on the selected word, first removing the given characters. -The button is named "Retry without <display name>". Whatever is found with the -replacements is pasted into the regular text box for the "Add replacement" -functionality. +The button is named "<display name>" and located after the "Retry without" label. +Whatever is found with the replacements is pasted into the regular text box for +the "Add replacement" functionality. This can be used as an aid when, for instance, words can be written with or without certain diacritics. If the actual word without diacritics is already in the @@ -1931,6 +1948,11 @@ button can be used to quickly find the replacement for the word instead of havin to type it out manually. The same goes for compound words that can be written with or without a space. +It is also possible to specify B<retrywithout> without any characters, which just +adds a button that takes whatever word is selected and retries the replacements +on it. This can be useful if you want to manually edit words and quickly see if +they are found with the edits in place. + Note that all input text is first normalized to the unicode canonical decomposition form so that diacritics can be removed individually.