2 eval 'exec perl -wS $0 ${1+"$@"}'
6 #*************************************************************************
8 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
10 # Copyright 2008 by Sun Microsystems, Inc.
12 # OpenOffice.org - a multi-platform office productivity suite
14 # $RCSfile: localize.pl,v $
16 # $Revision: 1.18.6.2 $
18 # This file is part of OpenOffice.org.
20 # OpenOffice.org is free software: you can redistribute it and/or modify
21 # it under the terms of the GNU Lesser General Public License version 3
22 # only, as published by the Free Software Foundation.
24 # OpenOffice.org is distributed in the hope that it will be useful,
25 # but WITHOUT ANY WARRANTY; without even the implied warranty of
26 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 # GNU Lesser General Public License version 3 for more details
28 # (a copy is included in the LICENSE file that accompanied this code).
30 # You should have received a copy of the GNU Lesser General Public License
31 # version 3 along with OpenOffice.org. If not, see
32 # <http://www.openoffice.org/license.html>
33 # for a copy of the LGPLv3 License.
35 #*************************************************************************
44 use File
::Glob
qw(:glob csh_glob);
47 my $CVS_BINARY = "/usr/bin/cvs";
51 #use lib ("$ENV{SOLARENV}/bin/modules", "$ENV{COMMON_ENV_TOOLS}/modules");
57 if ( !defined($ENV{SOLARENV
}) ) {
58 die "No environment found (environment variable SOLARENV is undefined)";
60 push(@lib_dirs, "$ENV{SOLARENV}/bin/modules");
61 push(@lib_dirs, "$ENV{COMMON_ENV_TOOLS}/modules") if defined($ENV{COMMON_ENV_TOOLS
});
69 my $multi_localize_files = '';
70 my $module_to_merge = '';
71 my $sort_sdf_before = '';
79 #my %sl_modules; # Contains all modules where en-US and de is source language
80 my $use_default_date = '0';
85 # ( leftpart ) ( rightpart )
86 # prj file dummy type gid lid helpid pform width lang text helptext qhelptext title timestamp
87 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]*))";
88 my $file_types = "(src|hrc|xcs|xcu|lng|ulf|xrm|xhp|xcd|xgf|xxl|xrb)";
89 # Always use this date to prevent cvs conflicts
90 my $default_date = "2002-02-02 02:02:02";
97 if ( defined $ENV{USE_SHELL
} && $ENV{USE_SHELL
} eq '4nt' ) {
107 if( defined $ENV{UPDMINOREXT
} )
109 $binpath = $ENV{SOLARVER
}.$DELIMITER.$ENV{INPATH
}.$DELIMITER."bin".$ENV{UPDMINOREXT
}.$DELIMITER ;
113 $binpath = $ENV{SOLARVER
}.$DELIMITER.$ENV{INPATH
}.$DELIMITER."bin".$DELIMITER ;
116 #%sl_modules = fetch_sourcelanguage_dirlist();
119 if ( $mode eq "merge" ) {
120 if ( ! $no_gsicheck ){
123 splitfile
( $sdffile );
124 if ( ! $no_gsicheck ){
125 unlink $sdffile; # remove temp file!
128 elsif( $mode eq "extract" ) {
129 collectfiles
( $outputfile );
137 #########################################################
141 my $currentFile = '';
142 my $cur_sdffile = '';
143 my $last_sdffile = '';
150 STDOUT
->autoflush( 1 );
152 #print STDOUT "Open File $sdffile\n";
153 open MYFILE
, "< $sdffile"
154 or die "Can't open '$sdffile'\n";
160 $so_modules{ "extras_full" } = "TRUE";
164 my $line = defined $_ ?
$_ : '';
165 my $prj = defined $3 ?
$3 : '';
166 my $file = defined $4 ?
$4 : '';
167 my $type = defined $6 ?
$6 : '';
168 my $gid = defined $7 ?
$7 : '';
169 my $lid = defined $8 ?
$8 : '';
170 my $lang = defined $12 ?
$12 : '';
171 my $plattform = defined $10 ?
$10 : '';
172 my $helpid = defined $9 ?
$9 : '';
173 next if( $prj eq "binfilter" ); # Don't merge strings into binfilter module
176 if( is_openoffice_module
( $prj ) )
178 $string_hash_ooo { $lang }{ "$prj\t$file\t$type\t$gid\t$lid\t$helpid\t$plattform\t$lang" } = $line;
182 $string_hash_so{ $lang }{ "$prj\t$file\t$type\t$gid\t$lid\t$helpid\t$plattform\t$lang" } = $line;
188 if( !defined $ENV{SRC_ROOT
} ){
189 print "Error, no SRC_ROOT in env found.\n";
192 my $src_root = $ENV{SRC_ROOT
};
193 #print $WIN eq "TRUE" ? $src_root."\\l10n_so\n" : $src_root."/l10n_so\n";
194 my $so_l10n_path = $WIN eq "TRUE" ?
$src_root."\\l10n_so\\source" : $src_root."/l10n_so/source";
195 my $ooo_l10n_path = $WIN eq "TRUE" ?
$src_root."\\l10n\\source" : $src_root."/l10n/source";
197 #print "$so_l10n_path\n";
198 #print "$ooo_l10n_path\n";
200 write_sdf
( \
%string_hash_so , $so_l10n_path );
201 write_sdf
( \
%string_hash_ooo , $ooo_l10n_path );
204 sub check_modules_scm
208 my $src_path = $ENV{ SRC_ROOT
} ;
209 my $last_dir = getcwd
();
211 my @modules = <*/.svn/entries
>;
213 foreach my $module ( @modules )
216 if( open ( FILE
, "<$module" ) )
221 my @path = split ( "/" , $module ) ;
223 if( /svn.services.openoffice.org/ )
225 my $mod = $path[ 0 ];
226 #push @ooo_modules , $mod;
227 $is_ooo_module{ $mod } = "true";
228 # print "$module -> ooo ";
230 elsif ( /jumbo2.germany.sun.com/ )
232 my $mod = $path[ 0 ];
233 #push @so_modules , $mod;
234 # print "$module -> so ";
235 #$so_lookup_hash{ $mod } = "true";
239 # print "ERROR: Is $module a SO or OOo module? Can not parese the $module/.svn/entries file ... please check mwsfinnish/merge/splitsdf.pl line 280\n";
255 # my $command = "$CVS_BINARY -d:pserver:anoncvs\@anoncvs.services.openoffice.org:/cvs co -c";
256 # my $output = `$command`;
258 # if ( $output eq "" || $rc < 0 ){
259 # print STDERR "ERROR: Can not fetch cvs alias list, please login to the cvs server and press at the password prompt just return\ncvs -d:pserver:anoncvs\@anoncvs.services.openoffice.org:/cvs login\n";
262 # my @list = split /\n/ , $output ;
263 # foreach my $string( @list )
266 # # print "Found '$1'\n" , if( $string =~ /^(\w*)/ && $1 ne "" );
268 # $is_ooo_module{ $1 } = "TRUE", if( $string =~ /^(\w*)/ && $1 ne "" );
270 # # foreach my $key( keys( %is_ooo_module ) )
275 sub is_openoffice_module
278 return "TRUE", if defined $is_ooo_module{ $module };
284 my $string_hash = shift;
285 my $l10n_file = shift;
287 foreach my $lang( keys( %{ $string_hash } ) )
292 my $current_l10n_file = $WIN eq "TRUE" ?
$l10n_file."\\$lang\\localize.sdf" : $l10n_file."/$lang/localize.sdf";
293 print "Writing '$current_l10n_file'\n";
294 if( open DESTFILE
, "< $current_l10n_file" ){
298 my $line = defined $_ ?
$_ : '';
299 my $prj = defined $3 ?
$3 : '';
300 my $file = defined $4 ?
$4 : '';
301 my $type = defined $6 ?
$6 : '';
302 my $gid = defined $7 ?
$7 : '';
303 my $lid = defined $8 ?
$8 : '';
304 my $lang = defined $12 ?
$12 : '';
305 my $plattform = defined $10 ?
$10 : '';
306 my $helpid = defined $9 ?
$9 : '';
309 if ( defined $string_hash->{ $lang }{ "$prj\t$file\t$type\t$gid\t$lid\t$helpid\t$plattform\t$lang" } )
312 push @sdf_file , $string_hash->{ $lang }{ "$prj\t$file\t$type\t$gid\t$lid\t$helpid\t$plattform\t$lang" } ;
313 $string_hash->{ $lang }{ "$prj\t$file\t$type\t$gid\t$lid\t$helpid\t$plattform\t$lang" } = undef;
318 push @sdf_file , $line;
324 #Now just append the enw strings
325 #FIXME!!! Implement insertion in the correct order
326 foreach my $key ( keys ( %{ $string_hash->{ $lang } } ) )
328 push @sdf_file , $string_hash->{ $lang }{ $key } , if ( defined $string_hash->{ $lang }{ $key } );
329 #print "WARNING: Not defined = ".$string_hash->{ $lang }{ $key }."\n", if( ! defined $string_hash->{ $lang }{ $key } );
333 my ( $TMPFILE , $tmpfile ) = File
::Temp
::tempfile
();
334 if( open DESTFILE
, "+> $tmpfile " ){
335 print DESTFILE get_license_header
();
336 foreach my $string( @sdf_file ){
337 print DESTFILE
"$string\n";
340 if( move
( $current_l10n_file , $current_l10n_file.".backup" ) ){
341 if( copy
( $tmpfile , $current_l10n_file ) ){
342 unlink $l10n_file.".backup";
343 } else { print STDERR
"Can't open/create '$l10n_file', original file is renamed to $l10n_file.backup\n"; }
344 } else { print STDERR
"Can't open/create '$l10n_file'\n"; }
346 print STDERR
"WARNING: Can't open/create '$l10n_file'\n";
352 #########################################################
354 sub get_license_header
{
357 "# #### ### # # ### ##### ##### #### ##### ##### \n".
358 "# # # # # ## # # # # # # # # # \n".
359 "# # # # # # # # # # # ### # # # # \n".
360 "# # # # # # ## # # # # # # # # \n".
361 "# #### ### # # ### # ##### #### ##### # \n".
363 "# DO NOT EDIT! This file will be overwritten by localisation process\n".
365 "#*************************************************************************\n".
367 "# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.\n".
369 "# Copyright 2008 by Sun Microsystems, Inc.\n".
371 "# OpenOffice.org - a multi-platform office productivity suite\n".
374 "localize.pl,v \$\n".
379 "# This file is part of OpenOffice.org.\n".
381 "# OpenOffice.org is free software: you can redistribute it and/or modify\n".
382 "# it under the terms of the GNU Lesser General Public License version 3\n".
383 "# only, as published by the Free Software Foundation.\n".
385 "# OpenOffice.org is distributed in the hope that it will be useful,\n".
386 "# but WITHOUT ANY WARRANTY; without even the implied warranty of\n".
387 "# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n".
388 "# GNU Lesser General Public License version 3 for more details\n".
389 "# (a copy is included in the LICENSE file that accompanied this code).\n".
391 "# You should have received a copy of the GNU Lesser General Public License\n".
392 "# version 3 along with OpenOffice.org. If not, see\n".
393 "# <http://www.openoffice.org/license.html>\n".
394 "# for a copy of the LGPLv3 License.\n".
396 "#*************************************************************************\n";
398 ######## Check input sdf file and use only the correct part
401 my ( $TMPHANDLE , $tmpfile ) = File
::Temp
::tempfile
();
402 close ( $TMPHANDLE );
405 $command = "$ENV{WRAPCMD} gsicheck";
407 $command = "gsicheck";
409 my $errfile = $sdffile.".err";
410 $command .= " -k -c -wcf $tmpfile -wef ".fix_cygwin_path
($errfile)." -l \"\" ".fix_cygwin_path
($sdffile);
411 #my $rc = system( $command );
412 if ($bVerbose) { print STDOUT
"localize.pl running $command\n"; }
413 my $output = `$command`;
415 if ( $output ne "" ){
416 print STDOUT
"### gsicheck ###\n";
417 print STDOUT
"### The file $errfile have been written containing the errors in your sdf file. Those lines will not be merged: ###\n\n";
418 print STDOUT
"$output\n";
419 print STDOUT
"################\n";
422 # Remove the 0 Byte file
427 #########################################################
428 # find search function
431 my $file = $File::Find
::name
;
432 if( -f
$file && $file =~ /.*localize.sdf$/ && !( $file =~ /.*\.svn.*/ ) ) {
433 push @sdfparticles , $file;
434 if( $bVerbose eq "1" ) { print STDOUT
"$file\n"; }
441 my $langhash_ref = shift;
442 my $root_dir = $ENV{ SRC_ROOT
};
443 my $ooo_l10n_dir = "$root_dir"."$DELIMITER"."l10n"."$DELIMITER"."source";
444 my $so_l10n_dir = "$root_dir"."$DELIMITER"."l10n_so"."$DELIMITER"."source";
446 if( -e
$ooo_l10n_dir )
448 foreach my $lang ( keys( %{ $langhash_ref } ) )
450 my $loc_file = "$ooo_l10n_dir"."$DELIMITER"."$lang"."$DELIMITER"."localize.sdf";
453 push @sdfparticles , "$ooo_l10n_dir"."$DELIMITER"."$lang"."$DELIMITER"."localize.sdf";
455 else { print "WARNING: $loc_file not found ....\n"; }
458 else { die "ERROR: Can not find directory $ooo_l10n_dir!!!" }
459 if( -e
$so_l10n_dir )
461 foreach my $lang ( keys( %{ $langhash_ref } ) )
463 my $loc_file = "$so_l10n_dir"."$DELIMITER"."$lang"."$DELIMITER"."localize.sdf";
466 push @sdfparticles , "$ooo_l10n_dir"."$DELIMITER"."$lang"."$DELIMITER"."localize.sdf";
468 else { #print "WARNING: $loc_file not found ....\n";
475 print STDOUT
"### Localize\n";
476 my $localizehash_ref;
477 my ( $bAll , $bUseLocalize, $langhash_ref , $bHasSourceLanguage , $bFakeEnglish ) = parseLanguages
();
479 # Enable autoflush on STDOUT
481 STDOUT
->autoflush( 1 );
483 ### Search sdf particles
484 #print STDOUT "### Searching sdf particles\n";
485 my $working_path = getcwd
();
487 #find ( { wanted => \&wanted , follow => 1 }, getcwd() );
488 #chdir $working_path;
489 add_paths
( $langhash_ref );
490 #my $nFound = $#sdfparticles +1;
491 #print "\n $nFound files found !\n";
493 my ( $LOCALIZEPARTICLE , $localizeSDF ) = File
::Temp
::tempfile
();
494 close( $LOCALIZEPARTICLE );
496 my ( $ALLPARTICLES_MERGED , $particleSDF_merged ) = File
::Temp
::tempfile
();
497 close( $ALLPARTICLES_MERGED );
498 my ( $LOCALIZE_LOG , $my_localize_log ) = File
::Temp
::tempfile
();
499 close( $LOCALIZE_LOG );
501 ## Get the localize en-US extract
502 if( $bAll || $bUseLocalize ){
503 print "### Fetching source language strings\n";
508 $command = $ENV{WRAPCMD
}.$binpath."localize_sl";
510 $command = $binpath."localize_sl";
514 # if ( -x $command ){
516 if( !$bVerbose ){ $args .= " -QQ "; }
517 $args .= " -e -f ".fix_cygwin_path
($localizeSDF)." -l ";
519 if( $bAll ) {$args .= " en-US";}
522 foreach my $isokey ( keys( %{ $langhash_ref } ) ){
523 push @list , $isokey;
524 if( $langhash_ref->{ $isokey } ne "" ){
525 push @list , $langhash_ref->{ $isokey };
528 remove_duplicates
( \
@list );
529 foreach my $isokey ( @list ){
531 ( $isokey=~ /^en-US$/i )
533 if( $bFlag eq "TRUE" ){ $args .= ",en-US"; }
535 $args .= "en-US"; $bFlag = "TRUE";
544 # if ( $WIN eq "TRUE" ) { $args .= " > $my_localize_log"; }
545 # else { $args .= " >& $my_localize_log"; }
547 if ( $bVerbose ) { print STDOUT
"localize.pl running $command.$args.\n"; }
549 my $rc = system( $command.$args );
551 if( $rc < 0 ){ print STDERR
"ERROR: localize rc = $rc\n"; exit( -1 ); }
552 ( $localizehash_ref ) = read_file
( $localizeSDF , $langhash_ref );
557 open ALLPARTICLES_MERGED
, "+>> $particleSDF_merged"
558 or die "Can't open $particleSDF_merged";
560 ## Fill fackback hash
561 my( $fallbackhashhash_ref ) = fetch_fallback
( \
@sdfparticles , $localizeSDF , $langhash_ref );
565 foreach my $cur_lang ( keys( %{ $langhash_ref } ) ){
566 #print STDOUT "DBG: G1 cur_lang=$cur_lang\n";
567 $cur_fallback = $langhash_ref->{ $cur_lang };
568 if( $cur_fallback ne "" ){
569 # Insert fallback strings
570 #print STDOUT "DBG: Renaming $cur_fallback to $cur_lang in fallbackhash\n";
571 rename_language
( $fallbackhashhash_ref , $cur_fallback , $cur_lang );
573 foreach my $currentfile ( @sdfparticles ){
574 if ( open MYFILE
, "< $currentfile" ) {
577 my $line = defined $_ ?
$_ : '';
578 my $prj = defined $3 ?
$3 : '';
579 my $file = defined $4 ?
$4 : '';
580 my $type = defined $6 ?
$6 : '';
581 my $gid = defined $7 ?
$7 : '';
582 my $lid = defined $8 ?
$8 : '';
583 my $lang = defined $12 ?
$12 : '';
584 my $plattform = defined $10 ?
$10 : '';
585 my $helpid = defined $9 ?
$9 : '';
589 if ( $lang eq $cur_lang ){
590 # Overwrite fallback strings with collected strings
591 #if( ( !has_two_sourcelanguages( $cur_lang) && $cur_lang eq "de" ) || $cur_lang ne "en-US" ){
592 $fallbackhashhash_ref->{ $cur_lang }{ $prj.$gid.$lid.$file.$type.$plattform.$helpid } = $line ;
598 }else { print STDERR
"WARNING: Can't open file $currentfile"; }
601 foreach my $line ( keys( %{$fallbackhashhash_ref->{ $cur_lang } } )) {
602 if( #$cur_lang ne "de" &&
603 $cur_lang ne "en-US" ){
604 print ALLPARTICLES_MERGED
( $fallbackhashhash_ref->{ $cur_lang }{ $line }, "\n" );
609 foreach my $currentfile ( @sdfparticles ){
610 if ( open MYFILE
, "< $currentfile" ) {
612 print ALLPARTICLES_MERGED
( $_, "\n" ); # recheck de / en-US !
615 else { print STDERR
"WARNING: Can't open file $currentfile"; }
618 close ALLPARTICLES_MERGED
;
627 if( open DESTFILE
, "+> $outputfile" ){
628 if( !open LOCALIZEPARTICLE
, "< $localizeSDF" ) { print STDERR
"ERROR: Can't open file $localizeSDF\n"; }
629 if( !open ALLPARTICLES_MERGED
, "< $particleSDF_merged" ) { print STDERR
"ERROR: Can't open file $particleSDF_merged\n"; }
633 while ( <LOCALIZEPARTICLE
> ){
635 my $leftpart = defined $2 ?
$2 : '';
636 my $lang = defined $12 ?
$12 : '';
637 my $rightpart = defined $13 ?
$13 : '';
638 my $timestamp = defined $18 ?
$18 : '';
640 my $prj = defined $3 ?
$3 : '';
641 my $file = defined $4 ?
$4 : '';
642 my $type = defined $6 ?
$6 : '';
643 my $gid = defined $7 ?
$7 : '';
644 my $lid = defined $8 ?
$8 : '';
645 #my $lang = defined $12 ? $12 : '';
646 my $plattform = defined $10 ?
$10 : '';
647 my $helpid = defined $9 ?
$9 : '';
650 if( $use_default_date )
652 $extract_date = "$default_date\n" ;
654 elsif( $extract_date eq "" ) {
655 $extract_date = $timestamp ;
656 $extract_date =~ tr/\r\n//d;
657 $extract_date .= "\n";
660 if( $bAll ){ print DESTFILE
$leftpart."\t".$lang."\t".$rightpart.$extract_date ; }
662 foreach my $sLang ( keys( %{ $langhash_ref } ) ){
663 if( $sLang=~ /all/i ) {
664 push @
{ $output{ $prj.$gid.$lid.$file.$type.$plattform.$helpid } } , $leftpart."\t".$lang."\t".$rightpart.$extract_date ;
665 #print DESTFILE $leftpart."\t".$lang."\t".$rightpart.$extract_date;
667 #if( $sLang eq "de" && $lang eq "de" ) {
668 # push @{ $output{ $prj.$gid.$lid.$file.$type.$plattform.$helpid } } , $leftpart."\t".$lang."\t".$rightpart.$extract_date ;
669 #print DESTFILE $leftpart."\t".$lang."\t".$rightpart.$extract_date;
671 if( $sLang eq "en-US" && $lang eq "en-US" ) {
672 push @order , $prj.$gid.$lid.$file.$type.$plattform.$helpid;
673 if( !$bFakeEnglish ){ push @
{ $output{ $prj.$gid.$lid.$file.$type.$plattform.$helpid } } , $leftpart."\t".$lang."\t".$rightpart.$extract_date ; }
674 #print DESTFILE $leftpart."\t".$lang."\t".$rightpart.$extract_date;
682 while ( <ALLPARTICLES_MERGED
> ){
684 my $leftpart = defined $2 ?
$2 : '';
685 my $prj = defined $3 ?
$3 : '';
686 my $lang = defined $12 ?
$12 : '';
687 my $rightpart = defined $13 ?
$13 : '';
688 my $timestamp = defined $18 ?
$18 : '';
690 #my $prj = defined $3 ? $3 : '';
691 my $file = defined $4 ?
$4 : '';
692 my $type = defined $6 ?
$6 : '';
693 my $gid = defined $7 ?
$7 : '';
694 my $lid = defined $8 ?
$8 : '';
695 #my $lang = defined $12 ? $12 : '';
696 my $plattform = defined $10 ?
$10 : '';
697 my $helpid = defined $9 ?
$9 : '';
700 if( $use_default_date )
702 $extract_date = "$default_date\n" ;
704 elsif( $extract_date eq "" )
706 $extract_date = $timestamp;
709 if( ! ( $prj =~ /binfilter/i ) ) {
710 push @
{ $output{ $prj.$gid.$lid.$file.$type.$plattform.$helpid } } , $leftpart."\t".$lang."\t".$rightpart.$extract_date ;
711 #print DESTFILE $leftpart."\t".$lang."\t".$rightpart.$extract_date ;
717 foreach my $curkey ( @order ){
718 foreach my $curlist ( $output{ $curkey } ){
719 foreach my $line ( @
{$curlist} ){
720 print DESTFILE
$line;
725 }else { print STDERR
"Can't open $outputfile";}
728 close LOCALIZEPARTICLE
;
729 close ALLPARTICLES_MERGED
;
731 #print STDOUT "DBG: \$localizeSDF $localizeSDF \$particleSDF_merged $particleSDF_merged\n";
732 unlink $localizeSDF , $particleSDF_merged , $my_localize_log;
734 #sort_outfile( $outputfile );
735 #remove_obsolete( $outputfile ) , if $bHasSourceLanguage ne "";
738 #########################################################
745 print STDOUT
"### Removing obsolete strings\n";
747 # Kick out all strings without en-US reference
748 if ( open ( SORTEDFILE
, "< $outfile" ) ){
749 while( <SORTEDFILE
> ){
751 my $line = defined $_ ?
$_ : '';
752 my $language = defined $12 ?
$12 : '';
753 my $prj = defined $3 ?
$3 : '';
754 my $file = defined $4 ?
$4 : '';
755 my $type = defined $6 ?
$6 : '';
756 my $gid = defined $7 ?
$7 : '';
757 my $lid = defined $8 ?
$8 : '';
758 my $plattform = defined $10 ?
$10 : '';
759 my $helpid = defined $9 ?
$9 : '';
761 my $leftpart = $prj.$gid.$lid.$file.$type.$plattform.$helpid;
763 if( $language eq "en-US" ){ # source string found, 1. entry
764 $enusleftpart = $leftpart;
765 push @good_lines , $line;
767 if( !defined $enusleftpart or !defined $leftpart ){
768 print STDERR
"BADLINE: $line\n";
769 print STDERR
"\$enusleftpart = $enusleftpart\n";
770 print STDERR
"\$leftpart = $leftpart\n";
772 if( $enusleftpart eq $leftpart ){ # matching language
773 push @good_lines , $line;
776 # print STDERR "OUT: \$enusleftpart=$enusleftpart \$leftpart=$leftpart \$line=$line\n";
782 } else { print STDERR
"ERROR: Can't open file $outfile\n";}
785 if ( open ( SORTEDFILE
, "> $outfile" ) ){
786 foreach my $newline ( @good_lines ) {
787 print SORTEDFILE
$newline;
790 } else { print STDERR
"ERROR: Can't open file $outfile\n";}
793 #########################################################
796 print STDOUT
"### Sorting ... $outfile ...";
801 #if ( open ( SORTEDFILE , "< $outputfile" ) ){
802 if ( open ( SORTEDFILE
, "< $outfile" ) ){
804 while ( <SORTEDFILE
> ){
806 if( $line =~ /^[^\#]/ ){
811 @sorted_lines = sort {
813 my $xa_left_part = "";
814 my $xa_right_part = "";
815 my $xa_timestamp = "";
817 my $xb_left_part = "";
818 my $xb_right_part = "";
819 my $xb_timestamp = "";
825 if( $a=~ /$sdf_regex/ ){
826 $xa_left_part = defined $2 ?
$2 : '';
827 $xa_lang = defined $12 ?
$12 : '';
828 $xa_right_part = defined $13 ?
$13 : '';
829 $xa_left_part = remove_last_column
( $xa_left_part );
832 if( $b=~ /$sdf_regex/ ){
833 $xb_left_part = defined $2 ?
$2 : '';
834 $xb_lang = defined $12 ?
$12 : '';
835 $xb_right_part = defined $13 ?
$13 : '';
836 $xb_left_part = remove_last_column
( $xb_left_part );
840 if( ( $xa_left_part cmp $xb_left_part ) == 0 ){ # Left part equal
841 if( ( $xa_lang cmp $xb_lang ) == 0 ){ # Lang equal
842 return ( $xa_right_part cmp $xb_right_part ); # Right part compare
844 elsif( $xa_lang eq "en-US" ) { return -1; } # en-US wins
845 elsif( $xb_lang eq "en-US" ) { return 1; } # en-US wins
846 else { return $xa_lang cmp $xb_lang; } # lang compare
849 return $xa_left_part cmp $xb_left_part; # Left part compare
853 if ( open ( SORTEDFILE
, "> $outfile" ) ){
854 print SORTEDFILE get_license_header
();
855 foreach my $newline ( @sorted_lines ) {
856 print SORTEDFILE
$newline;
857 #print STDOUT $newline;
861 } else { print STDERR
"WARNING: Can't open file $outfile\n";}
865 #########################################################
866 sub remove_last_column
{
868 my @alist = split ( "\t" , $string );
870 return join( "\t" , @alist );
873 #########################################################
875 my $fallbackhashhash_ref = shift;
876 my $cur_fallback = shift;
877 my $cur_lang = shift;
880 foreach my $key( keys ( %{ $fallbackhashhash_ref->{ $cur_fallback } } ) ){
881 $line = $fallbackhashhash_ref->{ $cur_fallback }{ $key };
882 if( $line =~ /$sdf_regex/ ){
883 my $leftpart = defined $2 ?
$2 : '';
884 my $lang = defined $12 ?
$12 : '';
885 my $rightpart = defined $13 ?
$13 : '';
887 $fallbackhashhash_ref->{ $cur_lang }{ $key } = $leftpart."\t".$cur_lang."\t".$rightpart;
892 ############################################################
893 sub remove_duplicates
{
894 my $list_ref = shift;
896 foreach my $key ( @
{ $list_ref } ){ $tmphash{ $key } = '' ; }
897 @
{$list_ref} = keys( %tmphash );
900 ##############################################################
902 my $sdfparticleslist_ref = shift;
903 my $localizeSDF = shift;
904 my $langhash_ref = shift;
905 my %fallbackhashhash;
909 foreach my $key ( keys ( %{ $langhash_ref } ) ){
910 $cur_lang = $langhash_ref->{ $key };
911 if ( $cur_lang ne "" ) {
912 push @langlist , $cur_lang;
915 remove_duplicates
( \
@langlist );
916 foreach $cur_lang ( @langlist ){
917 if( $cur_lang eq "en-US" ){
918 read_fallbacks_from_source
( $localizeSDF , $cur_lang , \
%fallbackhashhash );
924 foreach $cur_lang( @langlist ){
925 if( $cur_lang ne "en-US" ){
926 push @tmplist , $cur_lang;
930 @langlist = @tmplist;
931 if ( $#langlist +1 ){
932 read_fallbacks_from_particles
( $sdfparticleslist_ref , \
@langlist , \
%fallbackhashhash );
935 return (\
%fallbackhashhash);
938 #########################################################
941 my $localizeFile = shift;
942 my $index_ref = shift;
944 if( open DESTFILE
, "+> $localizeFile" ){
945 foreach my $key( %{ $index_ref } ){
946 print DESTFILE
($index_ref->{ $key }, "\n" );
950 print STDERR
"Can't open/create '$localizeFile'";
954 #########################################################
958 my $langhash_ref = shift;
961 open MYFILE
, "< $sdffile"
962 or die "Can't open '$sdffile'\n";
965 my $line = defined $_ ?
$_ : '';
966 my $prj = defined $3 ?
$3 : '';
967 my $file = defined $4 ?
$4 : '';
968 my $type = defined $6 ?
$6 : '';
969 my $gid = defined $7 ?
$7 : '';
970 my $lid = defined $8 ?
$8 : '';
971 my $plattform = defined $10 ?
$10 : '';
972 my $lang = defined $12 ?
$12 : '';
973 my $helpid = defined $9 ?
$9 : '';
975 foreach my $isolang ( keys ( %{ $langhash_ref } ) ){
976 if( $isolang=~ /$lang/i || $isolang=~ /all/i ) { $block{$prj.$gid.$lid.$file.$type.$plattform.$helpid } = $line ; }
983 #########################################################
984 sub read_fallbacks_from_particles
{
986 my $sdfparticleslist_ref = shift;
987 my $isolanglist_ref = shift;
988 my $fallbackhashhash_ref = shift;
990 foreach my $currentfile ( @
{ $sdfparticleslist_ref } ){
991 if ( open MYFILE
, "< $currentfile" ) {
994 my $line = defined $_ ?
$_ : '';
995 my $prj = defined $3 ?
$3 : '';
996 my $file = defined $4 ?
$4 : '';
997 my $type = defined $6 ?
$6 : '';
998 my $gid = defined $7 ?
$7 : '';
999 my $lid = defined $8 ?
$8 : '';
1000 my $lang = defined $12 ?
$12 : '';
1001 my $plattform = defined $10 ?
$10 : '';
1002 my $helpid = defined $9 ?
$9 : '';
1006 foreach my $isolang ( @
{$isolanglist_ref} ){
1007 if( $isolang=~ /$lang/i ) {
1008 $fallbackhashhash_ref->{ $isolang }{ $prj.$gid.$lid.$file.$type.$plattform.$helpid } = $line ;
1013 }else { print STDERR
"WARNING: Can't open file $currentfile"; }
1017 #########################################################
1018 sub read_fallbacks_from_source
{
1020 my $sdffile = shift;
1021 my $isolang = shift;
1022 my $fallbackhashhash_ref = shift;
1024 # read fallback for single file
1025 open MYFILE
, "< $sdffile"
1026 or die "Can't open '$sdffile'\n";
1030 my $line = defined $_ ?
$_ : '';
1031 my $prj = defined $3 ?
$3 : '';
1032 my $file = defined $4 ?
$4 : '';
1033 my $type = defined $6 ?
$6 : '';
1034 my $gid = defined $7 ?
$7 : '';
1035 my $lid = defined $8 ?
$8 : '';
1036 my $helpid = defined $9 ?
$9 : '';
1037 my $lang = defined $12 ?
$12 : '';
1038 my $plattform = defined $10 ?
$10 : '';
1041 if( $isolang=~ /$lang/i ) { $fallbackhashhash_ref->{ $isolang }{ $prj.$gid.$lid.$file.$type.$plattform.$helpid } = $line ;
1047 #########################################################
1052 my $bHasSourceLanguage="";
1053 my $bFakeEnglish="";
1059 if( $languages=~ /all/ ){
1061 $bHasSourceLanguage = "TRUE";
1064 elsif( $languages=~ /.*,.*/ ){
1065 my @tmpstr = split "," , $languages;
1066 for my $lang ( @tmpstr ){
1067 if( $lang=~ /([a-zA-Z]{2,3}(-[a-zA-Z\-]*)*)(=([a-zA-Z]{2,3}(-[a-zA-Z\-]*)*))?/ ){
1071 if( ( $iso && $iso=~ /(en-US)/i ) || ( $fallback && $fallback=~ /(en-US)/i ) ) {
1072 $bUseLocalize = "TRUE";
1074 if( ( $iso && $iso=~ /(en-US)/i ) ) {
1075 $bHasSourceLanguage = "TRUE";
1077 if( $fallback ) { $langhash{ $iso } = $fallback; }
1078 else { $langhash{ $iso } = ""; }
1084 if( $languages=~ /([a-zA-Z]{2,3}(-[a-zA-Z\-]*)*)(=([a-zA-Z]{2,3}(-[a-zA-Z\-]*)*))?/ ){
1088 if( ( $iso && $iso=~ /(en-US)/i ) || ( $fallback && $fallback=~ /(en-US)/i ) ) {
1089 $bUseLocalize = "TRUE";
1092 if( ( $iso && $iso=~ /(en-US)/i ) ) {
1093 $bHasSourceLanguage = "TRUE";
1096 if( $fallback ) { $langhash{ $iso } = $fallback; }
1097 else { $langhash{ $iso } = ""; }
1100 # HACK en-US always needed!
1101 if( !$bHasSourceLanguage ){
1102 #$bHasSourceLanguage = "TRUE";
1103 $bUseLocalize = "TRUE";
1104 $bFakeEnglish = "TRUE";
1105 $langhash{ "en-US" } = "";
1107 return ( $bAll , $bUseLocalize , \
%langhash , $bHasSourceLanguage, $bFakeEnglish);
1110 #########################################################
1116 my $success = GetOptions
('f=s' => \
$sdffile , 'l=s' => \
$languages , 's=s' => \
$srcpath , 'h' => \
$help , 'v' => \
$bVerbose ,
1117 'm' => \
$merge , 'e' => \
$extract , 'x' => \
$no_sort , 'd' => \
$use_default_date , 'c' => \
$create_dirs ,
1118 'n' => \
$no_gsicheck );
1119 $outputfile = $sdffile;
1121 #print STDOUT "DBG: lang = $languages\n";
1123 $srcpath = "$ENV{SRC_ROOT}";
1125 print STDERR
"No path to the source root found!\n\n";
1130 if( $help || !$success || $#ARGV > 1 || ( !$sdffile ) ){
1134 if( $merge && $sdffile && ! ( -r
$sdffile)){
1135 print STDERR
"Can't open file '$sdffile'\n";
1138 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\-]*)*)?)*/ ) ){
1139 print STDERR
"Please check the -l iso code\n";
1142 if( ( !$merge && !$extract ) || ( $merge && $extract ) ){ usage
();exit( -1 );}
1143 if( $extract ){ $mode = "extract"; }
1144 else { $mode = "merge"; }
1146 #my $multi_localize_files = ''; h
1147 #my $module_to_merge = ''; i
1148 #my $sort_sdf_before = ''; g
1150 #########################################################
1153 print STDERR
"Usage: localize.pl\n";
1154 print STDERR
"Split or collect SDF files\n";
1155 print STDERR
" merge: -m -f <sdffile> -l l1[=f1][,l2[=f2]][...] [ -s <sourceroot> ] [ -c ]\n";
1156 print STDERR
" extract: -e -f <outputfile> -l <lang> [ -s <sourceroot> ] [-d]\n";
1157 print STDERR
"Options:\n";
1158 print STDERR
" -h help\n";
1159 print STDERR
" -m Merge mode\n";
1160 print STDERR
" -e Extract mode\n";
1161 print STDERR
" -f <sdffile> To split a big SDF file into particles\n";
1162 print STDERR
" <outputfile> To collect and join all particles to one big file\n";
1163 print STDERR
" -s <sourceroot> Path to the modules, if no \$SRC_ROOT is set\n";
1164 print STDERR
" -l ( all | <isocode> | <isocode>=fallback ) comma seperated languages\n";
1165 print STDERR
" -d Use default date in extracted sdf file\n";
1166 print STDERR
" -c Create needed directories\n";
1167 print STDERR
" -g Sort sdf file before mergeing\n";
1168 print STDERR
" -h File with localize.sdf's\n!";
1169 print STDERR
" -n No gsicheck\n";
1170 print STDERR
" -i Module to merge\n";
1171 print STDERR
" -v Verbose\n";
1172 print STDERR
"\nExample:\n";
1173 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";
1174 print STDERR
"\nlocalize -m -l cs -f my.sdf\n( Merge cs translation into the sourcecode ) \n";
1181 if ( $^O
eq 'cygwin' )
1183 $path = qx{cygpath
-m
"$path"};
1190 # my $line = defined $_ ? $_ : '';
1191 # my $leftpart = defined $2 ? $2 : '';
1192 # my $prj = defined $3 ? $3 : '';
1193 # my $file = defined $4 ? $4 : '';
1194 # my $dummy = defined $5 ? $5 : '';
1195 # my $type = defined $6 ? $6 : '';
1196 # my $gid = defined $7 ? $7 : '';
1197 # my $lid = defined $8 ? $8 : '';
1198 # my $helpid = defined $9 ? $9 : '';
1199 # my $plattform = defined $10 ? $10 : '';
1200 # my $width = defined $11 ? $11 : '';
1201 # my $lang = defined $12 ? $12 : '';
1202 # my $rightpart = defined $13 ? $13 : '';
1203 # my $text = defined $14 ? $14 : '';
1204 # my $helptext = defined $15 ? $15 : '';
1205 # my $quickhelptext = defined $16 ? $16 : '';
1206 # my $title = defined $17 ? $17 : '';
1207 # my $timestamp = defined $18 ? $18 : '';