transliterate

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

commit 1679620c311e9d20a76f682e3207e9ba65d03b36
parent ee44072feff9eeba94834b38a2d710f6a9454bde
Author: lumidify <nobody@lumidify.org>
Date:   Mon, 30 Mar 2020 15:27:45 +0200

Add nodisplay attribute to table loading in the config

Diffstat:
Mtransliterate.pl | 34+++++++++++++++++++---------------
1 file changed, 19 insertions(+), 15 deletions(-)

diff --git a/transliterate.pl b/transliterate.pl @@ -634,6 +634,8 @@ sub interpret_config { # the "replacement id" is just the number of the replacement group, # starting at 0 with the first group in the config $config{"table_paths"} = {}; + # these are the paths of the tables that are displayed in the GUI + $config{"display_tables"} = {}; # a mapping between the table ids and tables for all tables used as # ending tables in expand statements - so expansions can be done # on the fly when adding a replacement word from the GUI @@ -681,6 +683,10 @@ sub interpret_config { } if ($cmd->[0]->{"value"} eq "table") { my $table_path = $cmd->[2]->{"value"}; + my $nodisplay = 0; + if ($#$cmd >= 3 && $cmd->[3]->{"value"} eq "nodisplay") { + $nodisplay = 1; + } my $table; # add to temporary path-to-table mapping so tables aren't # loaded unnecessarily @@ -694,6 +700,9 @@ sub interpret_config { my $table_id = $cmd->[1]->{"value"}; $tables{$table_id} = $table; $table_id_to_path{$table_id} = $table_path; + # this is a hash to avoid duplicates if the same file + # is loaded multiple times + $config{"display_tables"}->{$table_path} = 1 if !$nodisplay; } elsif ($cmd->[0]->{"value"} eq "expand") { my $orig_table_id = $cmd->[1]->{"value"}; my $ending_table_id = $cmd->[2]->{"value"}; @@ -1178,7 +1187,7 @@ sub get_unknown_words { } my $action = prompt_unknown_word($contextl, $contextl_orig, $word->[1], $contextr, $contextr_orig, - $config->{"table_paths"}, "$cur_lineno" + $config->{"display_tables"}, "$cur_lineno" ); # if $ret == 2, config could not be loaded # if $ret == 1, line must be redone with new config @@ -1188,7 +1197,7 @@ sub get_unknown_words { while ($ret == 2) { $action = prompt_unknown_word($contextl, $contextl_orig, $word->[1], $contextr, $contextr_orig, - $config->{"table_paths"}, "$cur_lineno", 1); + $config->{"display_tables"}, "$cur_lineno", 1); $ret = handle_unknown_word_action($action, $config, $args); } # re-transliterate the line with the new config @@ -1473,6 +1482,8 @@ configuration. Adds the word typed in the text box beside "Add replacement" to the selected table file and re-runs the replacement on the current line. +All table files that do not have B<nodisplay> set are shown as +options, see L</"CONFIGURATION">. Note that this could be made to be faster by simply replacing the word directly in the text instead of running the entire replacement @@ -1486,18 +1497,6 @@ probably not change very soon. If a mistake is made, the word can always be removed again manually from the list and "Reload config" pressed. -The filtering for which table files are actually shown here is -currently a bit rudimentary. First, all paths that are used in the -B<table> statements in the config are put into a list. Then, only -the paths corresponding to table IDs actually used in B<replace> -statements are added to the list that gets shown in the GUI. The -reason for not showing all table paths in the list is that it gets -somewhat confusing when all the tables that are only used for word -endings are also in the list, and it is very unlikely that an -unknown word would need to be written to one of those files. If -necessary, the word can always be added manually and the config -reloaded. - =item Reload config Reload the configuration file along with all tables an re-runs the @@ -1675,11 +1674,16 @@ Sets the file of words to ignore. This has to be set even if the file is just empty because the user can add words to it from the unknown word window. -=item B<table> <table identifier> <filename> +=item B<table> <table identifier> <filename> [nodisplay] Load the table from C<< <filename> >>, making it available for later use in the B<expand> and B<replace> commands using the identifier C<< <table identifier> >>. +if B<nodisplay> is set, the filename for this table is not shown in the +L<unknown word window|/"UNKNOWN WORD WINDOW">. If, however, the same filename +is loaded again for another table that does not have B<nodisplay> set, it is +still displayed. + Note that if C<< <filename> >> is not an absolute path, it is taken to be relative to the location of the configuration file.