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>,
	"Eric Sunshine" <sunshine@sunshineco.com>
Subject: [PATCH v2 16/22] i18n: rebase-interactive: mark comments of squash for translation
Date: Mon, 23 May 2016 19:27:35 +0000	[thread overview]
Message-ID: <1464031661-18988-17-git-send-email-vascomalmeida@sapo.pt> (raw)
In-Reply-To: <1464031661-18988-1-git-send-email-vascomalmeida@sapo.pt>

Mark comment messages of squash/fixup file ($squash_msg) for
translation.

Helper functions this_nth_commit_message and skip_nth_commit_message
replace the previous method of making the comment messages (such as
"This is the 2nd commit message:") aided by nth_string helper function.
This step was taken as a workaround to enabled translation of entire
sentences. However, doesn't change any text seen in English by the user,
except for string "The first commit's message is:" which was changed to
match the style of other instances.

The test t3404-rebase-interactive.sh resorts to set_fake_editor which
didn't account for GETTEXT_POISON. Fix it by assuming success when we
find dummy gettext poison output where was supposed to find the first
comment line "This is a combination of $count commits.".

For that same message, use plural aware eval_ngettext instead of
eval_gettext, since other languages have more complex plural forms.

Signed-off-by: Vasco Almeida <vascomalmeida@sapo.pt>
---
 git-rebase--interactive.sh | 69 +++++++++++++++++++++++++++++++++++++---------
 t/lib-rebase.sh            |  1 +
 2 files changed, 57 insertions(+), 13 deletions(-)

diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index cb302b0..8e58127 100644
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -401,12 +401,52 @@ pick_one_preserving_merges () {
 	esac
 }
 
-nth_string () {
-	case "$1" in
-	*1[0-9]|*[04-9]) echo "$1"th;;
-	*1) echo "$1"st;;
-	*2) echo "$1"nd;;
-	*3) echo "$1"rd;;
+this_nth_commit_message () {
+	n=$1
+	case "$n" in
+	1) gettext "This is the 1st commit message:";;
+	2) gettext "This is the 2nd commit message:";;
+	3) gettext "This is the 3rd commit message:";;
+	4) gettext "This is the 4th commit message:";;
+	5) gettext "This is the 5th commit message:";;
+	6) gettext "This is the 6th commit message:";;
+	7) gettext "This is the 7th commit message:";;
+	8) gettext "This is the 8th commit message:";;
+	9) gettext "This is the 9th commit message:";;
+	10) gettext "This is the 10th commit message:";;
+	# TRANSLATORS: if the language you are translating into
+	# doesn't allow you to compose a sentence in this fashion,
+	# consider translating as if this and the following few strings
+	# were "This is the commit message ${n}:"
+	*1[0-9]|*[04-9]) eval_gettext "This is the \${n}th commit message:";;
+	*1) eval_gettext "This is the \${n}st commit message:";;
+	*2) eval_gettext "This is the \${n}nd commit message:";;
+	*3) eval_gettext "This is the \${n}rd commit message:";;
+	*) eval_gettext "This is the commit message \${n}:";;
+	esac
+}
+skip_nth_commit_message () {
+	n=$1
+	case "$n" in
+	1) gettext "The 1st commit message will be skipped:";;
+	2) gettext "The 2nd commit message will be skipped:";;
+	3) gettext "The 3rd commit message will be skipped:";;
+	4) gettext "The 4th commit message will be skipped:";;
+	5) gettext "The 5th commit message will be skipped:";;
+	6) gettext "The 6th commit message will be skipped:";;
+	7) gettext "The 7th commit message will be skipped:";;
+	8) gettext "The 8th commit message will be skipped:";;
+	9) gettext "The 9th commit message will be skipped:";;
+	10) gettext "The 10th commit message will be skipped:";;
+	# TRANSLATORS: if the language you are translating into
+	# doesn't allow you to compose a sentence in this fashion,
+	# consider translating as if this and the following few strings
+	# were "The commit message ${n} will be skipped:"
+	*1[0-9]|*[04-9]) eval_gettext "The \${n}th commit message will be skipped:";;
+	*1) eval_gettext "The \${n}st commit message will be skipped:";;
+	*2) eval_gettext "The \${n}nd commit message will be skipped:";;
+	*3) eval_gettext "The \${n}rd commit message will be skipped:";;
+	*) eval_gettext "The commit message \${n} will be skipped:";;
 	esac
 }
 
