[PATCH RFC 0/2] Mixing English and a local language

STALE3741d

4 messages, 1 author, 2016-06-15 · open the first message on its own page

[PATCH RFC 0/2] Mixing English and a local language

From: Nguyễn Thái Ngọc Duy <hidden>
Date: 2016-06-15 22:54:34

The l10n effort leads to a situation where a contributor can submit a
patch with some auto-generated information in his language, which may
not be the team's language. We need to make sure exchange medium like
patch is always in a common language that the team understands.

Now this team language may not necessarily be English. However there
are technical difficulties involved in switching between two
languages. The only way I can think of, on top of gettext, is provide
git translations in multiple domains. Say diff machinery uses
"git-diff" domain while the rest is in "git". We can drive gettext to
use language X for diff machinery, and Y for the rest. For that, we
replace gettext() with dgettext().

It's cumbersome. And there has not been any sign that there will be
a real user for it. So I assume that the "team language" will always
be English. It's simpler and should cover 90% of the user base. If
someday people ask for that, supporting it is simply a matter of
rewriting C_() and CQ_() macros in the first patch to use dgettext()
instead.

Switching between a language and English is easier. We just need an
if/else to decide whether to call gettext(). Which is what the first
patch does, just for certain parts of diff machinery. Error messages
will alway be in native language.

The second patch puts format-patch output in English unconditionally.
Again I'm partly lazy and not so sure that there will be needs for
format-patch to produce in native language. If someone needs it, we
can introduce a new config key that flip no_l10n flag back to 0.

More commands may follow format-patch. I think that 'apply' should also
use English for non-tty output, unless users request it to be in local
language. IOW local language is treated pretty much like coloring.

Nguyễn Thái Ngọc Duy (2):
  Allow to print diffstat in English regardless current locale
  format-patch: always print diffstat in English

 builtin/apply.c |  2 +-
 builtin/log.c   |  1 +
 diff.c          | 19 ++++++++++++-------
 diff.h          |  3 ++-
 4 files changed, 16 insertions(+), 9 deletions(-)

-- 
1.7.12.rc1.27.g6d3049b.dirty

[PATCH 1/2] Allow to print diffstat in English regardless current locale

From: Nguyễn Thái Ngọc Duy <hidden>
Date: 2016-06-15 22:54:34

Signed-off-by: Nguyễn Thái Ngọc Duy <redacted>
---
 builtin/apply.c |  2 +-
 diff.c          | 19 ++++++++++++-------
 diff.h          |  2 +-
 3 files changed, 14 insertions(+), 9 deletions(-)
diff --git a/builtin/apply.c b/builtin/apply.c
index d453c83..3f2779f 100644
--- a/builtin/apply.c
+++ b/builtin/apply.c
@@ -3627,7 +3627,7 @@ static void stat_patch_list(struct patch *patch)
 		show_stats(patch);
 	}
 
-	print_stat_summary(stdout, files, adds, dels);
+	print_stat_summary(stdout, 0, files, adds, dels);
 }
 
 static void numstat_patch_list(struct patch *patch)
diff --git a/diff.c b/diff.c
index 95706a5..47d7e50 100644
--- a/diff.c
+++ b/diff.c
@@ -1390,18 +1390,21 @@ static void fill_print_name(struct diffstat_file *file)
 	file->print_name = pname;
 }
 
-int print_stat_summary(FILE *fp, int files, int insertions, int deletions)
+int print_stat_summary(FILE *fp, int no_l10n, int files,
+		       int insertions, int deletions)
 {
+#define C_(s) (no_l10n ? s : _(s))
+#define CQ_(s1, s2, num) (no_l10n ? (num == 1 ? s1 : s2) : Q_(s1, s2, num))
 	struct strbuf sb = STRBUF_INIT;
 	int ret;
 
 	if (!files) {
 		assert(insertions == 0 && deletions == 0);
-		return fprintf(fp, "%s\n", _(" 0 files changed"));
+		return fprintf(fp, "%s\n", C_(" 0 files changed"));
 	}
 
 	strbuf_addf(&sb,
-		    Q_(" %d file changed", " %d files changed", files),
+		    CQ_(" %d file changed", " %d files changed", files),
 		    files);
 
 	/*
@@ -1418,7 +1421,7 @@ int print_stat_summary(FILE *fp, int files, int insertions, int deletions)
 		 * do not translate it.
 		 */
 		strbuf_addf(&sb,
-			    Q_(", %d insertion(+)", ", %d insertions(+)",
+			    CQ_(", %d insertion(+)", ", %d insertions(+)",
 			       insertions),
 			    insertions);
 	}
@@ -1429,7 +1432,7 @@ int print_stat_summary(FILE *fp, int files, int insertions, int deletions)
 		 * do not translate it.
 		 */
 		strbuf_addf(&sb,
-			    Q_(", %d deletion(-)", ", %d deletions(-)",
+			    CQ_(", %d deletion(-)", ", %d deletions(-)",
 			       deletions),
 			    deletions);
 	}
@@ -1437,6 +1440,8 @@ int print_stat_summary(FILE *fp, int files, int insertions, int deletions)
 	ret = fputs(sb.buf, fp);
 	strbuf_release(&sb);
 	return ret;
+#undef C_
+#undef CQ_
 }
 
 static void show_stats(struct diffstat_t *data, struct diff_options *options)
@@ -1682,7 +1687,7 @@ static void show_stats(struct diffstat_t *data, struct diff_options *options)
 		extra_shown = 1;
 	}
 	fprintf(options->file, "%s", line_prefix);
-	print_stat_summary(options->file, total_files, adds, dels);
+	print_stat_summary(options->file, 0, total_files, adds, dels);
 }
 
 static void show_shortstats(struct diffstat_t *data, struct diff_options *options)
