Debian Codegraph @

po/po-data/Rules-others

raw
1 # Additional make targets
2
3 .NOTPARALLEL:
4 DISTFILES.extra2 = Rules-others Makevars.in
5
6 #-- Compute the rsrc name of a source file, prefix with the act name
7 # if the source is in a storyline subdir
8 # $(1) = source file
9
10 define rsrc_name =
11 rsrc=`basename $(1) | sed -e 's/\..*$$//'`; \
12 actname=`dirname $(1) | grep -o -E "storyline/.*" | sed -E "s,storyline/([^/]*).*,\1-,"`; \
13 rsrc=$$actname$$rsrc
14 endef
15
16 #== Output statistics
17
18 l10n-stats:
19 @catalogs='$(CATALOGS)'; \
20 for cat in $$catalogs; do \
21 lang=`basename $$cat .gmo;`; \
22 stats=`msgfmt --statistics -o /dev/null $$lang.po 2>&1`; \
23 echo " $$lang: $$stats"; \
24 done
25
26 #== List translators
27
28 l10n-translators:
29 @catalogs='$(CATALOGS)'; \
30 for cat in $$catalogs; do \
31 lang=`basename $$cat .gmo;`; \
32 echo " $$lang:"; \
33 sed -n -E "/# Translators/,/msgid/s/# ([^<,]*).*/ \1/p" $$lang.po | tail -n +2 | sort -u; \
34 done
35
36 #== Clean obsolete strings and clear fuzzy flags
37
38 define clean_po =
39 msgattrib $(MSGCAT_OPTIONS) --no-obsolete --clear-fuzzy -o cleaned.po $(1); \
40 if ! cmp -s cleaned.po $(1) ; then \
41 count_obsolete=`grep -c "#~ msgid" $(1)`; \
42 count_fuzzy=`grep -c "#, fuzzy" $(1)`; \
43 echo "Cleaning $(1): $$count_obsolete obsolete entries, $$count_fuzzy fuzzy entries"; \
44 rm $(1) && mv cleaned.po $(1); \
45 else \
46 rm cleaned.po; \
47 fi
48 endef
49
50 l10n-clean:
51 @catalogs='$(CATALOGS)'; \
52 for cat in $$catalogs; do \
53 lang=`basename $$cat .gmo;`; \
54 $(call clean_po,$$lang.po); \
55 done
56
57 #== Regenerate POTFILES.in if the list of source files changed
58 #== (executed before the main update-po rule)
59
60 POTSRCS = $(foreach act, $(POTINCLUDES), -i $(act) $(foreach excl, $(POTEXCLUDES), -x $(act)/$(excl)))
61
62 update-po: update-pot
63 update-pot:
64 @if [ -x $(top_srcdir)/po/update-potfiles ] ; then \
65 $(top_srcdir)/po/update-potfiles $(POTSRCS) > POTFILES.inT ; \
66 if ! cmp -s POTFILES.inT POTFILES.in ; then \
67 rm POTFILES.in && mv POTFILES.inT POTFILES.in; \
68 echo "POTFILES.in updated"; \
69 else \
70 rm POTFILES.inT; \
71 fi; \
72 fi
73
74 #== Auto-install catalogs locally
75
76 update-gmo: stamp-li
77 all: stamp-li
78
79 stamp-li: $(GMOFILES)
80 @$(MAKE) local-install ; \
81 echo "touch stamp-li" && \
82 echo timestamp > stamp-liT && \
83 mv stamp-liT stamp-li
84
85 local-install:
86 @$(mkdir_p) $(top_srcdir)/locale &>/dev/null; \
87 if [ $$? -eq 0 ] ; then \
88 catalogs='$(CATALOGS)'; \
89 for cat in $$catalogs; do \
90 cat=`basename $$cat`; \
91 lang=`echo $$cat | sed -e 's/\.gmo$$//'`; \
92 dir=$(top_srcdir)/locale/$$lang/LC_MESSAGES; \
93 $(mkdir_p) $$dir; \
94 if test -r $$cat; then realcat=$$cat; else realcat=$(srcdir)/$$cat; fi; \
95 $(INSTALL_DATA) $$realcat $$dir/$(DOMAIN).mo; \
96 echo "installing $$realcat as $$dir/$(DOMAIN).mo"; \
97 done; \
98 fi
99
100 .PHONY: local-install update-pot
101
102 #== Transifex synchronization
103
104 CURL = curl
105 TX = tx
106 TXORG = artic-games
107 TXPROJ = freedroid-rpg
108 TXFILES = $(shell grep -v -E "^\#" POTFILES.in)
109 TXPREFIX = data
110 TXPROPS = '{"category":["data"]}'
111 TXCRED = $(shell $(top_srcdir)/po/tx-credentials -t)
112 TXHOST = $(shell $(top_srcdir)/po/tx-credentials -r)
113
114 comma:= ,
115 empty:=
116 space:= $(empty) $(empty)
117 TXLANGS = $(subst $(space),$(comma),$(foreach cata,$(CATALOGS),$(basename $(cata))))
118
119 # Update the transifex potfiles
120 #
121 # The single game's pot file is split into individual pot files (as defined by TXFILES),
122 # and for each individual file:
123 # - if the associated resource is not found in the tx config file:
124 # - the resource is created,
125 # - the pot file is pushed,
126 # - and the category is changed.
127 # - else:
128 # - the pot file is pushed.
129 #
130 # Note: It is not yet possible to define a resource's category using tx-set
131 # (transifex-client version 0.10). We thus directly use the transifex remote
132 # API to change it once the resource has been pushed.
133
134 tx-update: $(DOMAIN).pot
135 @test " $(TXCRED)" = " " \
136 && { \
137 echo "You do not have a Transifex account"; \
138 exit 1; \
139 }; \
140 $(mkdir_p) tx-$(TXPREFIX); \
141 files='$(TXFILES)'; \
142 for file in $$files; do \
143 $(call rsrc_name,$$file); \
144 msggrep $(MSGCAT_OPTIONS) --location=$$file -o tx-$(TXPREFIX)/$$rsrc.pot $(DOMAIN).pot; \
145 if test -r tx-$(TXPREFIX)/$$rsrc.pot; then \
146 if ! $(TX) status $(TXPROJ).$(TXPREFIX)-$$rsrc >/dev/null 2>/dev/null; then \
147 echo "Creating $(TXPREFIX)-$$rsrc"; \
148 $(TX) add --file-filter="tx-$(TXPREFIX)/$$rsrc-<lang>.po" --type=PO --organization=$(TXORG) --project=$(TXPROJ) --resource=$(TXPREFIX)-$$rsrc tx-$(TXPREFIX)/$$rsrc.pot; \
149 if $(TX) push -s $(TXPROJ).$(TXPREFIX)-$$rsrc >/dev/null 2>/dev/null; then \
150 curl_output=`curl --request PATCH \
151 -s -o /dev/null -w "%{http_code}" \
152 --url $(TXHOST)/resources/o%3A$(TXORG)%3Ap%3A$(TXPROJ)%3Ar%3A$(TXPREFIX)-$$rsrc \
153 --header 'Accept: application/vnd.api+json' \
154 --header 'Authorization: Bearer $(TXCRED)' \
155 --header 'Content-Type: application/vnd.api+json' \
156 --data '{ "data": { "attributes": $(TXPROPS), \
157 "id": "o:$(TXORG):p:$(TXPREFIX):r:$(TXPREFIX)-$$rsrc", \
158 "type": "resources" } \
159 }'`; \
160 rtn=$$?; \
161 if test $$rtn -ne 0 -o " $$curl_output" != " 200"; then echo "Warning. Failed to set properties: error code $$curl_output"; fi; \
162 fi; \
163 else \
164 echo "Updating $(TXPREFIX)-$$rsrc"; \
165 $(TX) push -s $(TXPROJ).$(TXPREFIX)-$$rsrc; \
166 fi; \
167 fi; \
168 done; \
169 rm -rf tx-$(TXPREFIX)
170
171 # Pull the translations from transifex.
172 #
173 # For each lang and each individual pot file (as defined by TXFILES):
174 # - the translation is fetched from transifex
175 # - merged into the game's po file of that lang
176 # - merged with the game's pot file (to synchronize comments and file positions)
177 #
178 # Note: the translated strings of a transifex file will override the
179 # translated strings of the game's file.
180
181 tx-pull:
182 @test " $(TXCRED)" = " " \
183 && { \
184 echo "You do not have a Transifex account"; \
185 exit 1; \
186 }; \
187 $(mkdir_p) tx-$(TXPREFIX); \
188 catalogs='$(CATALOGS)'; \
189 files='$(TXFILES)'; \
190 for file in $$files; do \
191 $(call rsrc_name,$$file); \
192 echo "Pulling $$rsrc-<lang>.po from transifex"; \
193 if $(TX) pull -l $(TXLANGS) $(TXPROJ).$(TXPREFIX)-$$rsrc; then \
194 for cat in $$catalogs; do \
195 cat=`basename $$cat`; \
196 lang=`echo $$cat | sed -e 's/\.gmo$$//'`; \
197 if test -r tx-$(TXPREFIX)/$$rsrc-$$lang.po; then \
198 echo "Merging with $$lang.po"; \
199 msgcat $(MSGCAT_OPTIONS) --use-first -o $$lang.po tx-$(TXPREFIX)/$$rsrc-$$lang.po $$lang.po; \
200 else \
201 echo "Nothing to merge"; \
202 fi; \
203 $(MSGMERGE_UPDATE) $(MSGMERGE_OPTIONS) $$lang.po $(DOMAIN).pot; \
204 $(call clean_po,$$lang.po); \
205 done; \
206 fi; \
207 done; \
208 rm -rf tx-$(TXPREFIX)
209
210 # Push the translations to transifex.
211 #
212 # For each lang:
213 # - the game's po file is split into individual po files (as defined by TXFILES)
214 # - for each individual po file:
215 # - the po file is pushed to transifex
216
217 tx-push:
218 @test " $(TXCRED)" = " " \
219 && { \
220 echo "You do not have a Transifex account"; \
221 exit 1; \
222 }; \
223 test -e tx-push-granted \
224 || { \
225 echo "tx-push is a risky command."; \
226 echo "Create a 'tx-push-granted' file if you really want to execute it."; \
227 exit 1; \
228 }; \
229 rm -f tx-push-granted; \
230 $(mkdir_p) tx-$(TXPREFIX); \
231 catalogs='$(CATALOGS)'; \
232 files='$(shell cat POTFILES.in | grep -v -E "^#")'; \
233 for cat in $$catalogs; do \
234 cat=`basename $$cat`; \
235 lang=`echo $$cat | sed -e 's/\.gmo$$//'`; \
236 for file in $$files; do \
237 $(call rsrc_name,$$file); \
238 msggrep $(MSGCAT_OPTIONS) --location=$$file -o tx/$$rsrc-$$lang.po $$lang.po; \
239 echo "Pushing $$rsrc-$$lang.po to transifex"; \
240 $(TX) push -l $$lang -t -r $(TXPROJ).$(TXPREFIX)-$$rsrc; \
241 done; \
242 done; \
243 rm -rf tx-$(TXPREFIX)
244
245 .PHONY: l10n-stats l10n-translators
246 .PHONY: tx-update tx-pull tx-push