git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] Support generate poison .mo files for testing

From
Junio C Hamano <gitster@pobox.com>
Date
Aug 22, 2012, 11:13 UTC
Message-ID
<7vboi3b2n8.fsf@alter.siamese.dyndns.org>
In-Reply-To
<1345613246-4053-1-git-send-email-pclouds@gmail.com>
Nguyễn Thái Ngọc Duy <pclouds@gmail.com> writes:
> test-poisongen does a similar job to gettext poison feature except
> that it does it at build time. Gibberish .mo files are generated for
> all supported langauges and put in po/build/poison-locale. Target
> "poison-locale" is for this.

What is the significance of this locale being "Gibberish"? Currently, for any string, we give "### gettext poison ###" or something but the only thing we care about in the poison mode is that it is different from the message id, no? I was wondering if these phony translations can be something simple like "Add QQ at the beginning of the message id string" and still can catch mistakenly marked messages that come from the plumbing layer, or something.

As you have already written a printf skipper that looks fairly conservative, perhaps I shouldn't be worried too much about it, but we seem to be spending considerable effort on the "poison", and it makes me wonder (even though no better alternative comes to mind) if we could do better. The reason we do "poison" (be it the current one or locale based one) in the first place is so that we want to make sure messages from the plumbing are not marked for i18n, and we do so by running our test under the "poison" mode that produces output different from the in-code text that are marked for i18n, which somehow feels quite a roundabout way of doing so.

> User can run the test with these .mo files by setting POISON_LOCALE
> while running the test suite. User must also set LANG/LC_* correctly
> (and the system is supposed to support that locale).
>  OK let me redo step one. test-poisongen requires libgettextpo. I'm
>  not sure if this library if gnu specific. We may need another flag
>  for it instead of NO_GETTEXT. We don't need a fake language code with
>  this approach.
		
OK.
Show 8 quoted lines
>  Makefile         |  19 ++++++++
>  t/test-lib.sh    |  10 +++-
>  test-poisongen.c | 139 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  wrap-for-bin.sh  |   6 ++-
>  4 files changed, 171 insertions(+), 3 deletions(-)
>  mode change 100644 => 100755 t/test-lib.sh
>  create mode 100644 test-poisongen.c
>  mode change 100644 => 100755 wrap-for-bin.sh
Thanks.  I suspect two mode changes weren't intentional?
Show 30 quoted lines
> +static void translate(const char *msg, struct strbuf *buf)
> +{
> +	const char *end = msg + strlen(msg);
> +	const char *text = "* GETTEXT POISON *";
> +	int text_len = strlen(text);
> +	int t = 0;
> +
> +	strbuf_reset(buf);
> +	/* preserve \n and printf format specifiers because msgfmt
> +	   barfs otherwise. */
> +	while (msg < end) {
> +		/* printf specifiers and shell variables, it's a quite
> +		   relax check */
> +		if ((*msg == '%' || *msg == '$') && msg+1 < end) {
> +			strbuf_addch(buf, *msg++);
> +			do
> +			       strbuf_addch(buf, *msg);
> +			while (msg < end && !isspace(*msg++));
> +		} else if (*msg == '\n') {
> +			/* we only need to preserve trailing newlines, doing
> +			   more does not really harm */
> +			strbuf_addch(buf, '\n');
> +			msg++;
> +		} else {
> +			strbuf_addch(buf, text[t]);
> +			t = (t + 1) % text_len;
> +			msg++;
> +		}
> +	}
> +}
Previous: Nguyễn Thái Ngọc DuyNext: Nguyen Thai Ngoc Duy
Message 5 of 10 in “Build in gettext poison feature unconditionally”
  1. Build in gettext poison feature unconditionallyNguyễn Thái Ngọc Duy, Aug 21, 2012
  2. Jonathan NiederAug 21, 2012
  3. Junio C HamanoAug 21, 2012
  4. Support generate poison .mo files for testingNguyễn Thái Ngọc Duy, Aug 22, 2012
  5. Junio C HamanoAug 22, 2012
  6. Nguyen Thai Ngoc DuyAug 22, 2012
  7. Junio C HamanoAug 22, 2012
  8. Nguyen Thai Ngoc DuyAug 23, 2012
  9. Junio C HamanoAug 22, 2012
  10. Nguyen Thai Ngoc DuyAug 23, 2012

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.