Makefile 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. LOGNAME ?= $(shell logname)
  6. # adding the name of the user's login name to the template file, so that
  7. # on a multi-user system several users can run this without interference
  8. TEMPLATE_POT ?= /tmp/template-$(LOGNAME).pot
  9. # Where to find input files (it can be multiple paths).
  10. INPUT_FILES = ./src
  11. # Where to write the files generated by this makefile.
  12. OUTPUT_DIR = ./src
  13. # Available locales for the app.
  14. LOCALES = zh_CN zh_TW en
  15. # Name of the generated .po files for each available locale.
  16. LOCALE_FILES ?= $(patsubst %,$(OUTPUT_DIR)/locale/%/LC_MESSAGES/app.po,$(LOCALES))
  17. GETTEXT_SOURCES ?= $(shell find $(INPUT_FILES) -name '*.jade' -o -name '*.html' -o -name '*.js' -o -name '*.vue' 2> /dev/null)
  18. # Makefile Targets
  19. .PHONY: clean makemessages translations all
  20. all:
  21. @echo choose a target from: clean makemessages translations
  22. clean:
  23. rm -f $(TEMPLATE_POT) $(OUTPUT_DIR)/translations.json
  24. makemessages: $(TEMPLATE_POT)
  25. translations: ./$(OUTPUT_DIR)/translations.json
  26. # Create a main .pot template, then generate .po files for each available language.
  27. # Thanx to Systematic: https://github.com/Polyconseil/systematic/blob/866d5a/mk/main.mk#L167-L183
  28. $(TEMPLATE_POT): $(GETTEXT_SOURCES)
  29. # `dir` is a Makefile built-in expansion function which extracts the directory-part of `$@`.
  30. # `$@` is a Makefile automatic variable: the file name of the target of the rule.
  31. # => `mkdir -p /tmp/`
  32. mkdir -p $(dir $@)
  33. # Extract gettext strings from templates files and create a POT dictionary template.
  34. gettext-extract --quiet --attribute v-translate --output $@ $(GETTEXT_SOURCES)
  35. # Generate .po files for each available language.
  36. @for lang in $(LOCALES); do \
  37. export PO_FILE=$(OUTPUT_DIR)/locale/$$lang/LC_MESSAGES/app.po; \
  38. mkdir -p $$(dirname $$PO_FILE); \
  39. if [ -f $$PO_FILE ]; then \
  40. echo "msgmerge --update $$PO_FILE $@"; \
  41. msgmerge --lang=$$lang --update $$PO_FILE $@ || break ;\
  42. else \
  43. msginit --no-translator --locale=$$lang --input=$@ --output-file=$$PO_FILE || break ; \
  44. msgattrib --no-wrap --no-obsolete -o $$PO_FILE $$PO_FILE || break; \
  45. fi; \
  46. done;
  47. $(OUTPUT_DIR)/translations.json: $(LOCALE_FILES)
  48. mkdir -p $(OUTPUT_DIR)
  49. gettext-compile --output $@ $(LOCALE_FILES)