summaryrefslogtreecommitdiff
path: root/makefiles/gmake/i18n.mk
blob: 08a29e4618093d46566168b9050b2e5f08900982 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# handle localization stuff (gettext)
# (this follows roughly the way Postgresql handles NLS)
#
# requires:
# - CATALOG_NAME: name of the catalog (name of the library or program)
#                 will be installed as $(CATALOG_NAME).po in the localedir
# - GETTEXT_LANGUAGES: list of languages supported
# - GETTEXT_FILES: list of source files that contain message strings
# - GETTEXT_TRIGGERS: (optional) list of functions/macros that contain
#                     translatable strings
#
# provides:
# - target: init-po
# - target: merge-po
# - taget: check-po
# - target: install_po
# - target: uninstall_po

.PHONY: init-po update-po all_po clean_po install_po uninstall_po

ifeq "$(ENABLE_NLS)" "1"

PO_FILES = $(addprefix po/, $(addsuffix .po, $(GETTEXT_LANGUAGES)))
MO_FILES = $(addprefix po/, $(addsuffix .mo, $(GETTEXT_LANGUAGES)))

%.mo : %.po
	$(MSGFMT) -c -o $@ $<

po/$(CATALOG_NAME).pot: $(GETTEXT_FILES)
	$(XGETTEXT) -n -F -d $(CATALOG_NAME) -o $@ \
		$(addprefix -k, $(GETTEXT_TRIGGERS)) --flag=_:1:pass-c-format \
		-d $(CATALOG_NAME) -n -F $(GETTEXT_FILES)

ifneq "$(GETTEXT_FILES)" ""
init-po: po/$(CATALOG_NAME).pot
else
init-po:
endif

ifneq "$(GETTEXT_FILES)" ""
merge-po: po/$(CATALOG_NAME).pot
	@test -z "$(GETTEXT_LANGUAGES)" || \
		for lang in $(GETTEXT_LANGUAGES)""; do ( \
			echo "merging po/$$lang.mo and $<.." && \
			if $(MSGMERGE) -F -o po/$$lang.po.new po/$$lang.po $<; then \
				cp po/$$lang.po po/$$lang.po.bak && \
				mv po/$$lang.po.new po/$$lang.po; \
			else \
				echo "Please check, msgmerge for po/$$lang.po failed!"; \
				rm -f po/$$lang.po.new; \
			fi \
		) done
else
merge-po:
endif

check-po: $(PO_FILES)
	@test -z "$^" || \
		for file in $^""; do ( \
			echo "checking gettext file $$file of catalog $(CATALOG_NAME).." && \
			$(MSGFMT) -c -v -o /dev/null $$file || exit 1 \
		) done

clean_po:
	@-rm -f $(MO_FILES) 2>/dev/null
	@-rm -f po/$(CATALOG_NAME).pot 2>/dev/null
	@-rm -f po/*.bak 2>/dev/null
	@-rm -f po/*~ 2>/dev/null

# hooks for the standard targets handling gettext stuff

all_po: $(MO_FILES)

install_po:
	@test -z "$(GETTEXT_LANGUAGES)" || \
		for lang in $(GETTEXT_LANGUAGES)""; do ( \
			echo "installing po/$$lang.mo to $(localedir)/$$lang/LC_MESSAGES.." && \
			$(INSTALL) -d -m 755 $(localedir)/$$lang/LC_MESSAGES && \
			$(INSTALL) -m 644 po/$$lang.mo $(localedir)/$$lang/LC_MESSAGES/$(CATALOG_NAME).mo || exit 1 \
		) done

uninstall_po:
	@test -z "$(GETTEXT_LANGUAGES)" || \
		for lang in $(GETTEXT_LANGUAGES)""; do ( \
			echo "uninstalling $(localedir)/$$lang/LC_MESSAGES.." && \
			rm $(localedir)/$$lang/LC_MESSAGES/$(CATALOG_NAME).mo && \
			rmdir $(localedir)/$$lang/LC_MESSAGES || exit 1 \
		) done

else

# No NLS supported wanted, provide dummy targets

init-po:
merge-po:
check-po:

all_po:
clean_po:
install_po:
uninstall_po:

endif