[PATCH] i18n: extract strings with xgettext

Martin Geisler mg at daimi.au.dk
Sun Jan 25 14:32:25 CST 2009


# HG changeset patch
# User Martin Geisler <mg at daimi.au.dk>
# Date 1232915514 -3600
# Node ID 88326ee85a1b701960a9f93c4820c3d20860874d
# Parent  752325f2208d4279a4fc892adddd1bfbc61b0ad1
i18n: extract strings with xgettext

The xgettext program knows about Python string formatting and will
mark messages with a special "#, python-format" comment in the hg.pot
file. When msgfmt compiles the file, it can check these messages to
ensure that the translated string uses the same conversion specifiers
as the original string.

The pygettext program is still used to extract the docstrings.

diff --git a/Makefile b/Makefile
--- a/Makefile
+++ b/Makefile
@@ -77,11 +77,17 @@
 
 update-pot:
 	mkdir -p i18n
-	pygettext -d doc -p i18n --docstrings \
-	mercurial/commands.py hgext/*.py hgext/*/__init__.py
-	pygettext -d all -p i18n mercurial hgext doc
-	msgcat --sort-by-file i18n/doc.pot i18n/all.pot > i18n/hg.pot
-	rm i18n/doc.pot i18n/all.pot
+	pygettext -d hg -p i18n --docstrings \
+	  mercurial/commands.py hgext/*.py hgext/*/__init__.py
+        # All strings marked for translation in Mercurial contain
+        # ASCII characters only. But some files contain string
+        # literals like this '\037\213'. xgettext thinks it has to
+        # parse these them even though they are not marked for
+        # translation. Extracting with an explicit encoding of
+        # ISO-8859-1 will make xgettext "parse" and ignore them.
+	find mercurial hgext doc -name '*.py' | xargs \
+	  xgettext --from-code ISO-8859-1 --join --sort-by-file \
+	  -d hg -p i18n -o hg.pot
 
 .PHONY: help all local build doc clean install install-bin install-doc \
 	install-home install-home-bin install-home-doc dist dist-notests tests \


More information about the Mercurial-devel mailing list