Enable localization (l10n) of bisect terms in messages for the user. Use an array to explicitly list and mark bisect terms for translation using the no-op N_(). Additionally, this catches at compile time errors such as wrongly writing the bisect terms, e.g., writing "god" instead of "good", since now we would use term_names[GOOD] syntax. Triggering the retrieval of the term translation is done at runtime with _(term_bad) and _(term_good). There are 2 messages that can't be marked for translation at this point, because they're grep'ed by bisect_run function in git-bisect.sh. Signed-off-by: Vasco Almeida <vascomalmeida@xxxxxxx> --- bisect.c | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/bisect.c b/bisect.c index a8713a8..293d7ec 100644 --- a/bisect.c +++ b/bisect.c @@ -23,6 +23,15 @@ static const char *argv_show_branch[] = {"show-branch", NULL, NULL}; static const char *term_bad; static const char *term_good; +enum term { BAD, GOOD, OLD, NEW }; +static const char *term_names[] = { +/* TRANSLATORS: in bisect.c source code file, the following terms are + used to describe a "bad commit", "good commit", "new revision", etc. + Please, if you can, check the source when you are not sure if a %s + would be replaced by one of the following terms. */ + N_("bad"), N_("good"), N_("old"), N_("new"), NULL +}; + /* Remember to update object flag allocation in object.h */ #define COUNTED (1u<<16) @@ -725,12 +734,12 @@ static void handle_bad_merge_base(void) if (is_expected_rev(current_bad_oid)) { char *bad_hex = oid_to_hex(current_bad_oid); char *good_hex = join_sha1_array_hex(&good_revs, ' '); - if (!strcmp(term_bad, "bad") && !strcmp(term_good, "good")) { + if (!strcmp(term_bad, term_names[BAD]) && !strcmp(term_good, term_names[GOOD])) { fprintf(stderr, _("The merge base %s is bad.\n" "This means the bug has been fixed " "between %s and [%s].\n"), bad_hex, bad_hex, good_hex); - } else if (!strcmp(term_bad, "new") && !strcmp(term_good, "old")) { + } else if (!strcmp(term_bad, term_names[NEW]) && !strcmp(term_good, term_names[OLD])) { fprintf(stderr, _("The merge base %s is new.\n" "The property has changed " "between %s and [%s].\n"), @@ -739,7 +748,7 @@ static void handle_bad_merge_base(void) fprintf(stderr, _("The merge base %s is %s.\n" "This means the first '%s' commit is " "between %s and [%s].\n"), - bad_hex, term_bad, term_good, bad_hex, good_hex); + bad_hex, _(term_bad), _(term_good), bad_hex, good_hex); } exit(3); } @@ -747,7 +756,7 @@ static void handle_bad_merge_base(void) fprintf(stderr, _("Some %s revs are not ancestor of the %s rev.\n" "git bisect cannot work properly in this case.\n" "Maybe you mistook %s and %s revs?\n"), - term_good, term_bad, term_good, term_bad); + _(term_good), _(term_bad), _(term_good), _(term_bad)); exit(1); } @@ -762,7 +771,7 @@ static void handle_skipped_merge_base(const unsigned char *mb) "So we cannot be sure the first %s commit is " "between %s and %s.\n" "We continue anyway."), - bad_hex, good_hex, term_bad, mb_hex, bad_hex); + bad_hex, good_hex, _(term_bad), mb_hex, bad_hex); free(good_hex); } @@ -843,7 +852,7 @@ static void check_good_are_ancestors_of_bad(const char *prefix, int no_checkout) int fd; if (!current_bad_oid) - die(_("a %s revision is needed"), term_bad); + die(_("a %s revision is needed"), _(term_bad)); /* Check if file BISECT_ANCESTORS_OK exists. */ if (!stat(filename, &st) && S_ISREG(st.st_mode)) @@ -906,8 +915,8 @@ void read_bisect_terms(const char **read_bad, const char **read_good) if (!fp) { if (errno == ENOENT) { - *read_bad = "bad"; - *read_good = "good"; + *read_bad = term_names[BAD]; + *read_good = term_names[GOOD]; return; } else { die_errno(_("could not read file '%s'"), filename); @@ -962,8 +971,8 @@ int bisect_next_all(const char *prefix, int no_checkout) printf(_("%s was both %s and %s\n"), oid_to_hex(current_bad_oid), - term_good, - term_bad); + _(term_good), + _(term_bad)); exit(1); } -- 2.7.3 -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html