@@ -1711,7 +1716,7 @@ static void show_shortstats(struct diffstat_t *data, struct diff_options *option
 				options->output_prefix_data);
 		fprintf(options->file, "%s", msg->buf);
 	}
-	print_stat_summary(options->file, total_files, adds, dels);
+	print_stat_summary(options->file, 0, total_files, adds, dels);
 }
 
 static void show_numstat(struct diffstat_t *data, struct diff_options *options)
diff --git a/diff.h b/diff.h
index e027650..eec79ef 100644
--- a/diff.h
+++ b/diff.h
@@ -329,7 +329,7 @@ extern struct userdiff_driver *get_textconv(struct diff_filespec *one);
 
 extern int parse_rename_score(const char **cp_p);
 
-extern int print_stat_summary(FILE *fp, int files,
+extern int print_stat_summary(FILE *fp, int no_l10n, int files,
 			      int insertions, int deletions);
 
 #endif /* DIFF_H */
-- 
1.7.12.rc1.27.g6d3049b.dirty

[PATCH 2/2] format-patch: always print diffstat in English

From: Nguyễn Thái Ngọc Duy <hidden>
Date: 2016-06-15 22:54:34

Signed-off-by: Nguyễn Thái Ngọc Duy <redacted>
---
 builtin/log.c | 1 +
 diff.c        | 4 ++--
 diff.h        | 1 +
 3 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/builtin/log.c b/builtin/log.c
index ecc2793..62f4b7e 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -1225,6 +1225,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
 
 	/* Always generate a patch */
 	rev.diffopt.output_format |= DIFF_FORMAT_PATCH;
+	rev.diffopt.no_l10n = 1;
 
 	if (!DIFF_OPT_TST(&rev.diffopt, TEXT) && !no_binary_diff)
 		DIFF_OPT_SET(&rev.diffopt, BINARY);
diff --git a/diff.c b/diff.c
index 47d7e50..a20cfcc 100644
--- a/diff.c
+++ b/diff.c
@@ -1687,7 +1687,7 @@ static void show_stats(struct diffstat_t *data, struct diff_options *options)
 		extra_shown = 1;
 	}
 	fprintf(options->file, "%s", line_prefix);
-	print_stat_summary(options->file, 0, total_files, adds, dels);
+	print_stat_summary(options->file, options->no_l10n, total_files, adds, dels);
 }
 
 static void show_shortstats(struct diffstat_t *data, struct diff_options *options)
@@ -1716,7 +1716,7 @@ static void show_shortstats(struct diffstat_t *data, struct diff_options *option
 				options->output_prefix_data);
 		fprintf(options->file, "%s", msg->buf);
 	}
-	print_stat_summary(options->file, 0, total_files, adds, dels);
+	print_stat_summary(options->file, options->no_l10n, total_files, adds, dels);
 }
 
 static void show_numstat(struct diffstat_t *data, struct diff_options *options)
diff --git a/diff.h b/diff.h
index eec79ef..ea4075d 100644
--- a/diff.h
+++ b/diff.h
@@ -125,6 +125,7 @@ struct diff_options {
 	int dirstat_permille;
 	int setup;
 	int abbrev;
+	int no_l10n;
 	const char *prefix;
 	int prefix_length;
 	const char *stat_sep;
-- 
1.7.12.rc1.27.g6d3049b.dirty

Re: [PATCH RFC 0/2] Mixing English and a local language

From: Nguyen Thai Ngoc Duy <hidden>
Date: 2016-06-15 22:54:43

Should I interpret the silence as "I don't care, if you want it, go
for it" or "not acceptable, but no reasons given"? I'd like some form
of it in. Reverting the i18n diffstat patch is the last resort that I
really don't want to do.

On Sun, Aug 26, 2012 at 2:26 AM, Nguyễn Thái Ngọc Duy [off-list ref] wrote:
The l10n effort leads to a situation where a contributor can submit a
patch with some auto-generated information in his language, which may
not be the team's language. We need to make sure exchange medium like
patch is always in a common language that the team understands.

Now this team language may not necessarily be English. However there
are technical difficulties involved in switching between two
languages. The only way I can think of, on top of gettext, is provide
git translations in multiple domains. Say diff machinery uses
"git-diff" domain while the rest is in "git". We can drive gettext to
use language X for diff machinery, and Y for the rest. For that, we
replace gettext() with dgettext().

It's cumbersome. And there has not been any sign that there will be
a real user for it. So I assume that the "team language" will always
be English. It's simpler and should cover 90% of the user base. If
someday people ask for that, supporting it is simply a matter of
rewriting C_() and CQ_() macros in the first patch to use dgettext()
instead.

Switching between a language and English is easier. We just need an
if/else to decide whether to call gettext(). Which is what the first
patch does, just for certain parts of diff machinery. Error messages
will alway be in native language.

The second patch puts format-patch output in English unconditionally.
Again I'm partly lazy and not so sure that there will be needs for
format-patch to produce in native language. If someone needs it, we
can introduce a new config key that flip no_l10n flag back to 0.

More commands may follow format-patch. I think that 'apply' should also
use English for non-tty output, unless users request it to be in local
language. IOW local language is treated pretty much like coloring.

Nguyễn Thái Ngọc Duy (2):
  Allow to print diffstat in English regardless current locale
  format-patch: always print diffstat in English

 builtin/apply.c |  2 +-
 builtin/log.c   |  1 +
 diff.c          | 19 ++++++++++++-------
 diff.h          |  3 ++-
 4 files changed, 16 insertions(+), 9 deletions(-)

--
1.7.12.rc1.27.g6d3049b.dirty


-- 
Duy
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help