141
|
1 # On OSX the PATH variable isn't exported unless "SHELL" is also set, see: http://stackoverflow.com/a/25506676
|
|
2 SHELL = /bin/bash
|
|
3 NODE_BINDIR = ./node_modules/.bin
|
|
4 export PATH := $(NODE_BINDIR):$(PATH)
|
|
5
|
|
6 # Where to write the files generated by this makefile.
|
|
7 OUTPUT_DIR = src
|
|
8
|
|
9 # Available locales for the app.
|
|
10 LOCALES = de_DE en_GB it_IT
|
|
11
|
|
12 # Name of the generated .po files for each available locale.
|
|
13 LOCALE_FILES ?= $(patsubst %,$(OUTPUT_DIR)/locale/%/LC_MESSAGES/app.po,$(LOCALES))
|
|
14
|
|
15 GETTEXT_HTML_SOURCES = $(shell find $(OUTPUT_DIR) -name '*.vue' -o -name '*.html' 2> /dev/null)
|
|
16 GETTEXT_JS_SOURCES = $(shell find $(OUTPUT_DIR) -name '*.vue' -o -name '*.js')
|
|
17
|
|
18 # Makefile Targets
|
|
19 .PHONY: clean makemessages translations
|
|
20
|
|
21 clean:
|
|
22 rm -f /tmp/template.pot $(OUTPUT_DIR)/translations.json
|
|
23
|
|
24 makemessages: /tmp/template.pot
|
|
25
|
|
26 translations: ./$(OUTPUT_DIR)/translations.json
|
|
27
|
|
28 # Create a main .pot template, then generate .po files for each available language.
|
|
29 # Thanx to Systematic: https://github.com/Polyconseil/systematic/blob/866d5a/mk/main.mk#L167-L183
|
|
30 /tmp/template.pot: $(GETTEXT_HTML_SOURCES)
|
|
31 # `dir` is a Makefile built-in expansion function which extracts the directory-part of `$@`.
|
|
32 # `$@` is a Makefile automatic variable: the file name of the target of the rule.
|
|
33 # => `mkdir -p /tmp/`
|
|
34 mkdir -p $(dir $@)
|
|
35 which gettext-extract
|
|
36 # Extract gettext strings from templates files and create a POT dictionary template.
|
|
37 gettext-extract --attribute v-translate --quiet --output $@ $(GETTEXT_HTML_SOURCES)
|
|
38 # Extract gettext strings from JavaScript files.
|
|
39 xgettext --language=JavaScript --keyword=npgettext:1c,2,3 \
|
|
40 --from-code=utf-8 --join-existing --no-wrap \
|
|
41 --package-name=$(shell node -e "console.log(require('./package.json').name);") \
|
|
42 --package-version=$(shell node -e "console.log(require('./package.json').version);") \
|
|
43 --output $@ $(GETTEXT_JS_SOURCES)
|
|
44 # Generate .po files for each available language.
|
|
45 @for lang in $(LOCALES); do \
|
|
46 export PO_FILE=$(OUTPUT_DIR)/locale/$$lang/LC_MESSAGES/app.po; \
|
|
47 echo "msgmerge --update $$PO_FILE $@"; \
|
|
48 mkdir -p $$(dirname $$PO_FILE); \
|
|
49 [ -f $$PO_FILE ] && msgmerge --lang=$$lang --update $$PO_FILE $@ || msginit --no-translator --locale=$$lang --input=$@ --output-file=$$PO_FILE; \
|
|
50 msgattrib --no-wrap --no-obsolete -o $$PO_FILE $$PO_FILE; \
|
|
51 done;
|
|
52
|
|
53 $(OUTPUT_DIR)/translations.json: clean /tmp/template.pot
|
|
54 mkdir -p $(OUTPUT_DIR)
|
|
55 gettext-compile --output $@ $(LOCALE_FILES)
|