[Pkg-shadow-devel] [Git][debian/adduser][zg/debian-bug-486877-yesno] 2 commits: add AdduserYesNo.pm

Marc Haber (@zugschlus) gitlab at salsa.debian.org
Sat Nov 28 14:55:50 GMT 2026



Marc Haber pushed to branch zg/debian-bug-486877-yesno at Debian / adduser


Commits:
490261dd by Marc Haber at 2026-11-28T15:53:18+01:00
add AdduserYesNo.pm

Git-Dch: ignore

- - - - -
f6e2e7fe by Marc Haber at 2026-11-28T15:53:34+01:00
accept more international yes/no input

Closes: #486877

- - - - -


2 changed files:

- + AdduserYesNo.pm
- adduser


Changes:

=====================================
AdduserYesNo.pm
=====================================
@@ -0,0 +1,202 @@
+package Adduser::Yesno 3.160;
+
+use utf8;
+use feature 'fc';
+use open ':std', ':encoding(UTF-8)';
+
+use parent qw(Exporter);
+
+ at EXPORT = (
+    'ask_i18n_yesno',
+);
+
+# Accepted answers.
+#
+# Each entry consists of a token and its meaning:
+#   1 = yes
+#   0 = no
+#
+# Add or remove entries freely. Tokens that occur in both
+# categories are automatically treated as ambiguous.
+
+my @yesno_tokens = (
+    # English (also universal fallback)
+    [ 'yes',       1 ],
+    [ 'y',         1 ],
+    [ 'no',        0 ],
+    [ 'n',         0 ],
+
+    # German
+    [ 'ja',        1 ],
+    [ 'j',         1 ],
+    [ 'nein',      0 ],
+
+    # French
+    [ 'oui',       1 ],
+    [ 'o',         1 ],
+    [ 'non',       0 ],
+
+    # Spanish
+    [ 'sí',        1 ],
+    [ 'si',        1 ],
+
+    # Italian
+    [ 'sì',        1 ],
+
+    # Portuguese
+    [ 'sim',       1 ],
+    [ 'não',       0 ],
+    [ 'nao',       0 ],
+
+    # Dutch
+    [ 'nee',       0 ],
+
+    # Swedish
+    [ 'nej',       0 ],
+
+    # Norwegian
+    [ 'nei',       0 ],
+
+    # Danish
+    # Shares ja and nej with Swedish.
+
+    # Finnish
+    [ 'kyllä',     1 ],
+    [ 'kylla',     1 ],
+    [ 'ei',        0 ],
+    [ 'e',         0 ],  # ambiguous with Turkish
+
+    # Polish
+    [ 'tak',       1 ],
+    [ 'nie',       0 ],
+
+    # Czech
+    [ 'ano',       1 ],
+    [ 'a',         1 ],
+    [ 'ne',        0 ],
+
+    # Slovak
+    [ 'áno',       1 ],
+    [ 'nie',       0 ],
+
+    # Hungarian
+    [ 'igen',      1 ],
+    [ 'i',         1 ],
+    [ 'nem',       0 ],
+
+    # Russian
+    [ 'да',        1 ],
+    [ 'd',         1 ],
+    [ 'нет',       0 ],
+
+    # Ukrainian
+    [ 'так',       1 ],
+    [ 't',         1 ],
+    [ 'ні',        0 ],
+
+    # Greek
+    [ 'ναι',       1 ],
+    [ 'όχι',       0 ],
+    [ 'οχι',       0 ],
+
+    # Turkish
+    [ 'evet',      1 ],
+    [ 'e',         1 ],  # ambiguous with Finnish
+    [ 'hayır',     0 ],
+    [ 'hayir',     0 ],
+
+    # Japanese
+    [ 'はい',      1 ],
+    [ 'いいえ',    0 ],
+
+    # Chinese (Mandarin)
+    [ '是',        1 ],
+    [ '不是',      0 ],
+);
+
+sub ask_i18n_yesno {
+    my ($question) = @_;
+
+    # Localized canonical answer labels.
+    my $yes = gtx('yes');
+    my $no  = gtx('no');
+
+    # Build the reverse lookup table.
+    # Bit 1 means yes, bit 2 means no.
+    # A value of 3 means ambiguous.
+
+    my %lookup;
+
+    for my $entry (@yesno_tokens) {
+        my ($token, $value) = @$entry;
+
+        $lookup{fc($token)} |= $value ? 1 : 2;
+    }
+
+    # Construct the help answer list.
+    # Include localized labels and universal English answers.
+
+    my %seen;
+    my @labels = grep {
+        !$seen{fc($_)}++
+    } ($yes, $no, 'yes', 'no');
+
+    my $answer_list;
+
+    if (@labels == 2) {
+        $answer_list = sprintf(
+            gtx('%s or %s'),
+            @labels
+        );
+    }
+    elsif (@labels == 3) {
+        $answer_list = sprintf(
+            gtx('%s, %s, or %s'),
+            @labels
+        );
+    }
+    else {
+        $answer_list = sprintf(
+            gtx('%s, %s, %s, or %s'),
+            @labels
+        );
+    }
+
+    while (1) {
+        printf "%s [%s/%s] ", $question, $yes, $no;
+
+        local $! = 0;
+        my $answer = <STDIN>;
+
+        if (!defined $answer) {
+            return (undef, $! ? 'input-error' : 'eof');
+        }
+
+        chomp $answer;
+        $answer =~ s/\A\s+|\s+\z//g;
+
+        my $key = fc($answer);
+
+        my $result = $lookup{$key} // 0;
+
+        return (1, undef) if $result == 1;
+        return (0, undef) if $result == 2;
+
+        if ($result == 3) {
+            printf gtx(
+                "Ambiguous answer: %s\n"
+            ), $answer;
+        }
+        else {
+            printf gtx(
+                "Unrecognized answer: %s\n"
+            ), $answer;
+        }
+
+        printf gtx(
+            "Please answer with %s.\n"
+        ), $answer_list;
+    }
+}
+
+1;


