ia64/xen-unstable

changeset 14865:66e935c09530

Fix up locale strings for xm

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
author Tom Wilkie <tom.wilkie@gmail.com>
date Fri Apr 13 16:46:41 2007 +0100 (2007-04-13)
parents b96df7a4e0a7
children 8ea56a6141dd
files config/StdGNU.mk tools/python/Makefile tools/python/xen/xm/XenAPI.py
line diff
     1.1 --- a/config/StdGNU.mk	Mon Apr 16 17:47:37 2007 +0100
     1.2 +++ b/config/StdGNU.mk	Fri Apr 13 16:46:41 2007 +0100
     1.3 @@ -10,6 +10,7 @@ OBJCOPY    = $(CROSS_COMPILE)objcopy
     1.4  OBJDUMP    = $(CROSS_COMPILE)objdump
     1.5  
     1.6  MSGFMT     = msgfmt
     1.7 +MSGMERGE   = msgmerge
     1.8  
     1.9  INSTALL      = install
    1.10  INSTALL_DIR  = $(INSTALL) -d -m0755 -p
     2.1 --- a/tools/python/Makefile	Mon Apr 16 17:47:37 2007 +0100
     2.2 +++ b/tools/python/Makefile	Fri Apr 13 16:46:41 2007 +0100
     2.3 @@ -4,17 +4,54 @@ include $(XEN_ROOT)/tools/Rules.mk
     2.4  .PHONY: all
     2.5  all: build
     2.6  
     2.7 -.PHONY: build
     2.8 -build:
     2.9 +# For each new supported translation, add its name here, eg 'fr_FR'
    2.10 +# to cause the .po file to be built & installed, eg
    2.11 +LINGUAS :=
    2.12 +POPACKAGE := xen-xm
    2.13 +PODIR := xen/xm/messages
    2.14 +POTFILE := $(PODIR)/xen-xm.pot
    2.15 +I18NSRCFILES = $(shell find xen/xm/ -name '*.py')
    2.16 +CATALOGS = $(patsubst %,xen/xm/messages/%.mo,$(LINGUAS))
    2.17 +NLSDIR = /usr/share/locale
    2.18 +
    2.19 +.PHONY: build buildpy
    2.20 +buildpy:
    2.21  	CC="$(CC)" CFLAGS="$(CFLAGS)" python setup.py build
    2.22 -	if which $(MSGFMT) >/dev/null ; then \
    2.23 -          for file in `cd ./xen/xm; find messages -name xen-xm.po`; do \
    2.24 -            dest=`echo "build/$$file" | \
    2.25 -                  sed -e 's#xen-xm.po#LC_MESSAGES/xen-xm.mo#'`; \
    2.26 -            mkdir -p `dirname "$$dest"`; \
    2.27 -            $(MSGFMT) -c -o "$$dest" "xen/xm/$$file"; \
    2.28 -          done; \
    2.29 -        fi
    2.30 +
    2.31 +build: buildpy refresh-pot refresh-po $(CATALOGS)
    2.32 +
    2.33 +# NB we take care to only update the .pot file it strings have
    2.34 +# actually changed. This is complicated by the embedded date
    2.35 +# string, hence the sed black magic. This avoids the expensive
    2.36 +# re-generation of .po files on every single build
    2.37 +refresh-pot: $(I18NSRCFILES)
    2.38 +	xgettext --default-domain=$(POPACAKGE) \
    2.39 +		--keyword=N_ \
    2.40 +		--keyword=_ \
    2.41 +		-o $(POTFILE)-tmp \
    2.42 +		$(I18NSRCFILES)
    2.43 +	sed -f remove-potcdate.sed < $(POTFILE) > $(POTFILE)-1
    2.44 +	sed -f remove-potcdate.sed < $(POTFILE)-tmp > $(POTFILE)-2
    2.45 +	if cmp -s $(POTFILE)-1 $(POTFILE)-2; then \
    2.46 +		rm -f $(POTFILE)-tmp $(POTFILE)-1 $(POTFILE)-2; \
    2.47 +	else \
    2.48 +		mv $(POTFILE)-tmp $(POTFILE); \
    2.49 +                rm -f $(POTFILE)-1 $(POTFILE)-2; \
    2.50 +	fi
    2.51 +
    2.52 +refresh-po: $(POTFILE)
    2.53 +	for l in $(LINGUAS); do \
    2.54 +		if $(MSGMERGE) $(PODIR)/$$l.po $(POTFILE) > $(PODIR)/$$l-tmp ; then \
    2.55 +			mv -f $(PODIR)/$$l-tmp $(PODIR)/$$l.po ; \
    2.56 +			echo "$(MSGMERGE) of $$l.po succeeded" ; \
    2.57 +		else \
    2.58 +			echo "$(MSGMERGE) of $$l.po failed" ; \
    2.59 +			rm -f $(PODIR)/$$l-tmp ; \
    2.60 +		fi \
    2.61 +	done
    2.62 +
    2.63 +%.mo: %.po
    2.64 +	$(MSGFMT) -c -o $@ $<
    2.65  
    2.66  .PHONY: install
    2.67  ifndef XEN_PYTHON_NATIVE_INSTALL
    2.68 @@ -28,8 +65,13 @@ endif
    2.69  
    2.70  install-messages: all
    2.71  	if which $(MSGFMT) >/dev/null ; then \
    2.72 -	  mkdir -p "$(DESTDIR)/usr/share/locale"; \
    2.73 -	  cp -R build/messages/* "$(DESTDIR)/usr/share/locale/"; \
    2.74 +		mkdir -p $(DESTDIR)$(NLSDIR); \
    2.75 +		for l in $(LINGUAS); do \
    2.76 +			$(INSTALL) -m 755 -d $(DESTDIR)$(NLSDIR)/$$l; \
    2.77 +			$(INSTALL) -m 755 -d $(DESTDIR)$(NLSDIR)/$$l/LC_MESSAGES; \
    2.78 +			$(INSTALL) -m 644 $(PODIR)/$$l.mo \
    2.79 +				$(DESTDIR)$(NLSDIR)/$$l/LC_MESSAGES/$(POPACKAGE).mo; \
    2.80 +		done ; \
    2.81  	fi
    2.82  
    2.83  .PHONY: test
    2.84 @@ -38,4 +80,4 @@ test:
    2.85  
    2.86  .PHONY: clean
    2.87  clean:
    2.88 -	rm -rf build *.pyc *.pyo *.o *.a *~
    2.89 +	rm -rf build *.pyc *.pyo *.o *.a *~ $(CATALOGS)
     3.1 --- a/tools/python/xen/xm/XenAPI.py	Mon Apr 16 17:47:37 2007 +0100
     3.2 +++ b/tools/python/xen/xm/XenAPI.py	Fri Apr 13 16:46:41 2007 +0100
     3.3 @@ -49,6 +49,22 @@ import xmlrpclib
     3.4  
     3.5  import xen.util.xmlrpcclient as xmlrpcclient
     3.6  
     3.7 +def gettext_noop(str):
     3.8 +    return str
     3.9 +
    3.10 +N_ = gettext_noop
    3.11 +
    3.12 +errormap = {
    3.13 +    "INTERNAL_ERROR": N_("Internal error: %(1)s."),
    3.14 +    "MAP_DUPLICATE_KEY": N_("This map already contains %(1)s -> %(2)s."),
    3.15 +    "MESSAGE_METHOD_UNKNOWN": N_("The method %(1)s is unsupported."),
    3.16 +    "MESSAGE_PARAMETER_COUNT_MISMATCH": N_("The method %(1)s takes %(2)s argument(s) (%(3)s given)."),
    3.17 +    "SESSION_AUTHENTICATION_FAILED": N_("Permission denied."),
    3.18 +    "VALUE_NOT_SUPPORTED": N_("Value \"%(2)s\" for %(1)s is not supported by this server.  The server said \"%(3)s\"."),
    3.19 +    "HANDLE_INVALID": N_("The %(1)s handle %(2)s is invalid."),
    3.20 +    "OPERATION_NOT_ALLOWED": N_("You attempted an operation that was not allowed."),
    3.21 +    "NETWORK_ALREADY_CONNECTED": N_("The network you specified already has a PIF attached to it, and so another one may not be attached."),
    3.22 +    }
    3.23  
    3.24  translation = gettext.translation('xen-xm', fallback = True)
    3.25  
    3.26 @@ -68,7 +84,7 @@ class Failure(Exception):
    3.27  
    3.28      def __str__(self):
    3.29          try:
    3.30 -            return translation.ugettext(self.details[0]) % self._details_map()
    3.31 +            return translation.ugettext(errormap[self.details[0]]) % self._details_map()
    3.32          except TypeError, exn:
    3.33              return "Message database broken: %s.\nXen-API failure: %s" % \
    3.34                     (exn, str(self.details))