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>,
	"David Aguilar" <davvid@gmail.com>
Subject: [PATCH v2 04/11] i18n: add--interactive: mark plural strings
Date: Wed, 29 Jun 2016 15:09:38 +0000	[thread overview]
Message-ID: <20160629150945.15015-5-vascomalmeida@sapo.pt> (raw)
In-Reply-To: <20160629150945.15015-1-vascomalmeida@sapo.pt>

Mark plural strings for translation.  Unfold each action case in one
entire sentence.

Pass new keyword for xgettext to extract.

Update test to include new subrotine Q__() for plural strings handling.

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

diff --git a/Makefile b/Makefile
index de5a030..eedf1fa 100644
--- a/Makefile
+++ b/Makefile
@@ -2061,7 +2061,8 @@ XGETTEXT_FLAGS_C = $(XGETTEXT_FLAGS) --language=C \
 	--keyword=_ --keyword=N_ --keyword="Q_:1,2"
 XGETTEXT_FLAGS_SH = $(XGETTEXT_FLAGS) --language=Shell \
 	--keyword=gettextln --keyword=eval_gettextln
-XGETTEXT_FLAGS_PERL = $(XGETTEXT_FLAGS) --keyword=__ --language=Perl
+XGETTEXT_FLAGS_PERL = $(XGETTEXT_FLAGS) --language=Perl \
+	--keyword=__ --keyword="Q__:1,2"
 LOCALIZED_C = $(C_OBJ:o=c) $(LIB_H) $(GENERATED_H)
 LOCALIZED_SH = $(SCRIPT_SH) git-parse-remote.sh
 LOCALIZED_PERL = $(SCRIPT_PERL)
