i18n: apply: split to fix a partial i18n message
PATCH 1/1 i18n: apply: split to fix a partial i18n message
The 4th arg of "new mode (%o) of %s does not match old mode (%o)%s%s" is blank string or string " of ". Even mark the string " of " for a complete i18n, this message is still hard to translate right.
Split it into two slight different messages would make l10n teams happy.
--- builtin/apply.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-)
builtin/apply.c +12 -4
@@ -3262,10 +3262,18 @@ static int check_patch(struct patch *patch)int same = !strcmp (old_name, new_name);if (!patch->new_mode) patch->new_mode = patch->old_mode; -if ((patch->old_mode ^ patch->new_mode) &S_IFMT ) -return error (_ ("new mode (%o) of %s does not match old mode (%o)%s%s" ), - patch->new_mode, new_name, patch->old_mode, - same ?"" :" of " , same ?"" : old_name); +if ((patch->old_mode ^ patch->new_mode) &S_IFMT ) { +if (same) +return error (_ ("new mode (%o) of %s does not " +"match old mode (%o)" ), + patch->new_mode, new_name, + patch->old_mode); +else +return error (_ ("new mode (%o) of %s does not " +"match old mode (%o) of %s" ), + patch->new_mode, new_name, + patch->old_mode, old_name); + } }if (apply_data (patch, &st, ce) <0 )
Signature · 1 line
1.7.10.2.559.g0ba0f00
Quoted 3 lines · Jiang Xin
The 4th arg of "new mode (%o) of %s does not match old mode (%o)%s%s" is blank string or string " of ". Even mark the string " of " for a complete i18n, this message is still hard to translate right.
Your patch looks good. I have a habit of looking for similar spots and the following patches are the result. These messages are not marked for translation because I think mass-marking by file or by command is better.
Not sure if it's the right way to fix these though. For example, while 1/1 looks very good from i18n perspective, code-wise it's quite ugly. Grouping format strings in array also prevents gcc from checking correct parameters, I think.
Nguyễn Thái Ngọc Duy (6):
Remove i18n legos in notifying new branch tracking setup
reflog: remove i18n legos in pruning message
merge-recursive: remove i18n legos in conflict messages
notes-merge: remove i18n legos in merge result message
rerere: remove i18n legos in result message
unpack-trees: remove i18n legos in unpack's porcelain error messages
branch.c | 48 +++++++++++++++++++++++++++++++++--------------- builtin/reflog.c | 8 ++++++-- merge-recursive.c | 49 +++++++++++++++++++++++++++++++++---------------- notes-merge.c | 11 ++++++++--- rerere.c | 12 ++++++------ unpack-trees.c | 55 +++++++++++++++++++++++++++++++++---------------------- 6 files changed, 119 insertions(+), 64 deletions(-)
Signature · 1 line
1.7.10.2.549.g9354186
PATCH 1/6 Remove i18n legos in notifying new branch tracking setup
--- branch.c | 48 +++++++++++++++++++++++++++++++++--------------- 1 file changed, 33 insertions(+), 15 deletions(-)
branch.c +33 -15
@@ -74,25 +74,43 @@ void install_branch_config(int flag, const char *local, const char *origin, consstrbuf_addf (&key,"branch.%s.rebase" , local);git_config_set (key.buf,"true" ); } +strbuf_release (&key);if (flag &BRANCH_CONFIG_VERBOSE ) { -strbuf_reset (&key); - -strbuf_addstr (&key, origin ?"remote" :"local" ); - -/* Are we tracking a proper "branch"? */ -if (remote_is_branch) { -strbuf_addf (&key," branch %s" , shortname); -if (origin) -strbuf_addf (&key," from %s" , origin); +if (rebasing) { +if (remote_is_branch) { +if (origin) +printf ("Branch %s set up to track remote branch %s from %s by rebasing.\n" , + local, shortname, origin); +else +printf ("Branch %s set up to track local branch %s by rebasing.\n" , + local, shortname); + }else { +if (origin) +printf ("Branch %s set up to track remote ref %s by rebasing.\n" , + local, remote); +else +printf ("Branch %s set up to track local ref %s by rebasing.\n" , + local, remote); + } + }else { +if (remote_is_branch) { +if (origin) +printf ("Branch %s set up to track remote branch %s from %s.\n" , + local, shortname, origin); +else +printf ("Branch %s set up to track local branch %s.\n" , + local, shortname); + }else { +if (origin) +printf ("Branch %s set up to track remote ref %s.\n" , + local, remote); +else +printf ("Branch %s set up to track local ref %s.\n" , + local, remote); + } } -else -strbuf_addf (&key," ref %s" , remote); -printf ("Branch %s set up to track %s%s.\n" , - local, key.buf, - rebasing ?" by rebasing" :"" ); } -strbuf_release (&key); }/*
Signature · 1 line
1.7.10.2.549.g9354186
Re: [PATCH 1/6] Remove i18n legos in notifying new branch tracking setup
Quoted 4 lines · Nguyễn Thái Ngọc Duy
Not sure if it's the right way to fix these though. For example, while 1/1 looks very good from i18n perspective, code-wise it's quite ugly. Grouping format strings in array also prevents gcc from checking correct parameters, I think.
[...]
Quoted 3 lines
branch.c +0
-0@@ -74,25 +74,43 @@ void install_branch_config(int flag, const char *local, const char *origin, cons
[...]
Quoted 13 lines
branch.c +6
-7-strbuf_addstr (&key, origin ?"remote" :"local" ); - -/* Are we tracking a proper "branch"? */ -if (remote_is_branch) { -strbuf_addf (&key," branch %s" , shortname); -if (origin) -strbuf_addf (&key," from %s" , origin); +if (rebasing) { +if (remote_is_branch) { +if (origin) +printf ("Branch %s set up to track remote branch %s from %s by rebasing.\n" , + local, shortname, origin); +else
[...]
Quoted 2 lines
branch.c +2
-0+ }else { +if (origin)
[...]
branch.c void install_branch_config(int flag, const char *local, const char *origin, cons · line 97
Quoted 3 lines
branch.c +3
-0+ } + }else { +if (remote_is_branch) {
[...]
I think a table-driven version of this switchboard would be much easier to read, even if it would hurt gcc's -Wformat checking. If the -Wformat safety is too precious to lose, would something like the following work?
switch (tracking_msg_flags) {
case REBASING | REMOTE_IS_BRANCH | ORIGIN:
printf(_("Branch %s set up to track remote branch %s ..."),
...
break;
case REBASING | REMOTE_IS_BRANCH:
printf(_(...PATCH 2/6 reflog: remove i18n legos in pruning message
In reply to Nguyễn Thái Ngọc Duy--- builtin/reflog.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
builtin/reflog.c +6 -2
@@ -330,8 +330,12 @@ static int expire_reflog_ent(unsigned char *osha1, unsigned char *nsha1,printf ("keep %s" , message);return 0 ; prune: -if (!cb->newlog || cb->cmd->verbose) -printf ("%sprune %s" , cb->newlog ?"" :"would " , message); +if (!cb->newlog || cb->cmd->verbose) { +if (cb->newlog) +printf ("prune %s" , message); +else +printf ("would prune %s" , message); + }return 0 ; }
Signature · 1 line
1.7.10.2.549.g9354186
Re: [PATCH 2/6] reflog: remove i18n legos in pruning message
Quoted 4 lines · Nguyễn Thái Ngọc Duy
builtin/reflog.c +0
-0@@ -330,8 +330,12 @@ static int expire_reflog_ent(unsigned char *osha1, unsigned char *nsha1,printf ("keep %s" , message);
builtin/reflog.c static int expire_reflog_ent(unsigned char *osha1, unsigned char *nsha1, · line 338
Quoted 10 lines
builtin/reflog.c +6
-2return 0 ; prune: -if (!cb->newlog || cb->cmd->verbose) -printf ("%sprune %s" , cb->newlog ?"" :"would " , message); +if (!cb->newlog || cb->cmd->verbose) { +if (cb->newlog) +printf ("prune %s" , message); +else +printf ("would prune %s" , message); + }
Thanks. Style: how about
if (!cb->newlog)
printf("would prune %s", message);
else if (cb->cmd->verbose)
printf("prune %s", message);? I think that would be more readable than the lego original.
BTW I'm not sure if this message would be a good candidate for translation. Especially in the --dry-run case, it feels like output that is intended to be simple enough for scripts to parse. (Though on the other hand, I don't know of any scripts or use cases that actually parse it, so maybe nobody would mind.)
Re: [PATCH 2/6] reflog: remove i18n legos in pruning message
Quoted 8 lines · Jonathan Nieder
Thanks. Style: how about
if (!cb->newlog) printf("would prune %s", message); else if (cb->cmd->verbose) printf("prune %s", message);? I think that would be more readable than the lego original.
That is very much more preferred.
Quoted 2 lines
BTW I'm not sure if this message would be a good candidate for translation.
These are for human consumption; they used to go to standard error stream back when it was written at 4264dc1 (git reflog expire, 2006-12-19).
Re: [PATCH 2/6] reflog: remove i18n legos in pruning message
Quoted 3 lines · Junio C Hamano
These are for human consumption; they used to go to standard error stream back when it was written at 4264dc1 (git reflog expire, 2006-12-19).
Good. Thanks for clarifying and for looking that up.
Why was this changed to write to standard output in 1389d9dd (reflog expire --fix-stale, 2007-01-06)? Would changing it back some time to follow the usual "progress and diagnostics go to stderr" pattern be worthwhile?
--- builtin/reflog.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
builtin/reflog.c +4 -4
@@ -327,11 +327,11 @@ static int expire_reflog_ent(unsigned char *osha1, unsigned char *nsha1,hashcpy (cb->last_kept_sha1, nsha1); }if (cb->cmd->verbose) -printf ("keep %s" , message); +fprintf (stderr,"keep %s" , message);return 0 ; prune:if (!cb->newlog || cb->cmd->verbose) -printf ("%sprune %s" , cb->newlog ?"" :"would " , message); +fprintf (stderr,"%sprune %s" , cb->newlog ?"" :"would " , message);return 0 ; }
@@ -646,10 +646,10 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix)if (cb.stalefix) {init_revisions (&cb.revs, prefix);if (cb.verbose) -printf ("Marking reachable objects..." ); +fprintf (stderr,"Marking reachable objects..." );mark_reachable_objects (&cb.revs,0 ,NULL );if (cb.verbose) -putchar ('\n' ); +fputc ('\n' , stderr); }if (do_all) {
Re: [PATCH 2/6] reflog: remove i18n legos in pruning message
In reply to Jonathan NiederQuoted 8 lines · Jonathan Nieder
Thanks. Style: how about
if (!cb->newlog)
printf("would prune %s", message);
else if (cb->cmd->verbose)
printf("prune %s", message);? I think that would be more readable than the lego original.
thanks
Quoted 5 lines
BTW I'm not sure if this message would be a good candidate for translation. Especially in the --dry-run case, it feels like output that is intended to be simple enough for scripts to parse. (Though on the other hand, I don't know of any scripts or use cases that actually parse it, so maybe nobody would mind.)
it's gray area. reflog is not categorized as plumbing. Maybe adding --plumbing for scripts?
Signature · 1 line
Duy
Re: [PATCH 2/6] reflog: remove i18n legos in pruning message
Quoted 2 lines · Nguyen Thai Ngoc Duy
Maybe adding
--plumbing for scripts?
That wouldn't take care of existing scripts, and new scripts should use LC_ALL=C to defend themselves when they don't want to be impacted by i18n.
Do you have some other reason in mind that a script should choose to pass --plumbing here? Is it an output format flag specific to 'git reflog expire', in the spirit of status --porcelain, or a more generic "I care about output stability" flag that spans multiple commands?
Jonathan
Re: [PATCH 2/6] reflog: remove i18n legos in pruning message
Quoted 5 lines · Jonathan Nieder
Quoted 2 lines · Nguyen Thai Ngoc Duy
Maybe adding --plumbing for scripts?
Quoted 8 lines
That wouldn't take care of existing scripts, and new scripts should use LC_ALL=C to defend themselves when they don't want to be impacted by i18n.
Do you have some other reason in mind that a script should choose to pass --plumbing here? Is it an output format flag specific to 'git reflog expire', in the spirit of status --porcelain, or a more generic "I care about output stability" flag that spans multiple commands?
I was thinking (but without checking) that this is the only way a script can check for expired reflog entries. Maybe something more script friendly, like ref names only.
Signature · 1 line
Duy
PATCH 3/6 merge-recursive: remove i18n legos in conflict messages
In reply to Nguyễn Thái Ngọc Duy--- merge-recursive.c | 49 +++++++++++++++++++++++++++++++++---------------- 1 file changed, 33 insertions(+), 16 deletions(-)
merge-recursive.c +33 -16
@@ -1018,9 +1018,27 @@ static void handle_change_delete(struct merge_options *o, const unsigned char *o_sha, int o_mode, const unsigned char *a_sha, int a_mode, const unsigned char *b_sha, int b_mode, - const char *change, const char *change_past) + const char *change) { char *renamed = NULL; +int idx; + +const char *msg[] = { +"CONFLICT (rename/delete): %s deleted in %s and renamed in %s. Version %s of %s left in tree." , +"CONFLICT (modify/delete): %s deleted in %s and modified in %s. Version %s of %s left in tree." , + }; +const char *renamed_msg[] = { +"CONFLICT (rename/delete): %s deleted in %s and renamed in %s. Version %s of %s left in tree at %s." , +"CONFLICT (modify/delete): %s deleted in %s and modified in %s. Version %s of %s left in tree at %s." , + }; + +if (!strcmp (change,"rename" )) + idx =0 ; +else if (!strcmp (change,"modify" )) + idx =1 ; +else +die ("BUG: unsupport action %s" , change); +if (dir_in_way (path, !o->call_depth)) { renamed =unique_path (o, path, a_sha ? o->branch1 : o->branch2); }
@@ -1034,22 +1052,21 @@ static void handle_change_delete(struct merge_options *o,remove_file_from_cache (path);update_file (o,0 , o_sha, o_mode, renamed ? renamed : path); }else if (!a_sha) { -output (o,1 ,"CONFLICT (%s/delete): %s deleted in %s " -"and %s in %s. Version %s of %s left in tree%s%s." , - change, path, o->branch1, - change_past, o->branch2, o->branch2, path, -NULL == renamed ?"" :" at " , -NULL == renamed ?"" : renamed); +if (renamed) +output (o,1 , renamed_msg[idx], path, o->branch1, + o->branch2, o->branch2, path, renamed); +else +output (o,1 , msg[idx], path, o->branch1, + o->branch2, o->branch2, path);update_file (o,0 , b_sha, b_mode, renamed ? renamed : path); }else { -output (o,1 ,"CONFLICT (%s/delete): %s deleted in %s " -"and %s in %s. Version %s of %s left in tree%s%s." , - change, path, o->branch2, - change_past, o->branch1, o->branch1, path, -NULL == renamed ?"" :" at " , -NULL == renamed ?"" : renamed); -if (renamed) +if (renamed) { +output (o,1 , renamed_msg[idx], path, o->branch2, + o->branch1, o->branch1, path, renamed);update_file (o,0 , a_sha, a_mode, renamed); + }else +output (o,1 , msg[idx], path, o->branch2, + o->branch1, o->branch1, path);/* * No need to call update_file() on path when !renamed, since * that would needlessly touch path. We could call
@@ -1085,7 +1102,7 @@ static void conflict_rename_delete(struct merge_options *o, orig->sha1, orig->mode, a_sha, a_mode, b_sha, b_mode, - "rename", "renamed"); + "rename");if (o->call_depth) {remove_file_from_cache (dest->path);
@@ -1568,7 +1585,7 @@ static void handle_modify_delete(struct merge_options *o, o_sha, o_mode, a_sha, a_mode, b_sha, b_mode, - "modify", "modified"); + "modify"); } static int merge_content(struct merge_options *o,
Signature · 1 line
1.7.10.2.549.g9354186
Re: [PATCH 3/6] merge-recursive: remove i18n legos in conflict messages
merge-recursive.c static void handle_change_delete(struct merge_options *o, · line 1033
Quoted 8 lines · Nguyễn Thái Ngọc Duy
merge-recursive.c +8
-0+const char *msg[] = { +"CONFLICT (rename/delete): %s deleted in %s and renamed in %s. Version %s of %s left in tree." , +"CONFLICT (modify/delete): %s deleted in %s and modified in %s. Version %s of %s left in tree." , + }; +const char *renamed_msg[] = { +"CONFLICT (rename/delete): %s deleted in %s and renamed in %s. Version %s of %s left in tree at %s." , +"CONFLICT (modify/delete): %s deleted in %s and modified in %s. Version %s of %s left in tree at %s." , + };
Is lego by sentence ok? i.e., having 4 translated messages:
CONFLICT (rename/delete): %s deleted in %s and renamed in %s. CONFLICT (modify/delete): %s deleted in %s and modified in %s. Version %s of %s left in tree.
Version %s of %s left in tree at %s.
Re: [PATCH 3/6] merge-recursive: remove i18n legos in conflict messages
Quoted 11 lines · Jonathan Nieder
Quoted 8 lines · Nguyễn Thái Ngọc Duy
+ const char *msg[] = {
+ "CONFLICT (rename/delete): %s deleted in %s and renamed in %s. Version %s of %s left in tree.",
+ "CONFLICT (modify/delete): %s deleted in %s and modified in %s. Version %s of %s left in tree.",
+ };
+ const char *renamed_msg[] = {
+ "CONFLICT (rename/delete): %s deleted in %s and renamed in %s. Version %s of %s left in tree at %s.",
+ "CONFLICT (modify/delete): %s deleted in %s and modified in %s. Version %s of %s left in tree at %s.",
+ };
Quoted 6 lines
Is lego by sentence ok? i.e., having 4 translated messages:
CONFLICT (rename/delete): %s deleted in %s and renamed in %s. CONFLICT (modify/delete): %s deleted in %s and modified in %s. Version %s of %s left in tree.
Version %s of %s left in tree at %s.
Yeah, should have separated these sentences, less work for translators.
Signature · 1 line
Duy
PATCH 4/6 notes-merge: remove i18n legos in merge result message
In reply to Nguyễn Thái Ngọc Duy--- notes-merge.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)
notes-merge.c +8 -3
@@ -523,9 +523,14 @@ static int merge_from_diffs(struct notes_merge_options *o, conflicts =merge_changes (o, changes, &num_changes, t);free (changes); -if (o->verbosity >=4 ) -printf ("Merge result: %i unmerged notes and a %s notes tree\n" , - conflicts, t->dirty ?"dirty" :"clean" ); +if (o->verbosity >=4 ) { +if (t->dirty) +printf ("Merge result: %i unmerged notes and a dirty notes tree\n" , + conflicts); +else +printf ("Merge result: %i unmerged notes and a clean notes tree\n" , + conflicts); + }return conflicts ?-1 :1 ; }
Signature · 1 line
1.7.10.2.549.g9354186
PATCH 5/6 rerere: remove i18n legos in result message
In reply to Nguyễn Thái Ngọc Duy--- rerere.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
rerere.c +6 -6
@@ -544,13 +544,13 @@ static int do_plain_rerere(struct string_list *rr, int fd)if (has_rerere_resolution (name)) {if (!merge (name, path)) { -if (rerere_autoupdate) +const char *msg; +if (rerere_autoupdate) {string_list_insert (&update, path); -fprintf (stderr, -"%s '%s' using previous resolution.\n" , - rerere_autoupdate - ?"Staged" :"Resolved" , - path); + msg ="Staged '%s' using previous resolution.\n" ; + }else + msg ="Resolved '%s' using previous resolution.\n" ; +fprintf (stderr, msg, path); goto mark_resolved; } }
Signature · 1 line
1.7.10.2.549.g9354186
PATCH 6/6 unpack-trees: remove i18n legos in unpack's porcelain error messages
In reply to Nguyễn Thái Ngọc Duy--- unpack-trees.c | 55 +++++++++++++++++++++++++++++++++---------------------- 1 file changed, 33 insertions(+), 22 deletions(-)
unpack-trees.c +33 -22
@@ -53,35 +53,46 @@ static const char *unpack_plumbing_errors[NB_UNPACK_TREES_ERROR_TYPES] = {void setup_unpack_trees_porcelain (struct unpack_trees_options *opts,const char *cmd) { -int i; +int i, idx;const char **msgs = opts->msgs; -const char *msg; -char *tmp; -const char *cmd2 =strcmp (cmd,"checkout" ) ? cmd :"switch branches" ; -if (advice_commit_before_merge) - msg ="Your local changes to the following files would be overwritten by %s:\n%%s" -"Please, commit your changes or stash them before you can %s." ; +struct strbuf msg =STRBUF_INIT ; +const char *overwrite_advice[] = { +"Please, commit your changes or stash them before you can merge." , +"Please, commit your changes or stash them before you can switch branches." + }; +const char *remove_untracked_advice[] = { +"Please move or remove them before you can merge." , +"Please move or remove them before you can switch branches." + }; + +if (!strcmp (cmd,"merge" )) + idx =0 ; +else if (!strcmp (cmd,"checkout" )) + idx =1 ;else - msg ="Your local changes to the following files would be overwritten by %s:\n%%s" ; - tmp =xmalloc (strlen (msg) +strlen (cmd) +strlen (cmd2) -2 ); -sprintf (tmp, msg, cmd, cmd2); - msgs[ERROR_WOULD_OVERWRITE ] = tmp; - msgs[ERROR_NOT_UPTODATE_FILE ] = tmp; +die ("BUG: unsupported command %s" , cmd); + +strbuf_addf (&msg,"Your local changes to the following files " +"would be overwritten by %s:\n%%s" , cmd); +if (advice_commit_before_merge) +strbuf_addstr (&msg, overwrite_advice[idx]); + msgs[ERROR_WOULD_OVERWRITE ] =strbuf_detach (&msg,NULL ); + msgs[ERROR_NOT_UPTODATE_FILE ] = msgs[ERROR_WOULD_OVERWRITE ]; msgs[ERROR_NOT_UPTODATE_DIR ] ="Updating the following directories would lose untracked files in it:\n%s" ; +strbuf_addf (&msg,"The following untracked working tree " +"files would be removed by %s:\n%%s" , cmd);if (advice_commit_before_merge) - msg ="The following untracked working tree files would be %s by %s:\n%%s" -"Please move or remove them before you can %s." ; -else - msg ="The following untracked working tree files would be %s by %s:\n%%s" ; - tmp =xmalloc (strlen (msg) +strlen (cmd) +strlen ("removed" ) +strlen (cmd2) -4 ); -sprintf (tmp, msg,"removed" , cmd, cmd2); - msgs[ERROR_WOULD_LOSE_UNTRACKED_REMOVED ] = tmp; - tmp =xmalloc (strlen (msg) +strlen (cmd) +strlen ("overwritten" ) +strlen (cmd2) -4 ); -sprintf (tmp, msg,"overwritten" , cmd, cmd2); - msgs[ERROR_WOULD_LOSE_UNTRACKED_OVERWRITTEN ] = tmp; +strbuf_addstr (&msg, remove_untracked_advice[idx]); + msgs[ERROR_WOULD_LOSE_UNTRACKED_REMOVED ] =strbuf_detach (&msg,NULL ); + +strbuf_addf (&msg,"The following untracked working tree " +"files would be overwritten by %s:\n%%s" , cmd); +if (advice_commit_before_merge) +strbuf_addstr (&msg, remove_untracked_advice[idx]); + msgs[ERROR_WOULD_LOSE_UNTRACKED_OVERWRITTEN ] =strbuf_detach (&msg,NULL );/* * Special case: ERROR_BIND_OVERLAP refers to a pair of paths, we
Signature · 1 line
1.7.10.2.549.g9354186