-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
59 lines (49 loc) · 2.57 KB
/
Makefile
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
# On Mac OS X the PATH variable isn't exported unless "SHELL" is also set.
# See: http://stackoverflow.com/a/25506676
SHELL = /bin/bash
NODE_BINDIR = ./node_modules/.bin
export PATH := $(NODE_BINDIR):$(PATH)
# Where to write the files generated by this makefile.
OUTPUT_DIR = translations
# Source directories.
SRC_DIRS = client lib server
# Available locales for the app.
LOCALES = en_US pt_BR
# Name of the generated .po files for each available locale.
LOCALE_FILES ?= $(patsubst %,$(OUTPUT_DIR)/locale/%/LC_MESSAGES/app.po,$(LOCALES))
GETTEXT_HTML_SOURCES = $(shell find $(SRC_DIRS) -name '*.vue' -o -name '*.html' 2>/dev/null)
GETTEXT_JS_SOURCES = $(shell find $(SRC_DIRS) -name '*.vue' -o -name '*.js' 2>/dev/null)
# Makefile targets.
.PHONY: all makemessages translations clean
all: makemessages translations
makemessages: ./$(OUTPUT_DIR)/template.pot
translations: ./$(OUTPUT_DIR)/translations.json
# Create a main .pot template, then generate .po files for each available language.
# Thanx to Systematic: https://github.com/Polyconseil/systematic/blob/866d5a/mk/main.mk#L167-L183
./$(OUTPUT_DIR)/template.pot: $(GETTEXT_HTML_SOURCES) $(GETTEXT_JS_SOURCES)
# `dir` is a Makefile built-in expansion function which extracts the directory-part of `$@`.
# `$@` is a Makefile automatic variable: the file name of the target of the rule.
# => `mkdir -p /tmp/`
mkdir -p $(dir $@)
which gettext-extract
# Extract gettext strings from templates files and create a POT dictionary template.
gettext-extract --attribute v-translate --quiet --output $@ $(GETTEXT_HTML_SOURCES)
# Extract gettext strings from JavaScript files.
xgettext --language=JavaScript --keyword=npgettext:1c,2,3 \
--from-code=utf-8 --join-existing --no-wrap --sort-output \
--package-name=$(shell node -e "console.log(require('./package.json').name);") \
--package-version=$(shell node -e "console.log(require('./package.json').version);") \
--output $@ $(GETTEXT_JS_SOURCES)
# Generate .po files for each available language.
@for lang in $(LOCALES); do \
export PO_FILE=$(OUTPUT_DIR)/locale/$$lang/LC_MESSAGES/app.po; \
echo "msgmerge --update $$PO_FILE $@"; \
mkdir -p $$(dirname $$PO_FILE); \
[ -f $$PO_FILE ] && msgmerge --lang=$$lang --sort-output --update $$PO_FILE $@ || msginit --no-translator --locale=$$lang --input=$@ --output-file=$$PO_FILE; \
msgattrib --no-wrap --no-obsolete --sort-output -o $$PO_FILE $$PO_FILE; \
done;
$(OUTPUT_DIR)/translations.json: $(LOCALE_FILES)
mkdir -p $(OUTPUT_DIR)
gettext-compile --output $@ $(LOCALE_FILES)
clean:
rm -f $(OUTPUT_DIR)/template.pot $(OUTPUT_DIR)/translations.json