# -*- Makefile -*-
MOFILES=$(POFILES:.po=.mo)

dist_noinst_DATA += $(POFILES) 	\
	po/bongo.pot 				\
	po/bongo-web.pot 			\
	po/POTFILES.bongo 			\
	po/POTFILES.bongo-web

po/all: update-mo

po/clean: 
	for file in ${MOFILES}; do \
		rm -f $$file; \
	done

po/install: po/all
	for file in $(MOFILES); do \
		lang=`echo $$file | sed -e 's,.*/,,' | sed -e 's/.mo//'`; \
		$(MKINSTALLDIRS) $(DESTDIR)/$(localedir)/$$lang/LC_MESSAGES/; \
		installfilename=`basename $$(dirname $$file)`; \
		$(INSTALL) -m 0644 $$file $(DESTDIR)/$(localedir)/$$lang/LC_MESSAGES/$$installfilename.mo; \
	done

update-pot:
	$(XGETTEXT) --directory=$(srcdir) \
	--add-comments=translators \
	--keyword=_ --keyword=N_ --keyword=M_ \
	--files-from=$(srcdir)/po/POTFILES.bongo \
	--msgid-bugs-address="bongo-devel@gna.org" \
	-o po/bongo.pot
# This is a bit of a hack. Nevertheless, it works, I hope.
	$(XGETTEXT) --directory=$(srcdir) \
	--add-comments=translators \
	--keyword=_ --keyword=N_ --keyword=M_ \
	--files-from=$(srcdir)/po/POTFILES.bongo-web \
	--msgid-bugs-address="bongo-devel@gna.org" \
	-L python \
	-o po/bongo-web.pot

update-mo: ${MOFILES}

update-po: ${POFILES}-update update-mo

%.mo:
	rm -f $@ && $(GMSGFMT) -o $@ $*.po

%.po-update: update-pot
	whichpotfile=`echo $*.po | sed -e 's,po/\([^/]*\)/.*,\1,'`; \
	$(MSGMERGE) $*.po po/$$whichpotfile.pot -o $*.po;
