git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Vasco Almeida <vascomalmeida@sapo.pt>
To: git@vger.kernel.org
Cc: "Vasco Almeida" <vascomalmeida@sapo.pt>,
	"Jiang Xin" <worldhello.net@gmail.com>,
	"Ævar Arnfjörð Bjarmason" <avarab@gmail.com>,
	"Jean-Noël AVILA" <jn.avila@free.fr>,
	"Jakub Narębski" <jnareb@gmail.com>,
	"David Aguilar" <davvid@gmail.com>,
	"Junio C Hamano" <gitster@pobox.com>
Subject: [PATCH v6 07/16] i18n: add--interactive: mark patch prompt for translation
Date: Fri, 11 Nov 2016 11:45:32 -0100	[thread overview]
Message-ID: <20161111124541.8216-8-vascomalmeida@sapo.pt> (raw)
In-Reply-To: <20161111124541.8216-1-vascomalmeida@sapo.pt>
In-Reply-To: <20161005172110.30801-1-vascomalmeida@sapo.pt>

Mark prompt message assembled in place for translation, unfolding each
use case for each entry in the %patch_modes hash table.

Previously, this script relied on whether $patch_mode was set to run the
command patch_update_cmd() or show status and loop the main loop. Now,
it uses $cmd to indicate we must run patch_update_cmd() and $patch_mode
is used to tell which flavor of the %patch_modes are we on.  This is
introduced in order to be able to mark and unfold the message prompt
knowing in which context we are.

The tracking of context was done previously by point %patch_mode_flavour
hash table to the correct entry of %patch_modes, focusing only on value
of %patch_modes. Now, we are also interested in the key ('staged',
'stash', 'checkout_head', ...).

Signed-off-by: Vasco Almeida <vascomalmeida@sapo.pt>
---
 Makefile                  |  2 +-
 git-add--interactive.perl | 54 ++++++++++++++++++++++++++++++++++++++++-------
 perl/Git/I18N.pm          | 11 +++++++++-
 t/t0202/test.pl           |  5 ++++-
 4 files changed, 61 insertions(+), 11 deletions(-)

diff --git a/Makefile b/Makefile
index 328151dd6..ee89c0624 100644
--- a/Makefile
+++ b/Makefile
@@ -2114,7 +2114,7 @@ XGETTEXT_FLAGS_C = $(XGETTEXT_FLAGS) --language=C \
 XGETTEXT_FLAGS_SH = $(XGETTEXT_FLAGS) --language=Shell \
 	--keyword=gettextln --keyword=eval_gettextln
 XGETTEXT_FLAGS_PERL = $(XGETTEXT_FLAGS) --language=Perl \
-	--keyword=__ --keyword="__n:1,2"
+	--keyword=__ --keyword=N__ --keyword="__n:1,2"
 LOCALIZED_C = $(C_OBJ:o=c) $(LIB_H) $(GENERATED_H)
 LOCALIZED_SH = $(SCRIPT_SH)
 LOCALIZED_SH += git-parse-remote.sh
diff --git a/git-add--interactive.perl b/git-add--interactive.perl
index cd617837b..b7d382b10 100755
--- a/git-add--interactive.perl
+++ b/git-add--interactive.perl
@@ -93,6 +93,7 @@ sub colored {
 }
 
 # command line options
+my $cmd;
 my $patch_mode;
 my $patch_mode_revision;
 
@@ -173,7 +174,8 @@ my %patch_modes = (
 	},
 );
 
