Skip to content

Commit 6599f66

Browse files
vascoolgitster
authored andcommitted
i18n: send-email: mark string with interpolation for translation
Mark warnings, errors and other messages that are interpolated for translation. We must call sprintf() before calling die() and in few other circumstances in order to interpolation take place. Signed-off-by: Vasco Almeida <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 27fe88f commit 6599f66

File tree

1 file changed

+38
-33
lines changed

1 file changed

+38
-33
lines changed

git-send-email.perl

Lines changed: 38 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -279,10 +279,13 @@ sub signal_handler {
279279
# tmp files from --compose
280280
if (defined $compose_filename) {
281281
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;
283285
}
284286
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;
286289
}
287290
}
288291

@@ -431,7 +434,7 @@ sub read_config {
431434
my(%suppress_cc);
432435
if (@suppress_cc) {
433436
foreach my $entry (@suppress_cc) {
434-
die "Unknown --suppress-cc field: '$entry'\n"
437+
die sprintf(__("Unknown --suppress-cc field: '%s'\n"), $entry)
435438
unless $entry =~ /^(?:all|cccmd|cc|author|self|sob|body|bodycc)$/;
436439
$suppress_cc{$entry} = 1;
437440
}
@@ -460,7 +463,7 @@ sub read_config {
460463
if ($confirm_unconfigured) {
461464
$confirm = scalar %suppress_cc ? 'compose' : 'auto';
462465
};
463-
die "Unknown --confirm setting: '$confirm'\n"
466+
die sprintf(__("Unknown --confirm setting: '%s'\n"), $confirm)
464467
unless $confirm =~ /^(?:auto|cc|compose|always|never)/;
465468

466469
# Debugging, print out the suppressions.
@@ -492,16 +495,16 @@ sub split_addrs {
492495
sub parse_sendmail_alias {
493496
local $_ = shift;
494497
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"), $_;
496499
} elsif (/:include:/) {
497-
print STDERR "warning: `:include:` not supported: $_\n";
500+
printf STDERR __("warning: `:include:` not supported: %s\n"), $_;
498501
} elsif (/[\/|]/) {
499-
print STDERR "warning: `/file` or `|pipe` redirection not supported: $_\n";
502+
printf STDERR __("warning: `/file` or `|pipe` redirection not supported: %s\n"), $_;
500503
} elsif (/^(\S+?)\s*:\s*(.+)$/) {
501504
my ($alias, $addr) = ($1, $2);
502505
$aliases{$alias} = [ split_addrs($addr) ];
503506
} else {
504-
print STDERR "warning: sendmail line is not recognized: $_\n";
507+
printf STDERR __("warning: sendmail line is not recognized: %s\n"), $_;
505508
}
506509
}
507510

@@ -582,13 +585,12 @@ sub is_format_patch_arg {
582585
if (defined($format_patch)) {
583586
return $format_patch;
584587
}
585-
die(<<EOF);
586-
File '$f' exists but it could also be the range of commits
588+
die sprintf(__(
589+
"File '%s' exists but it could also be the range of commits
587590
to produce patches for. Please disambiguate by...
588591
589-
* Saying "./$f" if you mean a file; or
590-
* Giving --format-patch option if you mean a range.
591-
EOF
592+
* Saying \"./%s\" if you mean a file; or
593+
* Giving --format-patch option if you mean a range."), $f, $f);
592594
} catch Git::Error::Command with {
593595
# Not a valid revision. Treat it as a filename.
594596
return 0;
@@ -604,7 +606,7 @@ sub is_format_patch_arg {
604606
@ARGV = ();
605607
} elsif (-d $f and !is_format_patch_arg($f)) {
606608
opendir my $dh, $f
607-
or die "Failed to opendir $f: $!";
609+
or die sprintf(__("Failed to opendir %s: %s"), $f, $!);
608610

609611
push @files, grep { -f $_ } map { catfile($f, $_) }
610612
sort readdir $dh;
@@ -628,7 +630,8 @@ sub is_format_patch_arg {
628630
foreach my $f (@files) {
629631
unless (-p $f) {
630632
my $error = validate_patch($f);
631-
$error and die "fatal: $f: $error\nwarning: no patches were sent\n";
633+
$error and die sprintf(__("fatal: %s: %s\nwarning: no patches were sent\n"),
634+
$f, $error);
632635
}
633636
}
634637
}
@@ -651,7 +654,7 @@ sub get_patch_subject {
651654
return "GIT: $1\n";
652655
}
653656
close $fh;
654-
die "No subject line in $fn ?";
657+
die sprintf(__("No subject line in %s ?"), $fn);
655658
}
656659

657660
if ($compose) {
@@ -661,7 +664,7 @@ sub get_patch_subject {
661664
tempfile(".gitsendemail.msg.XXXXXX", DIR => $repo->repo_path()) :
662665
tempfile(".gitsendemail.msg.XXXXXX", DIR => "."))[1];
663666
open my $c, ">", $compose_filename
664-
or die "Failed to open for writing $compose_filename: $!";
667+
or die sprintf(__("Failed to open for writing %s: %s"), $compose_filename, $!);
665668

666669

667670
my $tpl_sender = $sender || $repoauthor || $repocommitter || '';
@@ -692,10 +695,10 @@ sub get_patch_subject {
692695
}
693696

694697
open my $c2, ">", $compose_filename . ".final"
695-
or die "Failed to open $compose_filename.final : " . $!;
698+
or die sprintf(__("Failed to open %s.final : %s"), $compose_filename, $!);
696699

697700
open $c, "<", $compose_filename
698-
or die "Failed to open $compose_filename : " . $!;
701+
or die sprintf(__("Failed to open %s : %s"), $compose_filename, $!);
699702

700703
my $need_8bit_cte = file_has_nonascii($compose_filename);
701704
my $in_body = 0;
@@ -769,7 +772,9 @@ sub ask {
769772
return $resp;
770773
}
771774
if ($confirm_only) {
772-
my $yesno = $term->readline("Are you sure you want to use <$resp> [y/N]? ");
775+
# TRANSLATORS: Keep [y/N] as is.
776+
my $yesno = $term->readline(
777+
sprintf(__("Are you sure you want to use <%s> [y/N]? "), $resp));
773778
if (defined $yesno && $yesno =~ /y/i) {
774779
return $resp;
775780
}
@@ -848,7 +853,7 @@ sub expand_aliases {
848853
sub expand_one_alias {
849854
my $alias = shift;
850855
if ($EXPANDED_ALIASES{$alias}) {
851-
die "fatal: alias '$alias' expands to itself\n";
856+
die sprintf(__("fatal: alias '%s' expands to itself\n"), $alias);
852857
}
853858
local $EXPANDED_ALIASES{$alias} = 1;
854859
return $aliases{$alias} ? expand_aliases(@{$aliases{$alias}}) : $alias;
@@ -910,15 +915,15 @@ sub extract_valid_address {
910915
sub extract_valid_address_or_die {
911916
my $address = shift;
912917
$address = extract_valid_address($address);
913-
die "error: unable to extract a valid address from: $address\n"
918+
die sprintf(__("error: unable to extract a valid address from: %s\n"), $address)
914919
if !$address;
915920
return $address;
916921
}
917922

918923
sub validate_address {
919924
my $address = shift;
920925
while (!extract_valid_address($address)) {
921-
print STDERR "error: unable to extract a valid address from: $address\n";
926+
printf STDERR __("error: unable to extract a valid address from: %s\n"), $address;
922927
# TRANSLATORS: Make sure to include [q] [d] [e] in your
923928
# translation. The program will only accept English input
924929
# at this point.
@@ -1223,7 +1228,7 @@ sub ssl_verify_params {
12231228
return (SSL_verify_mode => SSL_VERIFY_PEER(),
12241229
SSL_ca_file => $smtp_ssl_cert_path);
12251230
} else {
1226-
die "CA path \"$smtp_ssl_cert_path\" does not exist";
1231+
die sprintf(__("CA path \"%s\" does not exist"), $smtp_ssl_cert_path);
12271232
}
12281233
}
12291234

@@ -1385,7 +1390,7 @@ sub send_message {
13851390
# supported commands
13861391
$smtp->hello($smtp_domain);
13871392
} else {
1388-
die "Server does not support STARTTLS! ".$smtp->message;
1393+
die sprintf(__("Server does not support STARTTLS! %s"), $smtp->message);
13891394
}
13901395
}
13911396
}
@@ -1442,7 +1447,7 @@ sub send_message {
14421447
$message_num = 0;
14431448

14441449
foreach my $t (@files) {
1445-
open my $fh, "<", $t or die "can't open file $t";
1450+
open my $fh, "<", $t or die sprintf(__("can't open file %s"), $t);
14461451

14471452
my $author = undef;
14481453
my $sauthor = undef;
@@ -1671,11 +1676,11 @@ sub recipients_cmd {
16711676
$address = sanitize_address($address);
16721677
next if ($address eq $sender and $suppress_cc{'self'});
16731678
push @addresses, $address;
1674-
printf("($prefix) Adding %s: %s from: '%s'\n",
1675-
$what, $address, $cmd) unless $quiet;
1679+
printf(__("(%s) Adding %s: %s from: '%s'\n"),
1680+
$prefix, $what, $address, $cmd) unless $quiet;
16761681
}
16771682
close $fh
1678-
or die "($prefix) failed to close pipe to '$cmd'";
1683+
or die sprintf(__("(%s) failed to close pipe to '%s'"), $prefix, $cmd);
16791684
return @addresses;
16801685
}
16811686

@@ -1729,10 +1734,10 @@ sub unique_email_list {
17291734
sub validate_patch {
17301735
my $fn = shift;
17311736
open(my $fh, '<', $fn)
1732-
or die "unable to open $fn: $!\n";
1737+
or die sprintf(__("unable to open %s: %s\n"), $fn, $!);
17331738
while (my $line = <$fh>) {
17341739
if (length($line) > 998) {
1735-
return "$.: patch contains a line longer than 998 characters";
1740+
return sprintf(__("%s: patch contains a line longer than 998 characters"), $.);
17361741
}
17371742
}
17381743
return;
@@ -1779,7 +1784,7 @@ sub handle_backup_files {
17791784
sub file_has_nonascii {
17801785
my $fn = shift;
17811786
open(my $fh, '<', $fn)
1782-
or die "unable to open $fn: $!\n";
1787+
or die sprintf(__("unable to open %s: %s\n"), $fn, $!);
17831788
while (my $line = <$fh>) {
17841789
return 1 if $line =~ /[^[:ascii:]]/;
17851790
}
@@ -1789,7 +1794,7 @@ sub file_has_nonascii {
17891794
sub body_or_subject_has_nonascii {
17901795
my $fn = shift;
17911796
open(my $fh, '<', $fn)
1792-
or die "unable to open $fn: $!\n";
1797+
or die sprintf(__("unable to open %s: %s\n"), $fn, $!);
17931798
while (my $line = <$fh>) {
17941799
last if $line =~ /^$/;
17951800
return 1 if $line =~ /^Subject.*[^[:ascii:]]/;

0 commit comments

Comments
 (0)