i18n: rebase-interactive: mark here-doc strings for translation

Use pipe to send gettext output to git stripspace instead of the original method of using shell here-document, because command substitution '$(...)' would not take place inside the here-documents. The exception is the case of the last here-document redirecting to cat, in which commands substitution works and, thus, is preserved in this commit. t3404: adapt test to the strings newly marked for translation Test t3404-rebase-interactive.sh would fail under GETTEXT_POISON unless using test_i18ngrep. Add eval_ngettext fallback functions to be called when running, for instance, under GETTEXT_POISON. Otherwise, tests would fail under GETTEXT_POISON, or other build that doesn't support the GNU gettext, because that function could not be found. Signed-off-by: Vasco Almeida <vascomalmeida@sapo.pt> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Vasco Almeida committed Jun 17, 2016 at 20:21 UTC b8fc9e43a7da5c8cb1e90eb569b5e821883c2e06
3 files changed +40 -22
git-rebase--interactive.sh
+15 -15
@@ -144,29 +144,28 @@ reschedule_last_action () {
144 }
145
146 append_todo_help () {
147 - git stripspace --comment-lines >>"$todo" <<\EOF
148 -
147 + gettext "
148 Commands:
149 p, pick = use commit
150 r, reword = use commit, but edit the commit message
151 e, edit = use commit, but stop for amending
152 s, squash = use commit, but meld into previous commit
154 - f, fixup = like "squash", but discard this commit's log message
153 + f, fixup = like \"squash\", but discard this commit's log message
154 x, exec = run command (the rest of the line) using shell
155 d, drop = remove commit
156
157 These lines can be re-ordered; they are executed from top to bottom.
158 +" | git stripspace --comment-lines >>"$todo"
159
160 -EOF
160 if test $(get_missing_commit_check_level) = error
161 then
163 - git stripspace --comment-lines >>"$todo" <<\EOF
162 + gettext "
163 Do not remove any line. Use 'drop' explicitly to remove a commit.
165 -EOF
164 +" | git stripspace --comment-lines >>"$todo"
165 else
167 - git stripspace --comment-lines >>"$todo" <<\EOF
166 + gettext "
167 If you remove a line here THAT COMMIT WILL BE LOST.
169 -EOF
168 +" | git stripspace --comment-lines >>"$todo"
169 fi
170 }
171
@@ -1123,13 +1122,12 @@ edit-todo)
1122 mv -f "$todo".new "$todo"
1123 collapse_todo_ids
1124 append_todo_help
1126 - git stripspace --comment-lines >>"$todo" <<\EOF
1127 -
1125 + gettext "
1126 You are editing the todo file of an ongoing interactive rebase.
1127 To continue rebase after editing, run:
1128 git rebase --continue
1129
1132 -EOF
1130 +" | git stripspace --comment-lines >>"$todo"
1131
1132 git_sequence_editor "$todo" ||
1133 die "$(gettext "Could not execute editor")"
@@ -1270,14 +1268,16 @@ todocount=${todocount##* }
1268
1269 cat >>"$todo" <<EOF
1270
1273 -$comment_char Rebase $shortrevisions onto $shortonto ($todocount command(s))
1271 +$comment_char $(eval_ngettext \
1272 + "Rebase \$shortrevisions onto \$shortonto (\$todocount command)" \
1273 + "Rebase \$shortrevisions onto \$shortonto (\$todocount commands)" \
1274 + "$todocount")
1275 EOF
1276 append_todo_help
1276 -git stripspace --comment-lines >>"$todo" <<\EOF
1277 -
1277 +gettext "
1278 However, if you remove everything, the rebase will be aborted.
1279
1280 -EOF
1280 +" | git stripspace --comment-lines >>"$todo"
1281
1282 if test -z "$keep_empty"
1283 then
git-sh-i18n.sh
+18
@@ -53,6 +53,13 @@ gettext_without_eval_gettext)
53 git sh-i18n--envsubst "$1"
54 )
55 }
56 +
57 + eval_ngettext () {
58 + ngettext "$1" "$2" "$3" | (
59 + export PATH $(git sh-i18n--envsubst --variables "$2");
60 + git sh-i18n--envsubst "$2"
61 + )
62 + }
63 ;;
64 poison)
65 # Emit garbage so that tests that incorrectly rely on translatable
@@ -64,6 +71,10 @@ poison)
71 eval_gettext () {
72 printf "%s" "# GETTEXT POISON #"
73 }
74 +
75 + eval_ngettext () {
76 + printf "%s" "# GETTEXT POISON #"
77 + }
78 ;;
79 *)
80 gettext () {
@@ -76,6 +87,13 @@ poison)
87 git sh-i18n--envsubst "$1"
88 )
89 }
90 +
91 + eval_ngettext () {
92 + (test "$3" = 1 && printf "%s" "$1" || printf "%s" "$2") | (
93 + export PATH $(git sh-i18n--envsubst --variables "$2");
94 + git sh-i18n--envsubst "$2"
95 + )
96 + }
97 ;;
98 esac
99
t/t3404-rebase-interactive.sh
+7 -7
@@ -540,7 +540,7 @@ test_expect_success 'clean error after failed "exec"' '
540 echo "edited again" > file7 &&
541 git add file7 &&
542 test_must_fail git rebase --continue 2>error &&
543 - grep "You have staged changes in your working tree." error
543 + test_i18ngrep "You have staged changes in your working tree." error
544 '
545
546 test_expect_success 'rebase a detached HEAD' '
@@ -1060,7 +1060,7 @@ test_expect_success 'todo count' '
1060 EOF
1061 test_set_editor "$(pwd)/dump-raw.sh" &&
1062 git rebase -i HEAD~4 >actual &&
1063 - grep "^# Rebase ..* onto ..* ([0-9]" actual
1063 + test_i18ngrep "^# Rebase ..* onto ..* ([0-9]" actual
1064 '
1065
1066 test_expect_success 'rebase -i commits that overwrite untracked files (pick)' '
@@ -1160,7 +1160,7 @@ test_expect_success 'rebase -i respects rebase.missingCommitsCheck = ignore' '
1160 FAKE_LINES="1 2 3 4" \
1161 git rebase -i --root 2>actual &&
1162 test D = $(git cat-file commit HEAD | sed -ne \$p) &&
1163 - test_cmp expect actual
1163 + test_i18ncmp expect actual
1164 '
1165
1166 cat >expect <<EOF
@@ -1181,7 +1181,7 @@ test_expect_success 'rebase -i respects rebase.missingCommitsCheck = warn' '
1181 set_fake_editor &&
1182 FAKE_LINES="1 2 3 4" \
1183 git rebase -i --root 2>actual &&
1184 - test_cmp expect actual &&
1184 + test_i18ncmp expect actual &&
1185 test D = $(git cat-file commit HEAD | sed -ne \$p)
1186 '
1187
@@ -1205,7 +1205,7 @@ test_expect_success 'rebase -i respects rebase.missingCommitsCheck = error' '
1205 set_fake_editor &&
1206 test_must_fail env FAKE_LINES="1 2 4" \
1207 git rebase -i --root 2>actual &&
1208 - test_cmp expect actual &&
1208 + test_i18ncmp expect actual &&
1209 cp .git/rebase-merge/git-rebase-todo.backup \
1210 .git/rebase-merge/git-rebase-todo &&
1211 FAKE_LINES="1 2 drop 3 4 drop 5" \
@@ -1228,7 +1228,7 @@ test_expect_success 'static check of bad command' '
1228 set_fake_editor &&
1229 test_must_fail env FAKE_LINES="1 2 3 bad 4 5" \
1230 git rebase -i --root 2>actual &&
1231 - test_cmp expect actual &&
1231 + test_i18ncmp expect actual &&
1232 FAKE_LINES="1 2 3 drop 4 5" git rebase --edit-todo &&
1233 git rebase --continue &&
1234 test E = $(git cat-file commit HEAD | sed -ne \$p) &&
@@ -1263,7 +1263,7 @@ test_expect_success 'static check of bad SHA-1' '
1263 set_fake_editor &&
1264 test_must_fail env FAKE_LINES="1 2 edit fakesha 3 4 5 #" \
1265 git rebase -i --root 2>actual &&
1266 - test_cmp expect actual &&
1266 + test_i18ncmp expect actual &&
1267 FAKE_LINES="1 2 4 5 6" git rebase --edit-todo &&
1268 git rebase --continue &&
1269 test E = $(git cat-file commit HEAD | sed -ne \$p)