1# written by Markus Neteler
2# tcl stuff by Cedric Shock
3# wxpython by Martin Landa
4
5MODULE_TOPDIR = ..
6include $(MODULE_TOPDIR)/include/Make/Other.make
7
8default:
9	@if [ "$(HAVE_NLS)" != "" ] ; then \
10		echo "Creating translations (= 'make mo')" >&2 ; \
11		$(MAKE) mo ; \
12		echo "Creating translation statistics (= 'make statistics')" >&2 ; \
13		$(MAKE) statistics ; \
14	else \
15		echo "NLS disabled." ; \
16	fi
17
18all:
19	@echo 'Usage:'
20	@echo '   make pot        create grass.pot (containing original messages)'
21	@echo '   make update-po  merge new messages into existing *.po files'
22	@echo '   make mo         create the *.mo files'
23	@echo '   make verify     verify the *.po files'
24
25# Directory for installing tcl .msg files:
26PO_DIR = po
27
28#distinguish between library messages and modules:
29LIBDOMAIN = grasslibs
30MODDOMAIN = grassmods
31WXPYDOMAIN = grasswxpy
32DOMAINS = $(LIBDOMAIN) $(MODDOMAIN) $(WXPYDOMAIN)
33
34LIB_POTFILES = find ../lib \( -name "*.c" -o -name "*.py" \) | xargs grep -l "_(\"\|n_(\""
35MOD_POTFILES = find ../ -name '*.c' | grep -v '../lib' | xargs grep -l "_(\"\|n_(\""
36WXPY_POTFILES = find ../gui/wxpython -name '*.py' | xargs grep -l "_(\"\|n_(\""
37#For Python script module messages
38MOD_PYFILES = find ../scripts -name '*.py' | xargs grep -l "_(\"\|n_(\""
39
40define po_stats
41GISBASE="$(RUN_GISBASE)" $(PYTHON) ./grass_po_stats.py
42endef
43
44#The xgettext utility is used to automate the creation of
45#portable message files (.po)
46pot:
47	if [ ! -f ../gui/wxpython/menustrings.py ] ; then \
48		echo "Build GRASS before running 'make pot'" >&2 ; \
49		exit 1 ; \
50	fi
51	@rm -f ./templates/*.pot
52	@echo "Generating $(LIBDOMAIN)..."
53	xgettext --keyword=_ --keyword=n_:1,2 -cGTC -o ./templates/$(LIBDOMAIN).pot `$(LIB_POTFILES)`
54	@echo "Generating $(MODDOMAIN)..."
55	xgettext --keyword=_ --keyword=n_:1,2 -cGTC -o ./templates/$(MODDOMAIN).pot `$(MOD_POTFILES)`
56	xgettext -j --keyword=_ --keyword=n_:1,2 -cGTC -o ./templates/$(MODDOMAIN).pot `$(MOD_PYFILES)`
57	@echo "Generating $(WXPYDOMAIN)..."
58	xgettext --keyword=_ --keyword=n_:1,2 -cGTC -o ./templates/$(WXPYDOMAIN).pot `$(WXPY_POTFILES)`
59
60#merge already existing translations with new messages in POT template file and create new po files:
61update-po:
62	@for i in $(DOMAINS) ; do \
63		if [ "`ls ./po/$$i\_*.po 2>/dev/null`" = "" ] ; then \
64		 echo "No $$i.po file found in ./po/ directory. Will create new po files from template." ; \
65		 cp ./templates/$$i.pot ./po/$$i.po ; \
66		 echo "Created ./po/$$i.po - Rename to ./po/$$i\_LANG.po (with LANG: de, ru, ...)" ; \
67		 echo "Then you can translate the messages in this file (e.g with kbabel)" ; \
68		fi ;\
69	done
70	@cd ./po/ ; for po in `ls *_*.po 2>/dev/null` ; do \
71		suffix=`echo $$po | cut -d'_' -f2-`; \
72		lingua=`basename $$suffix .po`; \
73		prefix=`echo $$po | cut -d'_' -f1`; \
74		if msgmerge -o $$prefix\_$$suffix.new $$prefix\_$$suffix ../templates/$$prefix.pot; then\
75		  mv $$prefix\_$$suffix.new $$prefix\_$$suffix; \
76		  echo "Merged new messages into $$prefix\_$$suffix" ; \
77		else \
78		    echo "Merging failed"; \
79		fi \
80		done
81	@echo "Be careful with git commits as .po file updates must be synchronized with the individual translators."
82
83verify:
84	@cd ./po/ ; for po in `ls *_*.po 2>/dev/null` ; do \
85		echo "----- $$po:" ; \
86		msgfmt -c $$po; \
87	done
88	@rm -f po/messages.mo
89	@echo "Note: In case of translations errors to be fixed, edit the respective translation on transifex (and not in git)"
90
91statistics:
92	$(call po_stats)
93
94define dom_rule
95$(1)_FILES := $$(patsubst po/grass$(1)_%.po,$$(MO_DIR)/%/LC_MESSAGES/grass$(1).mo,$$(wildcard po/grass$(1)_*.po))
96$$(MO_DIR)/%/LC_MESSAGES/grass$(1).mo: po/grass$(1)_%.po
97	@ [ -d $$(MO_DIR)/$$*/LC_MESSAGES ] || $(MKDIR) $$(MO_DIR)/$$*/LC_MESSAGES
98	msgfmt --statistics -o $$@ $$<
99endef
100$(foreach domain,libs mods wxpy,$(eval $(call dom_rule,$(domain))))
101
102$(MSG_DIR)/%.msg: po/grasstcl_%.po
103	@ [ -d $(MSG_DIR) ] || $(MKDIR) $(MSG_DIR)
104	msgfmt --statistics --tcl -l $* -d $(MSG_DIR)/ $<
105
106MSGFILES := $(patsubst po/grasstcl_%.po,$(MSG_DIR)/%.msg,$(wildcard po/grasstcl_*.po))
107
108#create binary messages files
109mo: $(libs_FILES) $(mods_FILES) $(wxpy_FILES) $(MSGFILES)
110
111.PHONY: mo
112