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 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
|
# -*- Makefile -*-
# This file was generated by the i18n leiningen plugin
# Do not edit this file; it will be overwritten the next time you run
# lein i18n init
#
# The locale in which our messages are written, and for which we therefore
# have messages without any further effort
MESSAGE_LOCALE=en
# The name of the package into which the translations bundle will be placed
BUNDLE=puppetlabs.trapperkeeper_metrics
# The list of names of packages covered by the translation bundle;
# by default it contains a single package - the same where the translations
# bundle itself is placed - but this can be overridden - preferably in
# the top level Makefile
PACKAGES?=$(BUNDLE)
LOCALES=$(basename $(notdir $(wildcard locales/*.po)))
BUNDLE_DIR=$(subst .,/,$(BUNDLE))
BUNDLE_FILES=$(patsubst %,resources/$(BUNDLE_DIR)/Messages_%.class,$(MESSAGE_LOCALE) $(LOCALES))
FIND_SOURCES=find src -name \*.clj
# xgettext before 0.19 does not understand --add-location=file. Even CentOS
# 7 ships with an older gettext. We will therefore generate full location
# info on those systems, and only file names where xgettext supports it
LOC_OPT=$(shell xgettext --add-location=file -f - </dev/null >/dev/null 2>&1 && echo --add-location=file || echo --add-location)
LOCALES_CLJ=resources/locales.clj
define LOCALES_CLJ_CONTENTS
{
:locales #{$(patsubst %,"%",$(MESSAGE_LOCALE) $(LOCALES))}
:packages [$(patsubst %,"%",$(PACKAGES))]
:bundle $(patsubst %,"%",$(BUNDLE).Messages)
}
endef
export LOCALES_CLJ_CONTENTS
i18n: msgfmt
# Update locales/messages.pot
update-pot: locales/messages.pot
locales/messages.pot: $(shell $(FIND_SOURCES)) | locales
@tmp=$$(mktemp $@.tmp.XXXX); \
$(FIND_SOURCES) \
| xgettext --from-code=UTF-8 --language=lisp \
--copyright-holder='Puppet <docs@puppet.com>' \
--package-name="$(BUNDLE)" \
--package-version="$(BUNDLE_VERSION)" \
--msgid-bugs-address="docs@puppet.com" \
-k \
-kmark:1 -ki18n/mark:1 \
-ktrs:1 -ki18n/trs:1 \
-ktru:1 -ki18n/tru:1 \
-ktrun:1,2 -ki18n/trun:1,2 \
-ktrsn:1,2 -ki18n/trsn:1,2 \
$(LOC_OPT) \
--add-comments --sort-by-file \
-o $$tmp -f -; \
sed -i.bak -e 's/charset=CHARSET/charset=UTF-8/' $$tmp; \
sed -i.bak -e 's/POT-Creation-Date: [^\\]*/POT-Creation-Date: /' $$tmp; \
rm -f $$tmp.bak; \
if ! diff -q -I POT-Creation-Date $$tmp $@ >/dev/null 2>&1; then \
mv $$tmp $@; \
else \
rm $$tmp; touch $@; \
fi
# Run msgfmt over all .po files to generate Java resource bundles
# and create the locales.clj file
msgfmt: $(BUNDLE_FILES) $(LOCALES_CLJ)
# force rebuild of locales.clj if its contents is not the
# the desired one
ifneq ($(shell cat $(LOCALES_CLJ) 2> /dev/null),$(shell echo '$(subst ','\'',$(LOCALES_CLJ_CONTENTS))'))
.PHONY: $(LOCALES_CLJ)
endif
$(LOCALES_CLJ): | resources
@echo "Writing $@"
@echo "$$LOCALES_CLJ_CONTENTS" > $@
resources/$(BUNDLE_DIR)/Messages_%.class: locales/%.po | resources
msgfmt --java2 -d resources -r $(BUNDLE).Messages -l $(*F) $<
resources/$(BUNDLE_DIR)/Messages_$(MESSAGE_LOCALE).class: locales/messages.pot | resources
msgfmt --java2 -d resources -r $(BUNDLE).Messages -l $(MESSAGE_LOCALE) $<
# Use this to initialize translations. Updating the PO files is done
# automatically through a CI job that utilizes the scripts in the project's
# `bin` file, which themselves come from the `clj-i18n` project.
locales/%.po: | locales
@if [ ! -f $@ ]; then \
touch $@ && msginit --no-translator -l $(*F) -o $@ -i $<; \
fi
resources locales:
@mkdir $@
help:
$(info $(HELP))
@echo
.PHONY: help
define HELP
This Makefile assists in handling i18n related tasks during development. Files
that need to be checked into source control are put into the locales/ directory.
They are
locales/messages.pot - the POT file generated by 'make update-pot'
locales/$$LANG.po - the translations for $$LANG
Only the $$LANG.po files should be edited manually; this is usually done by
translators.
You can use the following targets:
i18n: refresh all the files in locales/ and recompile resources
update-pot: extract strings and update locales/messages.pot
locales/LANG.po: create translations for LANG
msgfmt: compile the translations into Java classes; this step is
needed to make translations available to the Clojure code
and produces Java class files in resources/
endef
# @todo lutter 2015-04-20: for projects that use libraries with their own
# translation, we need to combine all their translations into one big po
# file and then run msgfmt over that so that we only have to deal with one
# resource bundle
|