|
1 # |
|
2 # Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 # All rights reserved. |
|
4 # This component and the accompanying materials are made available |
|
5 # under the terms of the License "Symbian Foundation License v1.0" |
|
6 # which accompanies this distribution, and is available |
|
7 # at the URL "http://www.symbianfoundation.org/legal/sfl-v10.html". |
|
8 # |
|
9 # Initial Contributors: |
|
10 # Nokia Corporation - initial contribution. |
|
11 # |
|
12 # Contributors: |
|
13 # |
|
14 # Description: |
|
15 # Adds a LOCALISE macro that enables configuration of localised files. |
|
16 # The localised language selection is done with a ADD_LANGUAGE macro. |
|
17 # |
|
18 |
|
19 |
|
20 |
|
21 ############################################################################### |
|
22 # |
|
23 # Syntax: LOCALISE |
|
24 # type=LOCALISE(source, target[, languages]) |
|
25 # source => the source file. The section that needs to be localised should be marked with ??. |
|
26 # target => the target file. The section that needs to be localised should be marked with ??. |
|
27 # languages => a space delimited list of language codes |
|
28 # |
|
29 # Syntax: ADD_LANGUAGE |
|
30 # ADD_LANGUAGE lang |
|
31 # |
|
32 # Example: |
|
33 # Add languages |
|
34 # ADD_LANGUAGE 01 |
|
35 # ADD_LANGUAGE 02 |
|
36 # ADD_LANGUAGE 03 |
|
37 # |
|
38 # Use Case 1: |
|
39 # Localises a App resoure file. |
|
40 # data=LOCALISE(APP_RESOURCE_DIR\App.r??, RESOURCE_DIR\app.r??) |
|
41 # Output: |
|
42 # data=APP_RESOURCE_DIR\App.r01 RESOURCE_DIR\app.r01 |
|
43 # data=APP_RESOURCE_DIR\App.r02 RESOURCE_DIR\app.r02 |
|
44 # data=APP_RESOURCE_DIR\App.r03 RESOURCE_DIR\app.r03 |
|
45 # |
|
46 # Use Case 2: |
|
47 # Localise all resource files under a section |
|
48 # ADD_LANGUAGE 01 |
|
49 # ADD_LANGUAGE 02 |
|
50 # ADD_LANGUAGE 03 |
|
51 # |
|
52 # LOCALISE_ALL_RESOURCES_BEGIN |
|
53 # // All resource files will be localised |
|
54 # data=APP_RESOURCE_DIR\App.rsc RESOURCE_DIR\app.rsc |
|
55 # data=APP_RESOURCE_DIR\App2.rsc RESOURCE_DIR\app2.rsc |
|
56 # LOCALISE_ALL_RESOURCES_END |
|
57 # Output: |
|
58 # data=APP_RESOURCE_DIR\App.r01 RESOURCE_DIR\app.r01 |
|
59 # data=APP_RESOURCE_DIR\App.r02 RESOURCE_DIR\app.r02 |
|
60 # data=APP_RESOURCE_DIR\App.r03 RESOURCE_DIR\app.r03 |
|
61 # data=APP_RESOURCE_DIR\App.r01 RESOURCE_DIR\app.r01 |
|
62 # data=APP_RESOURCE_DIR\App.r02 RESOURCE_DIR\app.r02 |
|
63 # data=APP_RESOURCE_DIR\App.r03 RESOURCE_DIR\app.r03 |
|
64 # |
|
65 ############################################################################### |
|
66 |
|
67 # |
|
68 # Version 4 |
|
69 # Path corrections to widget support. |
|
70 # |
|
71 # Version 3 |
|
72 # Support for Idle widgets. |
|
73 # |
|
74 # Version 2 |
|
75 # Localises also *.hlp to *.h%s. |
|
76 # |
|
77 # Version 1 |
|
78 # Initial version. |
|
79 |
|
80 |
|
81 package localise_all_resources; |
|
82 use strict; |
|
83 |
|
84 BEGIN |
|
85 { |
|
86 use Exporter (); |
|
87 our ( $VERSION, @ISA, @EXPORT ); |
|
88 # set the version for version checking |
|
89 $VERSION = 1.00; |
|
90 |
|
91 @ISA = qw( Exporter ); |
|
92 @EXPORT = qw( &localise_all_resources_info |
|
93 &do_localise_all_resources_extension |
|
94 &is_localise_all_resources_begin |
|
95 &is_localise_all_resources_end |
|
96 &is_resource_entry |
|
97 &is_help_entry_xhtml |
|
98 &is_help_entry_hlp |
|
99 &is_dtd_entry |
|
100 &is_active_idle_entry |
|
101 &is_elocl_entry |
|
102 &get_type_from_entry |
|
103 &get_source_from_entry |
|
104 &get_target_from_entry |
|
105 &create_localise_entry_from_resource |
|
106 &create_localise_entry_from_help |
|
107 &create_localise_entry_from_dtd |
|
108 &create_localise_entry_from_active_idle |
|
109 &create_localise_entry_from_elocl |
|
110 ); |
|
111 } |
|
112 |
|
113 my %localise_all_resources_infostruct = |
|
114 ( |
|
115 name => "localise_all_resources", |
|
116 invocation => "InvocationPoint1", |
|
117 single => "localise_all_resources::do_localise_all_resources_extension" |
|
118 ); |
|
119 |
|
120 my $line; |
|
121 my @newobydata; |
|
122 my %languages; |
|
123 my $verbose=0; |
|
124 my $errors=0; |
|
125 my $localise_all_resource=0; |
|
126 |
|
127 sub localise_all_resources_info |
|
128 { |
|
129 return \%localise_all_resources_infostruct; |
|
130 } |
|
131 |
|
132 # Entry point for the plugi |
|
133 sub do_localise_all_resources_extension |
|
134 { |
|
135 print "========================== Begin localise_all_resources =======================\n" if $verbose; |
|
136 my $obydata = shift; |
|
137 |
|
138 undef @newobydata; |
|
139 foreach $line (@{$obydata}) |
|
140 { |
|
141 # Ignore REM statements, to avoid processing "REM __SCALABLE_IMAGE( ... )" |
|
142 if ($line =~ /^\s*REM/i) |
|
143 { |
|
144 push @newobydata, $line; |
|
145 next; |
|
146 } |
|
147 # LOCALISE_ALL_RESOURCES_BEGIN |
|
148 if (is_localise_all_resources_begin($line)) |
|
149 { |
|
150 $localise_all_resource = 1; |
|
151 push @newobydata, "REM handled $line"; |
|
152 next; |
|
153 } |
|
154 # LOCALISE_ALL_RESOURCES_END |
|
155 if (is_localise_all_resources_end($line)) |
|
156 { |
|
157 $localise_all_resource = 0; |
|
158 push @newobydata, "REM handled $line"; |
|
159 next; |
|
160 } |
|
161 if ( $localise_all_resource ) |
|
162 { |
|
163 # localise all rsc files inside the localise_all_resources section |
|
164 # resource files .rsc |
|
165 if ( is_resource_entry($line) ) |
|
166 { |
|
167 # match data/file=foobar.rsc resource/foobar.rsc |
|
168 $line = create_localise_entry_from_resource($line); |
|
169 push @newobydata, "$line\n"; |
|
170 next; |
|
171 } |
|
172 # help files .hlp |
|
173 if ( is_help_entry_hlp($line) ) |
|
174 { |
|
175 # match data/file=foobar.rsc resource/foobar.rsc |
|
176 $line = create_localise_entry_from_help_hlp($line); |
|
177 push @newobydata, "$line\n"; |
|
178 next; |
|
179 } |
|
180 # localise the .dtd files that have \\01\\ in their source target path |
|
181 if ( is_dtd_entry($line) ) |
|
182 { |
|
183 # match data/file=foobar.rsc resource/foobar.rsc |
|
184 $line = create_localisable_path($line); |
|
185 $line = create_localise_entry_from_dtd($line); |
|
186 push @newobydata, "$line\n"; |
|
187 next; |
|
188 } |
|
189 # localise the active idle .o0001 files |
|
190 if ( is_active_idle_entry($line) ) |
|
191 { |
|
192 # match data/file=foobar.rsc resource/foobar.rsc |
|
193 $line = create_localisable_path($line); |
|
194 $line = create_localise_entry_from_active_idle($line); |
|
195 push @newobydata, "$line\n"; |
|
196 next; |
|
197 } |
|
198 # localise the elocl file |
|
199 if ( is_elocl_entry($line) ) |
|
200 { |
|
201 # match data/file=foobar.rsc resource/foobar.rsc |
|
202 $line = create_localise_entry_from_elocl($line); |
|
203 push @newobydata, "$line\n"; |
|
204 next; |
|
205 } |
|
206 |
|
207 } |
|
208 # Default case |
|
209 push @newobydata, $line; |
|
210 } |
|
211 @{$obydata} = @newobydata; |
|
212 print "========================== End localise_all_resources =======================\n" if $verbose; |
|
213 #Stop image creation in error case |
|
214 #exit(1) if ($errors); |
|
215 } |
|
216 |
|
217 # trim(string) |
|
218 # Removes spaces from both ends of the string. |
|
219 # Returns a trimmed string. |
|
220 sub trim($) |
|
221 { |
|
222 my $string = shift; |
|
223 $string =~ s/^\s+//; |
|
224 $string =~ s/\s+$//; |
|
225 return $string; |
|
226 } |
|
227 |
|
228 # match LOCALISE_ALL_RESOURCE_BEGIN |
|
229 sub is_localise_all_resources_begin($) |
|
230 { |
|
231 my $entry = shift; |
|
232 if ( $entry =~ m/^\s*LOCALISE_ALL_RESOURCES_BEGIN\s*$/i ) |
|
233 { |
|
234 return 1; |
|
235 } |
|
236 return 0; |
|
237 } |
|
238 |
|
239 # match LOCALISE_ALL_RESOURCE_END |
|
240 sub is_localise_all_resources_end($) |
|
241 { |
|
242 my $entry = shift; |
|
243 if ( $entry =~ m/^\s*LOCALISE_ALL_RESOURCES_END\s*$/i ) |
|
244 { |
|
245 return 1; |
|
246 } |
|
247 return 0; |
|
248 } |
|
249 # |
|
250 # match data=foobar.rsc resource/foobar.rsc |
|
251 sub is_resource_entry($) |
|
252 { |
|
253 my $entry = shift; |
|
254 my $type = get_type_from_entry($entry); |
|
255 my $source = get_source_from_entry($entry); |
|
256 my $target = get_target_from_entry($entry); |
|
257 if ($source =~ m/\.rsc[\"|\']?$/i && |
|
258 $target =~ m/\.rsc[\"|\']?$/i ) |
|
259 { |
|
260 return 1; |
|
261 } |
|
262 return 0; |
|
263 } |
|
264 |
|
265 # |
|
266 # match |
|
267 sub is_help_entry_xhtml($) |
|
268 { |
|
269 my $entry = shift; |
|
270 my $type = get_type_from_entry($entry); |
|
271 my $source = get_source_from_entry($entry); |
|
272 my $target = get_target_from_entry($entry); |
|
273 if ($source =~ m/\\01\\/i && |
|
274 $target =~ m/\\01\\/i ) |
|
275 { |
|
276 return 1; |
|
277 } |
|
278 return 0; |
|
279 } |
|
280 |
|
281 # match data=foobar.hlp resource/foobar.hlp |
|
282 sub is_help_entry_hlp($) |
|
283 { |
|
284 my $entry = shift; |
|
285 my $type = get_type_from_entry($entry); |
|
286 my $source = get_source_from_entry($entry); |
|
287 my $target = get_target_from_entry($entry); |
|
288 if ($source =~ m/\.hlp[\"|\']?$/i && |
|
289 $target =~ m/\.hlp[\"|\']?$/i ) |
|
290 { |
|
291 return 1; |
|
292 } |
|
293 return 0; |
|
294 } |
|
295 |
|
296 # |
|
297 # match data=DATAZ_\\resource\\xhtml\\01\\0x01000000\\contents.zip RESOURCE_FILES_DIR\\xhtml\\01\\0x01000000\\contents.zip |
|
298 sub is_dtd_entry($) |
|
299 { |
|
300 my $entry = shift; |
|
301 my $type = get_type_from_entry($entry); |
|
302 my $source = get_source_from_entry($entry); |
|
303 my $target = get_target_from_entry($entry); |
|
304 if (($source =~ m/\\01\\.*\.dtd/i && |
|
305 $target =~ m/\\01\\.*\.dtd/i ) || |
|
306 ($source =~ m/\\00\\.*\.dtd/i && |
|
307 $target =~ m/\\00\\.*\.dtd/i )) |
|
308 { |
|
309 return 1; |
|
310 } |
|
311 return 0; |
|
312 } |
|
313 |
|
314 # |
|
315 # match data=DATAZ_\\resource\\xhtml\\01\\0x01000000\\contents.zip RESOURCE_FILES_DIR\\xhtml\\01\\0x01000000\\contents.zip |
|
316 sub is_active_idle_entry($) |
|
317 { |
|
318 my $entry = shift; |
|
319 my $type = get_type_from_entry($entry); |
|
320 my $source = get_source_from_entry($entry); |
|
321 my $target = get_target_from_entry($entry); |
|
322 if (($source =~ m/\.o0001/i && |
|
323 $target =~ m/\.o0001/i ) || |
|
324 ($source =~ m/\.o0000/i && |
|
325 $target =~ m/\.o0000/i )) |
|
326 { |
|
327 return 1; |
|
328 } |
|
329 return 0; |
|
330 } |
|
331 |
|
332 # |
|
333 # |
|
334 sub is_elocl_entry($) |
|
335 { |
|
336 my $entry = shift; |
|
337 my $type = get_type_from_entry($entry); |
|
338 my $source = get_source_from_entry($entry); |
|
339 my $target = get_target_from_entry($entry); |
|
340 if ($source =~ m/elocl\.dll/i && |
|
341 $target =~ m/elocl\.loc/i ) |
|
342 { |
|
343 return 1; |
|
344 } |
|
345 return 0; |
|
346 } |
|
347 |
|
348 # get the type from an iby entry |
|
349 sub get_type_from_entry($) |
|
350 { |
|
351 my $entry = shift; |
|
352 if ( $entry =~ m/^\s*(\S+)\s*=\s*(\S+)\s+(\S+)\s*/i ) |
|
353 { |
|
354 return $1; |
|
355 } |
|
356 return ""; |
|
357 } |
|
358 # get the source file from an iby entry |
|
359 sub get_source_from_entry($) |
|
360 { |
|
361 my $entry = shift; |
|
362 if ( $entry =~ m/^\s*(\S+)\s*=\s*(\S+)\s+(\S+)\s*/i ) |
|
363 { |
|
364 return $2; |
|
365 } |
|
366 return ""; |
|
367 } |
|
368 # get the target file from an iby entry |
|
369 sub get_target_from_entry($) |
|
370 { |
|
371 my $entry = shift; |
|
372 if ( $entry =~ m/^\s*(\S+)\s*=\s*(\S+)\s+(\S+)\s*/i ) |
|
373 { |
|
374 return $3; |
|
375 } |
|
376 return ""; |
|
377 } |
|
378 |
|
379 # create localise entry from resource entry |
|
380 sub create_localise_entry_from_resource($) |
|
381 { |
|
382 my $entry = shift; |
|
383 my $type = get_type_from_entry($entry); |
|
384 my $source = get_source_from_entry($entry); |
|
385 my $target = get_target_from_entry($entry); |
|
386 #convert the .rsc to .r%02d |
|
387 $source =~ s/\.rsc/\.r%s/i; |
|
388 $target =~ s/\.rsc/\.r%s/i; |
|
389 #print "create_localise_entry_from_resource: $source\n"; |
|
390 return "$type=LOCALISE($source, $target)"; |
|
391 } |
|
392 |
|
393 # create localise entry from resource entry |
|
394 sub create_localise_entry_from_help($) |
|
395 { |
|
396 my $entry = shift; |
|
397 my $type = get_type_from_entry($entry); |
|
398 my $source = get_source_from_entry($entry); |
|
399 my $target = get_target_from_entry($entry); |
|
400 #convert the \\01\\ to \\%02d\\ |
|
401 $source =~ s/\\01\\/\\%02d\\/i; |
|
402 $target =~ s/\\01\\/\\%02d\\/i; |
|
403 #print "create_localise_entry_from_resource: $source\n"; |
|
404 return "$type=LOCALISE($source, $target)"; |
|
405 } |
|
406 |
|
407 # create localise entry from help entry hlp |
|
408 sub create_localise_entry_from_help_hlp($) |
|
409 { |
|
410 my $entry = shift; |
|
411 my $type = get_type_from_entry($entry); |
|
412 my $source = get_source_from_entry($entry); |
|
413 my $target = get_target_from_entry($entry); |
|
414 #convert the .hlp to .h%02d |
|
415 $source =~ s/\.hlp/\.h%s/i; |
|
416 $target =~ s/\.hlp/\.h%s/i; |
|
417 #print "create_localise_entry_from_resource: $source\n"; |
|
418 return "$type=LOCALISE($source, $target)"; |
|
419 } |
|
420 |
|
421 # create localise entry from resource entry |
|
422 sub create_localise_entry_from_dtd($) |
|
423 { |
|
424 my $entry = shift; |
|
425 my $type = get_type_from_entry($entry); |
|
426 my $source = get_source_from_entry($entry); |
|
427 my $target = get_target_from_entry($entry); |
|
428 #convert the \\01\\ to \\%02d\\ |
|
429 # $source =~ s/\\01\\/\\%02d\\/i; |
|
430 # $target =~ s/\\01\\/\\%02d\\/i; |
|
431 # $source =~ s/\\00\\/\\%02d\\/i; |
|
432 # $target =~ s/\\00\\/\\%02d\\/i; |
|
433 # #print "create_localise_entry_from_resource: $source\n"; |
|
434 return "$type=LOCALISE($source, $target)"; |
|
435 } |
|
436 |
|
437 # create localise entry from resource entry |
|
438 sub create_localise_entry_from_active_idle($) |
|
439 { |
|
440 my $entry = shift; |
|
441 my $type = get_type_from_entry($entry); |
|
442 my $source = get_source_from_entry($entry); |
|
443 my $target = get_target_from_entry($entry); |
|
444 #convert the \\0001\\ to \\%04d\\ |
|
445 $source =~ s/o0001/o%04d/i; |
|
446 $target =~ s/o0001/o%04d/i; |
|
447 $source =~ s/o0000/o%04d/i; |
|
448 $target =~ s/o0000/o%04d/i; |
|
449 #print "create_localise_entry_from_resource: $source\n"; |
|
450 return "$type=LOCALISE($source, $target)"; |
|
451 } |
|
452 |
|
453 sub create_localise_entry_from_elocl($) |
|
454 { |
|
455 my $entry = shift; |
|
456 my $type = get_type_from_entry($entry); |
|
457 my $source = get_source_from_entry($entry); |
|
458 my $target = get_target_from_entry($entry); |
|
459 #convert the \\0001\\ to \\%04d\\ |
|
460 $source =~ s/\.dll/\.%02d/i; |
|
461 $target =~ s/\.loc/\.%02d/i; |
|
462 #print "create_localise_entry_from_resource: $source $target\n"; |
|
463 return "$type=LOCALISE($source, $target)"; |
|
464 } |
|
465 |
|
466 # create localisable path from /00/ or /01/ paths |
|
467 sub create_localisable_path($) |
|
468 { |
|
469 my $entry = shift; |
|
470 |
|
471 $entry =~ s/\\01\\/\\%02d\\/ig; |
|
472 $entry =~ s/\\00\\/\\%02d\\/ig; |
|
473 |
|
474 #print "create_localise_entry_from_resource: $source\n"; |
|
475 return $entry; |
|
476 } |
|
477 1; # Return a true value from the file |