Re: [PATCH 03/65] i18n: archive: mark parseopt strings for translation

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, May 30, 2012 at 01:24:24AM -0500, Jonathan Nieder wrote:
> Nguyen Thai Ngoc Duy wrote:
> 
> >                             Or generate a poisoned .mo file, then make
> > git use that.
> 
> Yes, I would like that very much.  I had vague ideas of using some
> valid language code that doesn't correspond to a human language, but
> an alternate GIT_TEXTDOMAINDIR might be simpler and work better.

We're half way there with the following PoC patch. Now if only I could
trick gettext into accepting a fake language like "foo". Right now
"vi" is the sacrified one

$ make po/build/locale/vi/LC_MESSAGES/git.mo
$ GIT_TEXTDOMAINDIR=po/build/locale ./git st -abc
error: unknown switch `a'
.................................................

    -v, --verbose         ..........
    -s, --short           .....................
    -b, --branch          .......................
    --porcelain           .......................
    -z, --null            ..........................
    -u, --untracked-files[=<....>]
                          .....................................................................
    --ignored             ..................
    --ignore-submodules[=<....>]
                          ..................................................................................
    --column[=<.....>]    list untracked files in columns

We also need to improve the shredder to recognize shell variables,
then we can turn on GETTEXT_LOG_UNTRANSLATED to catch i18n messages
that are not marked

-- 8< --
diff --git a/Makefile b/Makefile
index 96ebcf9..cd55650 100644
--- a/Makefile
+++ b/Makefile
@@ -2345,6 +2345,18 @@ LOCALIZED_SH += t/t0200/test.sh
 LOCALIZED_PERL += t/t0200/test.perl
 endif
 
+shredder: shredder.c
+	$(QUIET_CC)$(CC) -o $@ $^
+
+po/build/locale/vi/LC_MESSAGES/git.mo: $(LOCALIZED_C) shredder
+	mkdir -p `dirname $@`
+	$(QUIET_XGETTEXT)$(XGETTEXT) -o$@+ $(XGETTEXT_FLAGS_C) $(LOCALIZED_C)
+	$(QUIET_XGETTEXT)$(XGETTEXT) -o$@+ --join-existing $(XGETTEXT_FLAGS_SH) \
+		$(LOCALIZED_SH)
+	$(QUIET_XGETTEXT)$(XGETTEXT) -o$@+ --join-existing $(XGETTEXT_FLAGS_PERL) \
+		$(LOCALIZED_PERL)
+	msgen $@+|sed 's/charset=CHARSET/charset=utf-8/'|sed '/^#, fuzzy/d'|msgfilter ./shredder|msgfmt -o $@ -
+
 po/git.pot: $(LOCALIZED_C)
 	$(QUIET_XGETTEXT)$(XGETTEXT) -o$@+ $(XGETTEXT_FLAGS_C) $(LOCALIZED_C)
 	$(QUIET_XGETTEXT)$(XGETTEXT) -o$@+ --join-existing $(XGETTEXT_FLAGS_SH) \
diff --git a/shredder.c b/shredder.c
new file mode 100644
index 0000000..ea12c10
--- /dev/null
+++ b/shredder.c
@@ -0,0 +1,62 @@
+#include <stdio.h>
+#include <string.h>
+
+static const char *header =
+"Project-Id-Version: git.git\n"
+"Report-Msgid-Bugs-To: Git Mailing List <git@xxxxxxxxxxxxxxx>\n"
+"POT-Creation-Date: 2012-05-15 06:42+0800\n"
+"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
+"Last-Translator: 2012-05-15 06:42+0800\n"
+"Language-Team: gettext poison <gettext@xxxxxxxxxx>\n"
+"Language: poison\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=utf-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+"Plural-Forms: nplurals=2; plural=nr != 1;\n";
+
+static int is_fmt = 0;
+static int shred(int ch)
+{
+	const char *terminators = "diouxXeEfFgGaAcsp%";
+	if (is_fmt && strchr(terminators, ch))
+		is_fmt = 0;
+	else if (!is_fmt && isprint(ch)) {
+		if (ch == '%')
+			is_fmt = 1;
+		else
+			ch = '.';
+	}
+	return ch;
+}
+
+int main(int ac, char **av)
+{
+	const char *first_msg = "Project-Id-Version: ";
+	char buf[32];
+	int gotten = 0, len = strlen(first_msg);
+	int ch;
+	while ((ch = fgetc(stdin)) != EOF)
+	{
+		if (gotten < len) {
+			buf[gotten++] = ch;
+			if (gotten == len) {
+				if (!strncmp(first_msg, buf, len)) {
+					fputs(header, stdout);
+					return 0;
+				} else {
+					int i;
+					for (i = 0; i < len; i++)
+						putchar(shred(buf[i]));
+				}
+			}
+			continue;
+		}
+		putchar(shred(ch));
+	}
+	if (gotten < len) {
+		int i;
+		for (i = 0; i < gotten; i++)
+			putchar(shred(buf[i]));
+	}
+	return 0;
+}
-- 8< --
-- 
Duy
--
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


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]