diff --git a/git-add--interactive.perl b/git-add--interactive.perl
index 4e1e857..08badfa 100755
--- a/git-add--interactive.perl
+++ b/git-add--interactive.perl
@@ -666,12 +666,18 @@ sub status_cmd {
 sub say_n_paths {
 	my $did = shift @_;
 	my $cnt = scalar @_;
-	print "$did ";
-	if (1 < $cnt) {
-		print "$cnt paths\n";
-	}
-	else {
-		print "one path\n";
+	if ($did eq 'added') {
+		printf(Q__("added one path\n", "added %d paths\n",
+			   $cnt), $cnt);
+	} elsif ($did eq 'updated') {
+		printf(Q__("updated one path\n", "updated %d paths\n",
+			   $cnt), $cnt);
+	} elsif ($did eq 'reversed') {
+		printf(Q__("reversed one path\n", "reversed %d paths\n",
+			   $cnt), $cnt);
+	} else {
+		printf(Q__("touched one path\n", "touched %d paths\n",
+			   $cnt), $cnt);
 	}
 }
 
@@ -1508,8 +1514,10 @@ sub patch_update_file {
 			elsif ($other =~ /s/ && $line =~ /^s/) {
 				my @split = split_hunk($hunk[$ix]{TEXT}, $hunk[$ix]{DISPLAY});
 				if (1 < @split) {
-					print colored $header_color, "Split into ",
-					scalar(@split), " hunks.\n";
+					print colored $header_color, sprintf(
+						Q__("Split into %d hunk.\n",
+						    "Split into %d hunks.\n",
+						    scalar(@split)), scalar(@split));
 				}
 				splice (@hunk, $ix, 1, @split);
 				$num = scalar @hunk;
diff --git a/perl/Git/I18N.pm b/perl/Git/I18N.pm
index f889fd6..5a75dd5 100644
--- a/perl/Git/I18N.pm
+++ b/perl/Git/I18N.pm
@@ -13,7 +13,7 @@ BEGIN {
 	}
 }
 
-our @EXPORT = qw(__);
+our @EXPORT = qw(__ Q__);
 our @EXPORT_OK = @EXPORT;
 
 sub __bootstrap_locale_messages {
@@ -44,6 +44,7 @@ BEGIN
 	eval {
 		__bootstrap_locale_messages();
 		*__ = \&Locale::Messages::gettext;
+		*Q__ = \&Locale::Messages::ngettext;
 		1;
 	} or do {
 		# Tell test.pl that we couldn't load the gettext library.
@@ -51,6 +52,7 @@ BEGIN
 
 		# Just a fall-through no-op
 		*__ = sub ($) { $_[0] };
+		*Q__ = sub ($$$) { $_[2] == 1 ? $_[0] : $_[1] };
 	};
 }
 
diff --git a/t/t0202/test.pl b/t/t0202/test.pl
index 2c10cb4..98aa9a3 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 => 8;
+use Test::More tests => 11;
 use Git::I18N;
 
 my $has_gettext_library = $Git::I18N::__HAS_LIBRARY;
@@ -31,6 +31,7 @@ is_deeply(\@Git::I18N::EXPORT, \@Git::I18N::EXPORT_OK, "sanity: Git::I18N export
 	# more gettext wrapper functions.
 	my %prototypes = (qw(
 		__	$
+		Q__	$$$
 	));
 	while (my ($sub, $proto) = each %prototypes) {
 		is(prototype(\&{"Git::I18N::$sub"}), $proto, "sanity: $sub has a $proto prototype");
@@ -46,6 +47,14 @@ is_deeply(\@Git::I18N::EXPORT, \@Git::I18N::EXPORT_OK, "sanity: Git::I18N export
 	my ($got, $expect) = (('TEST: A Perl test string') x 2);
 
 	is(__($got), $expect, "Passing a string through __() in the C locale works");
+
+	my ($got_singular, $got_plural, $expect_singular, $expect_plural) =
+		(('TEST: 1 file', 'TEST: n files') x 2);
+
+	is(Q__($got_singular, $got_plural, 1), $expect_singular,
+		"Get singular string through Q__() in C locale");
+	is(Q__($got_singular, $got_plural, 2), $expect_plural,
+		"Get plural string through Q__() in C locale");
 }
 
 # Test a basic message on different locales
-- 
2.7.4


  parent reply	other threads:[~2016-06-29 15:10 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-29 15:09 [PATCH v2 00/11] Mark strings in perl script for translation Vasco Almeida
2016-06-29 15:09 ` [PATCH v2 01/11] i18n: add--interactive: mark strings " Vasco Almeida
2016-06-29 15:09 ` [PATCH v2 02/11] i18n: add--interactive: mark simple here documents " Vasco Almeida
2016-06-29 15:09 ` [PATCH v2 03/11] i18n: add--interactive: mark strings with interpolation " Vasco Almeida
2016-06-29 15:09 ` Vasco Almeida [this message]
2016-06-29 15:09 ` [PATCH v2 05/11] i18n: add--interactive: mark message " Vasco Almeida
2016-06-29 15:09 ` [PATCH v2 06/11] i18n: add--interactive: i18n of help_patch_cmd Vasco Almeida
2016-06-29 15:09 ` [PATCH v2 07/11] i18n: add--interactive: mark edit_hunk_manually message for translation Vasco Almeida
2016-06-29 15:09 ` [PATCH v2 08/11] i18n: send-email: mark strings " Vasco Almeida
2016-06-29 15:09 ` [PATCH v2 09/11] i18n: send-email: mark warnings and errors " Vasco Almeida
2016-06-29 15:09 ` [PATCH v2 10/11] i18n: send-email: mark string with interpolation " Vasco Almeida
2016-06-29 15:09 ` [PATCH v2 11/11] i18n: difftool: mark warnings " Vasco Almeida
  -- strict thread matches above, loose matches on Subject: below --
2016-08-31 12:31 [PATCH v2 00/11] Mark strings in perl script " Vasco Almeida
2016-08-31 12:31 ` [PATCH v2 04/11] i18n: add--interactive: mark plural strings Vasco Almeida
2016-09-26 18:15   ` Vasco Almeida
2016-09-26 18:21     ` Junio C Hamano
2016-10-01 16:49     ` Jakub Narębski
2016-10-03 12:46       ` 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=20160629150945.15015-5-vascomalmeida@sapo.pt \
    --to=vascomalmeida@sapo.pt \
    --cc=avarab@gmail.com \
    --cc=davvid@gmail.com \
    --cc=git@vger.kernel.org \
    --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).