git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v5 00/16] Mark strings in Perl scripts for translation

From
Vasco Almeida <vascomalmeida@sapo.pt>
Date
Nov 8, 2016, 12:08 UTC
Message-ID
<20161108120823.11204-1-vascomalmeida@sapo.pt>
In-Reply-To
<20161005172110.30801-1-vascomalmeida@sapo.pt>
Mark messages in some perl scripts for translation.
In these series v5:
- Add and use a subroutine to comment lines. This way we can mark strings
  for translation without including the comment char within them.
- Mark for translation a message for the user when she is composing an
  e-mail in git-send-email.perl.
Interdiff included below.
Vasco Almeida (16):
  Git.pm: add subroutines for commenting lines
  i18n: add--interactive: mark strings for translation
  i18n: add--interactive: mark simple here-documents for translation
  i18n: add--interactive: mark strings with interpolation for
    translation
  i18n: clean.c: match string with git-add--interactive.perl
  i18n: add--interactive: mark plural strings
  i18n: add--interactive: mark patch prompt for translation
  i18n: add--interactive: i18n of help_patch_cmd
  i18n: add--interactive: mark edit_hunk_manually message for
    translation
  i18n: add--interactive: remove %patch_modes entries
  i18n: add--interactive: mark status words for translation
  i18n: send-email: mark strings for translation
  i18n: send-email: mark warnings and errors for translation
  i18n: send-email: mark string with interpolation for translation
  i18n: send-email: mark composing message for translation
  i18n: difftool: mark warnings for translation
 Makefile                  |   3 +-
 builtin/clean.c           |  10 +-
 git-add--interactive.perl | 329 ++++++++++++++++++++++++++++++----------------
 git-difftool.perl         |  22 ++--
 git-send-email.perl       | 192 ++++++++++++++-------------
 perl/Git.pm               |  23 ++++
 perl/Git/I18N.pm          |  19 ++-
 t/t0202/test.pl           |  14 +-
 8 files changed, 391 insertions(+), 221 deletions(-)
