# # Definition of common Makefile tasks for PO merging and MO generation. # # Run make help to list available targets # define DOMAIN_CMD require "rubygems"; require "hammer_cli"; HammerCLI::Settings.load_from_defaults; HammerCLI::Modules.load_all; spec = Gem::Specification::load(Dir.glob("../*.gemspec").first); i18n_domain = spec.respond_to?(:metadata) && spec.metadata["i18n_domain"]; puts i18n_domain || HammerCLI::I18n.find_by_name(spec.name)&.domain_name || spec.name endef ifeq ($(origin DOMAIN), undefined) DOMAIN := $(shell bundle exec ruby -e '$(DOMAIN_CMD)') endif VERSION = $(shell ruby -rrubygems -e 'puts Gem::Specification::load(Dir.glob("../*.gemspec").first).version') POTFILE = $(DOMAIN).pot MOFILE = $(DOMAIN).mo POFILES = $(shell find . -name '$(DOMAIN).po') MOFILES = $(patsubst %.po,%.mo,$(POFILES)) POXFILES = $(patsubst %.po,%.pox,$(POFILES)) EDITFILES = $(patsubst %.po,%.edit.po,$(POFILES)) TIMESTAMPFILES = $(patsubst %.po,%.po.time_stamp,$(POFILES)) .PHONY: vars vars: @echo VERSION: $(VERSION) @echo DOMAIN: $(DOMAIN) .PHONY: all-mo all-mo: ## Generate MO files from PO files (default) for po_file in $(POFILES); do \ mkdir -p $$(dirname $$po_file)/LC_MESSAGES; \ msgfmt -o $$(dirname $$po_file)/LC_MESSAGES/$(MOFILE) $$po_file; \ done # Check for malformed strings %.pox: %.po @command -v pofilter >/dev/null 2>&1 || { echo "Command pofilter not found. Make sure you have translate-toolkit installed." >&2; exit 1; } msgfmt -c $< pofilter --nofuzzy -t variables -t blank -t urls -t emails -t long -t newlines \ -t endwhitespace -t endpunc -t puncspacing -t options -t printf -t validchars --gnome $< > $@; cat $@ ! grep -q msgid $@ .PHONY: check check: $(POXFILES) ## Check translations using translate-tool, run make with -k to skip errors and execute for all languages .PHONY: uniq-po uniq-po: ## Unify duplicate translations in .po files for f in $(shell find ./ -name "*.po") ; do \ msguniq $$f -o $$f ; \ done %.edit.po: touch $@ # Pull translaions from transifex .PHONY: tx-pull tx-pull: $(EDITFILES) @command -v tx >/dev/null 2>&1 || { echo "Command tx not found. Make sure you have transifex-client installed and configured." >&2; exit 1; } cd .. && tx pull -f for f in $(EDITFILES); do \ sed -i 's/^\("Project-Id-Version: \).*$$/\1$(DOMAIN) $(VERSION)\\n"/' $$f; \ done # Merge .edit.po into .po .PHONY: update-po update-po: for f in $(EDITFILES); do \ msgcat --use-first --no-location $$f $${f//.edit/} > $${f//.edit/}; \ done # Extract strings and update the .pot, prepare .edit.po files .PHONY: extract-strings extract-strings: bundle exec rake gettext:find # Check languages with 50% or more coverage and create needed files .PHONY: find-new find-new: bundle exec rake gettext:find_new .PHONY: tx-update tx-update: find-new extract-strings tx-pull update-po all-mo ## Download and merge translations from Transifex git add ../locale git commit -m "i18n - extracting new, pulling from tx" @echo Changes commited! .PHONY: clean clean: ## Clean everything, removes *.edit.po, *.po.timestamp and *.pox files rm -f $(EDITFILES) $(TIMESTAMPFILES) $(POXFILES) .PHONY: help help: ## This help message @echo -e "$$(grep -hE '^\S+:.*##' $(MAKEFILE_LIST) | sed -e 's/:.*##\s*/:/' -e 's/^\(.\+\):\(.*\)/\\x1b[36m\1\\x1b[m:\2/' | column -c2 -t -s :)"