commit a6c5da06d240b5739b8732bb4e8ffc7f40168b1f
parent 92c2f7acbbef5624803f1d296dce093edbe13dd3
Author: lumidify <nobody@lumidify.org>
Date: Thu, 2 Apr 2020 13:44:17 +0200
Add feature to targetdiacritics
Diffstat:
1 file changed, 16 insertions(+), 0 deletions(-)
diff --git a/transliterate.pl b/transliterate.pl
@@ -271,6 +271,22 @@ sub prompt_choose_word {
my @replacements;
foreach (0..$#$substrings) {
if ($substrings->[$_]->[1] =~ /\Q$config->{choicesep}\E/) {
+ if (exists $config->{"targetdiacritics"}) {
+ my @choices = split /\Q$config->{choicesep}\E/, $substrings->[$_]->[1];
+ my @diacritics = @{$config->{"targetdiacritics"}};
+ if (@choices == 2) {
+ @choices = map {NFD($_)} @choices;
+ my $first_matches = grep {$choices[0] =~ /$_/} @diacritics;
+ my $second_matches = grep {$choices[1] =~ /$_/} @diacritics;
+ if ($first_matches && !$second_matches) {
+ $substrings->[$_]->[1] = $choices[0];
+ next;
+ } elsif (!$first_matches && $second_matches) {
+ $substrings->[$_]->[1] = $choices[1];
+ next;
+ }
+ }
+ }
# Format of the elements in @replacements:
# [<id of substrings in $substrings>, <replacement word>, <original string>]
push @replacements, [$_, $substrings->[$_]->[1], $substrings->[$_]->[1]];