-- >8 --
diff --git a/git-add--interactive.perl b/git-add--interactive.perl
index 4754104..56e6889 100755
--- a/git-add--interactive.perl
+++ b/git-add--interactive.perl
@@ -1039,26 +1039,26 @@ sub color_diff {
 
 my %edit_hunk_manually_modes = (
 	stage => N__(
-"# If the patch applies cleanly, the edited hunk will immediately be
-# marked for staging."),
+"If the patch applies cleanly, the edited hunk will immediately be
+marked for staging."),
 	stash => N__(
-"# If the patch applies cleanly, the edited hunk will immediately be
-# marked for stashing."),
+"If the patch applies cleanly, the edited hunk will immediately be
+marked for stashing."),
 	reset_head => N__(
-"# If the patch applies cleanly, the edited hunk will immediately be
-# marked for unstaging."),
+"If the patch applies cleanly, the edited hunk will immediately be
+marked for unstaging."),
 	reset_nothead => N__(
-"# If the patch applies cleanly, the edited hunk will immediately be
-# marked for applying."),
+"If the patch applies cleanly, the edited hunk will immediately be
+marked for applying."),
 	checkout_index => N__(
-"# If the patch applies cleanly, the edited hunk will immediately be
-# marked for discarding"),
+"If the patch applies cleanly, the edited hunk will immediately be
+marked for discarding"),
 	checkout_head => N__(
-"# If the patch applies cleanly, the edited hunk will immediately be
-# marked for discarding."),
+"If the patch applies cleanly, the edited hunk will immediately be
+marked for discarding."),
 	checkout_nothead => N__(
-"# If the patch applies cleanly, the edited hunk will immediately be
-# marked for applying."),
+"If the patch applies cleanly, the edited hunk will immediately be
+marked for applying."),
 );
 
 sub edit_hunk_manually {
@@ -1068,21 +1068,22 @@ sub edit_hunk_manually {
 	my $fh;
 	open $fh, '>', $hunkfile
 		or die sprintf(__("failed to open hunk edit file for writing: %s"), $!);
-	print $fh __("# Manual hunk edit mode -- see bottom for a quick guide\n");
+	print $fh Git::comment_lines __("Manual hunk edit mode -- see bottom for a quick guide\n");
 	print $fh @$oldtext;
 	my $is_reverse = $patch_mode_flavour{IS_REVERSE};
 	my ($remove_plus, $remove_minus) = $is_reverse ? ('-', '+') : ('+', '-');
-	print $fh sprintf(__(
-"# ---
-# To remove '%s' lines, make them ' ' lines (context).
-# To remove '%s' lines, delete them.
-# Lines starting with # will be removed.
-#\n"), $remove_minus, $remove_plus),
-__($edit_hunk_manually_modes{$patch_mode}), __(
+	my $comment_line_char = Git::config("core.commentchar") || '#';
+	print $fh Git::comment_lines sprintf(__(
+"---
+To remove '%s' lines, make them ' ' lines (context).
+To remove '%s' lines, delete them.
+Lines starting with %s will be removed.
+\n"), $remove_minus, $remove_plus, $comment_line_char) .
+__($edit_hunk_manually_modes{$patch_mode}) ."\n". __(
 # TRANSLATORS: 'it' refers to the patch mentioned in the previous messages.
-" If it does not apply cleanly, you will be given
-# an opportunity to edit again. If all lines of the hunk are removed,
-# then the edit is aborted and the hunk is left unchanged.\n");
+"If it does not apply cleanly, you will be given an opportunity to
+edit again.  If all lines of the hunk are removed, then the edit is
+aborted and the hunk is left unchanged.\n");
 	close $fh;
 
 	chomp(my $editor = run_cmd_pipe(qw(git var GIT_EDITOR)));
@@ -1094,7 +1095,7 @@ __($edit_hunk_manually_modes{$patch_mode}), __(
 
 	open $fh, '<', $hunkfile
 		or die sprintf(__("failed to open hunk edit file for reading: %s"), $!);
-	my @newtext = grep { !/^#/ } <$fh>;
+	my @newtext = grep { !/^$comment_line_char/ } <$fh>;
 	close $fh;
 	unlink $hunkfile;
 
diff --git a/git-send-email.perl b/git-send-email.perl
index 5c01425..bbeb9fb 100755
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -671,18 +671,20 @@ if ($compose) {
 	my $tpl_subject = $initial_subject || '';
 	my $tpl_reply_to = $initial_reply_to || '';
 
-	print $c <<EOT;
+	print $c <<EOT1, Git::prefix_lines("GIT: ", __ <<EOT2), <<EOT3;
 From $tpl_sender # This line is ignored.
-GIT: Lines beginning in "GIT:" will be removed.
-GIT: Consider including an overall diffstat or table of contents
-GIT: for the patch you are writing.
-GIT:
-GIT: Clear the body content if you don't wish to send a summary.
+EOT1
+Lines beginning in "GIT:" will be removed.
+Consider including an overall diffstat or table of contents
+for the patch you are writing.
+
+Clear the body content if you don't wish to send a summary.
+EOT2
 From: $tpl_sender
 Subject: $tpl_subject
 In-Reply-To: $tpl_reply_to
 
-EOT
+EOT3
 	for my $f (@files) {
 		print $c get_patch_subject($f);
 	}
diff --git a/perl/Git.pm b/perl/Git.pm
index b273282..17be59f 100644
--- a/perl/Git.pm
+++ b/perl/Git.pm
@@ -1438,6 +1438,29 @@ sub END {
 
 } # %TEMP_* Lexical Context
 
+=item prefix_lines ( PREFIX, STRING )
+
+Prefixes lines in C<STRING> with C<PREFIX>.
+
+=cut
+
+sub prefix_lines {
+	my ($prefix, $string) = @_;
+	$string =~ s/^/$prefix/mg;
+	return $string;
+}
+
+=item comment_lines ( STRING )
+
+Comments lines following core.commentchar configuration.
+
+=cut
+
+sub comment_lines {
+	my $comment_line_char = config("core.commentchar") || '#';
+	return prefix_lines("$comment_line_char ", @_);
+}
+
 =back
 
 =head1 ERROR HANDLING
diff --git a/perl/Git/I18N.pm b/perl/Git/I18N.pm
index 32c4568..c41425c 100644
--- a/perl/Git/I18N.pm
+++ b/perl/Git/I18N.pm
@@ -74,7 +74,7 @@ Git::I18N - Perl interface to Git's Gettext localizations
 
 	printf __("The following error occurred: %s\n"), $error;
 
-	printf __n("commited %d file", "commited %d files", $files), $files;
+	printf __n("commited %d file\n", "commited %d files\n", $files), $files;
 
 
 =head1 DESCRIPTION
@@ -95,12 +95,14 @@ L<Locale::Messages>'s gettext function if all goes well, otherwise our
 passthrough fallback function.
 
 =head2 __n($$$)
+
 L<Locale::Messages>'s ngettext function or passthrough fallback function.
 
 =head2 N__($)
-No-op that only returns its argument. Use this if you want xgettext to
-extract the text to the pot template but do not want to trigger retrival of
-the translation at run time.
+
+No-operation that only returns its argument. Use this if you want xgettext to
+extract the text to the pot template but do not want to trigger retrival of the
+translation at run time.
 
 =head1 AUTHOR
 
-- >8 --
-- 
2.11.0.rc0.23.g8236252
Previous: Junio C HamanoNext: Vasco Almeida
Message 43 of 63 in “Mark strings in Perl scripts for translation”
  1. 00/14 Mark strings in Perl scripts for translationVasco Almeida, Oct 5, 2016
  2. 02/14 i18n: add--interactive: mark simple here-documents for translationVasco Almeida, Oct 5, 2016
  3. 04/14 i18n: clean.c: match string with git-add--interactive.perlVasco Almeida, Oct 5, 2016
  4. 05/14 i18n: add--interactive: mark plural stringsVasco Almeida, Oct 5, 2016
  5. Junio C HamanoOct 5, 2016
  6. 03/14 i18n: add--interactive: mark strings with interpolation for translationVasco Almeida, Oct 5, 2016
  7. Junio C HamanoOct 5, 2016
  8. 01/14 i18n: add--interactive: mark strings for translationVasco Almeida, Oct 5, 2016
  9. 06/14 i18n: add--interactive: mark patch prompt for translationVasco Almeida, Oct 5, 2016
  10. 07/14 i18n: add--interactive: i18n of help_patch_cmdVasco Almeida, Oct 5, 2016
  11. 08/14 i18n: add--interactive: mark edit_hunk_manually message for translationVasco Almeida, Oct 5, 2016
  12. 09/14 i18n: add--interactive: remove %patch_modes entriesVasco Almeida, Oct 5, 2016
  13. 10/14 i18n: add--interactive: mark status words for translationVasco Almeida, Oct 5, 2016
  14. 11/14 i18n: send-email: mark strings for translationVasco Almeida, Oct 5, 2016
  15. 12/14 i18n: send-email: mark warnings and errors for translationVasco Almeida, Oct 5, 2016
  16. 13/14 i18n: send-email: mark string with interpolation for translationVasco Almeida, Oct 5, 2016
  17. 14/14 i18n: difftool: mark warnings for translationVasco Almeida, Oct 5, 2016
  18. Jakub NarębskiOct 5, 2016
  19. 00/14 Mark strings in Perl scripts for translationVasco Almeida, Oct 10, 2016
  20. 01/14 i18n: add--interactive: mark strings for translationVasco Almeida, Oct 10, 2016
  21. Junio C HamanoOct 19, 2016
  22. Vasco AlmeidaOct 20, 2016
  23. Junio C HamanoOct 20, 2016
  24. 02/14 i18n: add--interactive: mark simple here-documents for translationVasco Almeida, Oct 10, 2016
  25. 03/14 i18n: add--interactive: mark strings with interpolation for translationVasco Almeida, Oct 10, 2016
  26. 04/14 i18n: clean.c: match string with git-add--interactive.perlVasco Almeida, Oct 10, 2016
  27. 05/14 i18n: add--interactive: mark plural stringsVasco Almeida, Oct 10, 2016
  28. Junio C HamanoOct 19, 2016
  29. Vasco AlmeidaOct 20, 2016
  30. Vasco AlmeidaOct 20, 2016
  31. Junio C HamanoOct 20, 2016
  32. 06/14 i18n: add--interactive: mark patch prompt for translationVasco Almeida, Oct 10, 2016
  33. 07/14 i18n: add--interactive: i18n of help_patch_cmdVasco Almeida, Oct 10, 2016
  34. 08/14 i18n: add--interactive: mark edit_hunk_manually message for translationVasco Almeida, Oct 10, 2016
  35. Vasco AlmeidaNov 7, 2016
  36. 09/14 i18n: add--interactive: remove %patch_modes entriesVasco Almeida, Oct 10, 2016
  37. 10/14 i18n: add--interactive: mark status words for translationVasco Almeida, Oct 10, 2016
  38. 11/14 i18n: send-email: mark strings for translationVasco Almeida, Oct 10, 2016
  39. 12/14 i18n: send-email: mark warnings and errors for translationVasco Almeida, Oct 10, 2016
  40. 13/14 i18n: send-email: mark string with interpolation for translationVasco Almeida, Oct 10, 2016
  41. 14/14 i18n: difftool: mark warnings for translationVasco Almeida, Oct 10, 2016
  42. Junio C HamanoOct 27, 2016
  43. 00/16 Mark strings in Perl scripts for translationVasco Almeida, Nov 8, 2016
  44. 02/16 i18n: add--interactive: mark strings for translationVasco Almeida, Nov 8, 2016
  45. 09/16 i18n: add--interactive: mark edit_hunk_manually message for translationVasco Almeida, Nov 8, 2016
  46. 10/16 i18n: add--interactive: remove %patch_modes entriesVasco Almeida, Nov 8, 2016
  47. 01/16 Git.pm: add subroutines for commenting linesVasco Almeida, Nov 8, 2016
  48. Junio C HamanoNov 9, 2016
  49. Vasco AlmeidaNov 9, 2016
  50. Jakub NarębskiNov 9, 2016
  51. Junio C HamanoNov 9, 2016
  52. 08/16 i18n: add--interactive: i18n of help_patch_cmdVasco Almeida, Nov 8, 2016
  53. 16/16 i18n: difftool: mark warnings for translationVasco Almeida, Nov 8, 2016
  54. 15/16 i18n: send-email: mark composing message for translationVasco Almeida, Nov 8, 2016
  55. 14/16 i18n: send-email: mark string with interpolation for translationVasco Almeida, Nov 8, 2016
  56. 13/16 i18n: send-email: mark warnings and errors for translationVasco Almeida, Nov 8, 2016
  57. 12/16 i18n: send-email: mark strings for translationVasco Almeida, Nov 8, 2016
  58. 07/16 i18n: add--interactive: mark patch prompt for translationVasco Almeida, Nov 8, 2016
  59. 11/16 i18n: add--interactive: mark status words for translationVasco Almeida, Nov 8, 2016
  60. 06/16 i18n: add--interactive: mark plural stringsVasco Almeida, Nov 8, 2016
  61. 05/16 i18n: clean.c: match string with git-add--interactive.perlVasco Almeida, Nov 8, 2016
  62. 04/16 i18n: add--interactive: mark strings with interpolation for translationVasco Almeida, Nov 8, 2016
  63. 03/16 i18n: add--interactive: mark simple here-documents for translationVasco Almeida, Nov 8, 2016

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.