@@ -414,20 +454,23 @@ update_squash_messages () {
 	if test -f "$squash_msg"; then
 		mv "$squash_msg" "$squash_msg".bak || exit
 		count=$(($(sed -n \
-			-e "1s/^. This is a combination of \(.*\) commits\./\1/p" \
+			-e "1s/^$comment_char.*\([0-9][0-9]*\).*/\1/p" \
 			-e "q" < "$squash_msg".bak)+1))
 		{
-			printf '%s\n' "$comment_char This is a combination of $count commits."
+			printf '%s\n' "$comment_char $(eval_ngettext \
+				"This is a combination of \$count commit." \
+				"This is a combination of \$count commits." \
+				$count)"
 			sed -e 1d -e '2,/^./{
 				/^$/d
 			}' <"$squash_msg".bak
 		} >"$squash_msg"
 	else
-		commit_message HEAD > "$fixup_msg" || die "Cannot write $fixup_msg"
+		commit_message HEAD > "$fixup_msg" || die "$(gettext "Cannot write \$fixup_msg")"
 		count=2
 		{
-			printf '%s\n' "$comment_char This is a combination of 2 commits."
-			printf '%s\n' "$comment_char The first commit's message is:"
+			printf '%s\n' "$comment_char $(gettext "This is a combination of 2 commits.")"
+			printf '%s\n' "$comment_char $(gettext "This is the 1st commit message:")"
 			echo
 			cat "$fixup_msg"
 		} >"$squash_msg"
@@ -436,13 +479,13 @@ update_squash_messages () {
 	squash)
 		rm -f "$fixup_msg"
 		echo
-		printf '%s\n' "$comment_char This is the $(nth_string $count) commit message:"
+		printf '%s\n' "$comment_char $(this_nth_commit_message $count)"
 		echo
 		commit_message $2
 		;;
 	fixup)
 		echo
-		printf '%s\n' "$comment_char The $(nth_string $count) commit message will be skipped:"
+		printf '%s\n' "$comment_char $(skip_nth_commit_message $count)"
 		echo
 		# Change the space after the comment character to TAB:
 		commit_message $2 | git stripspace --comment-lines | sed -e 's/ /	/'
diff --git a/t/lib-rebase.sh b/t/lib-rebase.sh
index 9a96e15..25a77ee 100644
--- a/t/lib-rebase.sh
+++ b/t/lib-rebase.sh
@@ -29,6 +29,7 @@ set_fake_editor () {
 	*/COMMIT_EDITMSG)
 		test -z "$EXPECT_HEADER_COUNT" ||
 			test "$EXPECT_HEADER_COUNT" = "$(sed -n '1s/^# This is a combination of \(.*\) commits\./\1/p' < "$1")" ||
+			test "# # GETTEXT POISON #" = "$(sed -n '1p' < "$1")" ||
 			exit
 		test -z "$FAKE_COMMIT_MESSAGE" || echo "$FAKE_COMMIT_MESSAGE" > "$1"
 		test -z "$FAKE_COMMIT_AMEND" || echo "$FAKE_COMMIT_AMEND" >> "$1"
