-
Notifications
You must be signed in to change notification settings - Fork 4
/
build_dita2translate_template.xml
327 lines (284 loc) · 9.07 KB
/
build_dita2translate_template.xml
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
<?xml version="1.0" encoding="UTF-8"?>
<!--
This file is part of the DITA Translate project.
See the accompanying LICENSE file for applicable licenses.
-->
<project
xmlns:dita="http://dita-ot.sourceforge.net"
xmlns:if="ant:if"
xmlns:unless="ant:unless"
name="fox.jason.translate.xliff"
>
<!--
Pre-processing for all XLIFF operations, ensure that we have
an XMLCatalog and set property defaults.
-->
<target name="xliff.init">
<!-- This defines the output file -->
<dita-ot-fail id="DOTA069F">
<condition>
<not>
<available file="${args.input}" type="file"/>
</not>
</condition>
<param name="1" value="${args.input}"/>
</dita-ot-fail>
<dirname property="args.input.dir" file="${args.input}"/>
<taskdef resource="fox/jason/translate/antlib.xml"/>
<taskdef classname="com.oopsconsultancy.xmltask.ant.XmlTask" name="xmltask">
<classpath>
<pathelement location="${dita.plugin.fox.jason.translate.xliff.dir}/lib/xmltask.jar"/>
</classpath>
</taskdef>
<property
name="translate.customization.dir"
value="${dita.plugin.fox.jason.translate.xliff.dir}/xsl"
/>
<property
name="translate.resource.dir"
value="${dita.plugin.fox.jason.translate.xliff.dir}/resource"
/>
<xmlcatalog id="fake.dita.catalog">
<dtd
publicId="-//OASIS//DTD DITA Topic//EN"
location="${translate.resource.dir}/fake.dtd"
/>
<dtd
publicId="-//OASIS//DTD DITA Map//EN"
location="${translate.resource.dir}/fake.dtd"
/>
<dtd
publicId="-//OASIS//DTD DITA BookMap//EN"
location="${translate.resource.dir}/fake.dtd"
/>
<dtd
publicId="-//OASIS//DTD DITA DITAVAL//EN"
location="${translate.resource.dir}/fake.dtd"
/>
<dtd
publicId="-//OASIS//DTD DITA Concept//EN"
location="${translate.resource.dir}/fake.dtd"
/>
<dtd
publicId="-//OASIS//DTD DITA Task//EN"
location="${translate.resource.dir}/fake.dtd"
/>
<catalogpath path="${dita.plugin.org.dita.base.dir}/catalog-dita.xml"/>
</xmlcatalog>
<!-- Load Service URLs from command line -->
<load-service-urls/>
</target>
<!--
Pre processing for translation operations, ensure that
we have some processing dirs in temp
-->
<target name="trans-unit.init" depends="xliff.init">
<mkdir dir="${dita.temp.dir}/stage1"/>
<mkdir dir="${dita.temp.dir}/stage2"/>
<mkdir dir="${dita.temp.dir}/stage3"/>
</target>
<target name="translate.init" depends="trans-unit.init">
<dita-ot-fail id="XLFF003F" if:set="translate.watson">
<condition>
<equals arg1="${watson.apikey}" arg2="XXX"/>
</condition>
</dita-ot-fail>
<dita-ot-fail id="XLFF004F" if:set="translate.bing">
<condition>
<equals arg1="${bing.apikey}" arg2="XXX"/>
</condition>
</dita-ot-fail>
<dita-ot-fail id="XLFF006F" if:set="translate.deepl">
<condition>
<equals arg1="${deepl.apikey}" arg2="XXX"/>
</condition>
</dita-ot-fail>
<dita-ot-fail id="XLFF007F" if:set="translate.yandex">
<condition>
<equals arg1="${yandex.apikey}" arg2="XXX"/>
</condition>
</dita-ot-fail>
<bing-authorization if:set="translate.bing"/>
</target>
<!--
Extract an XLIFF File and skeleton files from DITA
-->
<target
name="xliff-create"
description="Extract an XLIFF File and skeleton files from DITA"
>
<!-- Add a unique md5 id to each dita element containing text -->
<xslt
taskname="md5-src-gen"
destdir="${dita.temp.dir}/md5"
extension=".dita.xml"
style="${translate.customization.dir}/add-md5-src.xsl"
basedir="${args.input.dir}"
includes="*.dita,**/*.dita"
>
<xmlcatalog refid="fake.dita.catalog"/>
</xslt>
<!-- Add a unique md5 id to each ditamap element containing text -->
<xslt
taskname="md5-src-gen"
destdir="${dita.temp.dir}/md5"
extension=".ditamap.xml"
style="${translate.customization.dir}/add-md5-src.xsl"
basedir="${args.input.dir}"
includes="*.ditamap,**/*.ditamap"
>
<xmlcatalog refid="fake.dita.catalog"/>
</xslt>
<!-- Generate the skeleton files -->
<xslt
taskname="skeleton-gen"
destdir="${output.dir}/skl"
extension=".skl"
style="${translate.customization.dir}/dita2skeleton.xsl"
basedir="${dita.temp.dir}/md5"
>
<xmlcatalog refid="fake.dita.catalog"/>
<param expression="${translate.to}" name="TARGET_LANG"/>
</xslt>
<!-- For all generated skeletons, reinsert doc type. -->
<fileset id="skl.contents.all" dir="${output.dir}/skl" casesensitive="yes">
<include name="**/*.dita.skl"/>
<include name="**/*.ditamap.skl"/>
</fileset>
<reinsert-doctypes refid="skl.contents.all" dir="${output.dir}/skl"/>
<!-- DITA skeleton files without translatable texts -->
<restrict id="skl.contents.no-translate">
<fileset refid="skl.contents.all"/>
<not>
<contains text="@@@"/>
</not>
</restrict>
<!-- DITA skeleton files with translatable texts -->
<restrict id="skl.contents">
<fileset refid="skl.contents.all"/>
<contains text="@@@"/>
</restrict>
<!-- revert renamng of untranslated DITA files only -->
<move todir="${output.dir}/skl">
<restrict refid="skl.contents.no-translate"/>
<globmapper from="*.skl" to="*"/>
</move>
<!-- Copy over images and other untranslated sources -->
<copy todir="${output.dir}/skl" overwrite="true">
<fileset dir="${args.input.dir}">
<exclude name="**/*.dita"/>
<exclude name="**/*.ditamap"/>
</fileset>
</copy>
<!-- Fallback - load from and to langs from properties file -->
<property
file="${dita.plugin.fox.jason.translate.xliff.dir}/cfg/configuration.properties"
/>
<!-- Fallback - dummy cache file -->
<tempfile
unless:set="translate.cachefile"
deleteonexit="true"
destdir="${dita.temp.dir}"
property="dummy.translate.cachefile"
suffix=".xml"
/>
<echo
unless:set="translate.cachefile"
file="${dummy.translate.cachefile}"
message="<root/>"
/>
<!--
Generate a series of XLIFF files iterating each unique
md5 id
-->
<xslt
taskname="xliff-gen"
destdir="${dita.temp.dir}/xliff"
extension=".xlf.xml"
style="${translate.customization.dir}/${xliff.version}/dita-xliff.xsl"
basedir="${dita.temp.dir}/md5"
>
<xmlcatalog refid="fake.dita.catalog"/>
<param expression="${dita.temp.dir}/md5" name="SOURCE"/>
<param expression="${dita.temp.dir}/skl" name="SKELETON"/>
<param expression="${translate.from}" name="SOURCE_LANG"/>
<param expression="${translate.to}" name="TARGET_LANG"/>
<param
if:set="translate.cachefile"
expression="${translate.cachefile}"
name="TRANS_CACHE"
/>
<param
unless:set="translate.cachefile"
expression="${dummy.translate.cachefile}"
name="TRANS_CACHE"
/>
<fileset dir="${dita.temp.dir}/md5">
<include name="**/*.dita"/>
<include name="**/*.ditamap"/>
</fileset>
</xslt>
<!-- Merge the XLIFF files into one larger file -->
<xslt
taskname="xliff-merge"
force="true"
in="${translate.customization.dir}/${xliff.version}/xliff-merge.xsl"
out="${output.dir}/translate.xlf"
style="${translate.customization.dir}/${xliff.version}/xliff-merge.xsl"
>
<xmlcatalog refid="fake.dita.catalog"/>
<param expression="${dita.temp.dir}/xliff/" name="in"/>
<param expression="${dita.temp.dir}/md5" name="SOURCE"/>
<param expression="${dita.temp.dir}/skl" name="SKELETON"/>
<param expression="${translate.from}" name="SOURCE_LANG"/>
<param expression="${translate.to}" name="TARGET_LANG"/>
</xslt>
<replace file="${output.dir}/translate.xlf" token="xmlns=""" value=""/>
</target>
<!--
Take an untranslated XLIFF File and request translations
of the source into the specified target langauge.
-->
<target
name="xliff-translate"
description="Auto-translate an XLIFF File using an online service">
<get-translations xliff="${args.input}"/>
</target>
<target
name="xliff-dita"
description="Supply translated text into DITA skeleton files using an XLIFF File">
<skeleton-prepare xliff="${args.input}"/>
<!-- Replace the placeholders in the skeleton files -->
<fileset id="translated.dita" dir="${dita.temp.dir}/stage2" casesensitive="yes">
<include name="**/*.xml"/>
</fileset>
<skeleton-files src="translated.dita" dir="${dita.temp.dir}/stage2"/>
</target>
<target
dita:extension="depends org.dita.dost.platform.InsertDependsAction"
name="dita2xliff-create"
dita:depends="{depend.preprocess.pre},
build-init,
xliff.init,
{depend.preprocess.post},
xliff-create"
/>
<target
dita:extension="depends org.dita.dost.platform.InsertDependsAction"
name="dita2xliff-translate"
dita:depends="{depend.preprocess.pre},
build-init,
translate.init,
{depend.preprocess.post},
xliff-translate"
/>
<target
dita:extension="depends org.dita.dost.platform.InsertDependsAction"
name="dita2xliff-dita"
dita:depends="{depend.preprocess.pre},
build-init,
trans-unit.init,
{depend.preprocess.post},
xliff-dita"
/>
</project>