Debian Codegraph @

po/l10n-others/Makefile.am

raw
1 # The localized files handled here are not based on .po/.mo getext files.
2 # We generate one whole file per language, in a <lang> subdir.
3 # However, this Makefile implements the standard gettext rules, to be
4 # compatible with the main po/ Makefile.
5
6 .NOTPARALLEL:
7
8 update-pot:
9 tx-push:
10
11 EXTRA_DIST = LINGUAS Makevars
12
13 .PHONY: update-pot update-po update-gmo
14 .PHONY: l10n-stats l10n-translators
15 .PHONY: tx-update tx-pull tx-push
16
17 #== Output statistics
18
19 l10n-stats:
20 @echo " Not yet implemented."
21
22 #== List translators
23
24 l10n-translators:
25 @echo " Not yet implemented."
26
27 #== Clean obsolete strings
28
29 l10n-clean:
30 @echo " Not yet implemented."
31
32 #== Transifex synchronization - Shared functions definition
33
34 CURL = curl
35 TX = tx
36 TXORG = artic-games
37 TXPROJ = freedroid-rpg
38 TXPREFIX = other
39 TXPROPS = '{"category":["other"]}'
40 TXCRED = $(shell $(top_srcdir)/po/tx-credentials -t)
41 TXHOST = $(shell $(top_srcdir)/po/tx-credentials -r)
42
43 LANGS = $(shell tail -n +2 $(srcdir)/LINGUAS)
44 comma:= ,
45 empty:=
46 space:= $(empty) $(empty)
47 TXLANGS = $(subst $(space),$(comma),$(LANGS))
48
49
50 #-- Update tx rsrc
51 # $(1) = rsrc name
52 # $(2) = rsrc file
53
54 define rsrc_update =
55 if ! $(TX) status $(TXPROJ).$(1) >/dev/null 2>/dev/null; then \
56 echo "Creating $(1)"; \
57 $(TX) add --file-filter="tx-$(TXPREFIX)/$(1)-<lang>.txt" --type=TXT --organization=$(TXORG) --resource=$(1) $(2); \
58 if $(TX) push -s $(TXPROJ).$(1) >/dev/null 2>/dev/null; then \
59 curl_output=`$(CURL) --request PATCH \
60 -s -o /dev/null -w "%{http_code}" \
61 --url $(TXHOST)/resources/o%3A$(TXORG)%3Ap%3A$(TXPROJ)%3Ar%3A$(1) \
62 --header 'Accept: application/vnd.api+json' \
63 --header 'Authorization: Bearer $(TXCRED)' \
64 --header 'Content-Type: application/vnd.api+json' \
65 --data '{ "data": { "attributes": $(TXPROPS), \
66 "id": "o:$(TXORG):p:$(TXPREFIX):r:$(1)", \
67 "type": "resources" } \
68 }'`; \
69 rtn=$$?; \
70 if test $$rtn -ne 0 -o " $$curl_output" != " 200"; then echo "Warning. Failed to set properties: error code $$curl_output"; fi; \
71 fi; \
72 else \
73 echo "Updating $(1)"; \
74 $(TX) push -s $(TXPROJ).$(1); \
75 fi
76 endef
77
78 #-- Pull a translated rsrc
79 #-- If the translated rsrc does not contain any translated string, we remove it
80 #-- Note: TX does not correctly handle last blank lines and the last newline.
81 #-- So we add the possibly missing newline with a 'sed' script and do not
82 #-- take blank lines into account to compare files.
83 # $(1) = rsrc name
84 # $(2) = lang
85
86 define rsrc_pull =
87 echo "Pulling $(1)-<lang> from transifex"; \
88 $(TX) pull -l $(TXLANGS) $(TXPROJ).$(1); \
89 for lang in $(LANGS); do \
90 sed -i -e '$$a\' tx-$(TXPREFIX)/$(1)-$$lang.txt; \
91 if diff -q --ignore-blank-lines tx-$(TXPREFIX)/$(1).txt tx-$(TXPREFIX)/$(1)-$$lang.txt >/dev/null; then \
92 echo " no translated strings: removing"; \
93 rm tx-$(TXPREFIX)/$(1)-$$lang.txt; \
94 fi; \
95 done
96 endef
97
98 #-- Copy src file to dest file if src and dest are different
99 #-- (this avoid to change dest file timestamp if src and dest are identicals)
100 # $(1) = src file
101 # $(2) = dest file
102
103 define copy_on_diff =
104 if ! cmp -s $(1) $(2) ; then \
105 rm -f $(2) && mv $(1) $(2); \
106 echo "$(2) updated"; \
107 else \
108 rm $(1); \
109 fi
110 endef
111
112 #== l10n of fdrpg title files
113
114 TITLES_DIR = $(top_srcdir)/data/base/titles $(top_srcdir)/data/storyline/act1/titles $(top_srcdir)/data/storyline/act2/titles
115
116 # Extract "<act_name>-" from $(1), given $(1) contains 'storyline/<act_name>'
117 act_name = $(shell dirname $(1) | grep -o -E "storyline/.*" | sed -E "s,storyline/([^/]*).*,\1-,")
118 # Extract the file basename, without extension, from $(1)
119 src_basename = $(basename $(notdir $(1)))
120 # Generate 'title-<act_name>-<file_basename>' from $(1), without extension
121 rsrc_full_name = title-$(call act_name,$(1))$(call src_basename,$(1))
122 # Insert $(2) before the filename in $(1) [dir/subdir/name.ext -> dir/subdir/$(2)/name.ext]
123 l10n_name = $(dir $(1))$(2)/$(notdir $(1))
124
125 TITLES_POTSRC = $(wildcard $(addsuffix /*.lua, $(TITLES_DIR)))
126 TITLES_RSRC = $(foreach potsrc,$(TITLES_POTSRC),$(call rsrc_full_name,$(potsrc)))
127 TITLES_TX = $(TITLES_RSRC:%=tx-$(TXPREFIX)/%.txt)
128 TITLES_L10N = $(foreach lang,$(LANGS),$(foreach potsrc,$(TITLES_POTSRC),$(call l10n_name,$(potsrc),$(lang))))
129
130 #-- Create a TX rsrc by extracting the text part of a title
131 # $(1) = source file name
132
133 define update-po-title =
134 tx-$(TXPREFIX)/$(call rsrc_full_name,$(1)).txt: $(1)
135 @$(mkdir_p) tx-$(TXPREFIX); \
136 $(AWK) "BEGIN { isintext=0; } /^text[[:space:]]*=[[:space:]]*[\[]+/ { isintext=1; next; } /^[\]]+/ { exit; } isintext == 1 { print; }" $$< > $$@
137 endef
138
139 $(foreach potsrc,$(TITLES_POTSRC),$(eval $(call update-po-title,$(potsrc))))
140
141 #-- Merge a l10n version of a title's text with the title's header,
142 #-- and copy the result to data/storyline/act1/titles
143 #-- Note: $(wildcard) if used so that an empty prerequisite list is generated if
144 #-- the translation file does not exist
145 # $(1) = pot name
146 # $(2) = lang
147
148 define update-gmo-title =
149 $(call l10n_name,$(1),$(2)): $(wildcard tx-$(TXPREFIX)/$(call rsrc_full_name,$(1))-$(2).txt)
150 @if test -r tx-$(TXPREFIX)/$(call rsrc_full_name,$(1))-$(2).txt ; then \
151 $(mkdir_p) $(dir $(1))$(2); \
152 $(AWK) "/^text[[:space:]]*=[[:space:]]*[\[]+/ { print; nextfile; } { print; } END { print \"]]\"; print \"}\"; }" \
153 $(1) $$< > $$<.tmp; \
154 $(call copy_on_diff,$$<.tmp,$$@); \
155 fi
156 endef
157
158 $(foreach lang,$(LANGS),\
159 $(foreach potsrc,$(TITLES_POTSRC),\
160 $(eval $(call update-gmo-title,$(potsrc),$(lang)))))
161
162 #-- update-po creates the new tx/title-<title name>.txt files
163
164 update-po:: $(TITLES_TX)
165
166 #-- Push all title rsrcs to TX
167
168 tx-update:: $(TITLES_TX)
169 @if [ " $(TXCRED)" = " " ] ; then \
170 echo "You do not have a Transifex account"; \
171 exit 1; \
172 fi
173 @for rsrc in $(TITLES_RSRC); do \
174 $(call rsrc_update,$$rsrc,tx-$(TXPREFIX)/$$rsrc.txt); \
175 done
176
177 #-- Pull all l10n versions of the titles' text from TX
178
179 tx-pull:: $(TITLES_TX)
180 @if [ " $(TXCRED)" = " " ] ; then \
181 echo "You do not have a Transifex account"; \
182 exit 1; \
183 fi
184 @for rsrc in $(TITLES_RSRC); do \
185 $(call rsrc_pull,$$rsrc); \
186 done
187
188 #-- update-gmo creates the new l10n version of the titles
189
190 update-gmo:: $(TITLES_L10N)
191
192 #== l10n of the main README
193
194 README_DIR = $(top_srcdir)
195 README_RSRC = README
196 README_TX = tx-$(TXPREFIX)/README.txt
197 README_L10N = $(foreach lang,$(LANGS),$(README_RSRC:%=$(README_DIR)/README-$(lang)))
198
199 #-- Copy the README into the tx/ subdir
200
201 tx-$(TXPREFIX)/README.txt: $(README_DIR)/README
202 @$(mkdir_p) tx-$(TXPREFIX); \
203 cp $< $@
204
205
206 #-- Put localized versions in place
207 # $(1) = lang
208
209 define update-gmo-readme =
210 $(README_DIR)/README-$(1): $(wildcard tx-$(TXPREFIX)/README-$(1).txt)
211 @if test -r tx-$(TXPREFIX)/README-$(1).txt ; then \
212 cp $$< $$<.tmp; \
213 $(call copy_on_diff,$$<.tmp,$$@); \
214 fi
215 endef
216
217 $(foreach lang,$(LANGS),\
218 $(eval $(call update-gmo-readme,$(lang))))
219
220 #-- update-po creates the new tx/README.txt files
221
222 update-po:: $(README_TX)
223
224 #-- Push the README rsrc to TX
225
226 tx-update:: $(README_TX)
227 @if [ " $(TXCRED)" = " " ] ; then \
228 echo "You do not have a Transifex account"; \
229 exit 1; \
230 fi
231 @$(call rsrc_update,README,tx-$(TXPREFIX)/README.txt)
232
233 #-- Pull all l10n versions of the README from TX
234
235 tx-pull:: $(README_TX)
236 @if [ " $(TXCRED)" = " " ] ; then \
237 echo "You do not have a Transifex account"; \
238 exit 1; \
239 fi
240 @$(call rsrc_pull,README)
241
242 #-- update-gmo creates the new l10n version of the README
243
244 update-gmo:: $(README_L10N)
245
246 all: update-gmo