@@ -4,13 +4,13 @@ NODE_BINDIR = ./node_modules/.bin
4
4
export PATH := $(NODE_BINDIR ) :$(PATH )
5
5
6
6
# Where to write the files generated by this makefile.
7
- OUTPUT_DIR = example
7
+ OUTPUT_DIR = dev
8
8
9
9
# Available locales for the app.
10
10
LOCALES = en_GB fr_FR it_IT
11
11
12
12
# Name of the generated .po files for each available locale.
13
- LOCALE_FILES ?= $(patsubst % ,example /locale/% /LC_MESSAGES/app.po,$(LOCALES ) )
13
+ LOCALE_FILES ?= $(patsubst % ,$( OUTPUT_DIR ) /locale/% /LC_MESSAGES/app.po,$(LOCALES ) )
14
14
15
15
GETTEXT_HTML_SOURCES = $(shell find $(OUTPUT_DIR ) -name '* .vue' -o -name '* .html' 2> /dev/null)
16
16
GETTEXT_JS_SOURCES = $(shell find $(OUTPUT_DIR ) -name '* .vue' -o -name '* .js')
@@ -23,25 +23,33 @@ clean:
23
23
24
24
makemessages : /tmp/template.pot
25
25
26
- translations : ./example /translations.json
26
+ translations : ./$( OUTPUT_DIR ) /translations.json
27
27
28
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
29
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/`
30
34
mkdir -p $(dir $@)
31
35
which gettext-extract
36
+ # Extract gettext strings from templates files and create a POT dictionary template.
32
37
gettext-extract --quiet --output $@ $(GETTEXT_HTML_SOURCES)
33
- xgettext --language=JavaScript --keyword=i18n --keyword=npgettext:1c,2,3 \
34
- --from-code=utf-8 --sort-output --join-existing --no-wrap \
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);") \
35
42
--package-version=$(shell node -e "console.log(require('./package.json').version);") \
36
43
--output $@ $(GETTEXT_JS_SOURCES)
44
+ # Generate .po files for each available language.
37
45
@for lang in $(LOCALES); do \
38
46
export PO_FILE=$(OUTPUT_DIR)/locale/$$lang/LC_MESSAGES/app.po; \
39
- echo " msgmerge --sort-output -- update $$ PO_FILE $@ " ; \
47
+ echo "msgmerge --update $$PO_FILE $@"; \
40
48
mkdir -p $$(dirname $$PO_FILE); \
41
- [ -f $$ PO_FILE ] && msgmerge --lang=$$ lang --sort-output -- update $$ PO_FILE $@ || msginit --no-translator --locale=$$ lang --input=$@ -o $$ PO_FILE; \
42
- msgattrib --no-wrap --no-location --no- obsolete -o $$ PO_FILE $$ 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; \
43
51
done;
44
52
45
- $(OUTPUT_DIR ) /translations.json : /tmp/template.pot
53
+ $(OUTPUT_DIR ) /translations.json : clean /tmp/template.pot
46
54
mkdir -p $(OUTPUT_DIR )
47
55
gettext-compile --output $@ $(LOCALE_FILES )
0 commit comments