jw-pkg/make/gettext.mk
Jan Lindemann 185fe85ac0 gettext.mk: Add support for multiple .po and .pot files
Up to now, generating and installing gettext .mo files worked
for exactly one .po file. Now all files in the directory are
compiled by default.

Editing only targets $(PROJECT).po, though, so this works
as before.

Signed-off-by: Jan Lindemann <jan@janware.com>
2018-11-13 13:51:28 +00:00

72 lines
2.2 KiB
Makefile

GETTEXT_LOCALE ?= $(notdir $(shell $(PWD)))
include $(MODDIR)/make/defs.mk
include $(MODDIR)/make/rules.mk
GETTEXT_PROJECT_PO ?= $(PROJECT).po
GETTEXT_PROJECT_POT ?= $(PROJECT).pot
GETTEXT_PO ?= $(wildcard *.po)
GETTEXT_POT ?= $(patsubst %.po,%.pot,$(GETTEXT_PO))
GETTEXT_MO ?= $(patsubst %.po,%.mo,$(GETTEXT_PO))
GETTEXT_INPUT_DIRS ?= $(wildcard $(TOPDIR)/tools $(TOPDIR)/src $(TOPDIR)/conf)
GETTEXT_INPUT_FILES ?= $(foreach d,$(GETTEXT_INPUT_DIRS),\
$(shell find $d -name '*.php' -o -name '*.cpp' -o -name '*.conf'))
GETTEXT_KEYWORDS ?= htr ehtr
all: $(GETTEXT_MO)
clean: clean-mo
$(RM) -rf *~ .*.swp
install: install_MO
distclean: clean
extract: $(GETTEXT_POT)
clean-mo:
$(RM) -f *.mo *.tmp
$(GETTEXT_PROJECT_POT): $(GETTEXT_INPUT_FILES)
xgettext --from-code=utf-8 --package-name $(PROJECT) --package-version $(DIST_VERSION) \
--default-domain $(PROJECT) $(addprefix -k,$(GETTEXT_KEYWORDS)) \
--output $@.tmp $(XGETTEXT_EXTRA_OPTS) $(GETTEXT_INPUT_FILES)
mv $@.tmp $@
init: $(GETTEXT_PROJECT_POT)
msginit --no-translator --locale $(GETTEXT_LOCALE) \
--output-file $(GETTEXT_POJECT_PO).tmp --input $<
sed -i 's/charset=ASCII/charset=UTF-8/' $(GETTEXT_PROJECT_PO).tmp
mv $(GETTEXT_PROJECT_PO).tmp $(GETTEXT_PROJECT_PO)
merge: $(GETTEXT_PROJECT_POT)
msgmerge -v --lang $(GETTEXT_LOCALE) --output-file $(GETTEXT_PROJECT_PO).tmp \
$(wildcard $(GETTEXT_PROJECT_PO)) $<
mv $(GETTEXT_PROJECT_PO).tmp $(GETTEXT_PROJECT_PO)
edit: merge $(GETTEXT_PROJECT_POT)
poedit $(GETTEXT_PROJECT_PO)
%.mo: %.po
msgfmt --check --verbose --output-file $@.tmp $<
mv $@.tmp $@
#msginit --no-translator --locale es_MX --output-file $(PROJECT)_spanish.po --input $(PROJECT).pot
#sed --in-place $(PROJECT)_spanish.po --expression='/"hello, world!"/,/#: / s/""/"hola mundo"/'
#mkdir --parents ./es_MX.utf8/LC_MESSAGES
#msgfmt --check --verbose --output-file ./es_MX.utf8/LC_MESSAGES/$(PROJECT).mo $(PROJECT)_spanish.po
GETTEXT_TMP = $(patsubst %.php,%.htr,$(GETTEXT_PREPROCESS))
GETTEXT_INPUT_FILES += $(GETTEXT_TMP)
all: htr
clean: htr-tmp-clean
htr: $(GETTEXT_TMP)
htr-tmp-clean:
$(RM) -f *.htr
define copy_rule
./%.htr.tmp: $(1)/%.php
cp $$< $$@
endef
$(foreach d, $(HTR_SOURCE_DIRS), $(eval $(call copy_rule,$(d))))