transport.c: mark push status strings for translation
PATCH 1/1 transport.c: mark push status strings for translation
Strings are only marked for translations, the actual lookup is delayed until inside print_ref_status(), so we only have to check for porcelain flag once.
While at there, mark some error strings in git push for translation too.
---
I was doing something else and stumbled upon this code block, the porcelain flag says there's low risk that this change may break something.
builtin/push.c | 8 +++---- transport.c | 75 ++++++++++++++++++++++++++++++++-------------------------- 2 files changed, 46 insertions(+), 37 deletions(-)
builtin/push.c +4 -4
@@ -319,7 +319,7 @@ static int push_with_options(struct transport *transport, int flags)if (!is_empty_cas (&cas)) {if (!transport->smart_options) -die ("underlying transport does not support --%s option" , +die (_ ("underlying transport does not support --%s option" ),CAS_OPT_NAME ); transport->smart_options->cas = &cas; }
@@ -426,7 +426,7 @@ static int option_parse_recurse_submodules(const struct option *opt,if (*flags & (TRANSPORT_RECURSE_SUBMODULES_CHECK |TRANSPORT_RECURSE_SUBMODULES_ON_DEMAND )) -die ("%s can only be used once." , opt->long_name); +die (_ ("%s can only be used once." ), opt->long_name);if (arg) {if (!strcmp (arg,"check" ))
@@ -434,9 +434,9 @@ static int option_parse_recurse_submodules(const struct option *opt,else if (!strcmp (arg,"on-demand" )) *flags |=TRANSPORT_RECURSE_SUBMODULES_ON_DEMAND ;else -die ("bad %s argument: %s" , opt->long_name, arg); +die (_ ("bad %s argument: %s" ), opt->long_name, arg); }else -die ("option %s needs an argument (check|on-demand)" , +die (_ ("option %s needs an argument (check|on-demand)" ), opt->long_name);return 0 ;
transport.c +42 -33
132 lines not on this page · raw message
Signature · 1 line
1.8.2.82.gc24b958
Quoted 3 lines · Nguyễn Thái Ngọc Duy
Strings are only marked for translations, the actual lookup is delayed until inside
print_ref_status(), so we only have to check for porcelain flag once.
I was confused about what this means (why would it be faster to call gettext() once inside print_ref_status() instead of once per caller in the argument to print_ref_status()?) until I looked at the code. I guess you mean something like
Mark strings like "[up to date]" passed to print_ref_status() for translation with N_() instead of _() so they can remain untranslated in porcelain mode.
Quoted 2 lines
While at there, mark some error strings in git push for translation too.
Thanks.
[...]
Quoted 1 line
+++
b/transport.c
[...]
transport.c static void print_ref_status(char flag, const char *summary, struct ref *to, str · line 635
Quoted 10 lines
transport.c +5
-1@@ -627,16 +628,17 @@ static void print_ref_status(char flag, const char *summary, struct ref *to, strelse fprintf (stdout,"%s\n" , summary); }else { -fprintf (stderr," %c %-*s " , flag,TRANSPORT_SUMMARY_WIDTH , summary); +int width =TRANSPORT_SUMMARY_WIDTH ; +const char *localized_summary =_ (summary); +/* compensate the invisible bytes in utf-8 strings */ + width +=strlen (localized_summary) -utf8_strwidth (localized_summary); +fprintf (stderr," %c %-*s " , flag, width, localized_summary);
Nit: "Compensate for the ...".
What would happen if 'width' became negative? That can't happen because none of the doublewidth characters are ASCII characters, so the question is just academic, but maybe it's worth a note in the comment to avoid slowing down people reading.
transport.c static void print_ref_status(char flag, const char *summary, struct ref *to, str · line 637
Quoted 2 lines
transport.c +0
-0if (from)fprintf (stderr,"%s -> %s" ,prettify_refname (from->name),prettify_refname (to->name));
I'm not sure this is correct for right-to-left languages. Something to solve another day.
The rest looks good.
If the commit message is clarified,
Quoted 5 lines · Jonathan Nieder
Quoted 2 lines
if (from) fprintf(stderr, "%s -> %s", prettify_refname(from->name), prettify_refname(to->name));I'm not sure this is correct for right-to-left languages. Something to solve another day.
I don't speak rtl languages and don't know the support status for them. But to me rtl on terminal is a terrible idea as it's assumed everywhere that the terminal prints from left to right. Anyway let's wait until a rtl translation comes to git, then we'll have somebody knowledgable about the languages to talk about.
Signature · 1 line
Duy
PATCH v2 1/1 transport.c: mark push status strings for translation
In reply to Nguyễn Thái Ngọc DuyMark strings like "[up to date]" passed to print_ref_status() for translation with N_() instead of _() so they can remain untranslated in porcelain mode.
While at there, mark some error strings in git push for translation too.
--- builtin/push.c | 8 +++--- transport.c | 81 ++++++++++++++++++++++++++++++++++------------------------ 2 files changed, 52 insertions(+), 37 deletions(-)
builtin/push.c +4 -4
@@ -319,7 +319,7 @@ static int push_with_options(struct transport *transport, int flags)if (!is_empty_cas (&cas)) {if (!transport->smart_options) -die ("underlying transport does not support --%s option" , +die (_ ("underlying transport does not support --%s option" ),CAS_OPT_NAME ); transport->smart_options->cas = &cas; }
@@ -426,7 +426,7 @@ static int option_parse_recurse_submodules(const struct option *opt,if (*flags & (TRANSPORT_RECURSE_SUBMODULES_CHECK |TRANSPORT_RECURSE_SUBMODULES_ON_DEMAND )) -die ("%s can only be used once." , opt->long_name); +die (_ ("%s can only be used once." ), opt->long_name);if (arg) {if (!strcmp (arg,"check" ))
@@ -434,9 +434,9 @@ static int option_parse_recurse_submodules(const struct option *opt,else if (!strcmp (arg,"on-demand" )) *flags |=TRANSPORT_RECURSE_SUBMODULES_ON_DEMAND ;else -die ("bad %s argument: %s" , opt->long_name, arg); +die (_ ("bad %s argument: %s" ), opt->long_name, arg); }else -die ("option %s needs an argument (check|on-demand)" , +die (_ ("option %s needs an argument (check|on-demand)" ), opt->long_name);return 0 ;
transport.c +48 -33
138 lines not on this page · raw message
Signature · 1 line
1.8.2.83.gc99314b