1*cdf0e10cSrcweir:
2*cdf0e10cSrcweireval 'exec perl -wS $0 ${1+"$@"}'
3*cdf0e10cSrcweir    if 0;
4*cdf0e10cSrcweir
5*cdf0e10cSrcweir
6*cdf0e10cSrcweir#*************************************************************************
7*cdf0e10cSrcweir#
8*cdf0e10cSrcweir# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
9*cdf0e10cSrcweir#
10*cdf0e10cSrcweir# Copyright 2000, 2010 Oracle and/or its affiliates.
11*cdf0e10cSrcweir#
12*cdf0e10cSrcweir# OpenOffice.org - a multi-platform office productivity suite
13*cdf0e10cSrcweir#
14*cdf0e10cSrcweir# This file is part of OpenOffice.org.
15*cdf0e10cSrcweir#
16*cdf0e10cSrcweir# OpenOffice.org is free software: you can redistribute it and/or modify
17*cdf0e10cSrcweir# it under the terms of the GNU Lesser General Public License version 3
18*cdf0e10cSrcweir# only, as published by the Free Software Foundation.
19*cdf0e10cSrcweir#
20*cdf0e10cSrcweir# OpenOffice.org is distributed in the hope that it will be useful,
21*cdf0e10cSrcweir# but WITHOUT ANY WARRANTY; without even the implied warranty of
22*cdf0e10cSrcweir# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23*cdf0e10cSrcweir# GNU Lesser General Public License version 3 for more details
24*cdf0e10cSrcweir# (a copy is included in the LICENSE file that accompanied this code).
25*cdf0e10cSrcweir#
26*cdf0e10cSrcweir# You should have received a copy of the GNU Lesser General Public License
27*cdf0e10cSrcweir# version 3 along with OpenOffice.org.  If not, see
28*cdf0e10cSrcweir# <http://www.openoffice.org/license.html>
29*cdf0e10cSrcweir# for a copy of the LGPLv3 License.
30*cdf0e10cSrcweir#
31*cdf0e10cSrcweir#*************************************************************************
32*cdf0e10cSrcweir
33*cdf0e10cSrcweiruse strict;
34*cdf0e10cSrcweiruse Getopt::Long;
35*cdf0e10cSrcweiruse IO::Handle;
36*cdf0e10cSrcweiruse File::Find;
37*cdf0e10cSrcweiruse File::Temp;
38*cdf0e10cSrcweiruse File::Copy;
39*cdf0e10cSrcweiruse File::Glob qw(:glob csh_glob);
40*cdf0e10cSrcweiruse Cwd;
41*cdf0e10cSrcweir
42*cdf0e10cSrcweir# ver 1.1
43*cdf0e10cSrcweir#
44*cdf0e10cSrcweir#### module lookup
45*cdf0e10cSrcweir#use lib ("$ENV{SOLARENV}/bin/modules", "$ENV{COMMON_ENV_TOOLS}/modules");
46*cdf0e10cSrcweir
47*cdf0e10cSrcweir#### module lookup
48*cdf0e10cSrcweir# OOo conform
49*cdf0e10cSrcweirmy @lib_dirs;
50*cdf0e10cSrcweirBEGIN {
51*cdf0e10cSrcweir    if ( !defined($ENV{SOLARENV}) ) {
52*cdf0e10cSrcweir        die "No environment found (environment variable SOLARENV is undefined)";
53*cdf0e10cSrcweir    }
54*cdf0e10cSrcweir    push(@lib_dirs, "$ENV{SOLARENV}/bin/modules");
55*cdf0e10cSrcweir    push(@lib_dirs, "$ENV{COMMON_ENV_TOOLS}/modules") if defined($ENV{COMMON_ENV_TOOLS});
56*cdf0e10cSrcweir}
57*cdf0e10cSrcweiruse lib (@lib_dirs);
58*cdf0e10cSrcweir
59*cdf0e10cSrcweir#### globals ####
60*cdf0e10cSrcweirmy $sdffile = '';
61*cdf0e10cSrcweirmy $no_sort = '';
62*cdf0e10cSrcweirmy $outputfile = '';
63*cdf0e10cSrcweirmy $mode = '';
64*cdf0e10cSrcweirmy $bVerbose="0";
65*cdf0e10cSrcweirmy $srcpath = '';
66*cdf0e10cSrcweirmy $languages;
67*cdf0e10cSrcweir#my %sl_modules;     # Contains all modules where en-US and de is source language
68*cdf0e10cSrcweirmy $use_default_date = '0';
69*cdf0e10cSrcweir
70*cdf0e10cSrcweir         #         (                           leftpart                                                     )            (           rightpart                    )
71*cdf0e10cSrcweir         #            prj      file      dummy     type       gid       lid      helpid    pform     width      lang       text    helptext  qhelptext   title    timestamp
72*cdf0e10cSrcweirmy $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*cdf0e10cSrcweirmy $file_types = "(src|hrc|xcs|xcu|lng|ulf|xrm|xhp|xcd|xgf|xxl|xrb)";
74*cdf0e10cSrcweir# Always use this date to prevent cvs conflicts
75*cdf0e10cSrcweirmy $default_date = "2002-02-02 02:02:02";
76*cdf0e10cSrcweir
77*cdf0e10cSrcweir#### main ####
78*cdf0e10cSrcweirparse_options();
79*cdf0e10cSrcweir
80*cdf0e10cSrcweir#%sl_modules = fetch_sourcelanguage_dirlist();
81*cdf0e10cSrcweir
82*cdf0e10cSrcweir
83*cdf0e10cSrcweirif   ( $mode eq "merge"    )    {
84*cdf0e10cSrcweir    merge_gsicheck();
85*cdf0e10cSrcweir    splitfile( $sdffile );
86*cdf0e10cSrcweir    unlink $sdffile;             # remove temp file!
87*cdf0e10cSrcweir}
88*cdf0e10cSrcweirelsif( $mode eq "extract"  )    {
89*cdf0e10cSrcweir    collectfiles( $outputfile );
90*cdf0e10cSrcweir}
91*cdf0e10cSrcweirelse                            {
92*cdf0e10cSrcweir    usage();
93*cdf0e10cSrcweir}
94*cdf0e10cSrcweir
95*cdf0e10cSrcweirexit(0);
96*cdf0e10cSrcweir
97*cdf0e10cSrcweir#########################################################
98*cdf0e10cSrcweirsub splitfile{
99*cdf0e10cSrcweir
100*cdf0e10cSrcweir    my $lastFile        = '';
101*cdf0e10cSrcweir    my $currentFile     = '';
102*cdf0e10cSrcweir    my $cur_sdffile     = '';
103*cdf0e10cSrcweir    my $last_sdffile    = '';
104*cdf0e10cSrcweir    my $delim;
105*cdf0e10cSrcweir    my $badDelim;
106*cdf0e10cSrcweir    my $start           = 'TRUE';
107*cdf0e10cSrcweir    my %index  = ();
108*cdf0e10cSrcweir    my %block;
109*cdf0e10cSrcweir
110*cdf0e10cSrcweir    STDOUT->autoflush( 1 );
111*cdf0e10cSrcweir
112*cdf0e10cSrcweir    #print STDOUT "Open File $sdffile\n";
113*cdf0e10cSrcweir    open MYFILE , "< $sdffile"
114*cdf0e10cSrcweir    or die "Can't open '$sdffile'\n";
115*cdf0e10cSrcweir
116*cdf0e10cSrcweir    while( <MYFILE>){
117*cdf0e10cSrcweir         if( /$sdf_regex/ ){
118*cdf0e10cSrcweir            my $line           = defined $_ ? $_ : '';
119*cdf0e10cSrcweir            my $prj            = defined $3 ? $3 : '';
120*cdf0e10cSrcweir            my $file           = defined $4 ? $4 : '';
121*cdf0e10cSrcweir            my $type           = defined $6 ? $6 : '';
122*cdf0e10cSrcweir            my $gid            = defined $7 ? $7 : '';
123*cdf0e10cSrcweir            my $lid            = defined $8 ? $8 : '';
124*cdf0e10cSrcweir            my $lang           = defined $12 ? $12 : '';
125*cdf0e10cSrcweir            my $plattform      = defined $10 ? $10 : '';
126*cdf0e10cSrcweir            my $helpid         = defined $9 ? $9 : '';
127*cdf0e10cSrcweir
128*cdf0e10cSrcweir            next if( $prj eq "binfilter" );     # Don't merge strings into binfilter module
129*cdf0e10cSrcweir	        chomp( $line );
130*cdf0e10cSrcweir            $currentFile  = $srcpath . '\\' . $prj . '\\' . $file;
131*cdf0e10cSrcweir            $currentFile  =~ s/\\/\//g;
132*cdf0e10cSrcweir
133*cdf0e10cSrcweir            $cur_sdffile = $currentFile;
134*cdf0e10cSrcweir            #if( $cur_sdffile =~ /\.$file_types[\s]*$/ ){
135*cdf0e10cSrcweir                $cur_sdffile =~ s/\/[^\/]*\.$file_types[\s]*$/\/localize.sdf/;
136*cdf0e10cSrcweir            #}
137*cdf0e10cSrcweir
138*cdf0e10cSrcweir            # Set default date
139*cdf0e10cSrcweir            if( $line =~ /(.*)\t[^\t\$]*$/ ){
140*cdf0e10cSrcweir                $line = $1."\t".$default_date;
141*cdf0e10cSrcweir            }
142*cdf0e10cSrcweir
143*cdf0e10cSrcweir            if( $start ){
144*cdf0e10cSrcweir                $start='';
145*cdf0e10cSrcweir                $lastFile = $currentFile; # ?
146*cdf0e10cSrcweir                $last_sdffile = $cur_sdffile;
147*cdf0e10cSrcweir            }
148*cdf0e10cSrcweir
149*cdf0e10cSrcweir            if( $lang eq "en-US" ){}
150*cdf0e10cSrcweir            elsif( $cur_sdffile eq $last_sdffile )
151*cdf0e10cSrcweir            {
152*cdf0e10cSrcweir                $block{ "$prj\t$file\t$type\t$gid\t$lid\t$helpid\t$plattform\t$lang" } =  $line ;
153*cdf0e10cSrcweir            }
154*cdf0e10cSrcweir            else
155*cdf0e10cSrcweir            {
156*cdf0e10cSrcweir                writesdf( $lastFile , \%block );
157*cdf0e10cSrcweir                $lastFile = $currentFile; #?
158*cdf0e10cSrcweir                $last_sdffile = $cur_sdffile;
159*cdf0e10cSrcweir                %block = ();
160*cdf0e10cSrcweir                #if( ! $lang eq "en-US"  ) {
161*cdf0e10cSrcweir                $block{ "$prj\t$file\t$type\t$gid\t$lid\t$helpid\t$plattform\t$lang" } =  $line ;
162*cdf0e10cSrcweir                #}
163*cdf0e10cSrcweir
164*cdf0e10cSrcweir            }
165*cdf0e10cSrcweir        } #else { print STDOUT "splitfile REGEX kaputt\n";}
166*cdf0e10cSrcweir
167*cdf0e10cSrcweir    }
168*cdf0e10cSrcweir    writesdf( $lastFile , \%block );
169*cdf0e10cSrcweir    %block = ();
170*cdf0e10cSrcweir    close( MYFILE );
171*cdf0e10cSrcweir
172*cdf0e10cSrcweir}
173*cdf0e10cSrcweir#########################################################
174*cdf0e10cSrcweir
175*cdf0e10cSrcweirsub writesdf{
176*cdf0e10cSrcweir
177*cdf0e10cSrcweir    my $lastFile        = shift;
178*cdf0e10cSrcweir    my $blockhash_ref   = shift;
179*cdf0e10cSrcweir    my $localizeFile    = $lastFile;
180*cdf0e10cSrcweir    my %index=();
181*cdf0e10cSrcweir
182*cdf0e10cSrcweir    if( $localizeFile =~ /\.$file_types[\s]*$/ ){
183*cdf0e10cSrcweir        $localizeFile =~ s/\/[^\/]*\.$file_types[\s]*$/\/localize.sdf/;
184*cdf0e10cSrcweir        }else {
185*cdf0e10cSrcweir            print STDERR "Strange filetype found '$localizeFile'\n";
186*cdf0e10cSrcweir            return;
187*cdf0e10cSrcweir        }
188*cdf0e10cSrcweir        if( open DESTFILE , "< $localizeFile" ){
189*cdf0e10cSrcweir
190*cdf0e10cSrcweir        #or die "Can't open/create '\$localizeFile'";
191*cdf0e10cSrcweir
192*cdf0e10cSrcweir        #### Build hash
193*cdf0e10cSrcweir        while(<DESTFILE>){
194*cdf0e10cSrcweir         if( /$sdf_regex/ ){
195*cdf0e10cSrcweir            my $line           = defined $_ ? $_ : '';
196*cdf0e10cSrcweir            my $prj            = defined $3 ? $3 : '';
197*cdf0e10cSrcweir            my $file           = defined $4 ? $4 : '';
198*cdf0e10cSrcweir            my $type           = defined $6 ? $6 : '';
199*cdf0e10cSrcweir            my $gid            = defined $7 ? $7 : '';
200*cdf0e10cSrcweir            my $lid            = defined $8 ? $8 : '';
201*cdf0e10cSrcweir            my $lang           = defined $12 ? $12 : '';
202*cdf0e10cSrcweir            my $plattform      = defined $10 ? $10 : '';
203*cdf0e10cSrcweir            my $helpid         = defined $9 ? $9 : '';
204*cdf0e10cSrcweir
205*cdf0e10cSrcweir            chomp( $line );
206*cdf0e10cSrcweir            $index{ "$prj\t$file\t$type\t$gid\t$lid\t$helpid\t$plattform\t$lang" } =  $line ;
207*cdf0e10cSrcweir
208*cdf0e10cSrcweir         } #else { print STDOUT "writesdf REGEX kaputt $_\n";}
209*cdf0e10cSrcweir
210*cdf0e10cSrcweir        }
211*cdf0e10cSrcweir        close( DESTFILE );
212*cdf0e10cSrcweir    }
213*cdf0e10cSrcweir    #### Copy new strings
214*cdf0e10cSrcweir    my @mykeys = keys( %{ $blockhash_ref } );
215*cdf0e10cSrcweir    my $isDirty = "FALSE";
216*cdf0e10cSrcweir    foreach my $key( @mykeys ){
217*cdf0e10cSrcweir        if( ! defined $index{ $key } ){
218*cdf0e10cSrcweir            # Add new entry
219*cdf0e10cSrcweir            $index{ $key }  = $blockhash_ref->{ $key} ;
220*cdf0e10cSrcweir            $isDirty = "TRUE";
221*cdf0e10cSrcweir        }elsif( $index{ $key } ne $blockhash_ref->{ $key } ){
222*cdf0e10cSrcweir            # Overwrite old entry
223*cdf0e10cSrcweir            $index{ $key } = $blockhash_ref->{ $key };
224*cdf0e10cSrcweir            $isDirty = "TRUE";
225*cdf0e10cSrcweir        }else {
226*cdf0e10cSrcweir        }
227*cdf0e10cSrcweir    }
228*cdf0e10cSrcweir
229*cdf0e10cSrcweir    #### Write file
230*cdf0e10cSrcweir
231*cdf0e10cSrcweir    if( !$bVerbose ){ print STDOUT "."; }
232*cdf0e10cSrcweir    if( $isDirty eq "TRUE" ){
233*cdf0e10cSrcweir        if( $bVerbose ){ print STDOUT "$localizeFile\n"; }
234*cdf0e10cSrcweir        if( open DESTFILE , "+> $localizeFile" ){
235*cdf0e10cSrcweir            print DESTFILE get_license_header();
236*cdf0e10cSrcweir            @mykeys = sort keys( %index );
237*cdf0e10cSrcweir            foreach my $key( @mykeys ){
238*cdf0e10cSrcweir                print DESTFILE ( $index{ $key } , "\n" );
239*cdf0e10cSrcweir            }
240*cdf0e10cSrcweir            close DESTFILE;
241*cdf0e10cSrcweir         }else {
242*cdf0e10cSrcweir            print STDOUT "WARNING: File $localizeFile is not writable , try to merge ...\n";
243*cdf0e10cSrcweir            my ( $TMPFILE , $tmpfile ) = File::Temp::tempfile();
244*cdf0e10cSrcweir            if( open DESTFILE , "+> $tmpfile " ){
245*cdf0e10cSrcweir                @mykeys = keys( %index );
246*cdf0e10cSrcweir                foreach my $key( @mykeys ){
247*cdf0e10cSrcweir                    print DESTFILE ( $index{ $key } , "\n" );
248*cdf0e10cSrcweir                }
249*cdf0e10cSrcweir                close DESTFILE;
250*cdf0e10cSrcweir                if( move( $localizeFile , $localizeFile.".backup" ) ){
251*cdf0e10cSrcweir                    if( copy( $tmpfile , $localizeFile ) ){
252*cdf0e10cSrcweir                        unlink $localizeFile.".backup";
253*cdf0e10cSrcweir                    } else { print STDERR "Can't open/create '$localizeFile', original file is renamed to  $localizeFile.backup\n"; }
254*cdf0e10cSrcweir                } else { print STDERR "Can't open/create '$localizeFile'\n"; }
255*cdf0e10cSrcweir            }else{
256*cdf0e10cSrcweir                print STDERR "WARNING: Can't open/create '$localizeFile'\n";
257*cdf0e10cSrcweir            }
258*cdf0e10cSrcweir            unlink $tmpfile;
259*cdf0e10cSrcweir        }
260*cdf0e10cSrcweir    }
261*cdf0e10cSrcweir#    if( $no_sort eq '' ){
262*cdf0e10cSrcweir#        sort_outfile( $localizeFile );
263*cdf0e10cSrcweir#    }
264*cdf0e10cSrcweir}
265*cdf0e10cSrcweir
266*cdf0e10cSrcweirsub get_license_header{
267*cdf0e10cSrcweir    return
268*cdf0e10cSrcweir"#\n".
269*cdf0e10cSrcweir"#    ####    ###     #   #   ###   #####    #####  ####   #####  #####  \n".
270*cdf0e10cSrcweir"#    #   #  #   #    ##  #  #   #    #      #      #   #    #      #    \n".
271*cdf0e10cSrcweir"#    #   #  #   #    # # #  #   #    #      ###    #   #    #      #    \n".
272*cdf0e10cSrcweir"#    #   #  #   #    #  ##  #   #    #      #      #   #    #      #    \n".
273*cdf0e10cSrcweir"#    ####    ###     #   #   ###     #      #####  ####   #####    #    \n".
274*cdf0e10cSrcweir"#\n".
275*cdf0e10cSrcweir"#    DO NOT EDIT! This file will be overwritten by localisation process\n".
276*cdf0e10cSrcweir"#\n".
277*cdf0e10cSrcweir"#*************************************************************************\n".
278*cdf0e10cSrcweir"#\n".
279*cdf0e10cSrcweir"# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.\n".
280*cdf0e10cSrcweir"# \n".
281*cdf0e10cSrcweir"# Copyright 2000, 2010 Oracle and/or its affiliates.\n".
282*cdf0e10cSrcweir"#\n".
283*cdf0e10cSrcweir"# OpenOffice.org - a multi-platform office productivity suite\n".
284*cdf0e10cSrcweir"#\n".
285*cdf0e10cSrcweir"# This file is part of OpenOffice.org.\n".
286*cdf0e10cSrcweir"#\n".
287*cdf0e10cSrcweir"# OpenOffice.org is free software: you can redistribute it and/or modify\n".
288*cdf0e10cSrcweir"# it under the terms of the GNU Lesser General Public License version 3\n".
289*cdf0e10cSrcweir"# only, as published by the Free Software Foundation.\n".
290*cdf0e10cSrcweir"#\n".
291*cdf0e10cSrcweir"# OpenOffice.org is distributed in the hope that it will be useful,\n".
292*cdf0e10cSrcweir"# but WITHOUT ANY WARRANTY; without even the implied warranty of\n".
293*cdf0e10cSrcweir"# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n".
294*cdf0e10cSrcweir"# GNU Lesser General Public License version 3 for more details\n".
295*cdf0e10cSrcweir"# (a copy is included in the LICENSE file that accompanied this code).\n".
296*cdf0e10cSrcweir"#\n".
297*cdf0e10cSrcweir"# You should have received a copy of the GNU Lesser General Public License\n".
298*cdf0e10cSrcweir"# version 3 along with OpenOffice.org.  If not, see\n".
299*cdf0e10cSrcweir"# <http://www.openoffice.org/license.html>\n".
300*cdf0e10cSrcweir"# for a copy of the LGPLv3 License.\n".
301*cdf0e10cSrcweir"#\n".
302*cdf0e10cSrcweir"#*************************************************************************\n";
303*cdf0e10cSrcweir}
304*cdf0e10cSrcweir######## Check input sdf file and use only the correct part
305*cdf0e10cSrcweirsub merge_gsicheck{
306*cdf0e10cSrcweir    my $command = '';
307*cdf0e10cSrcweir    my ( $TMPHANDLE , $tmpfile ) = File::Temp::tempfile();
308*cdf0e10cSrcweir    my ( $TMPHANDLE2 , $tmpfile2 ) = File::Temp::tempfile();
309*cdf0e10cSrcweir    close ( $TMPHANDLE );
310*cdf0e10cSrcweir    close ( $TMPHANDLE2 );
311*cdf0e10cSrcweir
312*cdf0e10cSrcweir    unlink $tmpfile2;
313*cdf0e10cSrcweir    my $output2 = `cat $sdffile | sort > $tmpfile2`;
314*cdf0e10cSrcweir    my $rc2 = $? << 8;
315*cdf0e10cSrcweir    if( $rc2 ne  0 ){
316*cdf0e10cSrcweir        printf("ERROR: Failed -> cat $sdffile | sort > $tmpfile2\n$output2\n");
317*cdf0e10cSrcweir        exit( -1 );
318*cdf0e10cSrcweir    }
319*cdf0e10cSrcweir
320*cdf0e10cSrcweir#    if( $ENV{WRAPCMD} ){
321*cdf0e10cSrcweir#        $command = "$ENV{WRAPCMD} gsicheck";
322*cdf0e10cSrcweir#    }else{
323*cdf0e10cSrcweir#        $command = "gsicheck";
324*cdf0e10cSrcweir#    }
325*cdf0e10cSrcweir#    my $errfile = $tmpfile.".err";
326*cdf0e10cSrcweir#    $command .= " -k -c -wcf $tmpfile -wef $errfile -l \"\" $tmpfile2";
327*cdf0e10cSrcweir#    my $output = `$command`;
328*cdf0e10cSrcweir#    my $rc = $? << 8;
329*cdf0e10cSrcweir#    if ( $output ne "" ){
330*cdf0e10cSrcweir#        print STDOUT "### gsicheck ###\n";
331*cdf0e10cSrcweir#        print STDOUT "### The file $errfile have been written containing the errors in your sdf file. Those lines will not be merged: ###\n\n";
332*cdf0e10cSrcweir#        print STDOUT "$output\n";
333*cdf0e10cSrcweir#        print STDOUT "################\n";
334*cdf0e10cSrcweir#
335*cdf0e10cSrcweir#    }else{
336*cdf0e10cSrcweir#        # Remove the 0 Byte file
337*cdf0e10cSrcweir#        unlink $errfile;
338*cdf0e10cSrcweir#    }
339*cdf0e10cSrcweir    $sdffile = $tmpfile2;
340*cdf0e10cSrcweir#    unlink $tmpfile2;
341*cdf0e10cSrcweir}
342*cdf0e10cSrcweir#########################################################
343*cdf0e10cSrcweirsub collectfiles{
344*cdf0e10cSrcweir    print STDOUT "### Localize\n";
345*cdf0e10cSrcweir    my @sdfparticles;
346*cdf0e10cSrcweir    my $localizehash_ref;
347*cdf0e10cSrcweir    my ( $bAll , $bUseLocalize, $langhash_ref , $bHasSourceLanguage , $bFakeEnglish ) = parseLanguages();
348*cdf0e10cSrcweir
349*cdf0e10cSrcweir    # Enable autoflush on STDOUT
350*cdf0e10cSrcweir    # $| = 1;
351*cdf0e10cSrcweir    STDOUT->autoflush( 1 );
352*cdf0e10cSrcweir
353*cdf0e10cSrcweir    ### Search sdf particles
354*cdf0e10cSrcweir    print STDOUT "### Searching sdf particles\n";
355*cdf0e10cSrcweir    my $working_path = getcwd();
356*cdf0e10cSrcweir    chdir $srcpath;
357*cdf0e10cSrcweir    find sub {
358*cdf0e10cSrcweir        my $file = $File::Find::name;
359*cdf0e10cSrcweir        if( -f && $file =~ /.*localize.sdf$/ ) {
360*cdf0e10cSrcweir            push   @sdfparticles , $file;
361*cdf0e10cSrcweir            if( $bVerbose eq "1" ) { print STDOUT "$file\n"; }
362*cdf0e10cSrcweir            else { print ".";  }
363*cdf0e10cSrcweir
364*cdf0e10cSrcweir         }
365*cdf0e10cSrcweir    } , getcwd() ;#"."; #$srcpath;
366*cdf0e10cSrcweir    chdir $working_path;
367*cdf0e10cSrcweir
368*cdf0e10cSrcweir    my $nFound  = $#sdfparticles +1;
369*cdf0e10cSrcweir    print "\n    $nFound files found !\n";
370*cdf0e10cSrcweir
371*cdf0e10cSrcweir    my ( $LOCALIZEPARTICLE , $localizeSDF ) = File::Temp::tempfile();
372*cdf0e10cSrcweir    close( $LOCALIZEPARTICLE );
373*cdf0e10cSrcweir
374*cdf0e10cSrcweir    my ( $ALLPARTICLES_MERGED , $particleSDF_merged )     = File::Temp::tempfile();
375*cdf0e10cSrcweir    close( $ALLPARTICLES_MERGED );
376*cdf0e10cSrcweir    my ( $LOCALIZE_LOG , $my_localize_log ) = File::Temp::tempfile();
377*cdf0e10cSrcweir    close( $LOCALIZE_LOG );
378*cdf0e10cSrcweir
379*cdf0e10cSrcweir    ## Get the localize de,en-US extract
380*cdf0e10cSrcweir    if( $bAll || $bUseLocalize ){
381*cdf0e10cSrcweir        print "### Fetching source language strings\n";
382*cdf0e10cSrcweir        my $command = "";
383*cdf0e10cSrcweir        my $args    = "";
384*cdf0e10cSrcweir
385*cdf0e10cSrcweir        if( $ENV{WRAPCMD} ){
386*cdf0e10cSrcweir            $command = "$ENV{WRAPCMD} localize_sl";
387*cdf0e10cSrcweir        }else{
388*cdf0e10cSrcweir            $command = "localize_sl";
389*cdf0e10cSrcweir        }
390*cdf0e10cSrcweir
391*cdf0e10cSrcweir        # -e
392*cdf0e10cSrcweir        # if ( -x $command ){
393*cdf0e10cSrcweir        if( $command ){
394*cdf0e10cSrcweir            if( !$bVerbose  ){ $args .= " -QQ -skip_links "; }
395*cdf0e10cSrcweir            $args .= " -e -f $localizeSDF -l ";
396*cdf0e10cSrcweir            my $bFlag="";
397*cdf0e10cSrcweir            if( $bAll ) {$args .= " en-US";}
398*cdf0e10cSrcweir            else{
399*cdf0e10cSrcweir              my @list;
400*cdf0e10cSrcweir              foreach my $isokey ( keys( %{ $langhash_ref } ) ){
401*cdf0e10cSrcweir                push @list , $isokey;
402*cdf0e10cSrcweir                if( $langhash_ref->{ $isokey } ne "" ){
403*cdf0e10cSrcweir                    push @list , $langhash_ref->{ $isokey };
404*cdf0e10cSrcweir                }
405*cdf0e10cSrcweir              }
406*cdf0e10cSrcweir              remove_duplicates( \@list );
407*cdf0e10cSrcweir              foreach my $isokey ( @list ){
408*cdf0e10cSrcweir                switch :{
409*cdf0e10cSrcweir                    #( $isokey=~ /^de$/i  )
410*cdf0e10cSrcweir                    #    && do{
411*cdf0e10cSrcweir                    #            if( $bFlag eq "TRUE" ){ $args .= ",de"; }
412*cdf0e10cSrcweir                    #            else  {
413*cdf0e10cSrcweir                    #                $args .=  "de";  $bFlag = "TRUE";
414*cdf0e10cSrcweir                    #             }
415*cdf0e10cSrcweir                    #          };
416*cdf0e10cSrcweir                        ( $isokey=~ /^en-US$/i  )
417*cdf0e10cSrcweir                        && do{
418*cdf0e10cSrcweir                                if( $bFlag eq "TRUE" ){ $args .= ",en-US"; }
419*cdf0e10cSrcweir                                else {
420*cdf0e10cSrcweir                                    $args .= "en-US";  $bFlag = "TRUE";
421*cdf0e10cSrcweir                                 }
422*cdf0e10cSrcweir                              };
423*cdf0e10cSrcweir
424*cdf0e10cSrcweir                    } #switch
425*cdf0e10cSrcweir                } #foreach
426*cdf0e10cSrcweir              } # if
427*cdf0e10cSrcweir        } # if
428*cdf0e10cSrcweir        if ( $bVerbose ) { print STDOUT $command.$args."\n"; }
429*cdf0e10cSrcweir
430*cdf0e10cSrcweir        my $rc = system( $command.$args );
431*cdf0e10cSrcweir
432*cdf0e10cSrcweir        #my $output = `$command.$args`;
433*cdf0e10cSrcweir        #my $rc = $? << 8;
434*cdf0e10cSrcweir
435*cdf0e10cSrcweir        if( $rc < 0 ){    print STDERR "ERROR: localize rc = $rc\n"; exit( -1 ); }
436*cdf0e10cSrcweir        ( $localizehash_ref )  = read_file( $localizeSDF , $langhash_ref );
437*cdf0e10cSrcweir
438*cdf0e10cSrcweir    }
439*cdf0e10cSrcweir    ## Get sdf particles
440*cdf0e10cSrcweir   open ALLPARTICLES_MERGED , "+>> $particleSDF_merged"
441*cdf0e10cSrcweir    or die "Can't open $particleSDF_merged";
442*cdf0e10cSrcweir
443*cdf0e10cSrcweir    ## Fill fackback hash
444*cdf0e10cSrcweir    my( $fallbackhashhash_ref ) = fetch_fallback( \@sdfparticles , $localizeSDF ,  $langhash_ref );
445*cdf0e10cSrcweir#    my( $fallbackhashhash_ref ) = fetch_fallback( \@sdfparticles , $localizeSDF , $langhash_ref );
446*cdf0e10cSrcweir    my %block;
447*cdf0e10cSrcweir    my $cur_fallback;
448*cdf0e10cSrcweir    if( !$bAll) {
449*cdf0e10cSrcweir        foreach my $cur_lang ( keys( %{ $langhash_ref } ) ){
450*cdf0e10cSrcweir            #print STDOUT "DBG: G1 cur_lang=$cur_lang\n";
451*cdf0e10cSrcweir            $cur_fallback = $langhash_ref->{ $cur_lang };
452*cdf0e10cSrcweir            if( $cur_fallback ne "" ){
453*cdf0e10cSrcweir                # Insert fallback strings
454*cdf0e10cSrcweir                #print STDOUT "DBG: Renaming $cur_fallback to $cur_lang in fallbackhash\n";
455*cdf0e10cSrcweir                rename_language(  $fallbackhashhash_ref ,  $cur_fallback , $cur_lang );
456*cdf0e10cSrcweir            }
457*cdf0e10cSrcweir            foreach my $currentfile ( @sdfparticles ){
458*cdf0e10cSrcweir                if ( open MYFILE , "< $currentfile" ) {
459*cdf0e10cSrcweir                    while(<MYFILE>){
460*cdf0e10cSrcweir                        if( /$sdf_regex/ ){
461*cdf0e10cSrcweir                            my $line           = defined $_ ? $_ : '';
462*cdf0e10cSrcweir                            my $prj            = defined $3 ? $3 : '';
463*cdf0e10cSrcweir                            my $file           = defined $4 ? $4 : '';
464*cdf0e10cSrcweir                            my $type           = defined $6 ? $6 : '';
465*cdf0e10cSrcweir                            my $gid            = defined $7 ? $7 : '';
466*cdf0e10cSrcweir                            my $lid            = defined $8 ? $8 : '';
467*cdf0e10cSrcweir                            my $lang           = defined $12 ? $12 : '';
468*cdf0e10cSrcweir                            my $plattform      = defined $10 ? $10 : '';
469*cdf0e10cSrcweir                            my $helpid         = defined $9 ? $9 : '';
470*cdf0e10cSrcweir
471*cdf0e10cSrcweir                            chomp( $line );
472*cdf0e10cSrcweir
473*cdf0e10cSrcweir                            if ( $lang eq $cur_lang ){
474*cdf0e10cSrcweir                                # Overwrite fallback strings with collected strings
475*cdf0e10cSrcweir                                #if( ( !has_two_sourcelanguages( $cur_lang) && $cur_lang eq "de" ) || $cur_lang ne "en-US" ){
476*cdf0e10cSrcweir                                     $fallbackhashhash_ref->{ $cur_lang }{ $prj.$gid.$lid.$file.$type.$plattform.$helpid } =  $line ;
477*cdf0e10cSrcweir                                     #}
478*cdf0e10cSrcweir
479*cdf0e10cSrcweir                            }
480*cdf0e10cSrcweir                        }
481*cdf0e10cSrcweir                    }
482*cdf0e10cSrcweir                }else { print STDERR "WARNING: Can't open file $currentfile"; }
483*cdf0e10cSrcweir            }
484*cdf0e10cSrcweir
485*cdf0e10cSrcweir            foreach my $line ( keys( %{$fallbackhashhash_ref->{ $cur_lang } } )) {
486*cdf0e10cSrcweir                if( #$cur_lang ne "de" &&
487*cdf0e10cSrcweir                    $cur_lang ne "en-US" ){
488*cdf0e10cSrcweir                    print ALLPARTICLES_MERGED ( $fallbackhashhash_ref->{ $cur_lang }{ $line }, "\n" );
489*cdf0e10cSrcweir                }
490*cdf0e10cSrcweir             }
491*cdf0e10cSrcweir        }
492*cdf0e10cSrcweir    } else {
493*cdf0e10cSrcweir        foreach my $currentfile ( @sdfparticles ){
494*cdf0e10cSrcweir            if ( open MYFILE , "< $currentfile" ) {
495*cdf0e10cSrcweir                while( <MYFILE> ){
496*cdf0e10cSrcweir                    print ALLPARTICLES_MERGED ( $_, "\n" );  # recheck de / en-US !
497*cdf0e10cSrcweir                }
498*cdf0e10cSrcweir            }
499*cdf0e10cSrcweir            else { print STDERR "WARNING: Can't open file $currentfile"; }
500*cdf0e10cSrcweir        }
501*cdf0e10cSrcweir    }
502*cdf0e10cSrcweir    close ALLPARTICLES_MERGED;
503*cdf0e10cSrcweir
504*cdf0e10cSrcweir
505*cdf0e10cSrcweir    # Hash of array
506*cdf0e10cSrcweir    my %output;
507*cdf0e10cSrcweir    my @order;
508*cdf0e10cSrcweir
509*cdf0e10cSrcweir    ## Join both
510*cdf0e10cSrcweir    if( $outputfile ){
511*cdf0e10cSrcweir        if( open DESTFILE , "+> $outputfile" ){
512*cdf0e10cSrcweir            if( !open LOCALIZEPARTICLE ,  "< $localizeSDF" ) { print STDERR "ERROR: Can't open file $localizeSDF\n"; }
513*cdf0e10cSrcweir            if( !open ALLPARTICLES_MERGED , "< $particleSDF_merged" ) { print STDERR "ERROR: Can't open file $particleSDF_merged\n"; }
514*cdf0e10cSrcweir
515*cdf0e10cSrcweir            # Insert localize
516*cdf0e10cSrcweir            my $extract_date="";
517*cdf0e10cSrcweir            while ( <LOCALIZEPARTICLE> ){
518*cdf0e10cSrcweir                if( /$sdf_regex/ ){
519*cdf0e10cSrcweir                    my $leftpart       = defined $2 ? $2 : '';
520*cdf0e10cSrcweir                    my $lang           = defined $12 ? $12 : '';
521*cdf0e10cSrcweir                    my $rightpart      = defined $13 ? $13 : '';
522*cdf0e10cSrcweir                    my $timestamp      = defined $18 ? $18 : '';
523*cdf0e10cSrcweir
524*cdf0e10cSrcweir                    my $prj            = defined $3 ? $3 : '';
525*cdf0e10cSrcweir                    my $file           = defined $4 ? $4 : '';
526*cdf0e10cSrcweir                    my $type           = defined $6 ? $6 : '';
527*cdf0e10cSrcweir                    my $gid            = defined $7 ? $7 : '';
528*cdf0e10cSrcweir                    my $lid            = defined $8 ? $8 : '';
529*cdf0e10cSrcweir                    #my $lang           = defined $12 ? $12 : '';
530*cdf0e10cSrcweir                    my $plattform      = defined $10 ? $10 : '';
531*cdf0e10cSrcweir                    my $helpid         = defined $9 ? $9 : '';
532*cdf0e10cSrcweir
533*cdf0e10cSrcweir
534*cdf0e10cSrcweir                    if( $use_default_date )
535*cdf0e10cSrcweir                    {
536*cdf0e10cSrcweir                        $extract_date = "$default_date\n" ;
537*cdf0e10cSrcweir                    }
538*cdf0e10cSrcweir                    elsif( $extract_date eq "" ) {
539*cdf0e10cSrcweir                        $extract_date = $timestamp ;
540*cdf0e10cSrcweir                        $extract_date =~ tr/\r\n//d;
541*cdf0e10cSrcweir                        $extract_date .= "\n";
542*cdf0e10cSrcweir                    }
543*cdf0e10cSrcweir
544*cdf0e10cSrcweir                    if( $bAll ){ print DESTFILE $leftpart."\t".$lang."\t".$rightpart.$extract_date ; }
545*cdf0e10cSrcweir                    else {
546*cdf0e10cSrcweir                        foreach my $sLang ( keys( %{ $langhash_ref } ) ){
547*cdf0e10cSrcweir                            if( $sLang=~ /all/i )                       {
548*cdf0e10cSrcweir                                push @{ $output{ $prj.$gid.$lid.$file.$type.$plattform.$helpid } } ,  $leftpart."\t".$lang."\t".$rightpart.$extract_date ;
549*cdf0e10cSrcweir                                #print DESTFILE $leftpart."\t".$lang."\t".$rightpart.$extract_date;
550*cdf0e10cSrcweir                            }
551*cdf0e10cSrcweir                            #if( $sLang eq "de" && $lang eq "de" )       {
552*cdf0e10cSrcweir                            #    push @{ $output{ $prj.$gid.$lid.$file.$type.$plattform.$helpid } } ,  $leftpart."\t".$lang."\t".$rightpart.$extract_date ;
553*cdf0e10cSrcweir                                #print DESTFILE $leftpart."\t".$lang."\t".$rightpart.$extract_date;
554*cdf0e10cSrcweir                                #}
555*cdf0e10cSrcweir                            if( $sLang eq "en-US" && $lang eq "en-US" ) {
556*cdf0e10cSrcweir                                push @order , $prj.$gid.$lid.$file.$type.$plattform.$helpid;
557*cdf0e10cSrcweir                                if( !$bFakeEnglish ){ push @{ $output{ $prj.$gid.$lid.$file.$type.$plattform.$helpid } } ,  $leftpart."\t".$lang."\t".$rightpart.$extract_date ; }
558*cdf0e10cSrcweir                                #print DESTFILE $leftpart."\t".$lang."\t".$rightpart.$extract_date;
559*cdf0e10cSrcweir                            }
560*cdf0e10cSrcweir
561*cdf0e10cSrcweir                        }
562*cdf0e10cSrcweir                    }
563*cdf0e10cSrcweir                }
564*cdf0e10cSrcweir            }
565*cdf0e10cSrcweir            # Insert particles
566*cdf0e10cSrcweir            while ( <ALLPARTICLES_MERGED> ){
567*cdf0e10cSrcweir                if( /$sdf_regex/ ){
568*cdf0e10cSrcweir                    my $leftpart       = defined $2 ? $2 : '';
569*cdf0e10cSrcweir                    my $prj            = defined $3 ? $3 : '';
570*cdf0e10cSrcweir                    my $lang           = defined $12 ? $12 : '';
571*cdf0e10cSrcweir                    my $rightpart      = defined $13 ? $13 : '';
572*cdf0e10cSrcweir                    my $timestamp      = defined $18 ? $18 : '';
573*cdf0e10cSrcweir
574*cdf0e10cSrcweir                    #my $prj            = defined $3 ? $3 : '';
575*cdf0e10cSrcweir                    my $file           = defined $4 ? $4 : '';
576*cdf0e10cSrcweir                    my $type           = defined $6 ? $6 : '';
577*cdf0e10cSrcweir                    my $gid            = defined $7 ? $7 : '';
578*cdf0e10cSrcweir                    my $lid            = defined $8 ? $8 : '';
579*cdf0e10cSrcweir                    #my $lang           = defined $12 ? $12 : '';
580*cdf0e10cSrcweir                    my $plattform      = defined $10 ? $10 : '';
581*cdf0e10cSrcweir                    my $helpid         = defined $9 ? $9 : '';
582*cdf0e10cSrcweir
583*cdf0e10cSrcweir
584*cdf0e10cSrcweir                    if( $use_default_date )
585*cdf0e10cSrcweir                    {
586*cdf0e10cSrcweir                        $extract_date = "$default_date\n" ;
587*cdf0e10cSrcweir                    }
588*cdf0e10cSrcweir                    elsif( $extract_date eq "" )
589*cdf0e10cSrcweir                    {
590*cdf0e10cSrcweir                        $extract_date = $timestamp;
591*cdf0e10cSrcweir                    }
592*cdf0e10cSrcweir
593*cdf0e10cSrcweir                    if( ! ( $prj =~ /binfilter/i ) ) {
594*cdf0e10cSrcweir                        push @{ $output{ $prj.$gid.$lid.$file.$type.$plattform.$helpid } } , $leftpart."\t".$lang."\t".$rightpart.$extract_date ;
595*cdf0e10cSrcweir                        #print DESTFILE $leftpart."\t".$lang."\t".$rightpart.$extract_date ;
596*cdf0e10cSrcweir                    }
597*cdf0e10cSrcweir                 }
598*cdf0e10cSrcweir            }
599*cdf0e10cSrcweir
600*cdf0e10cSrcweir            # Write!
601*cdf0e10cSrcweir            foreach my $curkey ( @order ){
602*cdf0e10cSrcweir                foreach my $curlist ( $output{ $curkey } ){
603*cdf0e10cSrcweir                    foreach my $line ( @{$curlist} ){
604*cdf0e10cSrcweir                        print DESTFILE $line;
605*cdf0e10cSrcweir                    }
606*cdf0e10cSrcweir                }
607*cdf0e10cSrcweir            }
608*cdf0e10cSrcweir
609*cdf0e10cSrcweir        }else { print STDERR "Can't open $outputfile";}
610*cdf0e10cSrcweir    }
611*cdf0e10cSrcweir    close DESTFILE;
612*cdf0e10cSrcweir    close LOCALIZEPARTICLE;
613*cdf0e10cSrcweir    close ALLPARTICLES_MERGED;
614*cdf0e10cSrcweir
615*cdf0e10cSrcweir    #print STDOUT "DBG: \$localizeSDF $localizeSDF \$particleSDF_merged $particleSDF_merged\n";
616*cdf0e10cSrcweir    unlink $localizeSDF , $particleSDF_merged ,  $my_localize_log;
617*cdf0e10cSrcweir
618*cdf0e10cSrcweir    #sort_outfile( $outputfile );
619*cdf0e10cSrcweir    #remove_obsolete( $outputfile ) , if $bHasSourceLanguage ne "";
620*cdf0e10cSrcweir    }
621*cdf0e10cSrcweir
622*cdf0e10cSrcweir#########################################################
623*cdf0e10cSrcweirsub remove_obsolete{
624*cdf0e10cSrcweir    my $outfile = shift;
625*cdf0e10cSrcweir    my @lines;
626*cdf0e10cSrcweir    my $enusleftpart;
627*cdf0e10cSrcweir    my @good_lines;
628*cdf0e10cSrcweir
629*cdf0e10cSrcweir    print STDOUT "### Removing obsolete strings\n";
630*cdf0e10cSrcweir
631*cdf0e10cSrcweir    # Kick out all strings without en-US reference
632*cdf0e10cSrcweir    if ( open ( SORTEDFILE , "< $outfile" ) ){
633*cdf0e10cSrcweir        while( <SORTEDFILE> ){
634*cdf0e10cSrcweir            if( /$sdf_regex/ ){
635*cdf0e10cSrcweir                my $line           = defined $_ ? $_ : '';
636*cdf0e10cSrcweir                my $language       = defined $12 ? $12 : '';
637*cdf0e10cSrcweir                my $prj            = defined $3 ? $3 : '';
638*cdf0e10cSrcweir                my $file           = defined $4 ? $4 : '';
639*cdf0e10cSrcweir                my $type           = defined $6 ? $6 : '';
640*cdf0e10cSrcweir                my $gid            = defined $7 ? $7 : '';
641*cdf0e10cSrcweir                my $lid            = defined $8 ? $8 : '';
642*cdf0e10cSrcweir                my $plattform      = defined $10 ? $10 : '';
643*cdf0e10cSrcweir                my $helpid         = defined $9 ? $9 : '';
644*cdf0e10cSrcweir
645*cdf0e10cSrcweir                my $leftpart = $prj.$gid.$lid.$file.$type.$plattform.$helpid;
646*cdf0e10cSrcweir
647*cdf0e10cSrcweir                if( $language eq "en-US" ){                 # source string found, 1. entry
648*cdf0e10cSrcweir                    $enusleftpart = $leftpart;
649*cdf0e10cSrcweir                    push @good_lines , $line;
650*cdf0e10cSrcweir                }else{
651*cdf0e10cSrcweir                    if( !defined $enusleftpart or !defined $leftpart ){
652*cdf0e10cSrcweir                        print STDERR "BADLINE: $line\n";
653*cdf0e10cSrcweir                        print STDERR "\$enusleftpart = $enusleftpart\n";
654*cdf0e10cSrcweir                        print STDERR "\$leftpart = $leftpart\n";
655*cdf0e10cSrcweir                    }
656*cdf0e10cSrcweir                    if( $enusleftpart eq $leftpart ){   # matching language
657*cdf0e10cSrcweir                        push @good_lines , $line;
658*cdf0e10cSrcweir                    }
659*cdf0e10cSrcweir                    #else{
660*cdf0e10cSrcweir                    #    print STDERR "OUT:  \$enusleftpart=$enusleftpart \$leftpart=$leftpart \$line=$line\n";
661*cdf0e10cSrcweir                    #}
662*cdf0e10cSrcweir                }
663*cdf0e10cSrcweir            }
664*cdf0e10cSrcweir        }
665*cdf0e10cSrcweir        close SORTEDFILE;
666*cdf0e10cSrcweir    } else { print STDERR "ERROR: Can't open file $outfile\n";}
667*cdf0e10cSrcweir
668*cdf0e10cSrcweir    # Write file
669*cdf0e10cSrcweir    if ( open ( SORTEDFILE , "> $outfile" ) ){
670*cdf0e10cSrcweir        foreach my $newline ( @good_lines ) {
671*cdf0e10cSrcweir            print SORTEDFILE $newline;
672*cdf0e10cSrcweir        }
673*cdf0e10cSrcweir        close SORTEDFILE;
674*cdf0e10cSrcweir    } else { print STDERR "ERROR: Can't open file $outfile\n";}
675*cdf0e10cSrcweir
676*cdf0e10cSrcweir}
677*cdf0e10cSrcweir#########################################################
678*cdf0e10cSrcweirsub sort_outfile{
679*cdf0e10cSrcweir        my $outfile = shift;
680*cdf0e10cSrcweir        print STDOUT "### Sorting ... $outfile ...";
681*cdf0e10cSrcweir        my @lines;
682*cdf0e10cSrcweir        my @sorted_lines;
683*cdf0e10cSrcweir
684*cdf0e10cSrcweir
685*cdf0e10cSrcweir        #if ( open ( SORTEDFILE , "< $outputfile" ) ){
686*cdf0e10cSrcweir        if ( open ( SORTEDFILE , "< $outfile" ) ){
687*cdf0e10cSrcweir            my $line;
688*cdf0e10cSrcweir            while ( <SORTEDFILE> ){
689*cdf0e10cSrcweir                $line = $_;
690*cdf0e10cSrcweir                if( $line =~ /^[^\#]/ ){
691*cdf0e10cSrcweir                    push @lines , $line;
692*cdf0e10cSrcweir                }
693*cdf0e10cSrcweir            }
694*cdf0e10cSrcweir            close SORTEDFILE;
695*cdf0e10cSrcweir            @sorted_lines = sort {
696*cdf0e10cSrcweir                my $xa_lang          = "";
697*cdf0e10cSrcweir                my $xa_left_part    = "";
698*cdf0e10cSrcweir                my $xa_right_part    = "";
699*cdf0e10cSrcweir                my $xa_timestamp     = "";
700*cdf0e10cSrcweir                my $xb_lang          = "";
701*cdf0e10cSrcweir                my $xb_left_part    = "";
702*cdf0e10cSrcweir                my $xb_right_part    = "";
703*cdf0e10cSrcweir                my $xb_timestamp     = "";
704*cdf0e10cSrcweir                my $xa               = "";
705*cdf0e10cSrcweir                my $xb               = "";
706*cdf0e10cSrcweir                my @alist;
707*cdf0e10cSrcweir                my @blist;
708*cdf0e10cSrcweir
709*cdf0e10cSrcweir                if( $a=~ /$sdf_regex/ ){
710*cdf0e10cSrcweir                    $xa_left_part       = defined $2 ? $2 : '';
711*cdf0e10cSrcweir                    $xa_lang           = defined $12 ? $12 : '';
712*cdf0e10cSrcweir                    $xa_right_part     = defined $13 ? $13 : '';
713*cdf0e10cSrcweir                    $xa_left_part = remove_last_column( $xa_left_part );
714*cdf0e10cSrcweir
715*cdf0e10cSrcweir                }
716*cdf0e10cSrcweir                if( $b=~ /$sdf_regex/ ){
717*cdf0e10cSrcweir                    $xb_left_part       = defined $2 ? $2 : '';
718*cdf0e10cSrcweir                    $xb_lang           = defined $12 ? $12 : '';
719*cdf0e10cSrcweir                    $xb_right_part     = defined $13 ? $13 : '';
720*cdf0e10cSrcweir                    $xb_left_part = remove_last_column( $xb_left_part );
721*cdf0e10cSrcweir
722*cdf0e10cSrcweir
723*cdf0e10cSrcweir                }
724*cdf0e10cSrcweir                if( (  $xa_left_part cmp $xb_left_part ) == 0 ){         # Left part equal
725*cdf0e10cSrcweir                     if( ( $xa_lang cmp $xb_lang ) == 0 ){               # Lang equal
726*cdf0e10cSrcweir                         return ( $xa_right_part cmp $xb_right_part );   # Right part compare
727*cdf0e10cSrcweir                    }
728*cdf0e10cSrcweir                    elsif( $xa_lang eq "en-US" ) { return -1; }        # en-US wins
729*cdf0e10cSrcweir                    elsif( $xb_lang eq "en-US" ) { return 1;  }        # en-US wins
730*cdf0e10cSrcweir                    else { return $xa_lang cmp $xb_lang; }             # lang compare
731*cdf0e10cSrcweir                }
732*cdf0e10cSrcweir                else {
733*cdf0e10cSrcweir                    return $xa_left_part cmp $xb_left_part;        # Left part compare
734*cdf0e10cSrcweir                }
735*cdf0e10cSrcweir            } @lines;
736*cdf0e10cSrcweir
737*cdf0e10cSrcweir            if ( open ( SORTEDFILE , "> $outfile" ) ){
738*cdf0e10cSrcweir                print SORTEDFILE get_license_header();
739*cdf0e10cSrcweir                foreach my $newline ( @sorted_lines ) {
740*cdf0e10cSrcweir                    print SORTEDFILE $newline;
741*cdf0e10cSrcweir                    #print STDOUT $newline;
742*cdf0e10cSrcweir                }
743*cdf0e10cSrcweir            }
744*cdf0e10cSrcweir            close SORTEDFILE;
745*cdf0e10cSrcweir        } else { print STDERR "WARNING: Can't open file $outfile\n";}
746*cdf0e10cSrcweir	print "done\n";
747*cdf0e10cSrcweir
748*cdf0e10cSrcweir}
749*cdf0e10cSrcweir#########################################################
750*cdf0e10cSrcweirsub remove_last_column{
751*cdf0e10cSrcweir    my $string                  = shift;
752*cdf0e10cSrcweir    my @alist = split ( "\t" , $string );
753*cdf0e10cSrcweir    pop @alist;
754*cdf0e10cSrcweir    return join( "\t" , @alist );
755*cdf0e10cSrcweir}
756*cdf0e10cSrcweir
757*cdf0e10cSrcweir#########################################################
758*cdf0e10cSrcweirsub rename_language{
759*cdf0e10cSrcweir    my $fallbackhashhash_ref    = shift;
760*cdf0e10cSrcweir    my $cur_fallback            = shift;
761*cdf0e10cSrcweir    my $cur_lang                = shift;
762*cdf0e10cSrcweir    my $line;
763*cdf0e10cSrcweir
764*cdf0e10cSrcweir    foreach my $key( keys ( %{ $fallbackhashhash_ref->{ $cur_fallback } } ) ){
765*cdf0e10cSrcweir        $line = $fallbackhashhash_ref->{ $cur_fallback }{ $key };
766*cdf0e10cSrcweir        if( $line =~ /$sdf_regex/ ){
767*cdf0e10cSrcweir            my $leftpart       = defined $2 ? $2 : '';
768*cdf0e10cSrcweir            my $lang           = defined $12 ? $12 : '';
769*cdf0e10cSrcweir            my $rightpart      = defined $13 ? $13 : '';
770*cdf0e10cSrcweir
771*cdf0e10cSrcweir            $fallbackhashhash_ref->{ $cur_lang }{ $key } = $leftpart."\t".$cur_lang."\t".$rightpart;
772*cdf0e10cSrcweir        }
773*cdf0e10cSrcweir    }
774*cdf0e10cSrcweir}
775*cdf0e10cSrcweir
776*cdf0e10cSrcweir############################################################
777*cdf0e10cSrcweirsub remove_duplicates{
778*cdf0e10cSrcweir    my $list_ref    = shift;
779*cdf0e10cSrcweir    my %tmphash;
780*cdf0e10cSrcweir    foreach my $key ( @{ $list_ref } ){ $tmphash{ $key } = '' ; }
781*cdf0e10cSrcweir    @{$list_ref} = keys( %tmphash );
782*cdf0e10cSrcweir}
783*cdf0e10cSrcweir
784*cdf0e10cSrcweir##############################################################
785*cdf0e10cSrcweirsub fetch_fallback{
786*cdf0e10cSrcweir    my $sdfparticleslist_ref   = shift;
787*cdf0e10cSrcweir    my $localizeSDF            = shift;
788*cdf0e10cSrcweir    my $langhash_ref           = shift;
789*cdf0e10cSrcweir    my %fallbackhashhash;
790*cdf0e10cSrcweir    my $cur_lang;
791*cdf0e10cSrcweir    my @langlist;
792*cdf0e10cSrcweir
793*cdf0e10cSrcweir    foreach my $key ( keys ( %{ $langhash_ref } ) ){
794*cdf0e10cSrcweir        $cur_lang = $langhash_ref->{ $key };
795*cdf0e10cSrcweir        if ( $cur_lang ne "" ) {
796*cdf0e10cSrcweir            push @langlist , $cur_lang;
797*cdf0e10cSrcweir        }
798*cdf0e10cSrcweir    }
799*cdf0e10cSrcweir    remove_duplicates( \@langlist );
800*cdf0e10cSrcweir    foreach  $cur_lang ( @langlist ){
801*cdf0e10cSrcweir        if( $cur_lang eq "en-US" ){
802*cdf0e10cSrcweir            read_fallbacks_from_source( $localizeSDF , $cur_lang , \%fallbackhashhash );
803*cdf0e10cSrcweir        }
804*cdf0e10cSrcweir    }
805*cdf0e10cSrcweir
806*cdf0e10cSrcweir    # remove de / en-US
807*cdf0e10cSrcweir    my @tmplist;
808*cdf0e10cSrcweir    foreach $cur_lang( @langlist ){
809*cdf0e10cSrcweir        if(  $cur_lang ne "en-US" ){
810*cdf0e10cSrcweir           push @tmplist , $cur_lang;
811*cdf0e10cSrcweir
812*cdf0e10cSrcweir        }
813*cdf0e10cSrcweir    }
814*cdf0e10cSrcweir    @langlist = @tmplist;
815*cdf0e10cSrcweir    if ( $#langlist +1 ){
816*cdf0e10cSrcweir        read_fallbacks_from_particles( $sdfparticleslist_ref , \@langlist , \%fallbackhashhash );
817*cdf0e10cSrcweir
818*cdf0e10cSrcweir    }
819*cdf0e10cSrcweir    return (\%fallbackhashhash);
820*cdf0e10cSrcweir}
821*cdf0e10cSrcweir
822*cdf0e10cSrcweir#########################################################
823*cdf0e10cSrcweirsub write_file{
824*cdf0e10cSrcweir
825*cdf0e10cSrcweir    my $localizeFile = shift;
826*cdf0e10cSrcweir    my $index_ref    = shift;
827*cdf0e10cSrcweir
828*cdf0e10cSrcweir    if( open DESTFILE , "+> $localizeFile" ){
829*cdf0e10cSrcweir        foreach my $key( %{ $index_ref } ){
830*cdf0e10cSrcweir            print DESTFILE ($index_ref->{ $key }, "\n" );
831*cdf0e10cSrcweir        }
832*cdf0e10cSrcweir        close DESTFILE;
833*cdf0e10cSrcweir    }else {
834*cdf0e10cSrcweir      print STDERR "Can't open/create '$localizeFile'";
835*cdf0e10cSrcweir    }
836*cdf0e10cSrcweir}
837*cdf0e10cSrcweir
838*cdf0e10cSrcweir#########################################################
839*cdf0e10cSrcweirsub read_file{
840*cdf0e10cSrcweir
841*cdf0e10cSrcweir    my $sdffile         = shift;
842*cdf0e10cSrcweir    my $langhash_ref    = shift;
843*cdf0e10cSrcweir    my %block           = ();
844*cdf0e10cSrcweir
845*cdf0e10cSrcweir    open MYFILE , "< $sdffile"
846*cdf0e10cSrcweir        or die "Can't open '$sdffile'\n";
847*cdf0e10cSrcweir        while( <MYFILE>){
848*cdf0e10cSrcweir          if( /$sdf_regex/ ){
849*cdf0e10cSrcweir            my $line           = defined $_ ? $_ : '';
850*cdf0e10cSrcweir            my $prj            = defined $3 ? $3 : '';
851*cdf0e10cSrcweir            my $file           = defined $4 ? $4 : '';
852*cdf0e10cSrcweir            my $type           = defined $6 ? $6 : '';
853*cdf0e10cSrcweir            my $gid            = defined $7 ? $7 : '';
854*cdf0e10cSrcweir            my $lid            = defined $8 ? $8 : '';
855*cdf0e10cSrcweir            my $plattform      = defined $10 ? $10 : '';
856*cdf0e10cSrcweir            my $lang           = defined $12 ? $12 : '';
857*cdf0e10cSrcweir            my $helpid         = defined $9 ? $9 : '';
858*cdf0e10cSrcweir
859*cdf0e10cSrcweir            foreach my $isolang ( keys ( %{ $langhash_ref } ) ){
860*cdf0e10cSrcweir                if( $isolang=~ /$lang/i || $isolang=~ /all/i ) { $block{$prj.$gid.$lid.$file.$type.$plattform.$helpid } =  $line ; }
861*cdf0e10cSrcweir            }
862*cdf0e10cSrcweir        }
863*cdf0e10cSrcweir    }
864*cdf0e10cSrcweir    return (\%block);
865*cdf0e10cSrcweir}
866*cdf0e10cSrcweir
867*cdf0e10cSrcweir#########################################################
868*cdf0e10cSrcweirsub read_fallbacks_from_particles{
869*cdf0e10cSrcweir
870*cdf0e10cSrcweir    my $sdfparticleslist_ref    = shift;
871*cdf0e10cSrcweir    my $isolanglist_ref         = shift;
872*cdf0e10cSrcweir    my $fallbackhashhash_ref    = shift;
873*cdf0e10cSrcweir    my $block_ref;
874*cdf0e10cSrcweir    foreach my $currentfile ( @{ $sdfparticleslist_ref } ){
875*cdf0e10cSrcweir        if ( open MYFILE , "< $currentfile" ) {
876*cdf0e10cSrcweir            while(<MYFILE>){
877*cdf0e10cSrcweir                if( /$sdf_regex/ ){
878*cdf0e10cSrcweir                    my $line           = defined $_ ? $_ : '';
879*cdf0e10cSrcweir                    my $prj            = defined $3 ? $3 : '';
880*cdf0e10cSrcweir                    my $file           = defined $4 ? $4 : '';
881*cdf0e10cSrcweir                    my $type           = defined $6 ? $6 : '';
882*cdf0e10cSrcweir                    my $gid            = defined $7 ? $7 : '';
883*cdf0e10cSrcweir                    my $lid            = defined $8 ? $8 : '';
884*cdf0e10cSrcweir                    my $lang           = defined $12 ? $12 : '';
885*cdf0e10cSrcweir                    my $plattform      = defined $10 ? $10 : '';
886*cdf0e10cSrcweir                    my $helpid         = defined $9 ? $9 : '';
887*cdf0e10cSrcweir
888*cdf0e10cSrcweir                    chomp( $line );
889*cdf0e10cSrcweir
890*cdf0e10cSrcweir                    foreach my $isolang ( @{$isolanglist_ref}  ){
891*cdf0e10cSrcweir                        if( $isolang=~ /$lang/i ) {
892*cdf0e10cSrcweir                            $fallbackhashhash_ref->{ $isolang }{ $prj.$gid.$lid.$file.$type.$plattform.$helpid } =  $line ;
893*cdf0e10cSrcweir                        }
894*cdf0e10cSrcweir                    }
895*cdf0e10cSrcweir                }
896*cdf0e10cSrcweir            }
897*cdf0e10cSrcweir       }else { print STDERR "WARNING: Can't open file $currentfile"; }
898*cdf0e10cSrcweir    }
899*cdf0e10cSrcweir}
900*cdf0e10cSrcweir
901*cdf0e10cSrcweir#########################################################
902*cdf0e10cSrcweirsub read_fallbacks_from_source{
903*cdf0e10cSrcweir
904*cdf0e10cSrcweir    my $sdffile                 = shift;
905*cdf0e10cSrcweir    my $isolang                 = shift;
906*cdf0e10cSrcweir    my $fallbackhashhash_ref    = shift;
907*cdf0e10cSrcweir    my $block_ref;
908*cdf0e10cSrcweir    # read fallback for single file
909*cdf0e10cSrcweir    open MYFILE , "< $sdffile"
910*cdf0e10cSrcweir        or die "Can't open '$sdffile'\n";
911*cdf0e10cSrcweir
912*cdf0e10cSrcweir    while( <MYFILE>){
913*cdf0e10cSrcweir          if( /$sdf_regex/ ){
914*cdf0e10cSrcweir            my $line           = defined $_ ? $_ : '';
915*cdf0e10cSrcweir            my $prj            = defined $3 ? $3 : '';
916*cdf0e10cSrcweir            my $file           = defined $4 ? $4 : '';
917*cdf0e10cSrcweir            my $type           = defined $6 ? $6 : '';
918*cdf0e10cSrcweir            my $gid            = defined $7 ? $7 : '';
919*cdf0e10cSrcweir            my $lid            = defined $8 ? $8 : '';
920*cdf0e10cSrcweir            my $helpid         = defined $9 ? $9 : '';
921*cdf0e10cSrcweir            my $lang           = defined $12 ? $12 : '';
922*cdf0e10cSrcweir            my $plattform      = defined $10 ? $10 : '';
923*cdf0e10cSrcweir
924*cdf0e10cSrcweir            chomp( $line );
925*cdf0e10cSrcweir            if( $isolang=~ /$lang/i ) { $fallbackhashhash_ref->{ $isolang }{ $prj.$gid.$lid.$file.$type.$plattform.$helpid } =  $line ;
926*cdf0e10cSrcweir            }
927*cdf0e10cSrcweir        }
928*cdf0e10cSrcweir    }
929*cdf0e10cSrcweir}
930*cdf0e10cSrcweir
931*cdf0e10cSrcweir#########################################################
932*cdf0e10cSrcweirsub parseLanguages{
933*cdf0e10cSrcweir
934*cdf0e10cSrcweir    my $bAll;
935*cdf0e10cSrcweir    my $bUseLocalize;
936*cdf0e10cSrcweir    my $bHasSourceLanguage="";
937*cdf0e10cSrcweir    my $bFakeEnglish="";
938*cdf0e10cSrcweir    my %langhash;
939*cdf0e10cSrcweir    my $iso="";
940*cdf0e10cSrcweir    my $fallback="";
941*cdf0e10cSrcweir
942*cdf0e10cSrcweir    #### -l all
943*cdf0e10cSrcweir    if(   $languages=~ /all/ ){
944*cdf0e10cSrcweir        $bAll = "TRUE";
945*cdf0e10cSrcweir        $bHasSourceLanguage = "TRUE";
946*cdf0e10cSrcweir    }
947*cdf0e10cSrcweir    ### -l fr=de,de
948*cdf0e10cSrcweir    elsif( $languages=~ /.*,.*/ ){
949*cdf0e10cSrcweir        my @tmpstr =  split "," , $languages;
950*cdf0e10cSrcweir        for my $lang ( @tmpstr ){
951*cdf0e10cSrcweir            if( $lang=~ /([a-zA-Z]{2,3}(-[a-zA-Z\-]*)*)(=([a-zA-Z]{2,3}(-[a-zA-Z\-]*)*))?/ ){
952*cdf0e10cSrcweir                $iso        = $1;
953*cdf0e10cSrcweir                $fallback   = $4;
954*cdf0e10cSrcweir
955*cdf0e10cSrcweir                if( ( $iso && $iso=~ /(en-US)/i )  || ( $fallback && $fallback=~ /(en-US)/i ) ) {
956*cdf0e10cSrcweir                    $bUseLocalize = "TRUE";
957*cdf0e10cSrcweir                }
958*cdf0e10cSrcweir                if( ( $iso && $iso=~ /(en-US)/i ) ) {
959*cdf0e10cSrcweir                    $bHasSourceLanguage = "TRUE";
960*cdf0e10cSrcweir                }
961*cdf0e10cSrcweir             if( $fallback ) { $langhash{ $iso } = $fallback;   }
962*cdf0e10cSrcweir             else            { $langhash{ $iso } = "";          }
963*cdf0e10cSrcweir            }
964*cdf0e10cSrcweir        }
965*cdf0e10cSrcweir    }
966*cdf0e10cSrcweir    ### -l de
967*cdf0e10cSrcweir    else{
968*cdf0e10cSrcweir        if( $languages=~ /([a-zA-Z]{2,3}(-[a-zA-Z\-]*)*)(=([a-zA-Z]{2,3}(-[a-zA-Z\-]*)*))?/ ){
969*cdf0e10cSrcweir            $iso        = $1;
970*cdf0e10cSrcweir            $fallback   = $4;
971*cdf0e10cSrcweir
972*cdf0e10cSrcweir            if( ( $iso && $iso=~ /(en-US)/i )  || ( $fallback && $fallback=~ /(en-US)/i ) ) {
973*cdf0e10cSrcweir                $bUseLocalize = "TRUE";
974*cdf0e10cSrcweir
975*cdf0e10cSrcweir            }
976*cdf0e10cSrcweir            if( ( $iso && $iso=~ /(en-US)/i )  ) {
977*cdf0e10cSrcweir                $bHasSourceLanguage = "TRUE";
978*cdf0e10cSrcweir            }
979*cdf0e10cSrcweir
980*cdf0e10cSrcweir             if( $fallback ) { $langhash{ $iso } = $fallback;   }
981*cdf0e10cSrcweir             else            { $langhash{ $iso } = "";          }
982*cdf0e10cSrcweir        }
983*cdf0e10cSrcweir    }
984*cdf0e10cSrcweir    # HACK en-US always needed!
985*cdf0e10cSrcweir    if( !$bHasSourceLanguage ){
986*cdf0e10cSrcweir        #$bHasSourceLanguage = "TRUE";
987*cdf0e10cSrcweir        $bUseLocalize = "TRUE";
988*cdf0e10cSrcweir        $bFakeEnglish = "TRUE";
989*cdf0e10cSrcweir        $langhash{ "en-US" } = "";
990*cdf0e10cSrcweir    }
991*cdf0e10cSrcweir    return ( $bAll ,  $bUseLocalize , \%langhash , $bHasSourceLanguage, $bFakeEnglish);
992*cdf0e10cSrcweir}
993*cdf0e10cSrcweir
994*cdf0e10cSrcweir#########################################################
995*cdf0e10cSrcweirsub parse_options{
996*cdf0e10cSrcweir
997*cdf0e10cSrcweir    my $help;
998*cdf0e10cSrcweir    my $merge;
999*cdf0e10cSrcweir    my $extract;
1000*cdf0e10cSrcweir    my $success = GetOptions('f=s' => \$sdffile , 'l=s' => \$languages , 's=s' => \$srcpath ,  'h' => \$help , 'v' => \$bVerbose ,
1001*cdf0e10cSrcweir                             'm' => \$merge , 'e' => \$extract , 'x' => \$no_sort , 'd' => \$use_default_date );
1002*cdf0e10cSrcweir    $outputfile = $sdffile;
1003*cdf0e10cSrcweir
1004*cdf0e10cSrcweir    #print STDOUT "DBG: lang = $languages\n";
1005*cdf0e10cSrcweir    if( !$srcpath ){
1006*cdf0e10cSrcweir        #$srcpath = "$ENV{SRC_ROOT}";
1007*cdf0e10cSrcweir        if( !$srcpath ){
1008*cdf0e10cSrcweir	        print STDERR "No path to the source root found!\n\n";
1009*cdf0e10cSrcweir	        usage();
1010*cdf0e10cSrcweir            exit(1);
1011*cdf0e10cSrcweir        }
1012*cdf0e10cSrcweir    }
1013*cdf0e10cSrcweir    if( $help || !$success || $#ARGV > 1 || ( !$sdffile ) ){
1014*cdf0e10cSrcweir        usage();
1015*cdf0e10cSrcweir        exit(1);
1016*cdf0e10cSrcweir    }
1017*cdf0e10cSrcweir    if( $merge && $sdffile && ! ( -r $sdffile)){
1018*cdf0e10cSrcweir        print STDERR "Can't open file '$sdffile'\n";
1019*cdf0e10cSrcweir        exit(1);
1020*cdf0e10cSrcweir    }
1021*cdf0e10cSrcweir    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*cdf0e10cSrcweir        print STDERR "Please check the -l iso code\n";
1023*cdf0e10cSrcweir        exit(1);
1024*cdf0e10cSrcweir    }
1025*cdf0e10cSrcweir    if( ( !$merge && !$extract ) || ( $merge && $extract ) ){ usage();exit( -1 );}
1026*cdf0e10cSrcweir    if( $extract ){ $mode = "extract"; }
1027*cdf0e10cSrcweir    else          { $mode = "merge";   }
1028*cdf0e10cSrcweir}
1029*cdf0e10cSrcweir
1030*cdf0e10cSrcweir#########################################################
1031*cdf0e10cSrcweirsub usage{
1032*cdf0e10cSrcweir
1033*cdf0e10cSrcweir    print STDERR "Usage: localize.pl\n";
1034*cdf0e10cSrcweir    print STDERR "Split or collect SDF files\n";
1035*cdf0e10cSrcweir    print STDERR "           merge: -m -f <sdffile>    -l l1[=f1][,l2[=f2]][...] [ -s <sourceroot> ]\n";
1036*cdf0e10cSrcweir    print STDERR "         extract: -e -f <outputfile> -l <lang> [ -s <sourceroot> ] [-d]\n";
1037*cdf0e10cSrcweir    print STDERR "Options:\n";
1038*cdf0e10cSrcweir    print STDERR "    -h              help\n";
1039*cdf0e10cSrcweir    print STDERR "    -m              Merge mode\n";
1040*cdf0e10cSrcweir    print STDERR "    -e              Extract mode\n";
1041*cdf0e10cSrcweir    print STDERR "    -f <sdffile>    To split a big SDF file into particles\n";
1042*cdf0e10cSrcweir    print STDERR "       <outputfile> To collect and join all particles to one big file\n";
1043*cdf0e10cSrcweir    print STDERR "    -s <sourceroot> Path to the modules, if no \$SRC_ROOT is set\n";
1044*cdf0e10cSrcweir    print STDERR "    -l ( all | <isocode> | <isocode>=fallback ) comma seperated languages\n";
1045*cdf0e10cSrcweir    print STDERR "    -d              Use default date in extracted sdf file\n";
1046*cdf0e10cSrcweir    print STDERR "    -v              Verbose\n";
1047*cdf0e10cSrcweir    print STDERR "\nExample:\n";
1048*cdf0e10cSrcweir    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*cdf0e10cSrcweir    print STDERR "\nlocalize -m -l cs -f my.sdf\n( Merge cs translation into the sourcecode ) \n";
1050*cdf0e10cSrcweir}
1051*cdf0e10cSrcweir
1052*cdf0e10cSrcweir#            my $line           = defined $_ ? $_ : '';
1053*cdf0e10cSrcweir#            my $leftpart       = defined $2 ? $2 : '';
1054*cdf0e10cSrcweir#            my $prj            = defined $3 ? $3 : '';
1055*cdf0e10cSrcweir#            my $file           = defined $4 ? $4 : '';
1056*cdf0e10cSrcweir#            my $dummy          = defined $5 ? $5 : '';
1057*cdf0e10cSrcweir#            my $type           = defined $6 ? $6 : '';
1058*cdf0e10cSrcweir#            my $gid            = defined $7 ? $7 : '';
1059*cdf0e10cSrcweir#            my $lid            = defined $8 ? $8 : '';
1060*cdf0e10cSrcweir#            my $helpid         = defined $9 ? $9 : '';
1061*cdf0e10cSrcweir#            my $plattform      = defined $10 ? $10 : '';
1062*cdf0e10cSrcweir#            my $width          = defined $11 ? $11 : '';
1063*cdf0e10cSrcweir#            my $lang           = defined $12 ? $12 : '';
1064*cdf0e10cSrcweir#            my $rightpart      = defined $13 ? $13 : '';
1065*cdf0e10cSrcweir#            my $text           = defined $14 ? $14 : '';
1066*cdf0e10cSrcweir#            my $helptext       = defined $15 ? $15 : '';
1067*cdf0e10cSrcweir#            my $quickhelptext  = defined $16 ? $16 : '';
1068*cdf0e10cSrcweir#            my $title          = defined $17 ? $17 : '';
1069*cdf0e10cSrcweir#            my $timestamp      = defined $18 ? $18 : '';
1070*cdf0e10cSrcweir
1071