aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--config/StdGNU.mk1
-rw-r--r--tools/python/Makefile68
-rw-r--r--tools/python/xen/xm/XenAPI.py18
3 files changed, 73 insertions, 14 deletions
diff --git a/config/StdGNU.mk b/config/StdGNU.mk
index fd7bc53a56..4f08ea9a30 100644
--- a/config/StdGNU.mk
+++ b/config/StdGNU.mk
@@ -10,6 +10,7 @@ OBJCOPY = $(CROSS_COMPILE)objcopy
OBJDUMP = $(CROSS_COMPILE)objdump
MSGFMT = msgfmt
+MSGMERGE = msgmerge
INSTALL = install
INSTALL_DIR = $(INSTALL) -d -m0755 -p
diff --git a/tools/python/Makefile b/tools/python/Makefile
index ae4254c6e6..309c815352 100644
--- a/tools/python/Makefile
+++ b/tools/python/Makefile
@@ -4,17 +4,54 @@ include $(XEN_ROOT)/tools/Rules.mk
.PHONY: all
all: build
-.PHONY: build
-build:
+# For each new supported translation, add its name here, eg 'fr_FR'
+# to cause the .po file to be built & installed, eg
+LINGUAS :=
+POPACKAGE := xen-xm
+PODIR := xen/xm/messages
+POTFILE := $(PODIR)/xen-xm.pot
+I18NSRCFILES = $(shell find xen/xm/ -name '*.py')
+CATALOGS = $(patsubst %,xen/xm/messages/%.mo,$(LINGUAS))
+NLSDIR = /usr/share/locale
+
+.PHONY: build buildpy
+buildpy:
CC="$(CC)" CFLAGS="$(CFLAGS)" python setup.py build
- if which $(MSGFMT) >/dev/null ; then \
- for file in `cd ./xen/xm; find messages -name xen-xm.po`; do \
- dest=`echo "build/$$file" | \
- sed -e 's#xen-xm.po#LC_MESSAGES/xen-xm.mo#'`; \
- mkdir -p `dirname "$$dest"`; \
- $(MSGFMT) -c -o "$$dest" "xen/xm/$$file"; \
- done; \
- fi
+
+build: buildpy refresh-pot refresh-po $(CATALOGS)
+
+# NB we take care to only update the .pot file it strings have
+# actually changed. This is complicated by the embedded date
+# string, hence the sed black magic. This avoids the expensive
+# re-generation of .po files on every single build
+refresh-pot: $(I18NSRCFILES)
+ xgettext --default-domain=$(POPACAKGE) \
+ --keyword=N_ \
+ --keyword=_ \
+ -o $(POTFILE)-tmp \
+ $(I18NSRCFILES)
+ sed -f remove-potcdate.sed < $(POTFILE) > $(POTFILE)-1
+ sed -f remove-potcdate.sed < $(POTFILE)-tmp > $(POTFILE)-2
+ if cmp -s $(POTFILE)-1 $(POTFILE)-2; then \
+ rm -f $(POTFILE)-tmp $(POTFILE)-1 $(POTFILE)-2; \
+ else \
+ mv $(POTFILE)-tmp $(POTFILE); \
+ rm -f $(POTFILE)-1 $(POTFILE)-2; \
+ fi
+
+refresh-po: $(POTFILE)
+ for l in $(LINGUAS); do \
+ if $(MSGMERGE) $(PODIR)/$$l.po $(POTFILE) > $(PODIR)/$$l-tmp ; then \
+ mv -f $(PODIR)/$$l-tmp $(PODIR)/$$l.po ; \
+ echo "$(MSGMERGE) of $$l.po succeeded" ; \
+ else \
+ echo "$(MSGMERGE) of $$l.po failed" ; \
+ rm -f $(PODIR)/$$l-tmp ; \
+ fi \
+ done
+
+%.mo: %.po
+ $(MSGFMT) -c -o $@ $<
.PHONY: install
ifndef XEN_PYTHON_NATIVE_INSTALL
@@ -28,8 +65,13 @@ endif
install-messages: all
if which $(MSGFMT) >/dev/null ; then \
- mkdir -p "$(DESTDIR)/usr/share/locale"; \
- cp -R build/messages/* "$(DESTDIR)/usr/share/locale/"; \
+ mkdir -p $(DESTDIR)$(NLSDIR); \
+ for l in $(LINGUAS); do \
+ $(INSTALL) -m 755 -d $(DESTDIR)$(NLSDIR)/$$l; \
+ $(INSTALL) -m 755 -d $(DESTDIR)$(NLSDIR)/$$l/LC_MESSAGES; \
+ $(INSTALL) -m 644 $(PODIR)/$$l.mo \
+ $(DESTDIR)$(NLSDIR)/$$l/LC_MESSAGES/$(POPACKAGE).mo; \
+ done ; \
fi
.PHONY: test
@@ -38,4 +80,4 @@ test:
.PHONY: clean
clean:
- rm -rf build *.pyc *.pyo *.o *.a *~
+ rm -rf build *.pyc *.pyo *.o *.a *~ $(CATALOGS)
diff --git a/tools/python/xen/xm/XenAPI.py b/tools/python/xen/xm/XenAPI.py
index 74be43cbb3..a3717d70f2 100644
--- a/tools/python/xen/xm/XenAPI.py
+++ b/tools/python/xen/xm/XenAPI.py
@@ -49,6 +49,22 @@ import xmlrpclib
import xen.util.xmlrpcclient as xmlrpcclient
+def gettext_noop(str):
+ return str
+
+N_ = gettext_noop
+
+errormap = {
+ "INTERNAL_ERROR": N_("Internal error: %(1)s."),
+ "MAP_DUPLICATE_KEY": N_("This map already contains %(1)s -> %(2)s."),
+ "MESSAGE_METHOD_UNKNOWN": N_("The method %(1)s is unsupported."),
+ "MESSAGE_PARAMETER_COUNT_MISMATCH": N_("The method %(1)s takes %(2)s argument(s) (%(3)s given)."),
+ "SESSION_AUTHENTICATION_FAILED": N_("Permission denied."),
+ "VALUE_NOT_SUPPORTED": N_("Value \"%(2)s\" for %(1)s is not supported by this server. The server said \"%(3)s\"."),
+ "HANDLE_INVALID": N_("The %(1)s handle %(2)s is invalid."),
+ "OPERATION_NOT_ALLOWED": N_("You attempted an operation that was not allowed."),
+ "NETWORK_ALREADY_CONNECTED": N_("The network you specified already has a PIF attached to it, and so another one may not be attached."),
+ }
translation = gettext.translation('xen-xm', fallback = True)
@@ -68,7 +84,7 @@ class Failure(Exception):
def __str__(self):
try:
- return translation.ugettext(self.details[0]) % self._details_map()
+ return translation.ugettext(errormap[self.details[0]]) % self._details_map()
except TypeError, exn:
return "Message database broken: %s.\nXen-API failure: %s" % \
(exn, str(self.details))