Skip to content

Commit f2d1706

Browse files
vascoolgitster
authored andcommitted
i18n: rebase-interactive: mark comments of squash for translation
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent b8fc9e4 commit f2d1706

File tree

2 files changed

+57
-13
lines changed

2 files changed

+57
-13
lines changed

git-rebase--interactive.sh

Lines changed: 56 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -402,33 +402,76 @@ pick_one_preserving_merges () {
402402
esac
403403
}
404404

405-
nth_string () {
406-
case "$1" in
407-
*1[0-9]|*[04-9]) echo "$1"th;;
408-
*1) echo "$1"st;;
409-
*2) echo "$1"nd;;
410-
*3) echo "$1"rd;;
405+
this_nth_commit_message () {
406+
n=$1
407+
case "$n" in
408+
1) gettext "This is the 1st commit message:";;
409+
2) gettext "This is the 2nd commit message:";;
410+
3) gettext "This is the 3rd commit message:";;
411+
4) gettext "This is the 4th commit message:";;
412+
5) gettext "This is the 5th commit message:";;
413+
6) gettext "This is the 6th commit message:";;
414+
7) gettext "This is the 7th commit message:";;
415+
8) gettext "This is the 8th commit message:";;
416+
9) gettext "This is the 9th commit message:";;
417+
10) gettext "This is the 10th commit message:";;
418+
# TRANSLATORS: if the language you are translating into
419+
# doesn't allow you to compose a sentence in this fashion,
420+
# consider translating as if this and the following few strings
421+
# were "This is the commit message ${n}:"
422+
*1[0-9]|*[04-9]) eval_gettext "This is the \${n}th commit message:";;
423+
*1) eval_gettext "This is the \${n}st commit message:";;
424+
*2) eval_gettext "This is the \${n}nd commit message:";;
425+
*3) eval_gettext "This is the \${n}rd commit message:";;
426+
*) eval_gettext "This is the commit message \${n}:";;
427+
esac
428+
}
429+
skip_nth_commit_message () {
430+
n=$1
431+
case "$n" in
432+
1) gettext "The 1st commit message will be skipped:";;
433+
2) gettext "The 2nd commit message will be skipped:";;
434+
3) gettext "The 3rd commit message will be skipped:";;
435+
4) gettext "The 4th commit message will be skipped:";;
436+
5) gettext "The 5th commit message will be skipped:";;
437+
6) gettext "The 6th commit message will be skipped:";;
438+
7) gettext "The 7th commit message will be skipped:";;
439+
8) gettext "The 8th commit message will be skipped:";;
440+
9) gettext "The 9th commit message will be skipped:";;
441+
10) gettext "The 10th commit message will be skipped:";;
442+
# TRANSLATORS: if the language you are translating into
443+
# doesn't allow you to compose a sentence in this fashion,
444+
# consider translating as if this and the following few strings
445+
# were "The commit message ${n} will be skipped:"
446+
*1[0-9]|*[04-9]) eval_gettext "The \${n}th commit message will be skipped:";;
447+
*1) eval_gettext "The \${n}st commit message will be skipped:";;
448+
*2) eval_gettext "The \${n}nd commit message will be skipped:";;
449+
*3) eval_gettext "The \${n}rd commit message will be skipped:";;
450+
*) eval_gettext "The commit message \${n} will be skipped:";;
411451
esac
412452
}
413453

414454
update_squash_messages () {
415455
if test -f "$squash_msg"; then
416456
mv "$squash_msg" "$squash_msg".bak || exit
417457
count=$(($(sed -n \
418-
-e "1s/^. This is a combination of \(.*\) commits\./\1/p" \
458+
-e "1s/^$comment_char.*\([0-9][0-9]*\).*/\1/p" \
419459
-e "q" < "$squash_msg".bak)+1))
420460
{
421-
printf '%s\n' "$comment_char This is a combination of $count commits."
461+
printf '%s\n' "$comment_char $(eval_ngettext \
462+
"This is a combination of \$count commit." \
463+
"This is a combination of \$count commits." \
464+
$count)"
422465
sed -e 1d -e '2,/^./{
423466
/^$/d
424467
}' <"$squash_msg".bak
425468
} >"$squash_msg"
426469
else
427-
commit_message HEAD > "$fixup_msg" || die "Cannot write $fixup_msg"
470+
commit_message HEAD > "$fixup_msg" || die "$(gettext "Cannot write \$fixup_msg")"
428471
count=2
429472
{
430-
printf '%s\n' "$comment_char This is a combination of 2 commits."
431-
printf '%s\n' "$comment_char The first commit's message is:"
473+
printf '%s\n' "$comment_char $(gettext "This is a combination of 2 commits.")"
474+
printf '%s\n' "$comment_char $(gettext "This is the 1st commit message:")"
432475
echo
433476
cat "$fixup_msg"
434477
} >"$squash_msg"
@@ -437,13 +480,13 @@ update_squash_messages () {
437480
squash)
438481
rm -f "$fixup_msg"
439482
echo
440-
printf '%s\n' "$comment_char This is the $(nth_string $count) commit message:"
483+
printf '%s\n' "$comment_char $(this_nth_commit_message $count)"
441484
echo
442485
commit_message $2
443486
;;
444487
fixup)
445488
echo
446-
printf '%s\n' "$comment_char The $(nth_string $count) commit message will be skipped:"
489+
printf '%s\n' "$comment_char $(skip_nth_commit_message $count)"
447490
echo
448491
# Change the space after the comment character to TAB:
449492
commit_message $2 | git stripspace --comment-lines | sed -e 's/ / /'

t/lib-rebase.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ set_fake_editor () {
2929
*/COMMIT_EDITMSG)
3030
test -z "$EXPECT_HEADER_COUNT" ||
3131
test "$EXPECT_HEADER_COUNT" = "$(sed -n '1s/^# This is a combination of \(.*\) commits\./\1/p' < "$1")" ||
32+
test "# # GETTEXT POISON #" = "$(sed -n '1p' < "$1")" ||
3233
exit
3334
test -z "$FAKE_COMMIT_MESSAGE" || echo "$FAKE_COMMIT_MESSAGE" > "$1"
3435
test -z "$FAKE_COMMIT_AMEND" || echo "$FAKE_COMMIT_AMEND" >> "$1"

0 commit comments

Comments
 (0)