in main/l10ntools/scripts/localize_old.pl [333:610]
sub collectfiles{
print STDOUT "### Localize\n";
my @sdfparticles;
my $localizehash_ref;
my ( $bAll , $bUseLocalize, $langhash_ref , $bHasSourceLanguage , $bFakeEnglish ) = parseLanguages();
# Enable autoflush on STDOUT
# $| = 1;
STDOUT->autoflush( 1 );
### Search sdf particles
print STDOUT "### Searching sdf particles\n";
my $working_path = getcwd();
chdir $srcpath;
find sub {
my $file = $File::Find::name;
if( -f && $file =~ /.*localize.sdf$/ ) {
push @sdfparticles , $file;
if( $bVerbose eq "1" ) { print STDOUT "$file\n"; }
else { print "."; }
}
} , getcwd() ;#"."; #$srcpath;
chdir $working_path;
my $nFound = $#sdfparticles +1;
print "\n $nFound files found !\n";
my ( $LOCALIZEPARTICLE , $localizeSDF ) = File::Temp::tempfile();
close( $LOCALIZEPARTICLE );
my ( $ALLPARTICLES_MERGED , $particleSDF_merged ) = File::Temp::tempfile();
close( $ALLPARTICLES_MERGED );
my ( $LOCALIZE_LOG , $my_localize_log ) = File::Temp::tempfile();
close( $LOCALIZE_LOG );
## Get the localize de,en-US extract
if( $bAll || $bUseLocalize ){
print "### Fetching source language strings\n";
my $command = "";
my $args = "";
if( $ENV{WRAPCMD} ){
$command = "$ENV{WRAPCMD} localize_sl";
}else{
$command = "localize_sl";
}
# -e
# if ( -x $command ){
if( $command ){
if( !$bVerbose ){ $args .= " -QQ -skip_links "; }
$args .= " -e -f $localizeSDF -l ";
my $bFlag="";
if( $bAll ) {$args .= " en-US";}
else{
my @list;
foreach my $isokey ( keys( %{ $langhash_ref } ) ){
push @list , $isokey;
if( $langhash_ref->{ $isokey } ne "" ){
push @list , $langhash_ref->{ $isokey };
}
}
remove_duplicates( \@list );
foreach my $isokey ( @list ){
switch :{
#( $isokey=~ /^de$/i )
# && do{
# if( $bFlag eq "TRUE" ){ $args .= ",de"; }
# else {
# $args .= "de"; $bFlag = "TRUE";
# }
# };
( $isokey=~ /^en-US$/i )
&& do{
if( $bFlag eq "TRUE" ){ $args .= ",en-US"; }
else {
$args .= "en-US"; $bFlag = "TRUE";
}
};
} #switch
} #foreach
} # if
} # if
if ( $bVerbose ) { print STDOUT $command.$args."\n"; }
my $rc = system( $command.$args );
#my $output = `$command.$args`;
#my $rc = $? << 8;
if( $rc < 0 ){ print STDERR "ERROR: localize rc = $rc\n"; exit( -1 ); }
( $localizehash_ref ) = read_file( $localizeSDF , $langhash_ref );
}
## Get sdf particles
open ALLPARTICLES_MERGED , "+>> $particleSDF_merged"
or die "Can't open $particleSDF_merged";
## Fill fackback hash
my( $fallbackhashhash_ref ) = fetch_fallback( \@sdfparticles , $localizeSDF , $langhash_ref );
# my( $fallbackhashhash_ref ) = fetch_fallback( \@sdfparticles , $localizeSDF , $langhash_ref );
my %block;
my $cur_fallback;
if( !$bAll) {
foreach my $cur_lang ( keys( %{ $langhash_ref } ) ){
#print STDOUT "DBG: G1 cur_lang=$cur_lang\n";
$cur_fallback = $langhash_ref->{ $cur_lang };
if( $cur_fallback ne "" ){
# Insert fallback strings
#print STDOUT "DBG: Renaming $cur_fallback to $cur_lang in fallbackhash\n";
rename_language( $fallbackhashhash_ref , $cur_fallback , $cur_lang );
}
foreach my $currentfile ( @sdfparticles ){
if ( open MYFILE , "< $currentfile" ) {
while(<MYFILE>){
if( /$sdf_regex/ ){
my $line = defined $_ ? $_ : '';
my $prj = defined $3 ? $3 : '';
my $file = defined $4 ? $4 : '';
my $type = defined $6 ? $6 : '';
my $gid = defined $7 ? $7 : '';
my $lid = defined $8 ? $8 : '';
my $lang = defined $12 ? $12 : '';
my $platform = defined $10 ? $10 : '';
my $helpid = defined $9 ? $9 : '';
chomp( $line );
if ( $lang eq $cur_lang ){
# Overwrite fallback strings with collected strings
#if( ( !has_two_sourcelanguages( $cur_lang) && $cur_lang eq "de" ) || $cur_lang ne "en-US" ){
$fallbackhashhash_ref->{ $cur_lang }{ $prj.$gid.$lid.$file.$type.$platform.$helpid } = $line ;
#}
}
}
}
}else { print STDERR "WARNING: Can't open file $currentfile"; }
}
foreach my $line ( keys( %{$fallbackhashhash_ref->{ $cur_lang } } )) {
if( #$cur_lang ne "de" &&
$cur_lang ne "en-US" ){
print ALLPARTICLES_MERGED ( $fallbackhashhash_ref->{ $cur_lang }{ $line }, "\n" );
}
}
}
} else {
foreach my $currentfile ( @sdfparticles ){
if ( open MYFILE , "< $currentfile" ) {
while( <MYFILE> ){
print ALLPARTICLES_MERGED ( $_, "\n" ); # recheck de / en-US !
}
}
else { print STDERR "WARNING: Can't open file $currentfile"; }
}
}
close ALLPARTICLES_MERGED;
# Hash of array
my %output;
my @order;
## Join both
if( $outputfile ){
if( open DESTFILE , "+> $outputfile" ){
if( !open LOCALIZEPARTICLE , "< $localizeSDF" ) { print STDERR "ERROR: Can't open file $localizeSDF\n"; }
if( !open ALLPARTICLES_MERGED , "< $particleSDF_merged" ) { print STDERR "ERROR: Can't open file $particleSDF_merged\n"; }
# Insert localize
my $extract_date="";
while ( <LOCALIZEPARTICLE> ){
if( /$sdf_regex/ ){
my $leftpart = defined $2 ? $2 : '';
my $lang = defined $12 ? $12 : '';
my $rightpart = defined $13 ? $13 : '';
my $timestamp = defined $18 ? $18 : '';
my $prj = defined $3 ? $3 : '';
my $file = defined $4 ? $4 : '';
my $type = defined $6 ? $6 : '';
my $gid = defined $7 ? $7 : '';
my $lid = defined $8 ? $8 : '';
#my $lang = defined $12 ? $12 : '';
my $platform = defined $10 ? $10 : '';
my $helpid = defined $9 ? $9 : '';
if( $use_default_date )
{
$extract_date = "$default_date\n" ;
}
elsif( $extract_date eq "" ) {
$extract_date = $timestamp ;
$extract_date =~ tr/\r\n//d;
$extract_date .= "\n";
}
if( $bAll ){ print DESTFILE $leftpart."\t".$lang."\t".$rightpart.$extract_date ; }
else {
foreach my $sLang ( keys( %{ $langhash_ref } ) ){
if( $sLang=~ /all/i ) {
push @{ $output{ $prj.$gid.$lid.$file.$type.$platform.$helpid } } , $leftpart."\t".$lang."\t".$rightpart.$extract_date ;
#print DESTFILE $leftpart."\t".$lang."\t".$rightpart.$extract_date;
}
#if( $sLang eq "de" && $lang eq "de" ) {
# push @{ $output{ $prj.$gid.$lid.$file.$type.$platform.$helpid } } , $leftpart."\t".$lang."\t".$rightpart.$extract_date ;
#print DESTFILE $leftpart."\t".$lang."\t".$rightpart.$extract_date;
#}
if( $sLang eq "en-US" && $lang eq "en-US" ) {
push @order , $prj.$gid.$lid.$file.$type.$platform.$helpid;
if( !$bFakeEnglish ){ push @{ $output{ $prj.$gid.$lid.$file.$type.$platform.$helpid } } , $leftpart."\t".$lang."\t".$rightpart.$extract_date ; }
#print DESTFILE $leftpart."\t".$lang."\t".$rightpart.$extract_date;
}
}
}
}
}
# Insert particles
while ( <ALLPARTICLES_MERGED> ){
if( /$sdf_regex/ ){
my $leftpart = defined $2 ? $2 : '';
my $prj = defined $3 ? $3 : '';
my $lang = defined $12 ? $12 : '';
my $rightpart = defined $13 ? $13 : '';
my $timestamp = defined $18 ? $18 : '';
#my $prj = defined $3 ? $3 : '';
my $file = defined $4 ? $4 : '';
my $type = defined $6 ? $6 : '';
my $gid = defined $7 ? $7 : '';
my $lid = defined $8 ? $8 : '';
#my $lang = defined $12 ? $12 : '';
my $platform = defined $10 ? $10 : '';
my $helpid = defined $9 ? $9 : '';
if( $use_default_date )
{
$extract_date = "$default_date\n" ;
}
elsif( $extract_date eq "" )
{
$extract_date = $timestamp;
}
if( ! ( $prj =~ /binfilter/i ) ) {
push @{ $output{ $prj.$gid.$lid.$file.$type.$platform.$helpid } } , $leftpart."\t".$lang."\t".$rightpart.$extract_date ;
#print DESTFILE $leftpart."\t".$lang."\t".$rightpart.$extract_date ;
}
}
}
# Write!
foreach my $curkey ( @order ){
foreach my $curlist ( $output{ $curkey } ){
foreach my $line ( @{$curlist} ){
print DESTFILE $line;
}
}
}
}else { print STDERR "Can't open $outputfile";}
}
close DESTFILE;
close LOCALIZEPARTICLE;
close ALLPARTICLES_MERGED;
#print STDOUT "DBG: \$localizeSDF $localizeSDF \$particleSDF_merged $particleSDF_merged\n";
unlink $localizeSDF , $particleSDF_merged , $my_localize_log;
#sort_outfile( $outputfile );
#remove_obsolete( $outputfile ) , if $bHasSourceLanguage ne "";
}