forked from thebuggenie/thebuggenie
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.xml
340 lines (287 loc) · 16 KB
/
build.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
328
329
330
331
332
333
334
335
336
337
338
339
340
<?xml version="1.0" ?>
<project name="thebuggenie" basedir="." default="build">
<!-- ============================================ -->
<!-- Run settings -->
<!-- ============================================ -->
<property name="isMacOrUnix" value="false" />
<condition property="isMacOrUnix">
<or>
<os family="mac" />
<os family="Unix" />
</or>
</condition>
<!-- ============================================ -->
<!-- Directory settings -->
<!-- ============================================ -->
<property name="projectDir" value="."/>
<property name="localesDir" value="${projectDir}/i18n"/>
<!-- ============================================ -->
<!-- Files name settings -->
<!-- ============================================ -->
<property name="po_file_name" value="messages.po"/>
<property name="po_file_backup_name" value="messages_old.po"/>
<property name="ts_file_name" value="strings.inc.ts"/>
<property name="ts_file_backup_name" value="strings._bak_.ts"/>
<property name="strings_file_name" value="strings.inc.php"/>
<property name="strings_file_backup_name" value="strings._bak_.php"/>
<!-- ============================================ -->
<!-- Locale settings -->
<!-- ============================================ -->
<property name="base_locale" value="en_US"/>
<!-- ================================================================= -->
<!-- Path to gettext tools binaries -->
<!-- For Windows systems, download gettext from the following site: -->
<!-- http://gnuwin32.sourceforge.net/packages/gettext.htm -->
<!-- Install or Unpack the package, and add its /bin directory to PATH -->
<!-- or specify the /bin directory path in toolsDir property. -->
<!-- ================================================================= -->
<property name="xgettext_executable" value="xgettext"/>
<property name="msgmerge_executable" value="msgmerge"/>
<property name="xgettext_keyword" value="__" description="Name of the i18n function"/>
<!-- ============================================ -->
<!-- Fileset for gettext tools -->
<!-- ============================================ -->
<fileset dir="${projectDir}" id="files_to_process">
<patternset id="gettext_files_pattern" description="Include all PHP sources, except Test cases">
<include name="**/*.php"/>
<include name="**/*.inc"/>
<include name="**/*.lib"/>
<exclude name="**/*Test*"/>
<exclude name="**/*Phing*"/>
</patternset>
</fileset>
<!-- ============================================ -->
<!-- Lists of translations -->
<!-- ============================================ -->
<fileset dir="${localesDir}" id="locales_list">
<type type="dir"/>
<depth min="0" max="0"/>
<include name="**"/>
<exclude name="_tools"/>
</fileset>
<!-- ============================================ -->
<!-- Target: clean -->
<!-- ============================================ -->
<target name="clean" description="Cleans the build directory">
<echo msg="Removing old translation files (po only)..."/>
<if>
<equals arg1="${usePlainMessages}" arg2="N" casesensitive="false" trim="true"/>
<then>
<delete failonerror="false" file="${localesDir}/${po_file_name}" quiet="true"/>
</then>
</if>
<foreach param="current_locale_po" absparam="current_locale_abs" target="remove_translation">
<fileset refid="locales_list"/>
</foreach>
<echo msg="Old translation files removed..."/>
</target>
<!-- ============================================ -->
<!-- Target: remove_translation -->
<!-- ============================================ -->
<target name="remove_translation" description="Removes outdates translation file (.po only)" hidden="true">
<echo msg="Deleting old translation files in ${current_locale_array}"/>
<delete failonerror="false" file="${current_locale_abs}/${po_file_name}" quiet="true"/>
<delete failonerror="false" file="${current_locale_abs}/${po_file_backup_name}" quiet="true"/>
<delete failonerror="false" file="${current_locale_abs}/${ts_file_backup_name}" quiet="true"/>
<delete failonerror="false" file="${current_locale_abs}/${strings_file_backup_name}" quiet="true"/>
</target>
<!-- ============================================ -->
<!-- Target: prepare -->
<!-- ============================================ -->
<target name="prepare" description="Creates build directory and structure">
<echo msg="Creating a backup from previous translations..."/>
<if>
<equals arg1="${generateOnlyForDefaultLanguage}" arg2="Y" casesensitive="false" trim="true"/>
<then>
<property name="current_locale_abs" value="${localesDir}/${base_locale}"/>
<property name="current_locale_array" value="${base_locale}"/>
<phingcall target="generate_po_from_array"/>
</then>
<else>
<foreach param="current_locale_array" absparam="current_locale_abs" target="generate_po_from_array">
<fileset refid="locales_list"/>
</foreach>
</else>
</if>
<echo msg="Backups created successfully..."/>
</target>
<!-- ============================================ -->
<!-- Target: generate_po_from_array -->
<!-- ============================================ -->
<target name="generate_po_from_array" description="Generate PO files from strings.inc.php file" hidden="true">
<if>
<available file="${current_locale_abs}" property="localeFileExists" value="true"/>
<then>
<echo msg="${current_locale_array} locale extists, generating PO file from array..."/>
<exec dir="${localesDir}"
command="php -f ./_tools/convert_to_po.php ./${current_locale_array}/ ${strings_file_name} ${po_file_backup_name}"/>
</then>
</if>
</target>
<!-- ============================================ -->
<!-- Target: generate_translate -->
<!-- ============================================ -->
<target name="generate_translate" description="Generates gettext files for all PHP sources" hidden="true">
<if>
<available file="${localesDir}/${po_file_name}" property="existingPoFile" value="true"/>
<then>
<echo msg="PO file already exists, dont need to rebuild it..."/>
</then>
<else>
<echo msg="Generating new ${po_file_name} file from the project"/>
<foreach param="gettext_file" absparam="gettext_file_abs" target="gettext_translate">
<fileset refid="files_to_process"/>
</foreach>
</else>
</if>
</target>
<!-- ============================================ -->
<!-- Target: gettext_translate -->
<!-- ============================================ -->
<target name="gettext_translate" hidden="true">
<if>
<available file="${localesDir}/${po_file_name}" property="existingPoFile" value="true"/>
<then>
<echo msg="${tools_dir}${xgettext_executable} --from-code=UTF-8 --no-wrap --keyword=${xgettext_keyword} --keyword -n -j -F ${gettext_file_abs} -o ${localesDir}/${po_file_name}"/>
<exec dir="${project.basedir}"
command="${tools_dir}${xgettext_executable} --from-code=UTF-8 --no-wrap --keyword=${xgettext_keyword} --keyword -n -j -F ${gettext_file_abs} -o ${localesDir}/${po_file_name}"
logoutput="true"/>
</then>
<else>
<echo msg="${tools_dir}${xgettext_executable} --from-code=UTF-8 --no-wrap --keyword=${xgettext_keyword} --keyword -n -F ${gettext_file_abs} -o ${localesDir}/${po_file_name}"/>
<exec dir="${project.basedir}"
command="${tools_dir}${xgettext_executable} --from-code=UTF-8 --no-wrap --keyword=${xgettext_keyword} --keyword -n -F ${gettext_file_abs} -o ${localesDir}/${po_file_name}"
logoutput="true"/>
</else>
</if>
</target>
<!-- ============================================ -->
<!-- Target: merge_translations -->
<!-- ============================================ -->
<target name="merge_translations" description="Merge old .po files with the new messages.po">
<echo msg="Merging old locales with the new messages.po ..."/>
<if>
<equals arg1="${generateOnlyForDefaultLanguage}" arg2="Y" casesensitive="false" trim="true"/>
<then>
<property name="current_locale_abs" value="${localesDir}/${base_locale}"/>
<property name="current_locale_array" value="${base_locale}"/>
<phingcall target="merge_translation"/>
</then>
<else>
<foreach param="current_locale_array" absparam="current_locale_abs" target="merge_translation">
<fileset refid="locales_list"/>
</foreach>
</else>
</if>
</target>
<!-- ============================================ -->
<!-- Target: merge_translation -->
<!-- ============================================ -->
<target name="merge_translation" hidden="true">
<if>
<available file="${current_locale_abs}/${po_file_backup_name}" property="extistingMessages" value="true"/>
<then>
<echo msg="Locale exists in ${current_locale_array}, merging..."/>
<exec dir="${project.basedir}"
command="${msgmerge_executable} ${current_locale_abs}/${po_file_backup_name} --no-wrap -N ${localesDir}/${po_file_name} -o ${current_locale_abs}/${po_file_name}"
logoutput="true"/>
</then>
<else>
<echo msg="Messages.po not exists in ${current_locale_array}, copy plain one..."/>
<copy file="${localesDir}/${po_file_name}"
tofile="${localesDir}/${current_locale_array}/${po_file_name}"/>
</else>
</if>
<exec dir="${localesDir}"
command="php -f ./_tools/convert_to_po.php ./${current_locale_array}/ ${strings_file_name} ${po_file_backup_name}"
logoutput="true"/>
<move file="${localesDir}/${current_locale_array}/${strings_file_name}"
tofile="${localesDir}/${current_locale_array}/${strings_file_backup_name}"
tstamp="true"/>
<if>
<available file="${localesDir}/${current_locale_array}/${ts_file_name}" property="tsFileExists"
value="true"/>
<then>
<echo msg="TS File exists."/>
<php function="filemtime" returnProperty="ts_timestamp">
<param value="${localesDir}/${current_locale_array}/${ts_file_name}"/>
</php>
<php function="filemtime" returnProperty="strings_timestamp">
<param value="${localesDir}/${current_locale_array}/${strings_file_backup_name}"/>
</php>
<echo msg="TS File timestamp is: ${ts_timestamp}"/>
<echo msg="Strings File timestamp is: ${strings_timestamp}"/>
<php expression="${ts_timestamp} > ${strings_timestamp}" returnProperty="tsIsNewer"/>
<if>
<isfalse value="${tsIsNewer}"/>
<then>
<echo msg="TS File is older, updating TS file..."/>
<exec dir="${localesDir}"
command="php -f ./_tools/convert_to_ts.php ./${current_locale_array}/ ${base_locale} ${po_file_name} ${current_locale_array} ${ts_file_name}"
logoutput="true"/>
</then>
</if>
</then>
<else>
<echo msg="TS File not exists, generating..."/>
<exec dir="${localesDir}"
command="php -f ./_tools/convert_to_ts.php ./${current_locale_array}/ ${base_locale} ${po_file_name} ${current_locale_array} ${ts_file_name}"
logoutput="true"/>
</else>
</if>
<exec dir="${localesDir}"
command="php -f ./_tools/convert_to_array.php ./${current_locale_array}/ ${base_locale} ${ts_file_name} ${current_locale_array} ${strings_file_name}"
logoutput="true"/>
<if>
<available file="${localesDir}/${current_locale_array}/${strings_file_name}" property="existingStrings"
value="true"/>
<else>
<echo msg="New strings file is missing in ${current_locale_array}, restoring backup"/>
<copy file="${localesDir}/${current_locale_array}/${strings_file_backup_name}"
tofile="${localesDir}/${current_locale_array}/${strings_file_name}"
tstamp="true"/>
</else>
</if>
<echo msg="Touching files to match mtime..."/>
<touch file="${localesDir}/${current_locale_array}/${strings_file_name}"/>
<touch file="${localesDir}/${current_locale_array}/${ts_file_name}"/>
<if>
<equals arg1="${keepDebugFiles}" arg2="N" casesensitive="true" trim="true"/>
<then>
<echo msg="Deleting temporary files in ${current_locale_array} directory..."/>
<delete failonerror="false" file="${localesDir}/${current_locale_array}/${po_file_backup_name}" quiet="true"/>
<delete failonerror="false" file="${localesDir}/${current_locale_array}/${po_file_name}" quiet="true"/>
<delete failonerror="false" file="${localesDir}/${current_locale_array}/${strings_file_backup_name}" quiet="true"/>
</then>
</if>
</target>
<!-- ============================================ -->
<!-- Target: build -->
<!-- ============================================ -->
<target name="build" description="Runs every target (clean, prepare, generate_translate, merge_translation)">
<propertyprompt propertyName="keepDebugFiles" defaultValue="N"
promptText="Are you want to keep temporary files?"
useExistingValue="true" />
<propertyprompt propertyName="usePlainMessages" defaultValue="Y"
promptText="Are you want to keep plain messages.po (Next time, you don't need to rebuild these file)?"
useExistingValue="true" />
<propertyprompt propertyName="generateOnlyForDefaultLanguage" defaultValue="Y"
promptText="Generate only for default language? (Y = en_US only)"
useExistingValue="true" />
<if>
<istrue value="${isMacOrUnix}"/>
<then>
<property name="tools_dir" value="" />
</then>
<else>
<propertyprompt propertyName="tools_dir" defaultValue=""
promptText="Path to gettext tools bin directory? Not required if xgettexts bin directory added to System Path"
useExistingValue="true" />
</else>
</if>
<phingcall target="clean"/>
<phingcall target="prepare"/>
<phingcall target="generate_translate"/>
<phingcall target="merge_translations"/>
</target>
</project>