Skip to content

Commit 2e3926b

Browse files
vascoolgitster
authored andcommitted
i18n: unpack-trees: avoid substituting only a verb in sentences
Instead of reusing the same set of message templates for checkout and other actions and substituting the verb with "%s", prepare separate message templates for each known action. That would make it easier for translation into languages where the same verb may conjugate differently depending on the message we are giving. See gettext documentation for details: http://www.gnu.org/software/gettext/manual/html_node/Preparing-Strings.html Helped-by: Junio C Hamano <[email protected]> Signed-off-by: Vasco Almeida <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent daf9f64 commit 2e3926b

File tree

2 files changed

+56
-22
lines changed

2 files changed

+56
-22
lines changed

t/t7609-merge-co-error-msgs.sh

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,14 @@ EOF
3737

3838
test_expect_success 'untracked files overwritten by merge (fast and non-fast forward)' '
3939
test_must_fail git merge branch 2>out &&
40-
test_cmp out expect &&
40+
test_i18ncmp out expect &&
4141
git commit --allow-empty -m empty &&
4242
(
4343
GIT_MERGE_VERBOSITY=0 &&
4444
export GIT_MERGE_VERBOSITY &&
4545
test_must_fail git merge branch 2>out2
4646
) &&
47-
test_cmp out2 expect &&
47+
test_i18ncmp out2 expect &&
4848
git reset --hard HEAD^
4949
'
5050

@@ -53,7 +53,7 @@ error: Your local changes to the following files would be overwritten by merge:
5353
four
5454
three
5555
two
56-
Please, commit your changes or stash them before you can merge.
56+
Please commit your changes or stash them before you can merge.
5757
error: The following untracked working tree files would be overwritten by merge:
5858
five
5959
Please move or remove them before you can merge.
@@ -65,14 +65,14 @@ test_expect_success 'untracked files or local changes ovewritten by merge' '
6565
git add three &&
6666
git add four &&
6767
test_must_fail git merge branch 2>out &&
68-
test_cmp out expect
68+
test_i18ncmp out expect
6969
'
7070

7171
cat >expect <<\EOF
7272
error: Your local changes to the following files would be overwritten by checkout:
7373
rep/one
7474
rep/two
75-
Please, commit your changes or stash them before you can switch branches.
75+
Please commit your changes or stash them before you can switch branches.
7676
Aborting
7777
EOF
7878

@@ -87,21 +87,21 @@ test_expect_success 'cannot switch branches because of local changes' '
8787
echo uno >rep/one &&
8888
echo dos >rep/two &&
8989
test_must_fail git checkout branch 2>out &&
90-
test_cmp out expect
90+
test_i18ncmp out expect
9191
'
9292

9393
cat >expect <<\EOF
9494
error: Your local changes to the following files would be overwritten by checkout:
9595
rep/one
9696
rep/two
97-
Please, commit your changes or stash them before you can switch branches.
97+
Please commit your changes or stash them before you can switch branches.
9898
Aborting
9999
EOF
100100

101101
test_expect_success 'not uptodate file porcelain checkout error' '
102102
git add rep/one rep/two &&
103103
test_must_fail git checkout branch 2>out &&
104-
test_cmp out expect
104+
test_i18ncmp out expect
105105
'
106106

107107
cat >expect <<\EOF
@@ -132,7 +132,7 @@ test_expect_success 'not_uptodate_dir porcelain checkout error' '
132132
>rep/untracked-file &&
133133
>rep2/untracked-file &&
134134
test_must_fail git checkout branch 2>out &&
135-
test_cmp out ../expect
135+
test_i18ncmp out ../expect
136136
'
137137

138138
test_done

unpack-trees.c