-- 
2.7.3

  parent reply	other threads:[~2016-05-23 19:30 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-23 19:27 [PATCH v2 00/22] i18n and test updates Vasco Almeida
2016-05-23 19:27 ` [PATCH v2 01/22] i18n: builtin/remote.c: fix mark for translation Vasco Almeida
2016-05-23 19:27 ` [PATCH v2 02/22] i18n: advice: mark string about detached head " Vasco Almeida
2016-05-30 11:03   ` Vasco Almeida
2016-05-23 19:27 ` [PATCH v2 03/22] i18n: advice: internationalize message for conflicts Vasco Almeida
2016-05-23 19:27 ` [PATCH v2 04/22] i18n: transport: mark strings for translation Vasco Almeida
2016-05-23 19:27 ` [PATCH v2 05/22] i18n: sequencer: mark entire sentences " Vasco Almeida
2016-05-23 19:27 ` [PATCH v2 06/22] i18n: sequencer: mark string " Vasco Almeida
2016-05-23 19:27 ` [PATCH v2 07/22] i18n: merge-octopus: mark messages " Vasco Almeida
2016-05-23 19:27 ` [PATCH v2 08/22] merge-octupus: use die shell function from git-sh-setup.sh Vasco Almeida
2016-05-23 19:27 ` [PATCH v2 09/22] i18n: rebase: fix marked string to use eval_gettext variant Vasco Almeida
2016-05-23 19:27 ` [PATCH v2 10/22] i18n: rebase: mark placeholder for translation Vasco Almeida
2016-05-23 19:27 ` [PATCH v2 11/22] i18n: bisect: simplify error message for i18n Vasco Almeida
2016-05-23 19:27 ` [PATCH v2 12/22] t6030: update to use test_i18ncmp Vasco Almeida
2016-05-23 19:27 ` [PATCH v2 13/22] i18n: git-sh-setup.sh: mark strings for translation Vasco Almeida
2016-05-26 22:46   ` Junio C Hamano
2016-05-27 10:17     ` Vasco Almeida
2016-05-23 19:27 ` [PATCH v2 14/22] i18n: rebase-interactive: " Vasco Almeida
2016-05-26 22:36   ` Junio C Hamano
2016-05-27 10:08     ` Vasco Almeida
2016-05-27 16:58       ` Junio C Hamano
2016-05-23 19:27 ` [PATCH v2 15/22] i18n: rebase-interactive: mark here-doc " Vasco Almeida
2016-05-25 13:13   ` Vasco Almeida
2016-05-23 19:27 ` Vasco Almeida [this message]
2016-05-26 22:35   ` [PATCH v2 16/22] i18n: rebase-interactive: mark comments of squash " Junio C Hamano
2016-05-27 10:36     ` Vasco Almeida
2016-05-23 19:27 ` [PATCH v2 17/22] i18n: setup: mark strings " Vasco Almeida
2016-05-23 19:27 ` [PATCH v2 18/22] tests: use test_i18n* functions to suppress false positives Vasco Almeida
2016-05-27 17:08   ` Junio C Hamano
2016-05-27 19:34     ` Vasco Almeida
2016-05-27 19:51       ` Junio C Hamano
2016-05-23 19:27 ` [PATCH v2 19/22] tests: unpack-trees: update to use test_i18n* functions Vasco Almeida
2016-05-23 19:27 ` [PATCH v2 20/22] t9003: become resilient to GETTEXT_POISON Vasco Almeida
2016-05-23 19:27 ` [PATCH v2 21/22] t4153: fix negated test_i18ngrep call Vasco Almeida
2016-05-23 19:27 ` [PATCH v2 22/22] t5523: use test_i18ngrep for negation Vasco Almeida
2016-05-27 17:11 ` [PATCH v2 00/22] i18n and test updates Junio C Hamano
2016-05-28  8:18   ` Vasco Almeida
2016-05-30  0:03     ` Junio C Hamano

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=1464031661-18988-17-git-send-email-vascomalmeida@sapo.pt \
    --to=vascomalmeida@sapo.pt \
    --cc=avarab@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=sunshine@sunshineco.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).