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 <vascomalmeida@sapo.pt> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Vasco Almeida committed Jun 17, 2016 at 20:21 UTC f2d17068fd795f980811a3979d671f7d005d3f5c
2 files changed +57 -13
git-rebase--interactive.sh
+56 -13
@@ -402,12 +402,52 @@ pick_one_preserving_merges () {
402 esac
403 }
404
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:";;
451 esac
452 }
453
@@ -415,20 +455,23 @@ update_squash_messages () {
455 if test -f "$squash_msg"; then
456 mv "$squash_msg" "$squash_msg".bak || exit
457 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" \
459 -e "q" < "$squash_msg".bak)+1))
460 {
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)"
465 sed -e 1d -e '2,/^./{
466 /^$/d
467 }' <"$squash_msg".bak
468 } >"$squash_msg"
469 else
427 - commit_message HEAD > "$fixup_msg" || die "Cannot write $fixup_msg"
470 + commit_message HEAD > "$fixup_msg" || die "$(gettext "Cannot write \$fixup_msg")"
471 count=2
472 {
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:")"
475 echo
476 cat "$fixup_msg"
477 } >"$squash_msg"
@@ -437,13 +480,13 @@ update_squash_messages () {
480 squash)
481 rm -f "$fixup_msg"
482 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)"
484 echo
485 commit_message $2
486 ;;
487 fixup)
488 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)"
490 echo
491 # Change the space after the comment character to TAB:
492 commit_message $2 | git stripspace --comment-lines | sed -e 's/ / /'
t/lib-rebase.sh
+1
@@ -29,6 +29,7 @@ set_fake_editor () {
29 */COMMIT_EDITMSG)
30 test -z "$EXPECT_HEADER_COUNT" ||
31 test "$EXPECT_HEADER_COUNT" = "$(sed -n '1s/^# This is a combination of \(.*\) commits\./\1/p' < "$1")" ||
32 + test "# # GETTEXT POISON #" = "$(sed -n '1p' < "$1")" ||
33 exit
34 test -z "$FAKE_COMMIT_MESSAGE" || echo "$FAKE_COMMIT_MESSAGE" > "$1"
35 test -z "$FAKE_COMMIT_AMEND" || echo "$FAKE_COMMIT_AMEND" >> "$1"