Lines changed: 47 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -58,27 +58,61 @@ void setup_unpack_trees_porcelain(struct unpack_trees_options *opts,
5858
int i;
5959
const char **msgs = opts->msgs;
6060
const char *msg;
61-
const char *cmd2 = strcmp(cmd, "checkout") ? cmd : "switch branches";
6261

63-
if (advice_commit_before_merge)
64-
msg = _("Your local changes to the following files would be overwritten by %s:\n%%s"
65-
"Please, commit your changes or stash them before you can %s.");
62+
if (!strcmp(cmd, "checkout"))
63+
msg = advice_commit_before_merge
64+
? _("Your local changes to the following files would be overwritten by checkout:\n%%s"
65+
"Please commit your changes or stash them before you can switch branches.")
66+
: _("Your local changes to the following files would be overwritten by checkout:\n%%s");
67+
else if (!strcmp(cmd, "merge"))
68+
msg = advice_commit_before_merge
69+
? _("Your local changes to the following files would be overwritten by merge:\n%%s"
70+
"Please commit your changes or stash them before you can merge.")
71+
: _("Your local changes to the following files would be overwritten by merge:\n%%s");
6672
else
67-
msg = _("Your local changes to the following files would be overwritten by %s:\n%%s");
73+
msg = advice_commit_before_merge
74+
? _("Your local changes to the following files would be overwritten by %s:\n%%s"
75+
"Please commit your changes or stash them before you can %s.")
76+
: _("Your local changes to the following files would be overwritten by %s:\n%%s");
6877
msgs[ERROR_WOULD_OVERWRITE] = msgs[ERROR_NOT_UPTODATE_FILE] =
69-
xstrfmt(msg, cmd, cmd2);
78+
xstrfmt(msg, cmd, cmd);
7079

7180
msgs[ERROR_NOT_UPTODATE_DIR] =
7281
_("Updating the following directories would lose untracked files in it:\n%s");
7382

74-
if (advice_commit_before_merge)
75-
msg = _("The following untracked working tree files would be %s by %s:\n%%s"
76-
"Please move or remove them before you can %s.");
83+
if (!strcmp(cmd, "checkout"))
84+
msg = advice_commit_before_merge
85+
? _("The following untracked working tree files would be removed by checkout:\n%%s"
86+
"Please move or remove them before you can switch branches.")
87+
: _("The following untracked working tree files would be removed by checkout:\n%%s");
88+
else if (!strcmp(cmd, "merge"))
89+
msg = advice_commit_before_merge
90+
? _("The following untracked working tree files would be removed by merge:\n%%s"
91+
"Please move or remove them before you can merge.")
92+
: _("The following untracked working tree files would be removed by merge:\n%%s");
7793
else
78-
msg = _("The following untracked working tree files would be %s by %s:\n%%s");
79-
80-
msgs[ERROR_WOULD_LOSE_UNTRACKED_REMOVED] = xstrfmt(msg, "removed", cmd, cmd2);
81-
msgs[ERROR_WOULD_LOSE_UNTRACKED_OVERWRITTEN] = xstrfmt(msg, "overwritten", cmd, cmd2);
94+
msg = advice_commit_before_merge
95+
? _("The following untracked working tree files would be removed by %s:\n%%s"
96+
"Please move or remove them before you can %s.")
97+
: _("The following untracked working tree files would be removed by %s:\n%%s");
98+
msgs[ERROR_WOULD_LOSE_UNTRACKED_REMOVED] = xstrfmt(msg, cmd, cmd);
99+
100+
if (!strcmp(cmd, "checkout"))
101+
msg = advice_commit_before_merge
102+
? _("The following untracked working tree files would be overwritten by checkout:\n%%s"
103+
"Please move or remove them before you can switch branches.")
104+
: _("The following untracked working tree files would be overwritten by checkout:\n%%s");
105+
else if (!strcmp(cmd, "merge"))
106+
msg = advice_commit_before_merge
107+
? _("The following untracked working tree files would be overwritten by merge:\n%%s"
108+
"Please move or remove them before you can merge.")
109+
: _("The following untracked working tree files would be overwritten by merge:\n%%s");
110+
else
111+
msg = advice_commit_before_merge
112+
? _("The following untracked working tree files would be overwritten by %s:\n%%s"
113+
"Please move or remove them before you can %s.")
114+
: _("The following untracked working tree files would be overwritten by %s:\n%%s");
115+
msgs[ERROR_WOULD_LOSE_UNTRACKED_OVERWRITTEN] = xstrfmt(msg, cmd, cmd);
82116

83117
/*
84118
* Special case: ERROR_BIND_OVERLAP refers to a pair of paths, we

0 commit comments

Comments
 (0)