-my %patch_mode_flavour = %{$patch_modes{stage}};
+$patch_mode = 'stage';
+my %patch_mode_flavour = %{$patch_modes{$patch_mode}};
 
 sub run_cmd_pipe {
 	if ($^O eq 'MSWin32') {
@@ -1311,6 +1313,44 @@ sub display_hunks {
 	return $i;
 }
 
+my %patch_update_prompt_modes = (
+	stage => {
+		mode => N__("Stage mode change [y,n,q,a,d,/%s,?]? "),
+		deletion => N__("Stage deletion [y,n,q,a,d,/%s,?]? "),
+		hunk => N__("Stage this hunk [y,n,q,a,d,/%s,?]? "),
+	},
+	stash => {
+		mode => N__("Stash mode change [y,n,q,a,d,/%s,?]? "),
+		deletion => N__("Stash deletion [y,n,q,a,d,/%s,?]? "),
+		hunk => N__("Stash this hunk [y,n,q,a,d,/%s,?]? "),
+	},
+	reset_head => {
+		mode => N__("Unstage mode change [y,n,q,a,d,/%s,?]? "),
+		deletion => N__("Unstage deletion [y,n,q,a,d,/%s,?]? "),
+		hunk => N__("Unstage this hunk [y,n,q,a,d,/%s,?]? "),
+	},
+	reset_nothead => {
+		mode => N__("Apply mode change to index [y,n,q,a,d,/%s,?]? "),
+		deletion => N__("Apply deletion to index [y,n,q,a,d,/%s,?]? "),
+		hunk => N__("Apply this hunk to index [y,n,q,a,d,/%s,?]? "),
+	},
+	checkout_index => {
+		mode => N__("Discard mode change from worktree [y,n,q,a,d,/%s,?]? "),
+		deletion => N__("Discard deletion from worktree [y,n,q,a,d,/%s,?]? "),
+		hunk => N__("Discard this hunk from worktree [y,n,q,a,d,/%s,?]? "),
+	},
+	checkout_head => {
+		mode => N__("Discard mode change from index and worktree [y,n,q,a,d,/%s,?]? "),
+		deletion => N__("Discard deletion from index and worktree [y,n,q,a,d,/%s,?]? "),
+		hunk => N__("Discard this hunk from index and worktree [y,n,q,a,d,/%s,?]? "),
+	},
+	checkout_nothead => {
+		mode => N__("Apply mode change to index and worktree [y,n,q,a,d,/%s,?]? "),
+		deletion => N__("Apply deletion to index and worktree [y,n,q,a,d,/%s,?]? "),
+		hunk => N__("Apply this hunk to index and worktree [y,n,q,a,d,/%s,?]? "),
+	},
+);
+
 sub patch_update_file {
 	my $quit = 0;
 	my ($ix, $num);
@@ -1383,12 +1423,9 @@ sub patch_update_file {
 		for (@{$hunk[$ix]{DISPLAY}}) {
 			print;
 		}
-		print colored $prompt_color, $patch_mode_flavour{VERB},
-		  ($hunk[$ix]{TYPE} eq 'mode' ? ' mode change' :
-		   $hunk[$ix]{TYPE} eq 'deletion' ? ' deletion' :
-		   ' this hunk'),
-		  $patch_mode_flavour{TARGET},
-		  " [y,n,q,a,d,/$other,?]? ";
+		print colored $prompt_color,
+			sprintf(__($patch_update_prompt_modes{$patch_mode}{$hunk[$ix]{TYPE}}), $other);
+
 		my $line = prompt_single_character;
 		last unless defined $line;
 		if ($line) {
@@ -1644,6 +1681,7 @@ sub process_args {
 		die sprintf(__("invalid argument %s, expecting --"),
 			       $arg) unless $arg eq "--";
 		%patch_mode_flavour = %{$patch_modes{$patch_mode}};
+		$cmd = 1;
 	}
 	elsif ($arg ne "--") {
 		die sprintf(__("invalid argument %s, expecting --"), $arg);
@@ -1680,7 +1718,7 @@ sub main_loop {
 
 process_args();
 refresh();
-if ($patch_mode) {
+if ($cmd) {
 	patch_update_cmd();
 }
 else {
diff --git a/perl/Git/I18N.pm b/perl/Git/I18N.pm
index 617d8c2a1..c41425c8d 100644
--- a/perl/Git/I18N.pm
+++ b/perl/Git/I18N.pm
@@ -13,7 +13,7 @@ BEGIN {
 	}
 }
 
-our @EXPORT = qw(__ __n);
+our @EXPORT = qw(__ __n N__);
 our @EXPORT_OK = @EXPORT;
 
 sub __bootstrap_locale_messages {
@@ -54,6 +54,8 @@ BEGIN
 		*__ = sub ($) { $_[0] };
 		*__n = sub ($$$) { $_[2] == 1 ? $_[0] : $_[1] };
 	};
+
+	sub N__($) { return shift; }
 }
 
 1;
@@ -74,6 +76,7 @@ Git::I18N - Perl interface to Git's Gettext localizations
 
 	printf __n("commited %d file\n", "commited %d files\n", $files), $files;
 
+
 =head1 DESCRIPTION
 
 Git's internal Perl interface to gettext via L<Locale::Messages>. If
@@ -95,6 +98,12 @@ passthrough fallback function.
 
 L<Locale::Messages>'s ngettext function or passthrough fallback function.
 
+=head2 N__($)
+
+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
 
 E<AElig>var ArnfjE<ouml>rE<eth> Bjarmason <avarab@gmail.com>
diff --git a/t/t0202/test.pl b/t/t0202/test.pl
index 4101833a8..2cbf7b959 100755
--- a/t/t0202/test.pl
+++ b/t/t0202/test.pl
@@ -4,7 +4,7 @@ use lib (split(/:/, $ENV{GITPERLLIB}));
 use strict;
 use warnings;
 use POSIX qw(:locale_h);
-use Test::More tests => 11;
+use Test::More tests => 13;
 use Git::I18N;
 
 my $has_gettext_library = $Git::I18N::__HAS_LIBRARY;
@@ -32,6 +32,7 @@ is_deeply(\@Git::I18N::EXPORT, \@Git::I18N::EXPORT_OK, "sanity: Git::I18N export
 	my %prototypes = (qw(
 		__	$
 		__n	$$$
+		N__	$
 	));
 	while (my ($sub, $proto) = each %prototypes) {
 		is(prototype(\&{"Git::I18N::$sub"}), $proto, "sanity: $sub has a $proto prototype");
@@ -55,6 +56,8 @@ is_deeply(\@Git::I18N::EXPORT, \@Git::I18N::EXPORT_OK, "sanity: Git::I18N export
 		"Get singular string through __n() in C locale");
 	is(__n($got_singular, $got_plural, 2), $expect_plural,
 		"Get plural string through __n() in C locale");
+
+	is(N__($got), $expect, "Passing a string through N__() in the C locale works");
 }
 
 # Test a basic message on different locales
-- 
2.11.0.rc0.33.gec17dab


  parent reply	other threads:[~2016-11-11 12:46 UTC|newest]

Thread overview: 107+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-05 17:20 [PATCH v3 00/14] Mark strings in Perl scripts for translation Vasco Almeida
2016-10-05 17:20 ` [PATCH v3 01/14] i18n: add--interactive: mark strings " Vasco Almeida
2016-10-05 17:20 ` [PATCH v3 02/14] i18n: add--interactive: mark simple here-documents " Vasco Almeida
2016-10-05 17:20 ` [PATCH v3 03/14] i18n: add--interactive: mark strings with interpolation " Vasco Almeida
2016-10-05 22:28   ` Junio C Hamano
2016-10-05 17:21 ` [PATCH v3 04/14] i18n: clean.c: match string with git-add--interactive.perl Vasco Almeida
2016-10-05 17:21 ` [PATCH v3 05/14] i18n: add--interactive: mark plural strings Vasco Almeida
2016-10-05 22:41   ` Junio C Hamano
2016-10-05 17:21 ` [PATCH v3 06/14] i18n: add--interactive: mark patch prompt for translation Vasco Almeida
2016-10-05 17:21 ` [PATCH v3 07/14] i18n: add--interactive: i18n of help_patch_cmd Vasco Almeida
2016-10-05 17:21 ` [PATCH v3 08/14] i18n: add--interactive: mark edit_hunk_manually message for translation Vasco Almeida
2016-10-05 17:21 ` [PATCH v3 09/14] i18n: add--interactive: remove %patch_modes entries Vasco Almeida
2016-10-05 17:21 ` [PATCH v3 10/14] i18n: add--interactive: mark status words for translation Vasco Almeida
2016-10-05 17:21 ` [PATCH v3 11/14] i18n: send-email: mark strings " Vasco Almeida
2016-10-05 17:21 ` [PATCH v3 12/14] i18n: send-email: mark warnings and errors " Vasco Almeida
2016-10-05 17:21 ` [PATCH v3 13/14] i18n: send-email: mark string with interpolation " Vasco Almeida
2016-10-05 17:21 ` [PATCH v3 14/14] i18n: difftool: mark warnings " Vasco Almeida
2016-10-05 21:50 ` [PATCH v3 00/14] Mark strings in Perl scripts " Jakub Narębski
2016-10-10 12:54 ` [PATCH v4 " Vasco Almeida
2016-10-27 17:08   ` Junio C Hamano
2016-10-10 12:54 ` [PATCH v4 01/14] i18n: add--interactive: mark strings " Vasco Almeida
2016-10-19 18:14   ` Junio C Hamano
2016-10-20 16:21     ` Vasco Almeida
2016-10-20 16:25       ` Junio C Hamano
2016-10-10 12:54 ` [PATCH v4 02/14] i18n: add--interactive: mark simple here-documents " Vasco Almeida
2016-10-10 12:54 ` [PATCH v4 03/14] i18n: add--interactive: mark strings with interpolation " Vasco Almeida
2016-10-10 12:54 ` [PATCH v4 04/14] i18n: clean.c: match string with git-add--interactive.perl Vasco Almeida
2016-10-10 12:54 ` [PATCH v4 05/14] i18n: add--interactive: mark plural strings Vasco Almeida
2016-10-19 18:40   ` Junio C Hamano
2016-10-20 16:29     ` Vasco Almeida
2016-10-20 16:35   ` Vasco Almeida
2016-10-20 17:11     ` Junio C Hamano
2016-10-10 12:54 ` [PATCH v4 06/14] i18n: add--interactive: mark patch prompt for translation Vasco Almeida
2016-10-10 12:54 ` [PATCH v4 07/14] i18n: add--interactive: i18n of help_patch_cmd Vasco Almeida
2016-10-10 12:54 ` [PATCH v4 08/14] i18n: add--interactive: mark edit_hunk_manually message for translation Vasco Almeida
2016-11-07 16:04   ` Vasco Almeida
2016-10-10 12:54 ` [PATCH v4 09/14] i18n: add--interactive: remove %patch_modes entries Vasco Almeida
2016-10-10 12:54 ` [PATCH v4 10/14] i18n: add--interactive: mark status words for translation Vasco Almeida
2016-10-10 12:54 ` [PATCH v4 11/14] i18n: send-email: mark strings " Vasco Almeida
2016-10-10 12:54 ` [PATCH v4 12/14] i18n: send-email: mark warnings and errors " Vasco Almeida
2016-10-10 12:54 ` [PATCH v4 13/14] i18n: send-email: mark string with interpolation " Vasco Almeida
2016-10-10 12:54 ` [PATCH v4 14/14] i18n: difftool: mark warnings " Vasco Almeida
2016-11-08 12:08 ` [PATCH v5 00/16] Mark strings in Perl scripts " Vasco Almeida
2016-11-08 12:08 ` [PATCH v5 01/16] Git.pm: add subroutines for commenting lines Vasco Almeida
2016-11-09  1:06   ` Junio C Hamano
2016-11-09 17:02     ` Vasco Almeida
2016-11-09 22:25       ` Jakub Narębski
2016-11-09 23:16         ` Junio C Hamano
2016-11-08 12:08 ` [PATCH v5 02/16] i18n: add--interactive: mark strings for translation Vasco Almeida
2016-11-08 12:08 ` [PATCH v5 03/16] i18n: add--interactive: mark simple here-documents " Vasco Almeida
2016-11-08 12:08 ` [PATCH v5 04/16] i18n: add--interactive: mark strings with interpolation " Vasco Almeida
2016-11-08 12:08 ` [PATCH v5 05/16] i18n: clean.c: match string with git-add--interactive.perl Vasco Almeida
2016-11-08 12:08 ` [PATCH v5 06/16] i18n: add--interactive: mark plural strings Vasco Almeida
2016-11-08 12:08 ` [PATCH v5 07/16] i18n: add--interactive: mark patch prompt for translation Vasco Almeida
2016-11-08 12:08 ` [PATCH v5 08/16] i18n: add--interactive: i18n of help_patch_cmd Vasco Almeida
2016-11-08 12:08 ` [PATCH v5 09/16] i18n: add--interactive: mark edit_hunk_manually message for translation Vasco Almeida
2016-11-08 12:08 ` [PATCH v5 10/16] i18n: add--interactive: remove %patch_modes entries Vasco Almeida
2016-11-08 12:08 ` [PATCH v5 11/16] i18n: add--interactive: mark status words for translation Vasco Almeida
2016-11-08 12:08 ` [PATCH v5 12/16] i18n: send-email: mark strings " Vasco Almeida
2016-11-08 12:08 ` [PATCH v5 13/16] i18n: send-email: mark warnings and errors " Vasco Almeida
2016-11-08 12:08 ` [PATCH v5 14/16] i18n: send-email: mark string with interpolation " Vasco Almeida
2016-11-08 12:08 ` [PATCH v5 15/16] i18n: send-email: mark composing message " Vasco Almeida
2016-11-08 12:08 ` [PATCH v5 16/16] i18n: difftool: mark warnings " Vasco Almeida
2016-11-11 12:45 ` [PATCH v6 00/16] Mark strings in Perl scripts " Vasco Almeida
2016-11-11 12:45 ` [PATCH v6 01/16] Git.pm: add subroutines for commenting lines Vasco Almeida
2016-11-22 14:10   ` Vasco Almeida
2016-11-22 17:42     ` Junio C Hamano
2016-12-09 17:19       ` Vasco Almeida
2016-12-09 17:32         ` Johannes Schindelin
2016-12-09 22:23           ` Junio C Hamano
2016-12-10 10:08             ` Vasco Almeida
2016-12-10 22:09               ` Junio C Hamano
2016-12-13 11:17                 ` Vasco Almeida
2016-12-13 18:15                   ` Junio C Hamano
2016-11-11 12:45 ` [PATCH v6 02/16] i18n: add--interactive: mark strings for translation Vasco Almeida
2016-11-11 12:45 ` [PATCH v6 03/16] i18n: add--interactive: mark simple here-documents " Vasco Almeida
2016-11-11 12:45 ` [PATCH v6 04/16] i18n: add--interactive: mark strings with interpolation " Vasco Almeida
2016-11-11 12:45 ` [PATCH v6 05/16] i18n: clean.c: match string with git-add--interactive.perl Vasco Almeida
2016-11-11 12:45 ` [PATCH v6 06/16] i18n: add--interactive: mark plural strings Vasco Almeida
2016-11-11 12:45 ` Vasco Almeida [this message]
2016-11-11 12:45 ` [PATCH v6 08/16] i18n: add--interactive: i18n of help_patch_cmd Vasco Almeida
2016-11-11 12:45 ` [PATCH v6 09/16] i18n: add--interactive: mark edit_hunk_manually message for translation Vasco Almeida
2016-11-11 12:45 ` [PATCH v6 10/16] i18n: add--interactive: remove %patch_modes entries Vasco Almeida
2016-11-11 12:45 ` [PATCH v6 11/16] i18n: add--interactive: mark status words for translation Vasco Almeida
2016-11-11 12:45 ` [PATCH v6 12/16] i18n: send-email: mark strings " Vasco Almeida
2016-11-11 12:45 ` [PATCH v6 13/16] i18n: send-email: mark warnings and errors " Vasco Almeida
2016-11-11 12:45 ` [PATCH v6 14/16] i18n: send-email: mark string with interpolation " Vasco Almeida
2016-11-11 12:45 ` [PATCH v6 15/16] i18n: send-email: mark composing message " Vasco Almeida
2016-11-11 12:45 ` [PATCH v6 16/16] i18n: difftool: mark warnings " Vasco Almeida
2016-12-14 12:54 ` [PATCH v7 00/16] Mark strings in Perl scripts " Vasco Almeida
2016-12-14 19:02   ` Junio C Hamano
2016-12-14 12:54 ` [PATCH v7 01/16] Git.pm: add subroutines for commenting lines Vasco Almeida
2016-12-14 12:54 ` [PATCH v7 02/16] i18n: add--interactive: mark strings for translation Vasco Almeida
2016-12-14 12:54 ` [PATCH v7 03/16] i18n: add--interactive: mark simple here-documents " Vasco Almeida
2016-12-14 12:54 ` [PATCH v7 04/16] i18n: add--interactive: mark strings with interpolation " Vasco Almeida
2016-12-14 12:54 ` [PATCH v7 05/16] i18n: clean.c: match string with git-add--interactive.perl Vasco Almeida
2016-12-14 12:54 ` [PATCH v7 06/16] i18n: add--interactive: mark plural strings Vasco Almeida
2016-12-14 12:54 ` [PATCH v7 07/16] i18n: add--interactive: mark patch prompt for translation Vasco Almeida
2016-12-14 12:54 ` [PATCH v7 08/16] i18n: add--interactive: i18n of help_patch_cmd Vasco Almeida
2016-12-14 12:54 ` [PATCH v7 09/16] i18n: add--interactive: mark edit_hunk_manually message for translation Vasco Almeida
2016-12-14 12:54 ` [PATCH v7 10/16] i18n: add--interactive: remove %patch_modes entries Vasco Almeida
2016-12-14 12:54 ` [PATCH v7 11/16] i18n: add--interactive: mark status words for translation Vasco Almeida
2016-12-14 12:54 ` [PATCH v7 12/16] i18n: send-email: mark strings " Vasco Almeida
2016-12-14 12:54 ` [PATCH v7 13/16] i18n: send-email: mark warnings and errors " Vasco Almeida
2016-12-14 12:54 ` [PATCH v7 14/16] i18n: send-email: mark string with interpolation " Vasco Almeida
2016-12-14 12:54 ` [PATCH v7 15/16] i18n: send-email: mark composing message " Vasco Almeida
2016-12-14 12:54 ` [PATCH v7 16/16] i18n: difftool: mark warnings " Vasco Almeida

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20161111124541.8216-8-vascomalmeida@sapo.pt \
    --to=vascomalmeida@sapo.pt \
    --cc=avarab@gmail.com \
    --cc=davvid@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=jn.avila@free.fr \
    --cc=jnareb@gmail.com \
    --cc=worldhello.net@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).