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

[Xen-changelog] [xen-unstable] Fix up locale strings for xm



# HG changeset patch
# User Tom Wilkie <tom.wilkie@xxxxxxxxx>
# Date 1176479201 -3600
# Node ID 66e935c095301b6d3e75c8317fbb71afeff0e513
# Parent  b96df7a4e0a7c875cf9f78b228c5134f0b47de90
Fix up locale strings for xm

Signed-off-by: Daniel P. Berrange <berrange@xxxxxxxxxx>
---
 config/StdGNU.mk              |    1 
 tools/python/Makefile         |   68 +++++++++++++++++++++++++++++++++---------
 tools/python/xen/xm/XenAPI.py |   18 ++++++++++-
 3 files changed, 73 insertions(+), 14 deletions(-)

diff -r b96df7a4e0a7 -r 66e935c09530 config/StdGNU.mk
--- a/config/StdGNU.mk  Mon Apr 16 17:47:37 2007 +0100
+++ b/config/StdGNU.mk  Fri Apr 13 16:46:41 2007 +0100
@@ -10,6 +10,7 @@ OBJDUMP    = $(CROSS_COMPILE)objdump
 OBJDUMP    = $(CROSS_COMPILE)objdump
 
 MSGFMT     = msgfmt
+MSGMERGE   = msgmerge
 
 INSTALL      = install
 INSTALL_DIR  = $(INSTALL) -d -m0755 -p
diff -r b96df7a4e0a7 -r 66e935c09530 tools/python/Makefile
--- a/tools/python/Makefile     Mon Apr 16 17:47:37 2007 +0100
+++ b/tools/python/Makefile     Fri Apr 13 16:46:41 2007 +0100
@@ -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 -r b96df7a4e0a7 -r 66e935c09530 tools/python/xen/xm/XenAPI.py
--- a/tools/python/xen/xm/XenAPI.py     Mon Apr 16 17:47:37 2007 +0100
+++ b/tools/python/xen/xm/XenAPI.py     Fri Apr 13 16:46:41 2007 +0100
@@ -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))

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.