i18n: send-email: mark string with interpolation for translation

Mark warnings, errors and other messages that are interpolated for translation. We call sprintf() before calling die() and in few other circumstances in order to replace the values on the placeholders. Signed-off-by: Vasco Almeida <vascomalmeida@sapo.pt> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Vasco Almeida committed Dec 14, 2016 at 11:54 UTC 3c5cd20c7d177f0d93532271f421037c1440a2ff
1 file changed +47 -40
git-send-email.perl
+47 -40
@@ -279,10 +279,13 @@ sub signal_handler {
279 # tmp files from --compose
280 if (defined $compose_filename) {
281 if (-e $compose_filename) {
282 - print "'$compose_filename' contains an intermediate version of the email you were composing.\n";
282 + printf __("'%s' contains an intermediate version ".
283 + "of the email you were composing.\n"),
284 + $compose_filename;
285 }
286 if (-e ($compose_filename . ".final")) {
285 - print "'$compose_filename.final' contains the composed email.\n"
287 + printf __("'%s.final' contains the composed email.\n"),
288 + $compose_filename;
289 }
290 }
291
@@ -431,7 +434,7 @@ $smtp_encryption = '' unless (defined $smtp_encryption);
434 my(%suppress_cc);
435 if (@suppress_cc) {
436 foreach my $entry (@suppress_cc) {
434 - die "Unknown --suppress-cc field: '$entry'\n"
437 + die sprintf(__("Unknown --suppress-cc field: '%s'\n"), $entry)
438 unless $entry =~ /^(?:all|cccmd|cc|author|self|sob|body|bodycc)$/;
439 $suppress_cc{$entry} = 1;
440 }
@@ -460,7 +463,7 @@ my $confirm_unconfigured = !defined $confirm;
463 if ($confirm_unconfigured) {
464 $confirm = scalar %suppress_cc ? 'compose' : 'auto';
465 };
463 -die "Unknown --confirm setting: '$confirm'\n"
466 +die sprintf(__("Unknown --confirm setting: '%s'\n"), $confirm)
467 unless $confirm =~ /^(?:auto|cc|compose|always|never)/;
468
469 # Debugging, print out the suppressions.
@@ -492,16 +495,16 @@ my %aliases;
495 sub parse_sendmail_alias {
496 local $_ = shift;
497 if (/"/) {
495 - print STDERR "warning: sendmail alias with quotes is not supported: $_\n";
498 + printf STDERR __("warning: sendmail alias with quotes is not supported: %s\n"), $_;
499 } elsif (/:include:/) {
497 - print STDERR "warning: `:include:` not supported: $_\n";
500 + printf STDERR __("warning: `:include:` not supported: %s\n"), $_;
501 } elsif (/[\/|]/) {
499 - print STDERR "warning: `/file` or `|pipe` redirection not supported: $_\n";
502 + printf STDERR __("warning: `/file` or `|pipe` redirection not supported: %s\n"), $_;
503 } elsif (/^(\S+?)\s*:\s*(.+)$/) {
504 my ($alias, $addr) = ($1, $2);
505 $aliases{$alias} = [ split_addrs($addr) ];
506 } else {
504 - print STDERR "warning: sendmail line is not recognized: $_\n";
507 + printf STDERR __("warning: sendmail line is not recognized: %s\n"), $_;
508 }
509 }
510
@@ -582,11 +585,11 @@ sub is_format_patch_arg {
585 if (defined($format_patch)) {
586 return $format_patch;
587 }
585 - die(<<EOF);
586 -File '$f' exists but it could also be the range of commits
588 + die sprintf(__ <<EOF, $f, $f);
589 +File '%s' exists but it could also be the range of commits
590 to produce patches for. Please disambiguate by...
591
589 - * Saying "./$f" if you mean a file; or
592 + * Saying "./%s" if you mean a file; or
593 * Giving --format-patch option if you mean a range.
594 EOF
595 } catch Git::Error::Command with {
@@ -604,7 +607,7 @@ while (defined(my $f = shift @ARGV)) {
607 @ARGV = ();
608 } elsif (-d $f and !is_format_patch_arg($f)) {
609 opendir my $dh, $f
607 - or die "Failed to opendir $f: $!";
610 + or die sprintf(__("Failed to opendir %s: %s"), $f, $!);
611
612 push @files, grep { -f $_ } map { catfile($f, $_) }
613 sort readdir $dh;
@@ -628,7 +631,8 @@ if ($validate) {
631 foreach my $f (@files) {
632 unless (-p $f) {
633 my $error = validate_patch($f);
631 - $error and die "fatal: $f: $error\nwarning: no patches were sent\n";
634 + $error and die sprintf(__("fatal: %s: %s\nwarning: no patches were sent\n"),
635 + $f, $error);
636 }
637 }
638 }
@@ -651,7 +655,7 @@ sub get_patch_subject {
655 return "GIT: $1\n";
656 }
657 close $fh;
654 - die "No subject line in $fn ?";
658 + die sprintf(__("No subject line in %s?"), $fn);
659 }
660
661 if ($compose) {
@@ -661,7 +665,7 @@ if ($compose) {
665 tempfile(".gitsendemail.msg.XXXXXX", DIR => $repo->repo_path()) :
666 tempfile(".gitsendemail.msg.XXXXXX", DIR => "."))[1];
667 open my $c, ">", $compose_filename
664 - or die "Failed to open for writing $compose_filename: $!";
668 + or die sprintf(__("Failed to open for writing %s: %s"), $compose_filename, $!);
669
670
671 my $tpl_sender = $sender || $repoauthor || $repocommitter || '';
@@ -692,10 +696,10 @@ EOT
696 }
697
698 open my $c2, ">", $compose_filename . ".final"
695 - or die "Failed to open $compose_filename.final : " . $!;
699 + or die sprintf(__("Failed to open %s.final: %s"), $compose_filename, $!);
700
701 open $c, "<", $compose_filename
698 - or die "Failed to open $compose_filename : " . $!;
702 + or die sprintf(__("Failed to open %s: %s"), $compose_filename, $!);
703
704 my $need_8bit_cte = file_has_nonascii($compose_filename);
705 my $in_body = 0;
@@ -769,7 +773,9 @@ sub ask {
773 return $resp;
774 }
775 if ($confirm_only) {
772 - my $yesno = $term->readline("Are you sure you want to use <$resp> [y/N]? ");
776 + my $yesno = $term->readline(
777 + # TRANSLATORS: please keep [y/N] as is.
778 + sprintf(__("Are you sure you want to use <%s> [y/N]? "), $resp));
779 if (defined $yesno && $yesno =~ /y/i) {
780 return $resp;
781 }
@@ -811,9 +817,9 @@ if (!defined $auto_8bit_encoding && scalar %broken_encoding) {
817 if (!$force) {
818 for my $f (@files) {
819 if (get_patch_subject($f) =~ /\Q*** SUBJECT HERE ***\E/) {
814 - die "Refusing to send because the patch\n\t$f\n"
820 + die sprintf(__("Refusing to send because the patch\n\t%s\n"
821 . "has the template subject '*** SUBJECT HERE ***'. "
816 - . "Pass --force if you really want to send.\n";
822 + . "Pass --force if you really want to send.\n"), $f);
823 }
824 }
825 }
@@ -848,7 +854,7 @@ my %EXPANDED_ALIASES;
854 sub expand_one_alias {
855 my $alias = shift;
856 if ($EXPANDED_ALIASES{$alias}) {
851 - die "fatal: alias '$alias' expands to itself\n";
857 + die sprintf(__("fatal: alias '%s' expands to itself\n"), $alias);
858 }
859 local $EXPANDED_ALIASES{$alias} = 1;
860 return $aliases{$alias} ? expand_aliases(@{$aliases{$alias}}) : $alias;
@@ -910,7 +916,7 @@ sub extract_valid_address {
916 sub extract_valid_address_or_die {
917 my $address = shift;
918 $address = extract_valid_address($address);
913 - die "error: unable to extract a valid address from: $address\n"
919 + die sprintf(__("error: unable to extract a valid address from: %s\n"), $address)
920 if !$address;
921 return $address;
922 }
@@ -918,7 +924,7 @@ sub extract_valid_address_or_die {
924 sub validate_address {
925 my $address = shift;
926 while (!extract_valid_address($address)) {
921 - print STDERR "error: unable to extract a valid address from: $address\n";
927 + printf STDERR __("error: unable to extract a valid address from: %s\n"), $address;
928 # TRANSLATORS: Make sure to include [q] [d] [e] in your
929 # translation. The program will only accept English input
930 # at this point.
@@ -1223,7 +1229,7 @@ sub ssl_verify_params {
1229 return (SSL_verify_mode => SSL_VERIFY_PEER(),
1230 SSL_ca_file => $smtp_ssl_cert_path);
1231 } else {
1226 - die "CA path \"$smtp_ssl_cert_path\" does not exist";
1232 + die sprintf(__("CA path \"%s\" does not exist"), $smtp_ssl_cert_path);
1233 }
1234 }
1235
@@ -1386,14 +1392,14 @@ EOF
1392 # supported commands
1393 $smtp->hello($smtp_domain);
1394 } else {
1389 - die "Server does not support STARTTLS! ".$smtp->message;
1395 + die sprintf(__("Server does not support STARTTLS! %s"), $smtp->message);
1396 }
1397 }
1398 }
1399
1400 if (!$smtp) {
1395 - die "Unable to initialize SMTP properly. Check config and use --smtp-debug. ",
1396 - "VALUES: server=$smtp_server ",
1401 + die __("Unable to initialize SMTP properly. Check config and use --smtp-debug."),
1402 + " VALUES: server=$smtp_server ",
1403 "encryption=$smtp_encryption ",
1404 "hello=$smtp_domain",
1405 defined $smtp_server_port ? " port=$smtp_server_port" : "";
@@ -1410,10 +1416,10 @@ EOF
1416 $smtp->datasend("$line") or die $smtp->message;
1417 }
1418 $smtp->dataend() or die $smtp->message;
1413 - $smtp->code =~ /250|200/ or die "Failed to send $subject\n".$smtp->message;
1419 + $smtp->code =~ /250|200/ or die sprintf(__("Failed to send %s\n"), $subject).$smtp->message;
1420 }
1421 if ($quiet) {
1416 - printf (($dry_run ? "Dry-" : "")."Sent %s\n", $subject);
1422 + printf($dry_run ? __("Dry-Sent %s\n") : __("Sent %s\n"), $subject);
1423 } else {
1424 print($dry_run ? __("Dry-OK. Log says:\n") : __("OK. Log says:\n"));
1425 if (!file_name_is_absolute($smtp_server)) {
@@ -1443,7 +1449,7 @@ $subject = $initial_subject;
1449 $message_num = 0;
1450
1451 foreach my $t (@files) {
1446 - open my $fh, "<", $t or die "can't open file $t";
1452 + open my $fh, "<", $t or die sprintf(__("can't open file %s"), $t);
1453
1454 my $author = undef;
1455 my $sauthor = undef;
@@ -1665,18 +1671,18 @@ sub recipients_cmd {
1671
1672 my @addresses = ();
1673 open my $fh, "-|", "$cmd \Q$file\E"
1668 - or die "($prefix) Could not execute '$cmd'";
1674 + or die sprintf(__("(%s) Could not execute '%s'"), $prefix, $cmd);
1675 while (my $address = <$fh>) {
1676 $address =~ s/^\s*//g;
1677 $address =~ s/\s*$//g;
1678 $address = sanitize_address($address);
1679 next if ($address eq $sender and $suppress_cc{'self'});
1680 push @addresses, $address;
1675 - printf("($prefix) Adding %s: %s from: '%s'\n",
1676 - $what, $address, $cmd) unless $quiet;
1681 + printf(__("(%s) Adding %s: %s from: '%s'\n"),
1682 + $prefix, $what, $address, $cmd) unless $quiet;
1683 }
1684 close $fh
1679 - or die "($prefix) failed to close pipe to '$cmd'";
1685 + or die sprintf(__("(%s) failed to close pipe to '%s'"), $prefix, $cmd);
1686 return @addresses;
1687 }
1688
@@ -1730,10 +1736,10 @@ sub unique_email_list {
1736 sub validate_patch {
1737 my $fn = shift;
1738 open(my $fh, '<', $fn)
1733 - or die "unable to open $fn: $!\n";
1739 + or die sprintf(__("unable to open %s: %s\n"), $fn, $!);
1740 while (my $line = <$fh>) {
1741 if (length($line) > 998) {
1736 - return "$.: patch contains a line longer than 998 characters";
1742 + return sprintf(__("%s: patch contains a line longer than 998 characters"), $.);
1743 }
1744 }
1745 return;
@@ -1749,10 +1755,11 @@ sub handle_backup {
1755 (substr($file, 0, $lastlen) eq $last) &&
1756 ($suffix = substr($file, $lastlen)) !~ /^[a-z0-9]/i) {
1757 if (defined $known_suffix && $suffix eq $known_suffix) {
1752 - print "Skipping $file with backup suffix '$known_suffix'.\n";
1758 + printf(__("Skipping %s with backup suffix '%s'.\n"), $file, $known_suffix);
1759 $skip = 1;
1760 } else {
1755 - my $answer = ask("Do you really want to send $file? (y|N): ",
1761 + # TRANSLATORS: please keep "[y|N]" as is.
1762 + my $answer = ask(sprintf(__("Do you really want to send %s? [y|N]: "), $file),
1763 valid_re => qr/^(?:y|n)/i,
1764 default => 'n');
1765 $skip = ($answer ne 'y');
@@ -1780,7 +1787,7 @@ sub handle_backup_files {
1787 sub file_has_nonascii {
1788 my $fn = shift;
1789 open(my $fh, '<', $fn)
1783 - or die "unable to open $fn: $!\n";
1790 + or die sprintf(__("unable to open %s: %s\n"), $fn, $!);
1791 while (my $line = <$fh>) {
1792 return 1 if $line =~ /[^[:ascii:]]/;
1793 }
@@ -1790,7 +1797,7 @@ sub file_has_nonascii {
1797 sub body_or_subject_has_nonascii {
1798 my $fn = shift;
1799 open(my $fh, '<', $fn)
1793 - or die "unable to open $fn: $!\n";
1800 + or die sprintf(__("unable to open %s: %s\n"), $fn, $!);
1801 while (my $line = <$fh>) {
1802 last if $line =~ /^$/;
1803 return 1 if $line =~ /^Subject.*[^[:ascii:]]/;