git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
To: git@vger.kernel.org
Cc: "Junio C Hamano" <gitster@pobox.com>,
	"Avery Pennarun" <apenwarr@gmail.com>,
	"Jeff King" <peff@peff.net>,
	"Stephen R Guglielmo" <srguglielmo@gmail.com>,
	"A . Wilcox" <AWilcox@Wilcox-Tech.com>,
	"David Aguilar" <davvid@gmail.com>,
	"Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
Subject: [PATCH 4/4] i18n: translate the git-subtree command
Date: Mon, 30 Apr 2018 09:50:44 +0000	[thread overview]
Message-ID: <20180430095044.28492-5-avarab@gmail.com> (raw)
In-Reply-To: <20180430095044.28492-1-avarab@gmail.com>

One of the advantages of having git-subtree out of contrib/ is being
able to treat it as a first-class citizen when it comes to
translations.

Mark those messages that make sense to translate for translation, and
add a comment to the ones that shouldn't be translated. This has been
tested under GIT_GETTEXT_POISON=1.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 git-subtree.sh     | 90 +++++++++++++++++++++++++++-------------------
 t/t7900-subtree.sh |  4 +--
 2 files changed, 56 insertions(+), 38 deletions(-)

diff --git a/git-subtree.sh b/git-subtree.sh
index 1b8cd53c7f..03ef175428 100755
--- a/git-subtree.sh
+++ b/git-subtree.sh
@@ -141,7 +141,7 @@ do
 		break
 		;;
 	*)
-		die "Unexpected option: $opt"
+		die "$(eval_gettext "Unexpected option: \$opt")"
 		;;
 	esac
 done
@@ -157,23 +157,23 @@ split|push)
 	default="--default HEAD"
 	;;
 *)
-	die "Unknown command '$command'"
+	die "$(eval_gettext "Unknown command '\$command'")"
 	;;
 esac
 
 if test -z "$prefix"
 then
-	die "You must provide the --prefix option."
+	die "$(gettext "You must provide the --prefix option.")"
 fi
 
 case "$command" in
 add)
 	test -e "$prefix" &&
-		die "prefix '$prefix' already exists."
+		die "$(eval_gettext "prefix '\$prefix' already exists.")"
 	;;
 *)
 	test -e "$prefix" ||
-		die "'$prefix' does not exist; use 'git subtree add'"
+		die "$(eval_gettext "'\$prefix' does not exist; use 'git subtree add'")"
 	;;
 esac
 
@@ -187,7 +187,7 @@ then
 	dirs=$(git rev-parse --no-revs --no-flags "$@") || exit $?
 	if test -n "$dirs"
 	then
-		die "Error: Use --prefix instead of bare filenames."
+		die "$(gettext "Error: Use --prefix instead of bare filenames.")"
 	fi
 fi
 
@@ -201,12 +201,12 @@ debug
 cache_setup () {
 	cachedir="$GIT_DIR/subtree-cache/$$"
 	rm -rf "$cachedir" ||
-		die "Can't delete old cachedir: $cachedir"
+		die "$(eval_gettext "Can't delete old cachedir: \$cachedir")"
 	mkdir -p "$cachedir" ||
-		die "Can't create new cachedir: $cachedir"
+		die "$(eval_gettext "Can't create new cachedir: \$cachedir")"
 	mkdir -p "$cachedir/notree" ||
-		die "Can't create new cachedir: $cachedir/notree"
-	debug "Using cachedir: $cachedir" >&2
+		die "$(eval_gettext "Can't create new cachedir: \$cachedir/notree")"
+	debug "$(eval_gettext "Using cachedir: \$cachedir")" >&2
 }
 
 cache_get () {
@@ -252,7 +252,7 @@ cache_set () {
 		test "$oldrev" != "latest_new" &&
 		test -e "$cachedir/$oldrev"
 	then
-		die "cache for $oldrev already exists!"
+		die "$(eval_gettext "cache for \$oldrev already exists!")"
 	fi
 	echo "$newrev" >"$cachedir/$oldrev"
 }
@@ -311,7 +311,7 @@ find_latest_squash () {
 			;;
 		git-subtree-split:)
 			sub="$(git rev-parse "$b^0")" ||
-			die "could not rev-parse split hash $b from commit $sq"
+			die "$(eval_gettext "could not rev-parse split hash \$b from commit \$sq")"
 			;;
 		END)
 			if test -n "$sub"
@@ -353,7 +353,7 @@ find_existing_splits () {
 			;;
 		git-subtree-split:)
 			sub="$(git rev-parse "$b^0")" ||
-			die "could not rev-parse split hash $b from commit $sq"
+			die "$(eval_gettext "could not rev-parse split hash \$b from commit \$sq")"
 			;;
 		END)
 			debug "  Main is: '$main'"