=====================================
adduser
=====================================
@@ -90,7 +90,6 @@ BEGIN {
     }
 }
 
-my $yesexpr = langinfo(YESEXPR());
 my $charset = langinfo($codeset);
 if ($encode_loaded) {
     binmode(STDOUT, ":encoding($charset)");
@@ -1399,9 +1398,6 @@ sub interactive_command_with_confirmation {
     $always_confirm //= 0;   # default to false if not provided
     return unless -t STDIN;  # skip non-interactive
 
-    my $yesexpr = langinfo(YESEXPR);
-    my $noexpr  = langinfo(NOEXPR);
-
     my $retry = 1;
 
     while ($retry) {
@@ -1423,30 +1419,16 @@ sub interactive_command_with_confirmation {
 
         # Prompt for confirmation if requested
         if ($always_confirm) {
-            my $answer;
-            do {
-                print gtx("Is the information correct? [Y/n] ");
-                $answer = <STDIN>;
-
-                unless (defined $answer) {
-                    warn "No input available, assuming 'yes'\n";
-                    last;
-                }
-
-                chomp($answer);
-                $answer =~ s/^\s+|\s+$//g;
-
-                if ($answer =~ m/$yesexpr/o || $answer eq '') {
-                    $retry = 0;  # accepted
-                    last;
-                } elsif ($answer =~ m/$noexpr/o) {
-                    $retry = 1;  # retry command
-                } else {
-                    print "Please answer yes or no.\n";
-                    $answer = undef;  # repeat prompt
-                }
+            my ($answer, $error) = ask_i18n_yesno(
+                gtx("Is the information correct?")
+            );
 
-            } while (!defined $answer);
+            if (defined $answer) {
+                $retry = !$answer;
+            } elsif ($error eq 'eof') {
+                warn "No input available, assuming 'yes'\n";
+                $retry = 0;
+            }
         }
     }
 }



View it on GitLab: https://salsa.debian.org/debian/adduser/-/compare/abc5aea9576ff13438f942eaf9dc48c6e7bf3de4...f6e2e7fe2b7b0a20f18cec23aa1cb9c0dae26623

-- 
View it on GitLab: https://salsa.debian.org/debian/adduser/-/compare/abc5aea9576ff13438f942eaf9dc48c6e7bf3de4...f6e2e7fe2b7b0a20f18cec23aa1cb9c0dae26623
You're receiving this email because of your account on salsa.debian.org. Manage all notifications: https://salsa.debian.org/-/profile/notifications | Help: https://salsa.debian.org/help


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/pkg-shadow-devel/attachments/20261128/9e86a6cd/attachment-0001.htm>


More information about the Pkg-shadow-devel mailing list