1
0

Makefile 2.4 KB

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