[PATCH 4/4] i18n: translate the git-subtree command

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxx>
---
 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




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux