transliterate

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

commit 8798eb993523df956ad8b76f2ce500bbbe65870a
parent 229f872be7b4a68a74d1c9924845438968190809
Author: lumidify <nobody@lumidify.org>
Date:   Tue, 31 Mar 2020 20:05:47 +0200

Clean up diacritic handling

Diffstat:
Mtests/data/words1.txt | 1-
Mtests/test1/config | 2+-
Mtests/test1/err.txt | 3+--
Mtests/test5/input.txt | 1+
Mtransliterate.pl | 71++++++++++++++++++++++-------------------------------------------------
5 files changed, 25 insertions(+), 53 deletions(-)

diff --git a/tests/data/words1.txt b/tests/data/words1.txt @@ -8,4 +8,3 @@ word6,word6_replaced word7,word7_replaced word8,word8_replaced word9,word9_replaced -wörd0,word0_replaced|word0_replaced2 diff --git a/tests/test1/config b/tests/test1/config @@ -1,4 +1,4 @@ -split "[ \n]" +split "[ \n]+" beforeword " " afterword "[ \n]" diff --git a/tests/test1/err.txt b/tests/test1/err.txt @@ -1,5 +1,4 @@ -Unknown word: "word20" -Unknown word: "word01231" +Unknown word: "word20 word01231" Word "word0_replaced$word0_replaced2" with 2 word choices. Unknown word: "aword1" Unknown word: "end3" diff --git a/tests/test5/input.txt b/tests/test5/input.txt @@ -1,3 +1,4 @@ ignore wörd0 wörd0 word1end1 +wörd1end1 -dword9end2 word9end2-d diff --git a/transliterate.pl b/transliterate.pl @@ -157,7 +157,7 @@ sub prompt_unknown_word { $action = ["ignore", "permanent", $word]; $window->destroy; }, $window); - $hbox->pack_start($button, FALSE, FALSE, 0); + $hbox->pack_start($button, FALSE, FALSE, 5); $button->show; $vbox->pack_start($hbox, FALSE, FALSE, 10); $hbox->show; @@ -166,50 +166,11 @@ sub prompt_unknown_word { # Take note, kids - this is what happens when you keep adding # features without rethinking your basic design. - # declare this here so it can already be used - my $path_list; - if (exists $config->{"diacritics"}) { - $hbox = Gtk2::HBox->new(FALSE, 0); - my $orig_entry; - my $repl_entry; - my $accept_button = Gtk2::Button->new("Add to table"); - $accept_button->signal_connect( - clicked => sub { - if ($path_list->get_active != -1) { - $action = ["add", $orig_entry->get_text, $repl_entry->get_text, $path_list->get_active_text]; - $window->destroy; - } - }, $window); - $button = Gtk2::Button->new("Retry without diacritics"); - $button->signal_connect( - clicked => sub { - my $stripped = replace_strip_diacritics($config, $word); - my $repl_text = ""; - foreach (@$stripped) { - $repl_text .= $_->[1]; - } - $repl_entry->set_text($repl_text); - $orig_entry->set_text($word); - $repl_entry->show; - $orig_entry->show; - $accept_button->show; - }, $window); - $hbox->pack_start($button, FALSE, FALSE, 0); - $button->show; - $hbox->pack_start($accept_button, FALSE, FALSE, 0); - $orig_entry = Gtk2::Entry->new; - $repl_entry = Gtk2::Entry->new; - $hbox->pack_start($orig_entry, TRUE, TRUE, 10); - $hbox->pack_start($repl_entry, TRUE, TRUE, 10); - $vbox->pack_start($hbox, FALSE, FALSE, 0); - $hbox->show; - } - $hbox = Gtk2::HBox->new(FALSE, 0); $label = Gtk2::Label->new("Add to list: "); $hbox->pack_start($label, FALSE, FALSE, 0); $label->show; - $path_list = Gtk2::ComboBox->new_text; + my $path_list = Gtk2::ComboBox->new_text; foreach my $path (sort keys %{$config->{"display_tables"}}) { $path_list->append_text($path); } @@ -223,12 +184,27 @@ sub prompt_unknown_word { $hbox->pack_start($label, FALSE, FALSE, 0); $label->show; my $replace_entry = Gtk2::Entry->new; - $hbox->pack_start($replace_entry, FALSE, FALSE, 0); + $hbox->pack_start($replace_entry, TRUE, TRUE, 0); $replace_entry->show; $vbox->pack_start($hbox, FALSE, FALSE, 0); $hbox->show; $hbox = Gtk2::HBox->new(FALSE, 0); + if (exists $config->{"diacritics"}) { + $button = Gtk2::Button->new("Retry without diacritics"); + $button->signal_connect( + clicked => sub { + my $stripped = replace_strip_diacritics($config, $word); + my $repl_text = ""; + foreach (@$stripped) { + $repl_text .= $_->[1]; + } + $replace_entry->set_text($repl_text); + }, $window); + $hbox->pack_start($button, FALSE, FALSE, 0); + $button->show; + } + $button = Gtk2::Button->new("Add replacement"); $button->signal_connect( clicked => sub { @@ -237,9 +213,9 @@ sub prompt_unknown_word { $window->destroy; } }, $window); - $hbox->pack_start($button, FALSE, FALSE, 0); + $hbox->pack_start($button, FALSE, FALSE, 5); $button->show; - $vbox->pack_start($hbox, FALSE, FALSE, 0); + $vbox->pack_start($hbox, FALSE, FALSE, 5); $hbox->show; $hbox = Gtk2::HBox->new(FALSE, 0); @@ -251,17 +227,14 @@ sub prompt_unknown_word { }, $window); $hbox->pack_start($button, FALSE, FALSE, 0); $button->show; - $vbox->pack_start($hbox, FALSE, FALSE, 0); - $hbox->show; - $hbox = Gtk2::HBox->new(FALSE, 0); $button = Gtk2::Button->new("Reload config"); $button->signal_connect( clicked => sub { $action = ["reload"]; $window->destroy; }, $window); - $hbox->pack_start($button, FALSE, FALSE, 0); + $hbox->pack_start($button, FALSE, FALSE, 5); $button->show; if ($config_error) { @@ -269,7 +242,7 @@ sub prompt_unknown_word { $hbox->pack_start($label, FALSE, FALSE, 0); $label->show; } - $vbox->pack_start($hbox, FALSE, FALSE, 0); + $vbox->pack_start($hbox, FALSE, FALSE, 5); $hbox->show; $window->add($vbox);