2 eval 'exec perl -wS $0 ${1+"$@"}'
6 #*************************************************************************
8 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
10 # Copyright 2000, 2010 Oracle and/or its affiliates.
12 # OpenOffice.org - a multi-platform office productivity suite
14 # This file is part of OpenOffice.org.
16 # OpenOffice.org is free software: you can redistribute it and/or modify
17 # it under the terms of the GNU Lesser General Public License version 3
18 # only, as published by the Free Software Foundation.
20 # OpenOffice.org is distributed in the hope that it will be useful,
21 # but WITHOUT ANY WARRANTY; without even the implied warranty of
22 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 # GNU Lesser General Public License version 3 for more details
24 # (a copy is included in the LICENSE file that accompanied this code).
26 # You should have received a copy of the GNU Lesser General Public License
27 # version 3 along with OpenOffice.org. If not, see
28 # <http://www.openoffice.org/license.html>
29 # for a copy of the LGPLv3 License.
31 #*************************************************************************
39 use File
::Glob
qw(:glob csh_glob);
45 #use lib ("$ENV{SOLARENV}/bin/modules", "$ENV{COMMON_ENV_TOOLS}/modules");
51 if ( !defined($ENV{SOLARENV
}) ) {
52 die "No environment found (environment variable SOLARENV is undefined)";
54 push(@lib_dirs, "$ENV{SOLARENV}/bin/modules");
55 push(@lib_dirs, "$ENV{COMMON_ENV_TOOLS}/modules") if defined($ENV{COMMON_ENV_TOOLS
});
67 #my %sl_modules; # Contains all modules where en-US and de is source language
68 my $use_default_date = '0';
70 # ( leftpart ) ( rightpart )
71 # prj file dummy type gid lid helpid pform width lang text helptext qhelptext title timestamp
72 my $sdf_regex = "((([^\t]*)\t([^\t]*)\t([^\t]*)\t([^\t]*)\t([^\t]*)\t([^\t]*)\t([^\t]*)\t([^\t]*)\t([^\t]*))\t([^\t]*)\t(([^\t]*)\t([^\t]*)\t([^\t]*)\t([^\t]*)\t)([^\t]*))";
73 my $file_types = "(src|hrc|xcs|xcu|lng|ulf|xrm|xhp|xcd|xgf|xxl|xrb)";
74 # Always use this date to prevent cvs conflicts
75 my $default_date = "2002-02-02 02:02:02";
80 #%sl_modules = fetch_sourcelanguage_dirlist();
83 if ( $mode eq "merge" ) {
85 splitfile
( $sdffile );
86 unlink $sdffile; # remove temp file!
88 elsif( $mode eq "extract" ) {
89 collectfiles
( $outputfile );
97 #########################################################
101 my $currentFile = '';
102 my $cur_sdffile = '';
103 my $last_sdffile = '';
110 STDOUT
->autoflush( 1 );
112 #print STDOUT "Open File $sdffile\n";
113 open MYFILE
, "< $sdffile"
114 or die "Can't open '$sdffile'\n";
118 my $line = defined $_ ?
$_ : '';
119 my $prj = defined $3 ?
$3 : '';
120 my $file = defined $4 ?
$4 : '';
121 my $type = defined $6 ?
$6 : '';
122 my $gid = defined $7 ?
$7 : '';
123 my $lid = defined $8 ?
$8 : '';
124 my $lang = defined $12 ?
$12 : '';
125 my $plattform = defined $10 ?
$10 : '';
126 my $helpid = defined $9 ?
$9 : '';
128 next if( $prj eq "binfilter" ); # Don't merge strings into binfilter module
130 $currentFile = $srcpath . '\\' . $prj . '\\' . $file;
131 $currentFile =~ s/\\/\//g
;
133 $cur_sdffile = $currentFile;
134 #if( $cur_sdffile =~ /\.$file_types[\s]*$/ ){
135 $cur_sdffile =~ s/\/[^\/]*\
.$file_types[\s
]*$/\/localize
.sdf
/;
139 if( $line =~ /(.*)\t[^\t\$]*$/ ){
140 $line = $1."\t".$default_date;
145 $lastFile = $currentFile; # ?
146 $last_sdffile = $cur_sdffile;
149 if( $lang eq "en-US" ){}
150 elsif( $cur_sdffile eq $last_sdffile )
152 $block{ "$prj\t$file\t$type\t$gid\t$lid\t$helpid\t$plattform\t$lang" } = $line ;
156 writesdf
( $lastFile , \
%block );
157 $lastFile = $currentFile; #?
158 $last_sdffile = $cur_sdffile;
160 #if( ! $lang eq "en-US" ) {
161 $block{ "$prj\t$file\t$type\t$gid\t$lid\t$helpid\t$plattform\t$lang" } = $line ;
165 } #else { print STDOUT "splitfile REGEX kaputt\n";}
168 writesdf
( $lastFile , \
%block );
173 #########################################################
177 my $lastFile = shift;
178 my $blockhash_ref = shift;
179 my $localizeFile = $lastFile;
182 if( $localizeFile =~ /\.$file_types[\s]*$/ ){
183 $localizeFile =~ s/\/[^\/]*\
.$file_types[\s
]*$/\/localize
.sdf
/;
185 print STDERR
"Strange filetype found '$localizeFile'\n";
188 if( open DESTFILE
, "< $localizeFile" ){
190 #or die "Can't open/create '\$localizeFile'";
195 my $line = defined $_ ?
$_ : '';
196 my $prj = defined $3 ?
$3 : '';
197 my $file = defined $4 ?
$4 : '';
198 my $type = defined $6 ?
$6 : '';
199 my $gid = defined $7 ?
$7 : '';
200 my $lid = defined $8 ?
$8 : '';
201 my $lang = defined $12 ?
$12 : '';
202 my $plattform = defined $10 ?
$10 : '';
203 my $helpid = defined $9 ?
$9 : '';
206 $index{ "$prj\t$file\t$type\t$gid\t$lid\t$helpid\t$plattform\t$lang" } = $line ;
208 } #else { print STDOUT "writesdf REGEX kaputt $_\n";}
213 #### Copy new strings
214 my @mykeys = keys( %{ $blockhash_ref } );
215 my $isDirty = "FALSE";
216 foreach my $key( @mykeys ){
217 if( ! defined $index{ $key } ){
219 $index{ $key } = $blockhash_ref->{ $key} ;
221 }elsif( $index{ $key } ne $blockhash_ref->{ $key } ){
222 # Overwrite old entry
223 $index{ $key } = $blockhash_ref->{ $key };
231 if( !$bVerbose ){ print STDOUT
"."; }
232 if( $isDirty eq "TRUE" ){
233 if( $bVerbose ){ print STDOUT
"$localizeFile\n"; }
234 if( open DESTFILE
, "+> $localizeFile" ){
235 print DESTFILE get_license_header
();
236 @mykeys = sort keys( %index );
237 foreach my $key( @mykeys ){
238 print DESTFILE
( $index{ $key } , "\n" );
242 print STDOUT
"WARNING: File $localizeFile is not writable , try to merge ...\n";
243 my ( $TMPFILE , $tmpfile ) = File
::Temp
::tempfile
();
244 if( open DESTFILE
, "+> $tmpfile " ){
245 @mykeys = keys( %index );
246 foreach my $key( @mykeys ){
247 print DESTFILE
( $index{ $key } , "\n" );
250 if( move
( $localizeFile , $localizeFile.".backup" ) ){
251 if( copy
( $tmpfile , $localizeFile ) ){
252 unlink $localizeFile.".backup";
253 } else { print STDERR
"Can't open/create '$localizeFile', original file is renamed to $localizeFile.backup\n"; }
254 } else { print STDERR
"Can't open/create '$localizeFile'\n"; }
256 print STDERR
"WARNING: Can't open/create '$localizeFile'\n";
261 # if( $no_sort eq '' ){
262 # sort_outfile( $localizeFile );
266 sub get_license_header
{
269 "# #### ### # # ### ##### ##### #### ##### ##### \n".
270 "# # # # # ## # # # # # # # # # \n".
271 "# # # # # # # # # # # ### # # # # \n".
272 "# # # # # # ## # # # # # # # # \n".
273 "# #### ### # # ### # ##### #### ##### # \n".
275 "# DO NOT EDIT! This file will be overwritten by localisation process\n".
277 "#*************************************************************************\n".
279 "# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.\n".
281 "# Copyright 2000, 2010 Oracle and/or its affiliates.\n".
283 "# OpenOffice.org - a multi-platform office productivity suite\n".
285 "# This file is part of OpenOffice.org.\n".
287 "# OpenOffice.org is free software: you can redistribute it and/or modify\n".
288 "# it under the terms of the GNU Lesser General Public License version 3\n".
289 "# only, as published by the Free Software Foundation.\n".
291 "# OpenOffice.org is distributed in the hope that it will be useful,\n".
292 "# but WITHOUT ANY WARRANTY; without even the implied warranty of\n".
293 "# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n".
294 "# GNU Lesser General Public License version 3 for more details\n".
295 "# (a copy is included in the LICENSE file that accompanied this code).\n".
297 "# You should have received a copy of the GNU Lesser General Public License\n".
298 "# version 3 along with OpenOffice.org. If not, see\n".
299 "# <http://www.openoffice.org/license.html>\n".
300 "# for a copy of the LGPLv3 License.\n".
302 "#*************************************************************************\n";
304 ######## Check input sdf file and use only the correct part
307 my ( $TMPHANDLE , $tmpfile ) = File
::Temp
::tempfile
();
308 my ( $TMPHANDLE2 , $tmpfile2 ) = File
::Temp
::tempfile
();
309 close ( $TMPHANDLE );
310 close ( $TMPHANDLE2 );
313 my $output2 = `cat $sdffile | sort > $tmpfile2`;
316 printf("ERROR: Failed -> cat $sdffile | sort > $tmpfile2\n$output2\n");
320 # if( $ENV{WRAPCMD} ){
321 # $command = "$ENV{WRAPCMD} gsicheck";
323 # $command = "gsicheck";
325 # my $errfile = $tmpfile.".err";
326 # $command .= " -k -c -wcf $tmpfile -wef $errfile -l \"\" $tmpfile2";
327 # my $output = `$command`;
329 # if ( $output ne "" ){
330 # print STDOUT "### gsicheck ###\n";
331 # print STDOUT "### The file $errfile have been written containing the errors in your sdf file. Those lines will not be merged: ###\n\n";
332 # print STDOUT "$output\n";
333 # print STDOUT "################\n";
336 # # Remove the 0 Byte file
339 $sdffile = $tmpfile2;
342 #########################################################
344 print STDOUT
"### Localize\n";
346 my $localizehash_ref;
347 my ( $bAll , $bUseLocalize, $langhash_ref , $bHasSourceLanguage , $bFakeEnglish ) = parseLanguages
();
349 # Enable autoflush on STDOUT
351 STDOUT
->autoflush( 1 );
353 ### Search sdf particles
354 print STDOUT
"### Searching sdf particles\n";
355 my $working_path = getcwd
();
358 my $file = $File::Find
::name
;
359 if( -f
&& $file =~ /.*localize.sdf$/ ) {
360 push @sdfparticles , $file;
361 if( $bVerbose eq "1" ) { print STDOUT
"$file\n"; }
365 } , getcwd
() ;#"."; #$srcpath;
368 my $nFound = $#sdfparticles +1;
369 print "\n $nFound files found !\n";
371 my ( $LOCALIZEPARTICLE , $localizeSDF ) = File
::Temp
::tempfile
();
372 close( $LOCALIZEPARTICLE );
374 my ( $ALLPARTICLES_MERGED , $particleSDF_merged ) = File
::Temp
::tempfile
();
375 close( $ALLPARTICLES_MERGED );
376 my ( $LOCALIZE_LOG , $my_localize_log ) = File
::Temp
::tempfile
();
377 close( $LOCALIZE_LOG );
379 ## Get the localize de,en-US extract
380 if( $bAll || $bUseLocalize ){
381 print "### Fetching source language strings\n";
386 $command = "$ENV{WRAPCMD} localize_sl";
388 $command = "localize_sl";
392 # if ( -x $command ){
394 if( !$bVerbose ){ $args .= " -QQ -skip_links "; }
395 $args .= " -e -f $localizeSDF -l ";
397 if( $bAll ) {$args .= " en-US";}
400 foreach my $isokey ( keys( %{ $langhash_ref } ) ){
401 push @list , $isokey;
402 if( $langhash_ref->{ $isokey } ne "" ){
403 push @list , $langhash_ref->{ $isokey };
406 remove_duplicates
( \
@list );
407 foreach my $isokey ( @list ){
409 #( $isokey=~ /^de$/i )
411 # if( $bFlag eq "TRUE" ){ $args .= ",de"; }
413 # $args .= "de"; $bFlag = "TRUE";
416 ( $isokey=~ /^en-US$/i )
418 if( $bFlag eq "TRUE" ){ $args .= ",en-US"; }
420 $args .= "en-US"; $bFlag = "TRUE";
428 if ( $bVerbose ) { print STDOUT
$command.$args."\n"; }
430 my $rc = system( $command.$args );
432 #my $output = `$command.$args`;
435 if( $rc < 0 ){ print STDERR
"ERROR: localize rc = $rc\n"; exit( -1 ); }
436 ( $localizehash_ref ) = read_file
( $localizeSDF , $langhash_ref );
440 open ALLPARTICLES_MERGED
, "+>> $particleSDF_merged"
441 or die "Can't open $particleSDF_merged";
443 ## Fill fackback hash
444 my( $fallbackhashhash_ref ) = fetch_fallback
( \
@sdfparticles , $localizeSDF , $langhash_ref );
445 # my( $fallbackhashhash_ref ) = fetch_fallback( \@sdfparticles , $localizeSDF , $langhash_ref );
449 foreach my $cur_lang ( keys( %{ $langhash_ref } ) ){
450 #print STDOUT "DBG: G1 cur_lang=$cur_lang\n";
451 $cur_fallback = $langhash_ref->{ $cur_lang };
452 if( $cur_fallback ne "" ){
453 # Insert fallback strings
454 #print STDOUT "DBG: Renaming $cur_fallback to $cur_lang in fallbackhash\n";
455 rename_language
( $fallbackhashhash_ref , $cur_fallback , $cur_lang );
457 foreach my $currentfile ( @sdfparticles ){
458 if ( open MYFILE
, "< $currentfile" ) {
461 my $line = defined $_ ?
$_ : '';
462 my $prj = defined $3 ?
$3 : '';
463 my $file = defined $4 ?
$4 : '';
464 my $type = defined $6 ?
$6 : '';
465 my $gid = defined $7 ?
$7 : '';
466 my $lid = defined $8 ?
$8 : '';
467 my $lang = defined $12 ?
$12 : '';
468 my $plattform = defined $10 ?
$10 : '';
469 my $helpid = defined $9 ?
$9 : '';
473 if ( $lang eq $cur_lang ){
474 # Overwrite fallback strings with collected strings
475 #if( ( !has_two_sourcelanguages( $cur_lang) && $cur_lang eq "de" ) || $cur_lang ne "en-US" ){
476 $fallbackhashhash_ref->{ $cur_lang }{ $prj.$gid.$lid.$file.$type.$plattform.$helpid } = $line ;
482 }else { print STDERR
"WARNING: Can't open file $currentfile"; }
485 foreach my $line ( keys( %{$fallbackhashhash_ref->{ $cur_lang } } )) {
486 if( #$cur_lang ne "de" &&
487 $cur_lang ne "en-US" ){
488 print ALLPARTICLES_MERGED
( $fallbackhashhash_ref->{ $cur_lang }{ $line }, "\n" );
493 foreach my $currentfile ( @sdfparticles ){
494 if ( open MYFILE
, "< $currentfile" ) {
496 print ALLPARTICLES_MERGED
( $_, "\n" ); # recheck de / en-US !
499 else { print STDERR
"WARNING: Can't open file $currentfile"; }
502 close ALLPARTICLES_MERGED
;
511 if( open DESTFILE
, "+> $outputfile" ){
512 if( !open LOCALIZEPARTICLE
, "< $localizeSDF" ) { print STDERR
"ERROR: Can't open file $localizeSDF\n"; }
513 if( !open ALLPARTICLES_MERGED
, "< $particleSDF_merged" ) { print STDERR
"ERROR: Can't open file $particleSDF_merged\n"; }
517 while ( <LOCALIZEPARTICLE
> ){
519 my $leftpart = defined $2 ?
$2 : '';
520 my $lang = defined $12 ?
$12 : '';
521 my $rightpart = defined $13 ?
$13 : '';
522 my $timestamp = defined $18 ?
$18 : '';
524 my $prj = defined $3 ?
$3 : '';
525 my $file = defined $4 ?
$4 : '';
526 my $type = defined $6 ?
$6 : '';
527 my $gid = defined $7 ?
$7 : '';
528 my $lid = defined $8 ?
$8 : '';
529 #my $lang = defined $12 ? $12 : '';
530 my $plattform = defined $10 ?
$10 : '';
531 my $helpid = defined $9 ?
$9 : '';
534 if( $use_default_date )
536 $extract_date = "$default_date\n" ;
538 elsif( $extract_date eq "" ) {
539 $extract_date = $timestamp ;
540 $extract_date =~ tr/\r\n//d;
541 $extract_date .= "\n";
544 if( $bAll ){ print DESTFILE
$leftpart."\t".$lang."\t".$rightpart.$extract_date ; }
546 foreach my $sLang ( keys( %{ $langhash_ref } ) ){
547 if( $sLang=~ /all/i ) {
548 push @
{ $output{ $prj.$gid.$lid.$file.$type.$plattform.$helpid } } , $leftpart."\t".$lang."\t".$rightpart.$extract_date ;
549 #print DESTFILE $leftpart."\t".$lang."\t".$rightpart.$extract_date;
551 #if( $sLang eq "de" && $lang eq "de" ) {
552 # push @{ $output{ $prj.$gid.$lid.$file.$type.$plattform.$helpid } } , $leftpart."\t".$lang."\t".$rightpart.$extract_date ;
553 #print DESTFILE $leftpart."\t".$lang."\t".$rightpart.$extract_date;
555 if( $sLang eq "en-US" && $lang eq "en-US" ) {
556 push @order , $prj.$gid.$lid.$file.$type.$plattform.$helpid;
557 if( !$bFakeEnglish ){ push @
{ $output{ $prj.$gid.$lid.$file.$type.$plattform.$helpid } } , $leftpart."\t".$lang."\t".$rightpart.$extract_date ; }
558 #print DESTFILE $leftpart."\t".$lang."\t".$rightpart.$extract_date;
566 while ( <ALLPARTICLES_MERGED
> ){
568 my $leftpart = defined $2 ?
$2 : '';
569 my $prj = defined $3 ?
$3 : '';
570 my $lang = defined $12 ?
$12 : '';
571 my $rightpart = defined $13 ?
$13 : '';
572 my $timestamp = defined $18 ?
$18 : '';
574 #my $prj = defined $3 ? $3 : '';
575 my $file = defined $4 ?
$4 : '';
576 my $type = defined $6 ?
$6 : '';
577 my $gid = defined $7 ?
$7 : '';
578 my $lid = defined $8 ?
$8 : '';
579 #my $lang = defined $12 ? $12 : '';
580 my $plattform = defined $10 ?
$10 : '';
581 my $helpid = defined $9 ?
$9 : '';
584 if( $use_default_date )
586 $extract_date = "$default_date\n" ;
588 elsif( $extract_date eq "" )
590 $extract_date = $timestamp;
593 if( ! ( $prj =~ /binfilter/i ) ) {
594 push @
{ $output{ $prj.$gid.$lid.$file.$type.$plattform.$helpid } } , $leftpart."\t".$lang."\t".$rightpart.$extract_date ;
595 #print DESTFILE $leftpart."\t".$lang."\t".$rightpart.$extract_date ;
601 foreach my $curkey ( @order ){
602 foreach my $curlist ( $output{ $curkey } ){
603 foreach my $line ( @
{$curlist} ){
604 print DESTFILE
$line;
609 }else { print STDERR
"Can't open $outputfile";}
612 close LOCALIZEPARTICLE
;
613 close ALLPARTICLES_MERGED
;
615 #print STDOUT "DBG: \$localizeSDF $localizeSDF \$particleSDF_merged $particleSDF_merged\n";
616 unlink $localizeSDF , $particleSDF_merged , $my_localize_log;
618 #sort_outfile( $outputfile );
619 #remove_obsolete( $outputfile ) , if $bHasSourceLanguage ne "";
622 #########################################################
629 print STDOUT
"### Removing obsolete strings\n";
631 # Kick out all strings without en-US reference
632 if ( open ( SORTEDFILE
, "< $outfile" ) ){
633 while( <SORTEDFILE
> ){
635 my $line = defined $_ ?
$_ : '';
636 my $language = defined $12 ?
$12 : '';
637 my $prj = defined $3 ?
$3 : '';
638 my $file = defined $4 ?
$4 : '';
639 my $type = defined $6 ?
$6 : '';
640 my $gid = defined $7 ?
$7 : '';
641 my $lid = defined $8 ?
$8 : '';
642 my $plattform = defined $10 ?
$10 : '';
643 my $helpid = defined $9 ?
$9 : '';
645 my $leftpart = $prj.$gid.$lid.$file.$type.$plattform.$helpid;
647 if( $language eq "en-US" ){ # source string found, 1. entry
648 $enusleftpart = $leftpart;
649 push @good_lines , $line;
651 if( !defined $enusleftpart or !defined $leftpart ){
652 print STDERR
"BADLINE: $line\n";
653 print STDERR
"\$enusleftpart = $enusleftpart\n";
654 print STDERR
"\$leftpart = $leftpart\n";
656 if( $enusleftpart eq $leftpart ){ # matching language
657 push @good_lines , $line;
660 # print STDERR "OUT: \$enusleftpart=$enusleftpart \$leftpart=$leftpart \$line=$line\n";
666 } else { print STDERR
"ERROR: Can't open file $outfile\n";}
669 if ( open ( SORTEDFILE
, "> $outfile" ) ){
670 foreach my $newline ( @good_lines ) {
671 print SORTEDFILE
$newline;
674 } else { print STDERR
"ERROR: Can't open file $outfile\n";}
677 #########################################################
680 print STDOUT
"### Sorting ... $outfile ...";
685 #if ( open ( SORTEDFILE , "< $outputfile" ) ){
686 if ( open ( SORTEDFILE
, "< $outfile" ) ){
688 while ( <SORTEDFILE
> ){
690 if( $line =~ /^[^\#]/ ){
695 @sorted_lines = sort {
697 my $xa_left_part = "";
698 my $xa_right_part = "";
699 my $xa_timestamp = "";
701 my $xb_left_part = "";
702 my $xb_right_part = "";
703 my $xb_timestamp = "";
709 if( $a=~ /$sdf_regex/ ){
710 $xa_left_part = defined $2 ?
$2 : '';
711 $xa_lang = defined $12 ?
$12 : '';
712 $xa_right_part = defined $13 ?
$13 : '';
713 $xa_left_part = remove_last_column
( $xa_left_part );
716 if( $b=~ /$sdf_regex/ ){
717 $xb_left_part = defined $2 ?
$2 : '';
718 $xb_lang = defined $12 ?
$12 : '';
719 $xb_right_part = defined $13 ?
$13 : '';
720 $xb_left_part = remove_last_column
( $xb_left_part );
724 if( ( $xa_left_part cmp $xb_left_part ) == 0 ){ # Left part equal
725 if( ( $xa_lang cmp $xb_lang ) == 0 ){ # Lang equal
726 return ( $xa_right_part cmp $xb_right_part ); # Right part compare
728 elsif( $xa_lang eq "en-US" ) { return -1; } # en-US wins
729 elsif( $xb_lang eq "en-US" ) { return 1; } # en-US wins
730 else { return $xa_lang cmp $xb_lang; } # lang compare
733 return $xa_left_part cmp $xb_left_part; # Left part compare
737 if ( open ( SORTEDFILE
, "> $outfile" ) ){
738 print SORTEDFILE get_license_header
();
739 foreach my $newline ( @sorted_lines ) {
740 print SORTEDFILE
$newline;
741 #print STDOUT $newline;
745 } else { print STDERR
"WARNING: Can't open file $outfile\n";}
749 #########################################################
750 sub remove_last_column
{
752 my @alist = split ( "\t" , $string );
754 return join( "\t" , @alist );
757 #########################################################
759 my $fallbackhashhash_ref = shift;
760 my $cur_fallback = shift;
761 my $cur_lang = shift;
764 foreach my $key( keys ( %{ $fallbackhashhash_ref->{ $cur_fallback } } ) ){
765 $line = $fallbackhashhash_ref->{ $cur_fallback }{ $key };
766 if( $line =~ /$sdf_regex/ ){
767 my $leftpart = defined $2 ?
$2 : '';
768 my $lang = defined $12 ?
$12 : '';
769 my $rightpart = defined $13 ?
$13 : '';
771 $fallbackhashhash_ref->{ $cur_lang }{ $key } = $leftpart."\t".$cur_lang."\t".$rightpart;
776 ############################################################
777 sub remove_duplicates
{
778 my $list_ref = shift;
780 foreach my $key ( @
{ $list_ref } ){ $tmphash{ $key } = '' ; }
781 @
{$list_ref} = keys( %tmphash );
784 ##############################################################
786 my $sdfparticleslist_ref = shift;
787 my $localizeSDF = shift;
788 my $langhash_ref = shift;
789 my %fallbackhashhash;
793 foreach my $key ( keys ( %{ $langhash_ref } ) ){
794 $cur_lang = $langhash_ref->{ $key };
795 if ( $cur_lang ne "" ) {
796 push @langlist , $cur_lang;
799 remove_duplicates
( \
@langlist );
800 foreach $cur_lang ( @langlist ){
801 if( $cur_lang eq "en-US" ){
802 read_fallbacks_from_source
( $localizeSDF , $cur_lang , \
%fallbackhashhash );
808 foreach $cur_lang( @langlist ){
809 if( $cur_lang ne "en-US" ){
810 push @tmplist , $cur_lang;
814 @langlist = @tmplist;
815 if ( $#langlist +1 ){
816 read_fallbacks_from_particles
( $sdfparticleslist_ref , \
@langlist , \
%fallbackhashhash );
819 return (\
%fallbackhashhash);
822 #########################################################
825 my $localizeFile = shift;
826 my $index_ref = shift;
828 if( open DESTFILE
, "+> $localizeFile" ){
829 foreach my $key( %{ $index_ref } ){
830 print DESTFILE
($index_ref->{ $key }, "\n" );
834 print STDERR
"Can't open/create '$localizeFile'";
838 #########################################################
842 my $langhash_ref = shift;
845 open MYFILE
, "< $sdffile"
846 or die "Can't open '$sdffile'\n";
849 my $line = defined $_ ?
$_ : '';
850 my $prj = defined $3 ?
$3 : '';
851 my $file = defined $4 ?
$4 : '';
852 my $type = defined $6 ?
$6 : '';
853 my $gid = defined $7 ?
$7 : '';
854 my $lid = defined $8 ?
$8 : '';
855 my $plattform = defined $10 ?
$10 : '';
856 my $lang = defined $12 ?
$12 : '';
857 my $helpid = defined $9 ?
$9 : '';
859 foreach my $isolang ( keys ( %{ $langhash_ref } ) ){
860 if( $isolang=~ /$lang/i || $isolang=~ /all/i ) { $block{$prj.$gid.$lid.$file.$type.$plattform.$helpid } = $line ; }
867 #########################################################
868 sub read_fallbacks_from_particles
{
870 my $sdfparticleslist_ref = shift;
871 my $isolanglist_ref = shift;
872 my $fallbackhashhash_ref = shift;
874 foreach my $currentfile ( @
{ $sdfparticleslist_ref } ){
875 if ( open MYFILE
, "< $currentfile" ) {
878 my $line = defined $_ ?
$_ : '';
879 my $prj = defined $3 ?
$3 : '';
880 my $file = defined $4 ?
$4 : '';
881 my $type = defined $6 ?
$6 : '';
882 my $gid = defined $7 ?
$7 : '';
883 my $lid = defined $8 ?
$8 : '';
884 my $lang = defined $12 ?
$12 : '';
885 my $plattform = defined $10 ?
$10 : '';
886 my $helpid = defined $9 ?
$9 : '';
890 foreach my $isolang ( @
{$isolanglist_ref} ){
891 if( $isolang=~ /$lang/i ) {
892 $fallbackhashhash_ref->{ $isolang }{ $prj.$gid.$lid.$file.$type.$plattform.$helpid } = $line ;
897 }else { print STDERR
"WARNING: Can't open file $currentfile"; }
901 #########################################################
902 sub read_fallbacks_from_source
{
906 my $fallbackhashhash_ref = shift;
908 # read fallback for single file
909 open MYFILE
, "< $sdffile"
910 or die "Can't open '$sdffile'\n";
914 my $line = defined $_ ?
$_ : '';
915 my $prj = defined $3 ?
$3 : '';
916 my $file = defined $4 ?
$4 : '';
917 my $type = defined $6 ?
$6 : '';
918 my $gid = defined $7 ?
$7 : '';
919 my $lid = defined $8 ?
$8 : '';
920 my $helpid = defined $9 ?
$9 : '';
921 my $lang = defined $12 ?
$12 : '';
922 my $plattform = defined $10 ?
$10 : '';
925 if( $isolang=~ /$lang/i ) { $fallbackhashhash_ref->{ $isolang }{ $prj.$gid.$lid.$file.$type.$plattform.$helpid } = $line ;
931 #########################################################
936 my $bHasSourceLanguage="";
943 if( $languages=~ /all/ ){
945 $bHasSourceLanguage = "TRUE";
948 elsif( $languages=~ /.*,.*/ ){
949 my @tmpstr = split "," , $languages;
950 for my $lang ( @tmpstr ){
951 if( $lang=~ /([a-zA-Z]{2,3}(-[a-zA-Z\-]*)*)(=([a-zA-Z]{2,3}(-[a-zA-Z\-]*)*))?/ ){
955 if( ( $iso && $iso=~ /(en-US)/i ) || ( $fallback && $fallback=~ /(en-US)/i ) ) {
956 $bUseLocalize = "TRUE";
958 if( ( $iso && $iso=~ /(en-US)/i ) ) {
959 $bHasSourceLanguage = "TRUE";
961 if( $fallback ) { $langhash{ $iso } = $fallback; }
962 else { $langhash{ $iso } = ""; }
968 if( $languages=~ /([a-zA-Z]{2,3}(-[a-zA-Z\-]*)*)(=([a-zA-Z]{2,3}(-[a-zA-Z\-]*)*))?/ ){
972 if( ( $iso && $iso=~ /(en-US)/i ) || ( $fallback && $fallback=~ /(en-US)/i ) ) {
973 $bUseLocalize = "TRUE";
976 if( ( $iso && $iso=~ /(en-US)/i ) ) {
977 $bHasSourceLanguage = "TRUE";
980 if( $fallback ) { $langhash{ $iso } = $fallback; }
981 else { $langhash{ $iso } = ""; }
984 # HACK en-US always needed!
985 if( !$bHasSourceLanguage ){
986 #$bHasSourceLanguage = "TRUE";
987 $bUseLocalize = "TRUE";
988 $bFakeEnglish = "TRUE";
989 $langhash{ "en-US" } = "";
991 return ( $bAll , $bUseLocalize , \
%langhash , $bHasSourceLanguage, $bFakeEnglish);
994 #########################################################
1000 my $success = GetOptions
('f=s' => \
$sdffile , 'l=s' => \
$languages , 's=s' => \
$srcpath , 'h' => \
$help , 'v' => \
$bVerbose ,
1001 'm' => \
$merge , 'e' => \
$extract , 'x' => \
$no_sort , 'd' => \
$use_default_date );
1002 $outputfile = $sdffile;
1004 #print STDOUT "DBG: lang = $languages\n";
1006 #$srcpath = "$ENV{SRC_ROOT}";
1008 print STDERR
"No path to the source root found!\n\n";
1013 if( $help || !$success || $#ARGV > 1 || ( !$sdffile ) ){
1017 if( $merge && $sdffile && ! ( -r
$sdffile)){
1018 print STDERR
"Can't open file '$sdffile'\n";
1021 if( !( $languages=~ /[a-zA-Z]{2,3}(-[a-zA-Z\-]*)*(=[a-zA-Z]{2,3}(-[a-zA-Z\-]*)*)?(,[a-zA-Z]{2,3}(-[a-zA-Z\-]*)*(=[a-zA-Z]{2,3}(-[a-zA-Z\-]*)*)?)*/ ) ){
1022 print STDERR
"Please check the -l iso code\n";
1025 if( ( !$merge && !$extract ) || ( $merge && $extract ) ){ usage
();exit( -1 );}
1026 if( $extract ){ $mode = "extract"; }
1027 else { $mode = "merge"; }
1030 #########################################################
1033 print STDERR
"Usage: localize.pl\n";
1034 print STDERR
"Split or collect SDF files\n";
1035 print STDERR
" merge: -m -f <sdffile> -l l1[=f1][,l2[=f2]][...] [ -s <sourceroot> ]\n";
1036 print STDERR
" extract: -e -f <outputfile> -l <lang> [ -s <sourceroot> ] [-d]\n";
1037 print STDERR
"Options:\n";
1038 print STDERR
" -h help\n";
1039 print STDERR
" -m Merge mode\n";
1040 print STDERR
" -e Extract mode\n";
1041 print STDERR
" -f <sdffile> To split a big SDF file into particles\n";
1042 print STDERR
" <outputfile> To collect and join all particles to one big file\n";
1043 print STDERR
" -s <sourceroot> Path to the modules, if no \$SRC_ROOT is set\n";
1044 print STDERR
" -l ( all | <isocode> | <isocode>=fallback ) comma seperated languages\n";
1045 print STDERR
" -d Use default date in extracted sdf file\n";
1046 print STDERR
" -v Verbose\n";
1047 print STDERR
"\nExample:\n";
1048 print STDERR
"\nlocalize -e -l en-US,pt-BR=en-US -f my.sdf\n( Extract en-US and pt-BR with en-US fallback )\n";
1049 print STDERR
"\nlocalize -m -l cs -f my.sdf\n( Merge cs translation into the sourcecode ) \n";
1052 # my $line = defined $_ ? $_ : '';
1053 # my $leftpart = defined $2 ? $2 : '';
1054 # my $prj = defined $3 ? $3 : '';
1055 # my $file = defined $4 ? $4 : '';
1056 # my $dummy = defined $5 ? $5 : '';
1057 # my $type = defined $6 ? $6 : '';
1058 # my $gid = defined $7 ? $7 : '';
1059 # my $lid = defined $8 ? $8 : '';
1060 # my $helpid = defined $9 ? $9 : '';
1061 # my $plattform = defined $10 ? $10 : '';
1062 # my $width = defined $11 ? $11 : '';
1063 # my $lang = defined $12 ? $12 : '';
1064 # my $rightpart = defined $13 ? $13 : '';
1065 # my $text = defined $14 ? $14 : '';
1066 # my $helptext = defined $15 ? $15 : '';
1067 # my $quickhelptext = defined $16 ? $16 : '';
1068 # my $title = defined $17 ? $17 : '';
1069 # my $timestamp = defined $18 ? $18 : '';