@@ -401,7 +401,10 @@ copy_commit () {
 			cat
 		) |
 		git commit-tree "$2" $3  # reads the rest of stdin
-	) || die "Can't copy commit $1"
+	) || {
+		commit="$1"
+		die "$(eval_gettext "Can't copy commit \$commit")"
+	}
 }
 
 add_msg () {
@@ -412,6 +415,7 @@ add_msg () {
 	then
 		commit_message="$message"
 	else
+		# i18n: This message must not be translated!
 		commit_message="Add '$dir/' from commit '$latest_new'"
 	fi
 	cat <<-EOF
@@ -428,6 +432,7 @@ add_squashed_msg () {
 	then
 		echo "$message"
 	else
+		# i18n: This message must not be translated!
 		echo "Merge commit '$1' as '$2'"
 	fi
 }
@@ -440,6 +445,7 @@ rejoin_msg () {
 	then
 		commit_message="$message"
 	else
+		# i18n: This message must not be translated!
 		commit_message="Split '$dir/' into commit '$latest_new'"
 	fi
 	cat <<-EOF
@@ -460,12 +466,12 @@ squash_msg () {
 	if test -n "$oldsub"
 	then
 		oldsub_short=$(git rev-parse --short "$oldsub")
-		echo "Squashed '$dir/' changes from $oldsub_short..$newsub_short"
+		echo "$(eval_gettext "Squashed '\$dir/' changes from \$oldsub_short..\$newsub_short")"
 		echo
 		git log --no-show-signature --pretty=tformat:'%h %s' "$oldsub..$newsub"
 		git log --no-show-signature --pretty=tformat:'REVERT: %h %s' "$newsub..$oldsub"
 	else
-		echo "Squashed '$dir/' content from commit $newsub_short"
+		echo "$(eval_gettext "Squashed '\$dir/' content from commit \$newsub_short")"
 	fi
 
 	echo
@@ -585,31 +591,35 @@ copy_or_skip () {
 ensure_clean () {
 	if ! git diff-index HEAD --exit-code --quiet 2>&1
 	then
-		die "Working tree has modifications.  Cannot add."
+		die "$(gettext "Working tree has modifications.  Cannot add.")"
 	fi
 	if ! git diff-index --cached HEAD --exit-code --quiet 2>&1
 	then
-		die "Index has modifications.  Cannot add."
+		die "$(gettext "Index has modifications.  Cannot add.")"
 	fi
 }
 
 ensure_valid_ref_format () {
-	git check-ref-format "refs/heads/$1" ||
-		die "'$1' does not look like a ref"
+	git check-ref-format "refs/heads/$1" || {
+		reference="$1"
+		die "$(eval_gettext "'\$reference' does not look like a ref")"
+	}
 }
 
 cmd_add () {
 	if test -e "$dir"
 	then
-		die "'$dir' already exists.  Cannot add."
+		die "$(eval_gettext "'\$dir' already exists.  Cannot add.")"
 	fi
 
 	ensure_clean
 
 	if test $# -eq 1
 	then
-		git rev-parse -q --verify "$1^{commit}" >/dev/null ||
-			die "'$1' does not refer to a commit"
+		git rev-parse -q --verify "$1^{commit}" >/dev/null || {
+			reference="$1"
+			die "$(eval_gettext "'\$reference' does not refer to a commit")"
+		}
 
 		cmd_add_commit "$@"
 
@@ -625,7 +635,7 @@ cmd_add () {
 		cmd_add_repository "$@"
 	else
 		say "error: parameters were '$@'"
-		die "Provide either a commit or a repository and commit."
+		die "$(gettext "Provide either a commit or a repository and commit.")"
 	fi
 }
 
@@ -669,7 +679,7 @@ cmd_add_commit () {
 	fi
 	git reset "$commit" || exit $?
 
-	say "Added dir '$dir'"
+	say "$(eval_gettext "Added dir '\$dir'")"
 }
 
 cmd_split () {
@@ -747,7 +757,7 @@ cmd_split () {
 	latest_new=$(cache_get latest_new)
 	if test -z "$latest_new"
 	then
-		die "No new revisions were found"
+		die "$(gettext "No new revisions were found")"
 	fi
 
 	if test -n "$rejoin"
@@ -765,15 +775,23 @@ cmd_split () {
 		then
 			if ! rev_is_descendant_of_branch "$latest_new" "$branch"
 			then
-				die "Branch '$branch' is not an ancestor of commit '$latest_new'."
+				die "$(eval_gettext "Branch '\$branch' is not an ancestor of commit '\$latest_new'.")"
 			fi
-			action='Updated'
+			action='updated'
 		else
-			action='Created'
+			action='created'
 		fi
 		git update-ref -m 'subtree split' \
 			"refs/heads/$branch" "$latest_new" || exit $?
-		say "$action branch '$branch'"
+		if test $action = 'created'
+		then
+			say "$(eval_gettext "Created branch '\$branch'")"
+		elif test $action = 'updated'
+		then
+			say "$(eval_gettext "Updated branch '\$branch'")"
+		else
+			die "BUG: Should have updated the created/updated if/else!"
+		fi
 	fi
 	echo "$latest_new"
 	exit 0
@@ -786,7 +804,7 @@ cmd_merge () {
 	set -- $revs
 	if test $# -ne 1
 	then
-		die "You must provide exactly one revision.  Got: '$revs'"
+		die "$(eval_gettext "You must provide exactly one revision.  Got: '\$revs'")"
 	fi
 	rev="$1"
 
@@ -795,14 +813,14 @@ cmd_merge () {
 		first_split="$(find_latest_squash "$dir")"
 		if test -z "$first_split"
 		then
-			die "Can't squash-merge: '$dir' was never added."
+			die "$(eval_gettext "Can't squash-merge: '\$dir' was never added.")"
 		fi
 		set $first_split
 		old=$1
 		sub=$2
 		if test "$sub" = "$rev"
 		then
-			say "Subtree is already at commit $rev."
+			say "$(eval_gettext "Subtree is already at commit \$rev.")"
 			exit 0
 		fi
 		new=$(new_squash_commit "$old" "$sub" "$rev") || exit $?
@@ -822,7 +840,7 @@ cmd_merge () {
 cmd_pull () {
 	if test $# -ne 2
 	then
-		die "You must provide <repository> <ref>"
+		die "$(gettext "You must provide <repository> <ref>")"
 	fi
 	ensure_clean
 	ensure_valid_ref_format "$2"
@@ -835,7 +853,7 @@ cmd_pull () {
 cmd_push () {
 	if test $# -ne 2
 	then
-		die "You must provide <repository> <ref>"
+		die "$(gettext "You must provide <repository> <ref>")"
 	fi
 	ensure_valid_ref_format "$2"
 	if test -e "$dir"
@@ -846,7 +864,7 @@ cmd_push () {
 		localrev=$(git subtree split --prefix="$prefix") || die
 		git push "$repository" "$localrev":"refs/heads/$refspec"
 	else
-		die "'$dir' must already exist. Try 'git subtree add'."
+		die "$(eval_gettext "'\$dir' must already exist. Try 'git subtree add'.")"
 	fi
 }
 
diff --git a/t/t7900-subtree.sh b/t/t7900-subtree.sh
index a6e7103f92..009daa0c84 100755
--- a/t/t7900-subtree.sh
+++ b/t/t7900-subtree.sh
@@ -304,7 +304,7 @@ test_expect_success 'split requires option --prefix' '
 		test_debug "cat expected" &&
 		test_debug "printf '"actual: "'" &&
 		test_debug "cat actual" &&
-		test_cmp expected actual
+		test_i18ncmp expected actual
 	)
 '
 
@@ -324,7 +324,7 @@ test_expect_success 'split requires path given by option --prefix must exist' '
 		test_debug "cat expected" &&
 		test_debug "printf '"actual: "'" &&
 		test_debug "cat actual" &&
-		test_cmp expected actual
+		test_i18ncmp expected actual
 	)
 '
 
-- 
2.17.0.290.gded63e768a


  parent reply	other threads:[~2018-04-30  9:51 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-30  9:50 [PATCH 0/4] subtree: move out of contrib Ævar Arnfjörð Bjarmason
2018-04-30  9:50 ` [PATCH 1/4] git-subtree: move from contrib/subtree/ Ævar Arnfjörð Bjarmason
2018-04-30  9:50 ` [PATCH 2/4] subtree: remove support for git version <1.7 Ævar Arnfjörð Bjarmason
2018-04-30  9:50 ` [PATCH 3/4] subtree: fix a test failure under GETTEXT_POISON Ævar Arnfjörð Bjarmason
2018-04-30  9:50 ` Ævar Arnfjörð Bjarmason [this message]
2018-04-30 12:05 ` [PATCH 0/4] subtree: move out of contrib Philip Oakley
2018-04-30 20:45 ` Avery Pennarun
2018-04-30 21:38   ` Stefan Beller
2018-04-30 21:53     ` Avery Pennarun
2018-04-30 22:18       ` Stefan Beller
2018-04-30 22:21       ` Ævar Arnfjörð Bjarmason
2018-04-30 22:24         ` Avery Pennarun
2018-05-01 11:37 ` Duy Nguyen
2018-05-01 11:42 ` Johannes Schindelin
2018-05-01 12:48   ` Ævar Arnfjörð Bjarmason

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=20180430095044.28492-5-avarab@gmail.com \
    --to=avarab@gmail.com \
    --cc=AWilcox@Wilcox-Tech.com \
    --cc=apenwarr@gmail.com \
    --cc=davvid@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=peff@peff.net \
    --cc=srguglielmo@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).