File: Makefile.i18n

package info (click to toggle)
trapperkeeper-status-clojure 1.1.1-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 356 kB
  • sloc: sh: 71; makefile: 34; xml: 10
file content (136 lines) | stat: -rw-r--r-- 6,227 bytes parent folder | download | duplicates (3)
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
129
130
131
132
133
134
135
136
# -*- 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 name of the package into which the translations bundle will be placed
BUNDLE=puppetlabs.trapperkeeper_status

# The name of the POT file into which the gettext code strings (msgid) will be placed
POT_NAME=trapperkeeper-status.pot

# 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,$(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 %,"%",$(LOCALES))}
  :packages [$(patsubst %,"%",$(PACKAGES))]
  :bundle   $(patsubst %,"%",$(BUNDLE).Messages)
}
endef
export LOCALES_CLJ_CONTENTS


i18n: msgfmt

# Update locales/<project-name>.pot
update-pot: locales/$(POT_NAME)

locales/$(POT_NAME): $(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) clean-orphaned-bundles

# Force rebuild of locales.clj if its contents is not the the desired one. The
# shell echo is used to add a trailing newline to match the one from `cat`
ifneq ($(shell cat $(LOCALES_CLJ) 2> /dev/null),$(shell echo '$(LOCALES_CLJ_CONTENTS)'))
.PHONY: $(LOCALES_CLJ)
endif
$(LOCALES_CLJ): | resources
	@echo "Writing $@"
	@echo "$$LOCALES_CLJ_CONTENTS" > $@

# Remove every resource bundle that wasn't generated from a PO file.
# We do this because we used to generate the english bundle directly from the POT.
.PHONY: clean-orphaned-bundles
clean-orphaned-bundles:
	@for bundle in resources/$(BUNDLE_DIR)/Messages_*.class; do                                  \
	  locale=$$(basename "$$bundle" | sed -E -e 's/\$$?1?\.class$$/_class/' | cut -d '_' -f 2;); \
	  if [ ! -f "locales/$$locale.po" ]; then                                                    \
	    rm "$$bundle";                                                                           \
	  fi                                                                                         \
	done

resources/$(BUNDLE_DIR)/Messages_%.class: locales/%.po | resources
	msgfmt --java2 -d resources -r $(BUNDLE).Messages -l $(*F) $<

# 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 locales/$(POT_NAME); \
	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/$(POT_NAME)   - 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/$(POT_NAME)
  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