summaryrefslogtreecommitdiff
path: root/l10ntools/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'l10ntools/scripts')
-rw-r--r--l10ntools/scripts/fast_merge.pl334
-rw-r--r--l10ntools/scripts/keyidGen.pl185
-rw-r--r--l10ntools/scripts/localize.pl1078
-rwxr-xr-xl10ntools/scripts/localize_old.pl1070
-rw-r--r--l10ntools/scripts/makefile.mk59
-rw-r--r--l10ntools/scripts/tool/const.py39
-rw-r--r--l10ntools/scripts/tool/l10ntool.py210
-rw-r--r--l10ntools/scripts/tool/pseudo.py184
-rw-r--r--l10ntools/scripts/tool/sdf.py170
-rw-r--r--l10ntools/scripts/tool/xhtex.py136
-rw-r--r--l10ntools/scripts/tool/xtxex.py94
-rwxr-xr-xl10ntools/scripts/xhtex38
-rwxr-xr-xl10ntools/scripts/xtxex39
13 files changed, 3636 insertions, 0 deletions
diff --git a/l10ntools/scripts/fast_merge.pl b/l10ntools/scripts/fast_merge.pl
new file mode 100644
index 000000000000..5dc63cf95d79
--- /dev/null
+++ b/l10ntools/scripts/fast_merge.pl
@@ -0,0 +1,334 @@
+:
+eval 'exec perl -wS $0 ${1+"$@"}'
+ if 0;
+#*************************************************************************
+#
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# Copyright 2000, 2010 Oracle and/or its affiliates.
+#
+# OpenOffice.org - a multi-platform office productivity suite
+#
+# This file is part of OpenOffice.org.
+#
+# OpenOffice.org is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Lesser General Public License version 3
+# only, as published by the Free Software Foundation.
+#
+# OpenOffice.org is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Lesser General Public License version 3 for more details
+# (a copy is included in the LICENSE file that accompanied this code).
+#
+# You should have received a copy of the GNU Lesser General Public License
+# version 3 along with OpenOffice.org. If not, see
+# <http://www.openoffice.org/license.html>
+# for a copy of the LGPLv3 License.
+#
+#*************************************************************************
+
+use strict;
+use Class::Struct;
+use Getopt::Long;
+use File::Temp;
+use File::Path;
+
+my @files;
+my @file_names;
+my $module_name = '';
+my @current;
+my @buffer;
+my $last_file;
+my $last_path;
+my $last_localize_file;
+my $first_run = "1";
+my $sdf_filename;
+my $merge_dir;
+my $state = "none";
+
+$SIG{INT} = 'inthandler';
+$SIG{QUIT} = 'quithandler';
+
+struct ( sdf_obj =>
+{
+ module => '$',
+ file => '$',
+ dir => '$',
+ FILEHANDLE => '$',
+ line => '$',
+ endoffile => '$'
+}
+);
+
+parse_options();
+my $lock_file = $merge_dir."/lock.mk";
+acquire_lock();
+read_sdf_file_names();
+init();
+my $reference;
+my $path ;
+my $localize_file;
+while( hasLines() )
+{
+ @current = ();
+ foreach ( @files )
+ {
+ push @current , $_;
+ }
+
+ $reference = getNextIdentifier( );
+
+ @current = ();
+ foreach ( @files )
+ {
+ if( $_->module eq $reference->module && $_->dir eq $reference->dir )
+ {
+ push @current , $_ ;
+ }
+ }
+ write_lines();
+}
+if( $#current+1 ne 0 )
+{
+ ( $path , $localize_file ) = make_paths();
+ add_to_buffer();
+ write_buffer( $path , $localize_file );
+}
+release_lock();
+exit( 0 );
+
+##########################################################################################
+sub acquire_lock
+{
+ if( -e $lock_file ){
+ $state = "blocked";
+ print "WARNING: Lock file '$lock_file' 'found, waiting ....\n";
+ my $cnt = 0;
+ sleep 10 , while( -e $lock_file && $cnt++ < 180 );
+ exit( 0 );
+ }else
+ {
+ $state = "locked";
+ print "Writing lock file '$lock_file'\n";
+ open FILE, ">$lock_file" or die "Can't create lock file '$lock_file'";
+ print FILE "L10N_LOCK=YES" ;
+ close ( FILE );
+ }
+}
+sub release_lock
+{
+ print "Deleting lock file '$lock_file'\n";
+ unlink $lock_file, if( -e $lock_file );
+ $state = "none";
+}
+sub inthandler
+{
+ release_lock() , if( $state eq "locked" );
+ exit( -1 );
+}
+sub quithandler
+{
+ release_lock() , if( $state eq "locked" );
+ exit( 0 );
+}
+
+sub init
+{
+ foreach my $file ( @file_names )
+ {
+ my $obj = new sdf_obj;
+ open my $FILEHANDLE , "<$file" or die "Can't open file '$file'";
+ $obj->FILEHANDLE ( $FILEHANDLE ) ;
+ getNextSdfObj( $obj );
+ push @files, $obj ;
+ print "Open file '$file'\n";
+ }
+}
+
+# get the next module/file
+sub getNextIdentifier
+{
+ my @sorted = sort {
+ return $a->module.$a->dir cmp $b->module.$b->dir;
+ } @current ;
+ return shift @sorted;
+}
+
+# update the obj with the next line
+sub getNextSdfObj
+{
+ my $obj = shift;
+ my $line = readline ( $obj->FILEHANDLE );
+ if ( $line eq undef )
+ {
+ $obj->endoffile( "true" );
+ }
+ else
+ {
+ $line =~ /^(([^\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*)/o ;
+ if( defined $1 && defined $2 && defined $3 )
+ {
+ $obj->line ( $1 );
+ $obj->module( $2 );
+ $obj->file ( $3 );
+ $obj->dir ( getDir( $3 ) );
+ }
+ else
+ {
+ $obj->line ( "" );
+ $obj->module( "" );
+ $obj->file ( "" );
+ $obj->dir ( "" );
+ }
+ }
+ return $obj;
+}
+sub getNextSdfObjModule
+{
+ my $obj = shift;
+ while( !$obj->endoffile )
+ {
+ my $line = readline ( $obj->FILEHANDLE );
+ if ( $line eq undef )
+ {
+ $obj->endoffile( "true" );
+ }
+ else
+ {
+ $line =~ /^(([^\t]*)\t([^\t]*).*)/o ;
+ if( defined $1 && defined $2 && defined $3 )
+ {
+ $obj->line ( $1 );
+ $obj->module( $2 );
+ $obj->file ( $3 );
+ $obj->dir ( getDir( $3 ) );
+ }
+ else
+ {
+ $obj->line ( "" );
+ $obj->module( "" );
+ $obj->file ( "" );
+ $obj->dir ( "" );
+ }
+ return $obj , if( $obj->module eq $module_name )
+ }
+ }
+ #return $obj;
+}
+sub getDir
+{
+ my $path = shift ;
+ $path =~ s/\//\\/g;
+ my @tmp_path = split /\\/ , $path;
+ pop @tmp_path;
+ $path = join '\\' , @tmp_path;
+ return $path;
+}
+
+sub hasLines
+{
+ my $hasLines = "";
+ my @tmpfiles;
+ foreach ( @files )
+ {
+ push @tmpfiles , $_, if( !$_->endoffile );
+ }
+ @files = @tmpfiles;
+ return $#files+1;
+}
+
+sub make_paths
+{
+ my $localizeFile = $merge_dir."\\".$current[ 0 ]->module."\\".$current[ 0 ]->file;
+ my $path = getDir( $localizeFile );
+ $path =~ s/\\/\//g;
+
+ $localizeFile = $path."/localize.sdf";
+
+ return ( $path , $localizeFile );
+}
+sub write_lines
+{
+ if( $first_run ){
+ add_to_buffer();
+ my( $path , $localize_file ) = make_paths();
+ $last_path = $path;
+ $last_localize_file = $localize_file;
+ mkpath $path;
+ write_buffer( $path , $localize_file );
+ $first_run = '';
+ }
+ else
+ {
+ return , if ( $#current+1 eq 0 );
+ my( $path , $localize_file ) = make_paths();
+ if( $path eq $last_path )
+ {
+ add_to_buffer();
+ }
+ else
+ {
+ mkpath $path;
+ write_buffer( $last_path , $last_localize_file );
+ add_to_buffer();
+ $last_path = $path;
+ $last_localize_file = $localize_file;
+ }
+ }
+}
+sub add_to_buffer
+{
+ my $plainline;
+ my $afile;
+ my $amodule;
+ foreach my $elem ( @current )
+ {
+ do {
+ $amodule=$elem->module;
+ $afile=$elem->file;
+ $plainline=$elem->line;
+ push @buffer, $plainline;
+ getNextSdfObj( $elem );
+ } while ( !$elem->endoffile && $amodule eq $elem->module && $afile eq $elem->file );
+ }
+}
+sub write_buffer
+{
+ my $path = shift;
+ my $localize_file = shift;
+ my $cnt = $#buffer+1;
+ print "Write to $path $cnt lines\n";
+ open FILE , ">>$localize_file" or die "Can't open file '$localize_file'\n";
+ foreach ( @buffer )
+ {
+ print FILE $_."\n";
+ }
+ @buffer = ();
+}
+sub parse_options
+{
+ my $success = GetOptions( 'sdf_files=s' => \$sdf_filename , 'merge_dir=s' => \$merge_dir ); #, 'module=s' => \$module_name );
+ if( ! ( $sdf_filename && $merge_dir && $success ) )
+ {
+ usage();
+ exit( -1 );
+ }
+}
+
+sub usage
+{
+ print "Usage: fast_merge -sdf_files <file containing sdf file names> -merge_dir <directory>\n" ;
+}
+
+sub read_sdf_file_names
+{
+ open FILE , "<$sdf_filename" or die "Can't open file '$sdf_filename'\n";
+ while ( <FILE> )
+ {
+ push @file_names , split " " , $_ ;
+ }
+ close ( FILE );
+}
+
+
diff --git a/l10ntools/scripts/keyidGen.pl b/l10ntools/scripts/keyidGen.pl
new file mode 100644
index 000000000000..53423c2d6f02
--- /dev/null
+++ b/l10ntools/scripts/keyidGen.pl
@@ -0,0 +1,185 @@
+:
+eval 'exec perl -S $0 ${1+"$@"}'
+ if 0;
+#*************************************************************************
+#
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# Copyright 2000, 2010 Oracle and/or its affiliates.
+#
+# OpenOffice.org - a multi-platform office productivity suite
+#
+# This file is part of OpenOffice.org.
+#
+# OpenOffice.org is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Lesser General Public License version 3
+# only, as published by the Free Software Foundation.
+#
+# OpenOffice.org is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Lesser General Public License version 3 for more details
+# (a copy is included in the LICENSE file that accompanied this code).
+#
+# You should have received a copy of the GNU Lesser General Public License
+# version 3 along with OpenOffice.org. If not, see
+# <http://www.openoffice.org/license.html>
+# for a copy of the LGPLv3 License.
+#
+#*************************************************************************
+#
+# add keyids to sdf file
+#
+
+use Compress::Zlib();
+
+print "\nkeyidGen version 1.0 \n\n";
+
+my ( $infile,$outfile,$dbimport );
+get_options();
+
+print_help() if ( !defined $infile || $help );
+exit 1 if ( !defined $infile );
+if ( ! defined $outfile )
+{
+ $outfile = $infile;
+ $outfile =~ s/\.sdf$//i;
+ $outfile .= "_KeyID.sdf";
+}
+
+$collisions = 0;
+%hashcodes = ();
+$count = 0;
+print "writing to $outfile\n";
+open INFILE,"<$infile" || die "could not open $infile $! $^E\n";
+open OUTFILE,">$outfile" || die "could not open $outfile $! $^E\n";
+
+while ( <INFILE> )
+{
+ $line = $_;
+ chomp $line;
+ $hash = 0;
+ if ( $line =~ /^([^\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]*)$/ )
+ {
+ $string="$1 $2 $4 $5 $6 $7 $8";
+ $hashp = makeID( $string );
+
+ if ( defined ($hashcodes{ $hashp } ) )
+ {
+ $collisions ++ unless $hashcodes{ $hashp } eq $string;
+ }
+ $hashcodes{ $hashp } = $string;
+ $count++;
+ if ( $dbimport )
+ {
+ my ( $pre, $post, $old );
+ $pre = "$1\t$2\t";
+ $post = "\t$4\t$5\t$6\t$7\t$8\t$9\t$10\t$11\t$12\t$13\t$14\t$15\n";
+ $old = $3;
+ $old =~ s/;{0,1}keyid:......;{0,1}//;
+ $old =~ s/^0$//;
+ if ( $old ne "" ) { $old .= ";"; }
+ print OUTFILE "$pre${old}keyid:$hashp$post";
+ }
+ else
+ {
+ print OUTFILE "$1\t$2\t$3\t$4\t$5\t$6\t$7\t$8\t$9\t$10\t".makekidstr($hashp,$11)."\t".makekidstr($hashp,$12)."\t$13\t".makekidstr($hashp,$14)."\t$15\n";
+ }
+ }
+}
+print "$count entries\n";
+print "$collisions collisions\n";
+
+close INFILE;
+close OUTFILE;
+
+sub makeID
+{
+ my ( $String ) = shift;
+ my ( $hash );
+ # hardcoded to prevent windows installer to choke on bad directoryname :-((
+ if ( $String eq "scp2 source\\ooo\\directory_ooo.ulf LngText STR_DIR_KAPITEL " )
+ {
+ return "keyid1";
+ }
+
+ $hash = Compress::Zlib::crc32( $String, undef );
+ return makenumber( $hash );
+}
+
+sub makenumber
+{
+ $h = shift;
+ # 1 2 3 4
+ # 1234567890123456789012345678901234567890
+ $symbols="0123456789abcdefghijklmnopqrstuvwxyz+-[=]";
+ $order = length($symbols);
+ $result = "";
+ while ( length( $result ) < 6 )
+ {
+ $result .= substr( $symbols, ($h % $order), 1 );
+ $h = int( $h / $order );
+ }
+ die "makenumber failed because number is too big (this cannot be so this is a strange error)" if $h > 0;
+
+ return reverse $result;
+}
+
+
+sub makekidstr
+{
+ $kid = shift;
+ $str = shift;
+
+ if ( $str ne "" )
+ {
+ # special handling for strings starting with font descriptions like {&Tahoma8} (win system integration)
+ if ( $str =~ s/^(\{\&[^\}]+\})// )
+ {
+ return "$1$kid‖$str";
+ }
+ else
+ {
+ return "$kid‖$str";
+ }
+ }
+ else
+ {
+ return "";
+ }
+# return "default";
+}
+
+sub print_help
+{
+ print "\n\n";
+ print "keyidGen 0.5 for sdf files\n";
+ print "--------------------------\n";
+ print "Usage:\n";
+ print "keyidGen <infile> [<outfile>] [-dbimport]\n";
+ print " add keyids to the entries and write them to a file with\n";
+ print " _KeyID added to the name\n";
+ print " -dbimport Add KeyID to a new column instead of to the strings.\n";
+ print " This is needed to import the IDs into tha database.\n";
+ print "\n\n";
+}
+
+
+sub get_options {
+ my ($arg,$has_infile);
+
+ while ($arg = shift @ARGV) {
+ $arg =~ /^-dbimport$/ and $dbimport = 1 and next;
+ $arg =~ /^-help$/ and $help = 1 and next; #show help
+
+ if ( !$has_infile )
+ {
+ $infile = $arg;
+ $has_infile = 1;
+ }
+ else
+ {
+ $outfile = $arg;
+ }
+ }
+}
diff --git a/l10ntools/scripts/localize.pl b/l10ntools/scripts/localize.pl
new file mode 100644
index 000000000000..323f7fe549b6
--- /dev/null
+++ b/l10ntools/scripts/localize.pl
@@ -0,0 +1,1078 @@
+:
+eval 'exec perl -wS $0 ${1+"$@"}'
+ if 0;
+
+
+#*************************************************************************
+#
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# Copyright 2000, 2010 Oracle and/or its affiliates.
+#
+# OpenOffice.org - a multi-platform office productivity suite
+#
+# This file is part of OpenOffice.org.
+#
+# OpenOffice.org is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Lesser General Public License version 3
+# only, as published by the Free Software Foundation.
+#
+# OpenOffice.org is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Lesser General Public License version 3 for more details
+# (a copy is included in the LICENSE file that accompanied this code).
+#
+# You should have received a copy of the GNU Lesser General Public License
+# version 3 along with OpenOffice.org. If not, see
+# <http://www.openoffice.org/license.html>
+# for a copy of the LGPLv3 License.
+#
+#*************************************************************************
+
+use strict;
+use Getopt::Long;
+use IO::Handle;
+use File::Find;
+use File::Temp;
+use File::Path;
+use File::Copy;
+use File::Glob qw(:glob csh_glob);
+use Cwd;
+
+my $CVS_BINARY = "/usr/bin/cvs";
+# ver 1.1
+#
+#### module lookup
+#use lib ("$ENV{SOLARENV}/bin/modules", "$ENV{COMMON_ENV_TOOLS}/modules");
+
+#### module lookup
+# OOo conform
+my @lib_dirs;
+BEGIN {
+ if ( !defined($ENV{SOLARENV}) ) {
+ die "No environment found (environment variable SOLARENV is undefined)";
+ }
+ push(@lib_dirs, "$ENV{SOLARENV}/bin/modules");
+ push(@lib_dirs, "$ENV{COMMON_ENV_TOOLS}/modules") if defined($ENV{COMMON_ENV_TOOLS});
+}
+use lib (@lib_dirs);
+
+#### globals ####
+my $sdffile = '';
+my $no_sort = '';
+my $create_dirs = '';
+my $multi_localize_files = '';
+my $module_to_merge = '';
+my $sort_sdf_before = '';
+my $outputfile = '';
+my $no_gsicheck = '';
+my $mode = '';
+my $bVerbose = "0";
+my $srcpath = '';
+my $languages;
+#my %sl_modules; # Contains all modules where en-US and de is source language
+my $use_default_date = '0';
+my $force_ooo_module = '0';
+my %is_ooo_module;
+my %is_so_module;
+
+ # ( leftpart ) ( rightpart )
+ # prj file dummy type gid lid helpid pform width lang text helptext qhelptext title timestamp
+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]*))";
+my $file_types = "(src|hrc|xcs|xcu|lng|ulf|xrm|xhp|xcd|xgf|xxl|xrb)";
+# Always use this date to prevent cvs conflicts
+my $default_date = "2002-02-02 02:02:02";
+my @sdfparticles;
+
+#### main ####
+parse_options();
+
+my $binpath = '';
+if( defined $ENV{UPDMINOREXT} )
+{
+ $binpath = $ENV{SOLARVER}."/".$ENV{INPATH}."/bin".$ENV{UPDMINOREXT}."/" ;
+}
+else
+{
+ $binpath = $ENV{SOLARVER}."/".$ENV{INPATH}."/bin/" ;
+}
+
+#%sl_modules = fetch_sourcelanguage_dirlist();
+
+
+if ( $mode eq "merge" ) {
+ if ( ! $no_gsicheck ){
+ merge_gsicheck();
+ }
+ splitfile( $sdffile );
+ if ( ! $no_gsicheck ){
+ unlink $sdffile; # remove temp file!
+ }
+}
+elsif( $mode eq "extract" ) {
+ collectfiles( $outputfile );
+}
+else {
+ usage();
+}
+
+exit(0);
+
+#########################################################
+sub splitfile{
+
+ my $lastFile = '';
+ my $currentFile = '';
+ my $cur_sdffile = '';
+ my $last_sdffile = '';
+ my $delim;
+ my $badDelim;
+ my $start = 'TRUE';
+ my %index = ();
+ my %block;
+
+ STDOUT->autoflush( 1 );
+
+ #print STDOUT "Open File $sdffile\n";
+ open MYFILE , "< $sdffile"
+ or die "Can't open '$sdffile'\n";
+
+# my %lang_hash;
+ my %string_hash_ooo;
+ my %string_hash_so;
+ my %so_modules;
+ $so_modules{ "extras_full" } = "TRUE";
+
+ 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 $plattform = defined $10 ? $10 : '';
+ my $helpid = defined $9 ? $9 : '';
+ next if( $prj eq "binfilter" ); # Don't merge strings into binfilter module
+ chomp( $line );
+
+ if( $force_ooo_module )
+ {
+ $string_hash_ooo { $lang }{ "$prj\t$file\t$type\t$gid\t$lid\t$helpid\t$plattform\t$lang" } = $line;
+ }
+ else
+ {
+ $string_hash_so{ $lang }{ "$prj\t$file\t$type\t$gid\t$lid\t$helpid\t$plattform\t$lang" } = $line;
+ }
+ }
+ }
+ close( MYFILE );
+
+ if( !defined $ENV{SOURCE_ROOT_DIR} ){
+ print "Error, no SOURCE_ROOT_DIR in env found.\n";
+ exit( -1 );
+ }
+ my $src_root = $ENV{SOURCE_ROOT_DIR};
+ my $ooo_src_root = $ENV{SRC_ROOT};
+ my $so_l10n_path = $src_root."/sun/l10n_so/source";
+ my $ooo_l10n_path = $ooo_src_root."/l10n/source";
+
+ #print "$so_l10n_path\n";
+ #print "$ooo_l10n_path\n";
+
+ if( $force_ooo_module )
+ {
+ write_sdf( \%string_hash_ooo , $ooo_l10n_path );
+ }
+ else
+ {
+ write_sdf( \%string_hash_so , $so_l10n_path );
+ }
+}
+
+sub write_sdf
+{
+ my $string_hash = shift;
+ my $l10n_file = shift;
+
+ foreach my $lang( keys( %{ $string_hash } ) )
+ {
+ my @sdf_file;
+ next , if( $lang eq "en-US" );
+
+ mkdir $l10n_file."/$lang";
+ # mkdir!!!!
+ my $current_l10n_file = $l10n_file."/$lang/localize.sdf";
+ print "Writing '$current_l10n_file'\n";
+ if( open DESTFILE , "< $current_l10n_file" ){
+
+ while(<DESTFILE>){
+ 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 $plattform = defined $10 ? $10 : '';
+ my $helpid = defined $9 ? $9 : '';
+
+ chomp( $line );
+ if ( defined $string_hash->{ $lang }{ "$prj\t$file\t$type\t$gid\t$lid\t$helpid\t$plattform\t$lang" } )
+ {
+ # Changed String!
+ push @sdf_file , $string_hash->{ $lang }{ "$prj\t$file\t$type\t$gid\t$lid\t$helpid\t$plattform\t$lang" } ;
+ $string_hash->{ $lang }{ "$prj\t$file\t$type\t$gid\t$lid\t$helpid\t$plattform\t$lang" } = undef;
+ }
+ else
+ {
+ # No new string
+ push @sdf_file , $line;
+ }
+ }
+ }
+ }
+ close( DESTFILE );
+ #Now just append the enw strings
+ #FIXME!!! Implement insertion in the correct order
+ foreach my $key ( keys ( %{ $string_hash->{ $lang } } ) )
+ {
+ push @sdf_file , $string_hash->{ $lang }{ $key } , if ( defined $string_hash->{ $lang }{ $key } );
+ #print "WARNING: Not defined = ".$string_hash->{ $lang }{ $key }."\n", if( ! defined $string_hash->{ $lang }{ $key } );
+ }
+
+ # Write the new file
+ my ( $TMPFILE , $tmpfile ) = File::Temp::tempfile();
+ if( open DESTFILE , "+> $tmpfile " ){
+ print DESTFILE get_license_header();
+ foreach my $string( @sdf_file ){
+ print DESTFILE "$string\n";
+ }
+ close ( DESTFILE );
+ if( move( $current_l10n_file , $current_l10n_file.".backup" ) ){
+ if( copy( $tmpfile , $current_l10n_file ) ){
+ unlink $l10n_file.".backup";
+ } else { print STDERR "Can't open/create '$l10n_file', original file is renamed to $l10n_file.backup\n"; }
+ } else { print STDERR "Can't open/create '$l10n_file'\n"; }
+ }else{
+ print STDERR "WARNING: Can't open/create '$l10n_file'\n";
+ }
+ unlink $tmpfile;
+ }
+}
+
+#########################################################
+
+sub get_license_header{
+ return
+"#\n".
+"# #### ### # # ### ##### ##### #### ##### ##### \n".
+"# # # # # ## # # # # # # # # # \n".
+"# # # # # # # # # # # ### # # # # \n".
+"# # # # # # ## # # # # # # # # \n".
+"# #### ### # # ### # ##### #### ##### # \n".
+"#\n".
+"# DO NOT EDIT! This file will be overwritten by localisation process\n".
+"#\n".
+"#*************************************************************************\n".
+"#\n".
+"# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.\n".
+"# \n".
+"# Copyright 2000, 2010 Oracle and/or its affiliates.\n".
+"#\n".
+"# OpenOffice.org - a multi-platform office productivity suite\n".
+"#\n".
+"# This file is part of OpenOffice.org.\n".
+"#\n".
+"# OpenOffice.org is free software: you can redistribute it and/or modify\n".
+"# it under the terms of the GNU Lesser General Public License version 3\n".
+"# only, as published by the Free Software Foundation.\n".
+"#\n".
+"# OpenOffice.org is distributed in the hope that it will be useful,\n".
+"# but WITHOUT ANY WARRANTY; without even the implied warranty of\n".
+"# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n".
+"# GNU Lesser General Public License version 3 for more details\n".
+"# (a copy is included in the LICENSE file that accompanied this code).\n".
+"#\n".
+"# You should have received a copy of the GNU Lesser General Public License\n".
+"# version 3 along with OpenOffice.org. If not, see\n".
+"# <http://www.openoffice.org/license.html>\n".
+"# for a copy of the LGPLv3 License.\n".
+"#\n".
+"#*************************************************************************\n";
+}
+######## Check input sdf file and use only the correct part
+sub merge_gsicheck{
+ my $command = '';
+ my ( $TMPHANDLE , $tmpfile ) = File::Temp::tempfile();
+ close ( $TMPHANDLE );
+
+ $command = "$ENV{WRAPCMD} " if( $ENV{WRAPCMD} );
+ $command .= "$ENV{SOLARVER}/$ENV{INPATH}/bin/gsicheck";
+
+ my $errfile = $sdffile.".err";
+ $command .= " -k -c -wcf $tmpfile -wef $errfile -l \"\" $sdffile";
+ #my $rc = system( $command );
+ my $output = `$command`;
+ my $rc = $? << 8;
+ if ( $output ne "" ){
+ print STDOUT "### gsicheck ###\n";
+ print STDOUT "### The file $errfile have been written containing the errors in your sdf file. Those lines will not be merged: ###\n\n";
+ print STDOUT "$output\n";
+ print STDOUT "################\n";
+
+ }else{
+ # Remove the 0 Byte file
+ unlink $errfile;
+ }
+ $sdffile = $tmpfile;
+}
+#########################################################
+# find search function
+sub wanted
+{
+ my $file = $File::Find::name;
+ if( -f $file && $file =~ /.*localize.sdf$/ && !( $file =~ /.*\.svn.*/ ) ) {
+ push @sdfparticles , $file;
+ if( $bVerbose eq "1" ) { print STDOUT "$file\n"; }
+ else { print "."; }
+ }
+}
+
+sub add_paths
+{
+ my $langhash_ref = shift;
+ my $root_dir = $ENV{ SRC_ROOT };
+ my $ooo_l10n_dir = "$root_dir/l10n/source";
+ my $so_l10n_dir = "$root_dir/l10n_so/source";
+
+ if( -e $ooo_l10n_dir )
+ {
+ foreach my $lang ( keys( %{ $langhash_ref } ) )
+ {
+ my $loc_file = "$ooo_l10n_dir/$lang/localize.sdf";
+ if( -e $loc_file )
+ {
+ push @sdfparticles , "$ooo_l10n_dir/$lang/localize.sdf";
+ }
+ else { print "WARNING: $loc_file not found ....\n"; }
+ }
+ }
+ else { die "ERROR: Can not find directory $ooo_l10n_dir!!!" }
+ if( -e $so_l10n_dir )
+ {
+ foreach my $lang ( keys( %{ $langhash_ref } ) )
+ {
+ my $loc_file = "$so_l10n_dir/$lang/localize.sdf";
+ if( -e $loc_file )
+ {
+ push @sdfparticles , "$ooo_l10n_dir/$lang/localize.sdf";
+ }
+ else { #print "WARNING: $loc_file not found ....\n";
+ }
+ }
+
+ }
+}
+sub collectfiles{
+ print STDOUT "### Localize\n";
+ my $localizehash_ref;
+ my ( $bAll , $bUseLocalize, $langhash_ref , $bHasSourceLanguage , $bFakeEnglish ) = parseLanguages();
+
+ # Enable autoflush on STDOUT
+ # $| = 1;
+ STDOUT->autoflush( 1 );
+
+ my $working_path = getcwd();
+ chdir $ENV{SOURCE_ROOT_DIR}, if defined $ENV{SOURCE_ROOT_DIR};
+ add_paths( $langhash_ref );
+
+ 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 en-US extract
+ if( $bAll || $bUseLocalize ){
+ print "### Fetching source language strings\n";
+ my $command = "";
+ my $args = "";
+
+ if( $ENV{WRAPCMD} ){
+ $command = $ENV{WRAPCMD}.$binpath."localize_sl";
+ }else{
+ $command = $binpath."localize_sl";
+ }
+ print $command;
+ # -e
+ # if ( -x $command ){
+ if( $command ){
+ if( !$bVerbose ){ $args .= " "; }
+ $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=~ /^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 );
+
+ 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 %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 $plattform = 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.$plattform.$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 $plattform = 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.$plattform.$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.$plattform.$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.$plattform.$helpid;
+ if( !$bFakeEnglish ){ push @{ $output{ $prj.$gid.$lid.$file.$type.$plattform.$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 $plattform = 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.$plattform.$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;
+ chdir $working_path;
+
+ #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 "";
+ }
+
+#########################################################
+sub remove_obsolete{
+ my $outfile = shift;
+ my @lines;
+ my $enusleftpart;
+ my @good_lines;
+
+ print STDOUT "### Removing obsolete strings\n";
+
+ # Kick out all strings without en-US reference
+ if ( open ( SORTEDFILE , "< $outfile" ) ){
+ while( <SORTEDFILE> ){
+ if( /$sdf_regex/ ){
+ my $line = defined $_ ? $_ : '';
+ my $language = defined $12 ? $12 : '';
+ 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 $plattform = defined $10 ? $10 : '';
+ my $helpid = defined $9 ? $9 : '';
+
+ my $leftpart = $prj.$gid.$lid.$file.$type.$plattform.$helpid;
+
+ if( $language eq "en-US" ){ # source string found, 1. entry
+ $enusleftpart = $leftpart;
+ push @good_lines , $line;
+ }else{
+ if( !defined $enusleftpart or !defined $leftpart ){
+ print STDERR "BADLINE: $line\n";
+ print STDERR "\$enusleftpart = $enusleftpart\n";
+ print STDERR "\$leftpart = $leftpart\n";
+ }
+ if( $enusleftpart eq $leftpart ){ # matching language
+ push @good_lines , $line;
+ }
+ #else{
+ # print STDERR "OUT: \$enusleftpart=$enusleftpart \$leftpart=$leftpart \$line=$line\n";
+ #}
+ }
+ }
+ }
+ close SORTEDFILE;
+ } else { print STDERR "ERROR: Can't open file $outfile\n";}
+
+ # Write file
+ if ( open ( SORTEDFILE , "> $outfile" ) ){
+ foreach my $newline ( @good_lines ) {
+ print SORTEDFILE $newline;
+ }
+ close SORTEDFILE;
+ } else { print STDERR "ERROR: Can't open file $outfile\n";}
+
+}
+#########################################################
+sub sort_outfile{
+ my $outfile = shift;
+ print STDOUT "### Sorting ... $outfile ...";
+ my @lines;
+ my @sorted_lines;
+
+
+ #if ( open ( SORTEDFILE , "< $outputfile" ) ){
+ if ( open ( SORTEDFILE , "< $outfile" ) ){
+ my $line;
+ while ( <SORTEDFILE> ){
+ $line = $_;
+ if( $line =~ /^[^\#]/ ){
+ push @lines , $line;
+ }
+ }
+ close SORTEDFILE;
+ @sorted_lines = sort {
+ my $xa_lang = "";
+ my $xa_left_part = "";
+ my $xa_right_part = "";
+ my $xa_timestamp = "";
+ my $xb_lang = "";
+ my $xb_left_part = "";
+ my $xb_right_part = "";
+ my $xb_timestamp = "";
+ my $xa = "";
+ my $xb = "";
+ my @alist;
+ my @blist;
+
+ if( $a=~ /$sdf_regex/ ){
+ $xa_left_part = defined $2 ? $2 : '';
+ $xa_lang = defined $12 ? $12 : '';
+ $xa_right_part = defined $13 ? $13 : '';
+ $xa_left_part = remove_last_column( $xa_left_part );
+
+ }
+ if( $b=~ /$sdf_regex/ ){
+ $xb_left_part = defined $2 ? $2 : '';
+ $xb_lang = defined $12 ? $12 : '';
+ $xb_right_part = defined $13 ? $13 : '';
+ $xb_left_part = remove_last_column( $xb_left_part );
+
+
+ }
+ if( ( $xa_left_part cmp $xb_left_part ) == 0 ){ # Left part equal
+ if( ( $xa_lang cmp $xb_lang ) == 0 ){ # Lang equal
+ return ( $xa_right_part cmp $xb_right_part ); # Right part compare
+ }
+ elsif( $xa_lang eq "en-US" ) { return -1; } # en-US wins
+ elsif( $xb_lang eq "en-US" ) { return 1; } # en-US wins
+ else { return $xa_lang cmp $xb_lang; } # lang compare
+ }
+ else {
+ return $xa_left_part cmp $xb_left_part; # Left part compare
+ }
+ } @lines;
+
+ if ( open ( SORTEDFILE , "> $outfile" ) ){
+ print SORTEDFILE get_license_header();
+ foreach my $newline ( @sorted_lines ) {
+ print SORTEDFILE $newline;
+ #print STDOUT $newline;
+ }
+ }
+ close SORTEDFILE;
+ } else { print STDERR "WARNING: Can't open file $outfile\n";}
+ print "done\n";
+
+}
+#########################################################
+sub remove_last_column{
+ my $string = shift;
+ my @alist = split ( "\t" , $string );
+ pop @alist;
+ return join( "\t" , @alist );
+}
+
+#########################################################
+sub rename_language{
+ my $fallbackhashhash_ref = shift;
+ my $cur_fallback = shift;
+ my $cur_lang = shift;
+ my $line;
+
+ foreach my $key( keys ( %{ $fallbackhashhash_ref->{ $cur_fallback } } ) ){
+ $line = $fallbackhashhash_ref->{ $cur_fallback }{ $key };
+ if( $line =~ /$sdf_regex/ ){
+ my $leftpart = defined $2 ? $2 : '';
+ my $lang = defined $12 ? $12 : '';
+ my $rightpart = defined $13 ? $13 : '';
+
+ $fallbackhashhash_ref->{ $cur_lang }{ $key } = $leftpart."\t".$cur_lang."\t".$rightpart;
+ }
+ }
+}
+
+############################################################
+sub remove_duplicates{
+ my $list_ref = shift;
+ my %tmphash;
+ foreach my $key ( @{ $list_ref } ){ $tmphash{ $key } = '' ; }
+ @{$list_ref} = keys( %tmphash );
+}
+
+##############################################################
+sub fetch_fallback{
+ my $sdfparticleslist_ref = shift;
+ my $localizeSDF = shift;
+ my $langhash_ref = shift;
+ my %fallbackhashhash;
+ my $cur_lang;
+ my @langlist;
+
+ foreach my $key ( keys ( %{ $langhash_ref } ) ){
+ $cur_lang = $langhash_ref->{ $key };
+ if ( $cur_lang ne "" ) {
+ push @langlist , $cur_lang;
+ }
+ }
+ remove_duplicates( \@langlist );
+ foreach $cur_lang ( @langlist ){
+ if( $cur_lang eq "en-US" ){
+ read_fallbacks_from_source( $localizeSDF , $cur_lang , \%fallbackhashhash );
+ }
+ }
+
+ # remove de / en-US
+ my @tmplist;
+ foreach $cur_lang( @langlist ){
+ if( $cur_lang ne "en-US" ){
+ push @tmplist , $cur_lang;
+
+ }
+ }
+ @langlist = @tmplist;
+ if ( $#langlist +1 ){
+ read_fallbacks_from_particles( $sdfparticleslist_ref , \@langlist , \%fallbackhashhash );
+
+ }
+ return (\%fallbackhashhash);
+}
+
+#########################################################
+sub write_file{
+
+ my $localizeFile = shift;
+ my $index_ref = shift;
+
+ if( open DESTFILE , "+> $localizeFile" ){
+ foreach my $key( %{ $index_ref } ){
+ print DESTFILE ($index_ref->{ $key }, "\n" );
+ }
+ close DESTFILE;
+ }else {
+ print STDERR "Can't open/create '$localizeFile'";
+ }
+}
+
+#########################################################
+sub read_file{
+
+ my $sdffile = shift;
+ my $langhash_ref = shift;
+ my %block = ();
+
+ open MYFILE , "< $sdffile"
+ or die "Can't open '$sdffile'\n";
+ 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 $plattform = defined $10 ? $10 : '';
+ my $lang = defined $12 ? $12 : '';
+ my $helpid = defined $9 ? $9 : '';
+
+ foreach my $isolang ( keys ( %{ $langhash_ref } ) ){
+ if( $isolang=~ /$lang/i || $isolang=~ /all/i ) { $block{$prj.$gid.$lid.$file.$type.$plattform.$helpid } = $line ; }
+ }
+ }
+ }
+ return (\%block);
+}
+
+#########################################################
+sub read_fallbacks_from_particles{
+
+ my $sdfparticleslist_ref = shift;
+ my $isolanglist_ref = shift;
+ my $fallbackhashhash_ref = shift;
+ my $block_ref;
+ foreach my $currentfile ( @{ $sdfparticleslist_ref } ){
+ 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 $plattform = defined $10 ? $10 : '';
+ my $helpid = defined $9 ? $9 : '';
+
+ chomp( $line );
+
+ foreach my $isolang ( @{$isolanglist_ref} ){
+ if( $isolang=~ /$lang/i ) {
+ $fallbackhashhash_ref->{ $isolang }{ $prj.$gid.$lid.$file.$type.$plattform.$helpid } = $line ;
+ }
+ }
+ }
+ }
+ }else { print STDERR "WARNING: Can't open file $currentfile"; }
+ }
+}
+
+#########################################################
+sub read_fallbacks_from_source{
+
+ my $sdffile = shift;
+ my $isolang = shift;
+ my $fallbackhashhash_ref = shift;
+ my $block_ref;
+ # read fallback for single file
+ open MYFILE , "< $sdffile"
+ or die "Can't open '$sdffile'\n";
+
+ 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 $helpid = defined $9 ? $9 : '';
+ my $lang = defined $12 ? $12 : '';
+ my $plattform = defined $10 ? $10 : '';
+
+ chomp( $line );
+ if( $isolang=~ /$lang/i ) { $fallbackhashhash_ref->{ $isolang }{ $prj.$gid.$lid.$file.$type.$plattform.$helpid } = $line ;
+ }
+ }
+ }
+}
+
+#########################################################
+sub parseLanguages{
+
+ my $bAll;
+ my $bUseLocalize;
+ my $bHasSourceLanguage="";
+ my $bFakeEnglish="";
+ my %langhash;
+ my $iso="";
+ my $fallback="";
+
+ #### -l all
+ if( $languages=~ /all/ ){
+ $bAll = "TRUE";
+ $bHasSourceLanguage = "TRUE";
+ }
+ ### -l fr=de,de
+ elsif( $languages=~ /.*,.*/ ){
+ my @tmpstr = split "," , $languages;
+ for my $lang ( @tmpstr ){
+ if( $lang=~ /([a-zA-Z]{2,3}(-[a-zA-Z\-]*)*)(=([a-zA-Z]{2,3}(-[a-zA-Z\-]*)*))?/ ){
+ $iso = $1;
+ $fallback = $4;
+
+ if( ( $iso && $iso=~ /(en-US)/i ) || ( $fallback && $fallback=~ /(en-US)/i ) ) {
+ $bUseLocalize = "TRUE";
+ }
+ if( ( $iso && $iso=~ /(en-US)/i ) ) {
+ $bHasSourceLanguage = "TRUE";
+ }
+ if( $fallback ) { $langhash{ $iso } = $fallback; }
+ else { $langhash{ $iso } = ""; }
+ }
+ }
+ }
+ ### -l de
+ else{
+ if( $languages=~ /([a-zA-Z]{2,3}(-[a-zA-Z\-]*)*)(=([a-zA-Z]{2,3}(-[a-zA-Z\-]*)*))?/ ){
+ $iso = $1;
+ $fallback = $4;
+
+ if( ( $iso && $iso=~ /(en-US)/i ) || ( $fallback && $fallback=~ /(en-US)/i ) ) {
+ $bUseLocalize = "TRUE";
+
+ }
+ if( ( $iso && $iso=~ /(en-US)/i ) ) {
+ $bHasSourceLanguage = "TRUE";
+ }
+
+ if( $fallback ) { $langhash{ $iso } = $fallback; }
+ else { $langhash{ $iso } = ""; }
+ }
+ }
+ # HACK en-US always needed!
+ if( !$bHasSourceLanguage ){
+ #$bHasSourceLanguage = "TRUE";
+ $bUseLocalize = "TRUE";
+ $bFakeEnglish = "TRUE";
+ $langhash{ "en-US" } = "";
+ }
+ return ( $bAll , $bUseLocalize , \%langhash , $bHasSourceLanguage, $bFakeEnglish);
+}
+
+#########################################################
+sub parse_options{
+
+ my $help;
+ my $merge;
+ my $extract;
+ my $success = GetOptions('f=s' => \$sdffile , 'l=s' => \$languages , 's=s' => \$srcpath , 'h' => \$help , 'v' => \$bVerbose ,
+ 'm' => \$merge , 'e' => \$extract , 'x' => \$no_sort , 'd' => \$use_default_date , 'c' => \$create_dirs ,
+ 'n' => \$no_gsicheck , 'o' => \$force_ooo_module );
+ $outputfile = $sdffile;
+
+ #print STDOUT "DBG: lang = $languages\n";
+ if( !$srcpath ){
+ $srcpath = "$ENV{SRC_ROOT}";
+ if( !$srcpath ){
+ print STDERR "No path to the source root found!\n\n";
+ usage();
+ exit(1);
+ }
+ }
+ if( $help ){
+ usage();
+ exit(0);
+ }
+ if( !$success || $#ARGV > 1 || ( !$sdffile ) ){
+ usage();
+ exit(1);
+ }
+ if( $merge && $sdffile && ! ( -r $sdffile)){
+ print STDERR "Can't open file '$sdffile'\n";
+ exit(1);
+ }
+ 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\-]*)*)?)*/ ) ){
+ print STDERR "Please check the -l iso code\n";
+ exit(1);
+ }
+ if( ( !$merge && !$extract ) || ( $merge && $extract ) ){ usage();exit( -1 );}
+ if( $extract ){ $mode = "extract"; }
+ else { $mode = "merge"; }
+}
+#my $multi_localize_files = ''; h
+#my $module_to_merge = ''; i
+#my $sort_sdf_before = ''; g
+
+#########################################################
+sub usage{
+
+ print STDERR "Usage: localize.pl\n";
+ print STDERR "Split or collect SDF files\n";
+ print STDERR " merge: -m -f <sdffile> -l l1[=f1][,l2[=f2]][...] [ -s <sourceroot> ] [ -c ]\n";
+ print STDERR " extract: -e -f <outputfile> -l <lang> [ -s <sourceroot> ] [-d]\n";
+ print STDERR "Options:\n";
+ print STDERR " -h help\n";
+ print STDERR " -m Merge mode\n";
+ print STDERR " -e Extract mode\n";
+ print STDERR " -f <sdffile> To split a big SDF file into particles\n";
+ print STDERR " <outputfile> To collect and join all particles to one big file\n";
+ print STDERR " -s <sourceroot> Path to the modules, if no \$SRC_ROOT is set\n";
+ print STDERR " -l ( all | <isocode> | <isocode>=fallback ) comma seperated languages\n";
+ print STDERR " -d Use default date in extracted sdf file\n";
+ print STDERR " -c Create needed directories\n";
+ print STDERR " -g Sort sdf file before mergeing\n";
+ print STDERR " -h File with localize.sdf's\n!";
+ print STDERR " -n No gsicheck\n";
+ print STDERR " -i Module to merge\n";
+ print STDERR " -o force using ooo localization from the l10n module instead of l10n_so; \n";
+ print STDERR " useful if the type can't be detected by the .svn tags; \n";
+ print STDERR " -v Verbose\n";
+ print STDERR "\nExample:\n";
+ 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";
+ print STDERR "\nlocalize -m -l cs -f my.sdf\n( Merge cs translation into the sourcecode ) \n";
+}
+
diff --git a/l10ntools/scripts/localize_old.pl b/l10ntools/scripts/localize_old.pl
new file mode 100755
index 000000000000..d6b66d6bb535
--- /dev/null
+++ b/l10ntools/scripts/localize_old.pl
@@ -0,0 +1,1070 @@
+:
+eval 'exec perl -wS $0 ${1+"$@"}'
+ if 0;
+
+
+#*************************************************************************
+#
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# Copyright 2000, 2010 Oracle and/or its affiliates.
+#
+# OpenOffice.org - a multi-platform office productivity suite
+#
+# This file is part of OpenOffice.org.
+#
+# OpenOffice.org is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Lesser General Public License version 3
+# only, as published by the Free Software Foundation.
+#
+# OpenOffice.org is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Lesser General Public License version 3 for more details
+# (a copy is included in the LICENSE file that accompanied this code).
+#
+# You should have received a copy of the GNU Lesser General Public License
+# version 3 along with OpenOffice.org. If not, see
+# <http://www.openoffice.org/license.html>
+# for a copy of the LGPLv3 License.
+#
+#*************************************************************************
+
+use strict;
+use Getopt::Long;
+use IO::Handle;
+use File::Find;
+use File::Temp;
+use File::Copy;
+use File::Glob qw(:glob csh_glob);
+use Cwd;
+
+# ver 1.1
+#
+#### module lookup
+#use lib ("$ENV{SOLARENV}/bin/modules", "$ENV{COMMON_ENV_TOOLS}/modules");
+
+#### module lookup
+# OOo conform
+my @lib_dirs;
+BEGIN {
+ if ( !defined($ENV{SOLARENV}) ) {
+ die "No environment found (environment variable SOLARENV is undefined)";
+ }
+ push(@lib_dirs, "$ENV{SOLARENV}/bin/modules");
+ push(@lib_dirs, "$ENV{COMMON_ENV_TOOLS}/modules") if defined($ENV{COMMON_ENV_TOOLS});
+}
+use lib (@lib_dirs);
+
+#### globals ####
+my $sdffile = '';
+my $no_sort = '';
+my $outputfile = '';
+my $mode = '';
+my $bVerbose="0";
+my $srcpath = '';
+my $languages;
+#my %sl_modules; # Contains all modules where en-US and de is source language
+my $use_default_date = '0';
+
+ # ( leftpart ) ( rightpart )
+ # prj file dummy type gid lid helpid pform width lang text helptext qhelptext title timestamp
+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]*))";
+my $file_types = "(src|hrc|xcs|xcu|lng|ulf|xrm|xhp|xcd|xgf|xxl|xrb)";
+# Always use this date to prevent cvs conflicts
+my $default_date = "2002-02-02 02:02:02";
+
+#### main ####
+parse_options();
+
+#%sl_modules = fetch_sourcelanguage_dirlist();
+
+
+if ( $mode eq "merge" ) {
+ merge_gsicheck();
+ splitfile( $sdffile );
+ unlink $sdffile; # remove temp file!
+}
+elsif( $mode eq "extract" ) {
+ collectfiles( $outputfile );
+}
+else {
+ usage();
+}
+
+exit(0);
+
+#########################################################
+sub splitfile{
+
+ my $lastFile = '';
+ my $currentFile = '';
+ my $cur_sdffile = '';
+ my $last_sdffile = '';
+ my $delim;
+ my $badDelim;
+ my $start = 'TRUE';
+ my %index = ();
+ my %block;
+
+ STDOUT->autoflush( 1 );
+
+ #print STDOUT "Open File $sdffile\n";
+ open MYFILE , "< $sdffile"
+ or die "Can't open '$sdffile'\n";
+
+ 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 $plattform = defined $10 ? $10 : '';
+ my $helpid = defined $9 ? $9 : '';
+
+ next if( $prj eq "binfilter" ); # Don't merge strings into binfilter module
+ chomp( $line );
+ $currentFile = $srcpath . '\\' . $prj . '\\' . $file;
+ $currentFile =~ s/\\/\//g;
+
+ $cur_sdffile = $currentFile;
+ #if( $cur_sdffile =~ /\.$file_types[\s]*$/ ){
+ $cur_sdffile =~ s/\/[^\/]*\.$file_types[\s]*$/\/localize.sdf/;
+ #}
+
+ # Set default date
+ if( $line =~ /(.*)\t[^\t\$]*$/ ){
+ $line = $1."\t".$default_date;
+ }
+
+ if( $start ){
+ $start='';
+ $lastFile = $currentFile; # ?
+ $last_sdffile = $cur_sdffile;
+ }
+
+ if( $lang eq "en-US" ){}
+ elsif( $cur_sdffile eq $last_sdffile )
+ {
+ $block{ "$prj\t$file\t$type\t$gid\t$lid\t$helpid\t$plattform\t$lang" } = $line ;
+ }
+ else
+ {
+ writesdf( $lastFile , \%block );
+ $lastFile = $currentFile; #?
+ $last_sdffile = $cur_sdffile;
+ %block = ();
+ #if( ! $lang eq "en-US" ) {
+ $block{ "$prj\t$file\t$type\t$gid\t$lid\t$helpid\t$plattform\t$lang" } = $line ;
+ #}
+
+ }
+ } #else { print STDOUT "splitfile REGEX kaputt\n";}
+
+ }
+ writesdf( $lastFile , \%block );
+ %block = ();
+ close( MYFILE );
+
+}
+#########################################################
+
+sub writesdf{
+
+ my $lastFile = shift;
+ my $blockhash_ref = shift;
+ my $localizeFile = $lastFile;
+ my %index=();
+
+ if( $localizeFile =~ /\.$file_types[\s]*$/ ){
+ $localizeFile =~ s/\/[^\/]*\.$file_types[\s]*$/\/localize.sdf/;
+ }else {
+ print STDERR "Strange filetype found '$localizeFile'\n";
+ return;
+ }
+ if( open DESTFILE , "< $localizeFile" ){
+
+ #or die "Can't open/create '\$localizeFile'";
+
+ #### Build hash
+ while(<DESTFILE>){
+ 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 $plattform = defined $10 ? $10 : '';
+ my $helpid = defined $9 ? $9 : '';
+
+ chomp( $line );
+ $index{ "$prj\t$file\t$type\t$gid\t$lid\t$helpid\t$plattform\t$lang" } = $line ;
+
+ } #else { print STDOUT "writesdf REGEX kaputt $_\n";}
+
+ }
+ close( DESTFILE );
+ }
+ #### Copy new strings
+ my @mykeys = keys( %{ $blockhash_ref } );
+ my $isDirty = "FALSE";
+ foreach my $key( @mykeys ){
+ if( ! defined $index{ $key } ){
+ # Add new entry
+ $index{ $key } = $blockhash_ref->{ $key} ;
+ $isDirty = "TRUE";
+ }elsif( $index{ $key } ne $blockhash_ref->{ $key } ){
+ # Overwrite old entry
+ $index{ $key } = $blockhash_ref->{ $key };
+ $isDirty = "TRUE";
+ }else {
+ }
+ }
+
+ #### Write file
+
+ if( !$bVerbose ){ print STDOUT "."; }
+ if( $isDirty eq "TRUE" ){
+ if( $bVerbose ){ print STDOUT "$localizeFile\n"; }
+ if( open DESTFILE , "+> $localizeFile" ){
+ print DESTFILE get_license_header();
+ @mykeys = sort keys( %index );
+ foreach my $key( @mykeys ){
+ print DESTFILE ( $index{ $key } , "\n" );
+ }
+ close DESTFILE;
+ }else {
+ print STDOUT "WARNING: File $localizeFile is not writable , try to merge ...\n";
+ my ( $TMPFILE , $tmpfile ) = File::Temp::tempfile();
+ if( open DESTFILE , "+> $tmpfile " ){
+ @mykeys = keys( %index );
+ foreach my $key( @mykeys ){
+ print DESTFILE ( $index{ $key } , "\n" );
+ }
+ close DESTFILE;
+ if( move( $localizeFile , $localizeFile.".backup" ) ){
+ if( copy( $tmpfile , $localizeFile ) ){
+ unlink $localizeFile.".backup";
+ } else { print STDERR "Can't open/create '$localizeFile', original file is renamed to $localizeFile.backup\n"; }
+ } else { print STDERR "Can't open/create '$localizeFile'\n"; }
+ }else{
+ print STDERR "WARNING: Can't open/create '$localizeFile'\n";
+ }
+ unlink $tmpfile;
+ }
+ }
+# if( $no_sort eq '' ){
+# sort_outfile( $localizeFile );
+# }
+}
+
+sub get_license_header{
+ return
+"#\n".
+"# #### ### # # ### ##### ##### #### ##### ##### \n".
+"# # # # # ## # # # # # # # # # \n".
+"# # # # # # # # # # # ### # # # # \n".
+"# # # # # # ## # # # # # # # # \n".
+"# #### ### # # ### # ##### #### ##### # \n".
+"#\n".
+"# DO NOT EDIT! This file will be overwritten by localisation process\n".
+"#\n".
+"#*************************************************************************\n".
+"#\n".
+"# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.\n".
+"# \n".
+"# Copyright 2000, 2010 Oracle and/or its affiliates.\n".
+"#\n".
+"# OpenOffice.org - a multi-platform office productivity suite\n".
+"#\n".
+"# This file is part of OpenOffice.org.\n".
+"#\n".
+"# OpenOffice.org is free software: you can redistribute it and/or modify\n".
+"# it under the terms of the GNU Lesser General Public License version 3\n".
+"# only, as published by the Free Software Foundation.\n".
+"#\n".
+"# OpenOffice.org is distributed in the hope that it will be useful,\n".
+"# but WITHOUT ANY WARRANTY; without even the implied warranty of\n".
+"# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n".
+"# GNU Lesser General Public License version 3 for more details\n".
+"# (a copy is included in the LICENSE file that accompanied this code).\n".
+"#\n".
+"# You should have received a copy of the GNU Lesser General Public License\n".
+"# version 3 along with OpenOffice.org. If not, see\n".
+"# <http://www.openoffice.org/license.html>\n".
+"# for a copy of the LGPLv3 License.\n".
+"#\n".
+"#*************************************************************************\n";
+}
+######## Check input sdf file and use only the correct part
+sub merge_gsicheck{
+ my $command = '';
+ my ( $TMPHANDLE , $tmpfile ) = File::Temp::tempfile();
+ my ( $TMPHANDLE2 , $tmpfile2 ) = File::Temp::tempfile();
+ close ( $TMPHANDLE );
+ close ( $TMPHANDLE2 );
+
+ unlink $tmpfile2;
+ my $output2 = `cat $sdffile | sort > $tmpfile2`;
+ my $rc2 = $? << 8;
+ if( $rc2 ne 0 ){
+ printf("ERROR: Failed -> cat $sdffile | sort > $tmpfile2\n$output2\n");
+ exit( -1 );
+ }
+
+# if( $ENV{WRAPCMD} ){
+# $command = "$ENV{WRAPCMD} gsicheck";
+# }else{
+# $command = "gsicheck";
+# }
+# my $errfile = $tmpfile.".err";
+# $command .= " -k -c -wcf $tmpfile -wef $errfile -l \"\" $tmpfile2";
+# my $output = `$command`;
+# my $rc = $? << 8;
+# if ( $output ne "" ){
+# print STDOUT "### gsicheck ###\n";
+# print STDOUT "### The file $errfile have been written containing the errors in your sdf file. Those lines will not be merged: ###\n\n";
+# print STDOUT "$output\n";
+# print STDOUT "################\n";
+#
+# }else{
+# # Remove the 0 Byte file
+# unlink $errfile;
+# }
+ $sdffile = $tmpfile2;
+# unlink $tmpfile2;
+}
+#########################################################
+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 $plattform = 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.$plattform.$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 $plattform = 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.$plattform.$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.$plattform.$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.$plattform.$helpid;
+ if( !$bFakeEnglish ){ push @{ $output{ $prj.$gid.$lid.$file.$type.$plattform.$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 $plattform = 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.$plattform.$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 "";
+ }
+
+#########################################################
+sub remove_obsolete{
+ my $outfile = shift;
+ my @lines;
+ my $enusleftpart;
+ my @good_lines;
+
+ print STDOUT "### Removing obsolete strings\n";
+
+ # Kick out all strings without en-US reference
+ if ( open ( SORTEDFILE , "< $outfile" ) ){
+ while( <SORTEDFILE> ){
+ if( /$sdf_regex/ ){
+ my $line = defined $_ ? $_ : '';
+ my $language = defined $12 ? $12 : '';
+ 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 $plattform = defined $10 ? $10 : '';
+ my $helpid = defined $9 ? $9 : '';
+
+ my $leftpart = $prj.$gid.$lid.$file.$type.$plattform.$helpid;
+
+ if( $language eq "en-US" ){ # source string found, 1. entry
+ $enusleftpart = $leftpart;
+ push @good_lines , $line;
+ }else{
+ if( !defined $enusleftpart or !defined $leftpart ){
+ print STDERR "BADLINE: $line\n";
+ print STDERR "\$enusleftpart = $enusleftpart\n";
+ print STDERR "\$leftpart = $leftpart\n";
+ }
+ if( $enusleftpart eq $leftpart ){ # matching language
+ push @good_lines , $line;
+ }
+ #else{
+ # print STDERR "OUT: \$enusleftpart=$enusleftpart \$leftpart=$leftpart \$line=$line\n";
+ #}
+ }
+ }
+ }
+ close SORTEDFILE;
+ } else { print STDERR "ERROR: Can't open file $outfile\n";}
+
+ # Write file
+ if ( open ( SORTEDFILE , "> $outfile" ) ){
+ foreach my $newline ( @good_lines ) {
+ print SORTEDFILE $newline;
+ }
+ close SORTEDFILE;
+ } else { print STDERR "ERROR: Can't open file $outfile\n";}
+
+}
+#########################################################
+sub sort_outfile{
+ my $outfile = shift;
+ print STDOUT "### Sorting ... $outfile ...";
+ my @lines;
+ my @sorted_lines;
+
+
+ #if ( open ( SORTEDFILE , "< $outputfile" ) ){
+ if ( open ( SORTEDFILE , "< $outfile" ) ){
+ my $line;
+ while ( <SORTEDFILE> ){
+ $line = $_;
+ if( $line =~ /^[^\#]/ ){
+ push @lines , $line;
+ }
+ }
+ close SORTEDFILE;
+ @sorted_lines = sort {
+ my $xa_lang = "";
+ my $xa_left_part = "";
+ my $xa_right_part = "";
+ my $xa_timestamp = "";
+ my $xb_lang = "";
+ my $xb_left_part = "";
+ my $xb_right_part = "";
+ my $xb_timestamp = "";
+ my $xa = "";
+ my $xb = "";
+ my @alist;
+ my @blist;
+
+ if( $a=~ /$sdf_regex/ ){
+ $xa_left_part = defined $2 ? $2 : '';
+ $xa_lang = defined $12 ? $12 : '';
+ $xa_right_part = defined $13 ? $13 : '';
+ $xa_left_part = remove_last_column( $xa_left_part );
+
+ }
+ if( $b=~ /$sdf_regex/ ){
+ $xb_left_part = defined $2 ? $2 : '';
+ $xb_lang = defined $12 ? $12 : '';
+ $xb_right_part = defined $13 ? $13 : '';
+ $xb_left_part = remove_last_column( $xb_left_part );
+
+
+ }
+ if( ( $xa_left_part cmp $xb_left_part ) == 0 ){ # Left part equal
+ if( ( $xa_lang cmp $xb_lang ) == 0 ){ # Lang equal
+ return ( $xa_right_part cmp $xb_right_part ); # Right part compare
+ }
+ elsif( $xa_lang eq "en-US" ) { return -1; } # en-US wins
+ elsif( $xb_lang eq "en-US" ) { return 1; } # en-US wins
+ else { return $xa_lang cmp $xb_lang; } # lang compare
+ }
+ else {
+ return $xa_left_part cmp $xb_left_part; # Left part compare
+ }
+ } @lines;
+
+ if ( open ( SORTEDFILE , "> $outfile" ) ){
+ print SORTEDFILE get_license_header();
+ foreach my $newline ( @sorted_lines ) {
+ print SORTEDFILE $newline;
+ #print STDOUT $newline;
+ }
+ }
+ close SORTEDFILE;
+ } else { print STDERR "WARNING: Can't open file $outfile\n";}
+ print "done\n";
+
+}
+#########################################################
+sub remove_last_column{
+ my $string = shift;
+ my @alist = split ( "\t" , $string );
+ pop @alist;
+ return join( "\t" , @alist );
+}
+
+#########################################################
+sub rename_language{
+ my $fallbackhashhash_ref = shift;
+ my $cur_fallback = shift;
+ my $cur_lang = shift;
+ my $line;
+
+ foreach my $key( keys ( %{ $fallbackhashhash_ref->{ $cur_fallback } } ) ){
+ $line = $fallbackhashhash_ref->{ $cur_fallback }{ $key };
+ if( $line =~ /$sdf_regex/ ){
+ my $leftpart = defined $2 ? $2 : '';
+ my $lang = defined $12 ? $12 : '';
+ my $rightpart = defined $13 ? $13 : '';
+
+ $fallbackhashhash_ref->{ $cur_lang }{ $key } = $leftpart."\t".$cur_lang."\t".$rightpart;
+ }
+ }
+}
+
+############################################################
+sub remove_duplicates{
+ my $list_ref = shift;
+ my %tmphash;
+ foreach my $key ( @{ $list_ref } ){ $tmphash{ $key } = '' ; }
+ @{$list_ref} = keys( %tmphash );
+}
+
+##############################################################
+sub fetch_fallback{
+ my $sdfparticleslist_ref = shift;
+ my $localizeSDF = shift;
+ my $langhash_ref = shift;
+ my %fallbackhashhash;
+ my $cur_lang;
+ my @langlist;
+
+ foreach my $key ( keys ( %{ $langhash_ref } ) ){
+ $cur_lang = $langhash_ref->{ $key };
+ if ( $cur_lang ne "" ) {
+ push @langlist , $cur_lang;
+ }
+ }
+ remove_duplicates( \@langlist );
+ foreach $cur_lang ( @langlist ){
+ if( $cur_lang eq "en-US" ){
+ read_fallbacks_from_source( $localizeSDF , $cur_lang , \%fallbackhashhash );
+ }
+ }
+
+ # remove de / en-US
+ my @tmplist;
+ foreach $cur_lang( @langlist ){
+ if( $cur_lang ne "en-US" ){
+ push @tmplist , $cur_lang;
+
+ }
+ }
+ @langlist = @tmplist;
+ if ( $#langlist +1 ){
+ read_fallbacks_from_particles( $sdfparticleslist_ref , \@langlist , \%fallbackhashhash );
+
+ }
+ return (\%fallbackhashhash);
+}
+
+#########################################################
+sub write_file{
+
+ my $localizeFile = shift;
+ my $index_ref = shift;
+
+ if( open DESTFILE , "+> $localizeFile" ){
+ foreach my $key( %{ $index_ref } ){
+ print DESTFILE ($index_ref->{ $key }, "\n" );
+ }
+ close DESTFILE;
+ }else {
+ print STDERR "Can't open/create '$localizeFile'";
+ }
+}
+
+#########################################################
+sub read_file{
+
+ my $sdffile = shift;
+ my $langhash_ref = shift;
+ my %block = ();
+
+ open MYFILE , "< $sdffile"
+ or die "Can't open '$sdffile'\n";
+ 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 $plattform = defined $10 ? $10 : '';
+ my $lang = defined $12 ? $12 : '';
+ my $helpid = defined $9 ? $9 : '';
+
+ foreach my $isolang ( keys ( %{ $langhash_ref } ) ){
+ if( $isolang=~ /$lang/i || $isolang=~ /all/i ) { $block{$prj.$gid.$lid.$file.$type.$plattform.$helpid } = $line ; }
+ }
+ }
+ }
+ return (\%block);
+}
+
+#########################################################
+sub read_fallbacks_from_particles{
+
+ my $sdfparticleslist_ref = shift;
+ my $isolanglist_ref = shift;
+ my $fallbackhashhash_ref = shift;
+ my $block_ref;
+ foreach my $currentfile ( @{ $sdfparticleslist_ref } ){
+ 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 $plattform = defined $10 ? $10 : '';
+ my $helpid = defined $9 ? $9 : '';
+
+ chomp( $line );
+
+ foreach my $isolang ( @{$isolanglist_ref} ){
+ if( $isolang=~ /$lang/i ) {
+ $fallbackhashhash_ref->{ $isolang }{ $prj.$gid.$lid.$file.$type.$plattform.$helpid } = $line ;
+ }
+ }
+ }
+ }
+ }else { print STDERR "WARNING: Can't open file $currentfile"; }
+ }
+}
+
+#########################################################
+sub read_fallbacks_from_source{
+
+ my $sdffile = shift;
+ my $isolang = shift;
+ my $fallbackhashhash_ref = shift;
+ my $block_ref;
+ # read fallback for single file
+ open MYFILE , "< $sdffile"
+ or die "Can't open '$sdffile'\n";
+
+ 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 $helpid = defined $9 ? $9 : '';
+ my $lang = defined $12 ? $12 : '';
+ my $plattform = defined $10 ? $10 : '';
+
+ chomp( $line );
+ if( $isolang=~ /$lang/i ) { $fallbackhashhash_ref->{ $isolang }{ $prj.$gid.$lid.$file.$type.$plattform.$helpid } = $line ;
+ }
+ }
+ }
+}
+
+#########################################################
+sub parseLanguages{
+
+ my $bAll;
+ my $bUseLocalize;
+ my $bHasSourceLanguage="";
+ my $bFakeEnglish="";
+ my %langhash;
+ my $iso="";
+ my $fallback="";
+
+ #### -l all
+ if( $languages=~ /all/ ){
+ $bAll = "TRUE";
+ $bHasSourceLanguage = "TRUE";
+ }
+ ### -l fr=de,de
+ elsif( $languages=~ /.*,.*/ ){
+ my @tmpstr = split "," , $languages;
+ for my $lang ( @tmpstr ){
+ if( $lang=~ /([a-zA-Z]{2,3}(-[a-zA-Z\-]*)*)(=([a-zA-Z]{2,3}(-[a-zA-Z\-]*)*))?/ ){
+ $iso = $1;
+ $fallback = $4;
+
+ if( ( $iso && $iso=~ /(en-US)/i ) || ( $fallback && $fallback=~ /(en-US)/i ) ) {
+ $bUseLocalize = "TRUE";
+ }
+ if( ( $iso && $iso=~ /(en-US)/i ) ) {
+ $bHasSourceLanguage = "TRUE";
+ }
+ if( $fallback ) { $langhash{ $iso } = $fallback; }
+ else { $langhash{ $iso } = ""; }
+ }
+ }
+ }
+ ### -l de
+ else{
+ if( $languages=~ /([a-zA-Z]{2,3}(-[a-zA-Z\-]*)*)(=([a-zA-Z]{2,3}(-[a-zA-Z\-]*)*))?/ ){
+ $iso = $1;
+ $fallback = $4;
+
+ if( ( $iso && $iso=~ /(en-US)/i ) || ( $fallback && $fallback=~ /(en-US)/i ) ) {
+ $bUseLocalize = "TRUE";
+
+ }
+ if( ( $iso && $iso=~ /(en-US)/i ) ) {
+ $bHasSourceLanguage = "TRUE";
+ }
+
+ if( $fallback ) { $langhash{ $iso } = $fallback; }
+ else { $langhash{ $iso } = ""; }
+ }
+ }
+ # HACK en-US always needed!
+ if( !$bHasSourceLanguage ){
+ #$bHasSourceLanguage = "TRUE";
+ $bUseLocalize = "TRUE";
+ $bFakeEnglish = "TRUE";
+ $langhash{ "en-US" } = "";
+ }
+ return ( $bAll , $bUseLocalize , \%langhash , $bHasSourceLanguage, $bFakeEnglish);
+}
+
+#########################################################
+sub parse_options{
+
+ my $help;
+ my $merge;
+ my $extract;
+ my $success = GetOptions('f=s' => \$sdffile , 'l=s' => \$languages , 's=s' => \$srcpath , 'h' => \$help , 'v' => \$bVerbose ,
+ 'm' => \$merge , 'e' => \$extract , 'x' => \$no_sort , 'd' => \$use_default_date );
+ $outputfile = $sdffile;
+
+ #print STDOUT "DBG: lang = $languages\n";
+ if( !$srcpath ){
+ #$srcpath = "$ENV{SRC_ROOT}";
+ if( !$srcpath ){
+ print STDERR "No path to the source root found!\n\n";
+ usage();
+ exit(1);
+ }
+ }
+ if( $help || !$success || $#ARGV > 1 || ( !$sdffile ) ){
+ usage();
+ exit(1);
+ }
+ if( $merge && $sdffile && ! ( -r $sdffile)){
+ print STDERR "Can't open file '$sdffile'\n";
+ exit(1);
+ }
+ 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\-]*)*)?)*/ ) ){
+ print STDERR "Please check the -l iso code\n";
+ exit(1);
+ }
+ if( ( !$merge && !$extract ) || ( $merge && $extract ) ){ usage();exit( -1 );}
+ if( $extract ){ $mode = "extract"; }
+ else { $mode = "merge"; }
+}
+
+#########################################################
+sub usage{
+
+ print STDERR "Usage: localize.pl\n";
+ print STDERR "Split or collect SDF files\n";
+ print STDERR " merge: -m -f <sdffile> -l l1[=f1][,l2[=f2]][...] [ -s <sourceroot> ]\n";
+ print STDERR " extract: -e -f <outputfile> -l <lang> [ -s <sourceroot> ] [-d]\n";
+ print STDERR "Options:\n";
+ print STDERR " -h help\n";
+ print STDERR " -m Merge mode\n";
+ print STDERR " -e Extract mode\n";
+ print STDERR " -f <sdffile> To split a big SDF file into particles\n";
+ print STDERR " <outputfile> To collect and join all particles to one big file\n";
+ print STDERR " -s <sourceroot> Path to the modules, if no \$SRC_ROOT is set\n";
+ print STDERR " -l ( all | <isocode> | <isocode>=fallback ) comma seperated languages\n";
+ print STDERR " -d Use default date in extracted sdf file\n";
+ print STDERR " -v Verbose\n";
+ print STDERR "\nExample:\n";
+ 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";
+ print STDERR "\nlocalize -m -l cs -f my.sdf\n( Merge cs translation into the sourcecode ) \n";
+}
+
+# my $line = defined $_ ? $_ : '';
+# my $leftpart = defined $2 ? $2 : '';
+# my $prj = defined $3 ? $3 : '';
+# my $file = defined $4 ? $4 : '';
+# my $dummy = defined $5 ? $5 : '';
+# my $type = defined $6 ? $6 : '';
+# my $gid = defined $7 ? $7 : '';
+# my $lid = defined $8 ? $8 : '';
+# my $helpid = defined $9 ? $9 : '';
+# my $plattform = defined $10 ? $10 : '';
+# my $width = defined $11 ? $11 : '';
+# my $lang = defined $12 ? $12 : '';
+# my $rightpart = defined $13 ? $13 : '';
+# my $text = defined $14 ? $14 : '';
+# my $helptext = defined $15 ? $15 : '';
+# my $quickhelptext = defined $16 ? $16 : '';
+# my $title = defined $17 ? $17 : '';
+# my $timestamp = defined $18 ? $18 : '';
+
diff --git a/l10ntools/scripts/makefile.mk b/l10ntools/scripts/makefile.mk
new file mode 100644
index 000000000000..8bfa64e3fbad
--- /dev/null
+++ b/l10ntools/scripts/makefile.mk
@@ -0,0 +1,59 @@
+#*************************************************************************
+#
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# Copyright 2000, 2010 Oracle and/or its affiliates.
+#
+# OpenOffice.org - a multi-platform office productivity suite
+#
+# This file is part of OpenOffice.org.
+#
+# OpenOffice.org is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Lesser General Public License version 3
+# only, as published by the Free Software Foundation.
+#
+# OpenOffice.org is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Lesser General Public License version 3 for more details
+# (a copy is included in the LICENSE file that accompanied this code).
+#
+# You should have received a copy of the GNU Lesser General Public License
+# version 3 along with OpenOffice.org. If not, see
+# <http://www.openoffice.org/license.html>
+# for a copy of the LGPLv3 License.
+#
+#*************************************************************************
+
+# Copy *.py files into output tree and call a script once to
+# force python to create the *.pyc files.
+
+PRJ=..
+TARGET = l10ntools_dummy_pyc
+
+.INCLUDE: settings.mk
+
+.IF "$(SYSTEM_PYTHON)"!="YES"
+PYTHON=$(AUGMENT_LIBRARY_PATH) $(WRAPCMD) $(SOLARBINDIR)/python
+.ELSE # "$(SYSTEM_PYTHON)"!="YES"
+PYTHON=$(AUGMENT_LIBRARY_PATH) $(WRAPCMD) python
+.ENDIF # "$(SYSTEM_PYTHON)"!="YES"
+
+PYFILES = $(BIN)$/const.py \
+ $(BIN)$/l10ntool.py \
+ $(BIN)$/pseudo.py \
+ $(BIN)$/sdf.py \
+ $(BIN)$/xhtex.py \
+ $(BIN)$/xtxex.py
+
+.INCLUDE: target.mk
+
+.IGNORE : create_pyc
+ALLTAR : create_pyc
+create_pyc : $(PYFILES)
+ @$(PYTHON) $(BIN)/xtxex.py >& /dev/null
+
+$(BIN)$/%.py : tool/%.py
+ @$(COPY) $< $@
+
+
diff --git a/l10ntools/scripts/tool/const.py b/l10ntools/scripts/tool/const.py
new file mode 100644
index 000000000000..2d514eabdab6
--- /dev/null
+++ b/l10ntools/scripts/tool/const.py
@@ -0,0 +1,39 @@
+#*************************************************************************
+#
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# Copyright 2000, 2010 Oracle and/or its affiliates.
+#
+# OpenOffice.org - a multi-platform office productivity suite
+#
+# This file is part of OpenOffice.org.
+#
+# OpenOffice.org is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Lesser General Public License version 3
+# only, as published by the Free Software Foundation.
+#
+# OpenOffice.org is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Lesser General Public License version 3 for more details
+# (a copy is included in the LICENSE file that accompanied this code).
+#
+# You should have received a copy of the GNU Lesser General Public License
+# version 3 along with OpenOffice.org. If not, see
+# <http://www.openoffice.org/license.html>
+# for a copy of the LGPLv3 License.
+#
+#*************************************************************************
+
+# Pseudo const
+class _const:
+ class ConstError(TypeError): pass
+ def __setattr__(self, name, value):
+ if self.__dict__.has_key(name):
+ raise self.ConstError, "Can't rebind const(%s)"%name
+ self.__dict__[name] = value
+
+import sys
+sys.modules[__name__] = _const()
+
+
diff --git a/l10ntools/scripts/tool/l10ntool.py b/l10ntools/scripts/tool/l10ntool.py
new file mode 100644
index 000000000000..f1630027ccdc
--- /dev/null
+++ b/l10ntools/scripts/tool/l10ntool.py
@@ -0,0 +1,210 @@
+#*************************************************************************
+#
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# Copyright 2000, 2010 Oracle and/or its affiliates.
+#
+# OpenOffice.org - a multi-platform office productivity suite
+#
+# This file is part of OpenOffice.org.
+#
+# OpenOffice.org is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Lesser General Public License version 3
+# only, as published by the Free Software Foundation.
+#
+# OpenOffice.org is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Lesser General Public License version 3 for more details
+# (a copy is included in the LICENSE file that accompanied this code).
+#
+# You should have received a copy of the GNU Lesser General Public License
+# version 3 along with OpenOffice.org. If not, see
+# <http://www.openoffice.org/license.html>
+# for a copy of the LGPLv3 License.
+#
+#*************************************************************************
+
+from optparse import OptionParser
+from sdf import SdfData
+from pseudo import PseudoSet
+
+import sys
+import os
+import shutil
+
+class AbstractL10nTool:
+ _options = {}
+ _args = ""
+ _resource_type = ""
+ _source_language = "en-US"
+
+ ##### Implement these abstract methods
+
+ ##### Nameing scheme for the output files
+ def get_outputfile_format_str(self):
+ # filename,fileNoExt,language,extension,pathPrefix,pathPostFix,path
+ #return "{path}/{fileNoExt}_{language}.{extension}"
+ return self._options.pattern
+
+ ################################# Merge single files ###########################################
+
+ ##### Merge a single file
+ def merge_file(self, inputfilename, outputfilename, parsed_file_ref, lang, is_forced_lang, sdfdata):
+ pass
+
+ ##### Helper for parse-once-use-often like parsing a xml file is needed implement it here
+ def parse_file(self, filename):
+ return None
+
+ ################### Merge one big file containing all strings in all languages #################
+ def merge_one_big_file(self, inputfile, outputfilename, parsed_file_ref, lang, sdfdata):
+ pass
+
+ ################### Extract a single File ######################################################
+ def extract_file(self, inputfile):
+ pass
+
+ ################################################################################################
+
+ def format_outputfile(self, filename, language):
+ extension = filename[filename.rfind('.')+1:]
+ file = filename[:filename.rfind('.')]
+ # Python 2.3.x friendly
+ return self.get_outputfile_format_str().replace('[', '%(').replace(']',')s') % \
+ { 'filename': filename, 'fileNoExt': file, 'language': language, 'extension': extension, 'path_prefix': self._options.path_prefix,
+ 'path_postfix': self._options.path_postfix, 'path': self.get_path() }
+
+ #return self.get_outputfile_format_str().replace('[', '{').replace(']','}').format(
+ # filename=filename, fileNoExt=file, language=language, extension=extension, path_prefix=self._options.path_prefix,
+ # path_postfix=self._options.path_postfix, path=self.get_path())
+
+ def get_path(self):
+ if self._options.outputfile.find('/') == -1:
+ return ""
+ else:
+ return self._options.outputfile[:self._options.outputfile.rfind('/')]
+
+ def merge(self, sdfdata):
+ langset,forcedset, foundset = PseudoSet(), PseudoSet() , PseudoSet()
+
+ if self._options.languages:
+ langset = PseudoSet(self._options.languages)
+ if self._options.forcedlanguages:
+ forcedset = PseudoSet(self._options.forcedlanguages)
+ if sdfdata.get_languages_found_in_sdf():
+ foundset = sdfdata.get_languages_found_in_sdf()
+
+ if self.has_multi_inputfiles():
+ filelist = self.read_inputfile_list()
+ else:
+ filelist = self._options.inputfile
+
+ for inputfile in filelist:
+ ref = self.parse_file(inputfile)
+ # Don't write that files if there is no l10n present
+ if ((langset & foundset) - forcedset): # all langs given and found in sdf without enforced
+ [self.merge_file(inputfile,self.format_outputfile(inputfile, lang), ref, lang, False, sdfdata) for lang in ((langset & foundset) - forcedset)]
+ # Always write those files even if there is no l10n available
+ if forcedset: # all enforced langs
+ [self.merge_file(inputfile, self.format_outputfile(inputfile, lang), ref, lang, True, sdfdata) for lang in forcedset]
+ # In case a big file have to be written
+ if ((langset & foundset) | forcedset): # all langs given ,found in sdf and enforced ones
+ self.merge_one_big_file(inputfile, self.format_outputfile(inputfile, lang), ref, ((langset & foundset) | forcedset), sdfdata)
+
+ def has_multi_inputfiles(self):
+ return self._options.inputfile[0] == '@'
+
+ def copy_file(self, inputfilename, outputfilename):
+ try:
+ shutil.copy(inputfilename, outputfilename)
+ except IOError:
+ print "ERROR: Can not copy file '" + inputfilename + "' to " + "'" + outputfilename + "'"
+ sys.exit(-1)
+
+ def extract(self):
+ try:
+ f = open(self._options.outputfile, "w+")
+ f.write(self.extract_file(self._options.inputfile))
+ except IOError:
+ print "ERROR: Can not write file " + self._options.outputfile
+ else:
+ f.close()
+
+ # Parse the common options
+ def parse_options(self):
+ parser = OptionParser()
+ parser.add_option("-i", "--inputfile", dest="inputfile", metavar="FILE", help="resource file to read" )
+ parser.add_option("-o", "--outputfile", dest="outputfile", metavar="FILE", help="extracted sdf or merged file" )
+ parser.add_option("-m", "--inputsdffile", dest="input_sdf_file", metavar="FILE", help="merge this sdf file" )
+ parser.add_option("-x", "--pathprefix", dest="path_prefix", metavar="PATH", help="" )
+ parser.add_option("-y", "--pathpostfix", dest="path_postfix", metavar="PATH", help="" )
+ parser.add_option("-p", "--projectname", dest="project_name", metavar="NAME", help="" )
+ parser.add_option("-r", "--projectroot", dest="project_root", metavar="PATH", help="" )
+ parser.add_option("-f", "--forcedlanguages", dest="forcedlanguages", metavar="ISOCODE[,ISOCODE]", help="Always merge those langs even if no l10n is available for those langs" )
+ parser.add_option("-l", "--languages", dest="languages", metavar="ISOCODE[,ISOCODE]", help="Merge those langs if l10n is found for each")
+ parser.add_option("-s", "--pattern", dest="pattern", metavar="", help="" )
+ parser.add_option("-q", "--quiet", action="store_true", dest="quietmode", help="",default=False)
+ (self._options, self.args) = parser.parse_args()
+
+ # -l "de,pr,pt-BR" => [ "de" , "pt" , "pt-BR" ]
+ parse_complex_arg = lambda arg: arg.split(",")
+
+ if self._options.forcedlanguages:
+ self._options.forcedlanguages = parse_complex_arg(self._options.forcedlanguages)
+ if self._options.languages:
+ self._options.languages = parse_complex_arg(self._options.languages)
+ self.test_options()
+
+ def __init__(self):
+ self.parse_options()
+ if self._options.input_sdf_file != None and len(self._options.input_sdf_file):
+ sdfdata = SdfData(self._options.input_sdf_file)
+ sdfdata.read()
+ self.merge(sdfdata)
+ else:
+ self.extract()
+
+ def make_dirs(self, filename):
+ dir = filename[:filename.rfind('/')]
+ if os.path.exists(dir):
+ if os.path.isfile(dir):
+ print "ERROR: There is a file '"+dir+"' where I want create a directory"
+ sys.exit(-1)
+ else:
+ return
+ else:
+ try:
+ os.makedirs(dir)
+ except IOError:
+ print "Error: Can not create dir " + dir
+ sys.exit(-1)
+
+ def test_options(self):
+ opt = self._options
+ is_valid = lambda x: x != None and len(x) > 0
+ return is_valid(opt.project_root) and is_valid(opt.project_name) and is_valid(opt.languages) and \
+ ( is_valid(opt.inputfile) and (( is_valid(opt.path_prefix) and is_valid(opt.path_postfix) ) or is_valid(opt.outputfile)) and \
+ ( ( is_valid(opt.input_sdf_file) and ( is_valid(opt.outputfile) or ( is_valid(opt.path_prefix) and is_valid(opt.path_postfix) ) or \
+ ( is_valid(opt.inputfile) and is_valid(opt.outputFile)) ))))
+ print "Strange options ..."
+ sys.exit( -1 )
+
+ def read_inputfile_list(self):
+ if self.has_multi_inputfiles():
+ lines = []
+ try:
+ f = open(self._options.inputfile[1:], "r")
+ lines = [line.strip('\n') for line in f.readlines()]
+ except IOError:
+ print "ERROR: Can not read file list " + self._options.inputfile[2:]
+ sys.exit(-1)
+ else:
+ f.close()
+ return lines
+
+ def get_filename_string(self, inputfile):
+ absfile = os.path.realpath(os.path.abspath(inputfile))
+ absroot = os.path.realpath(os.path.abspath(self._options.project_root))
+ return absfile[len(absroot)+1:].replace('/','\\')
+
diff --git a/l10ntools/scripts/tool/pseudo.py b/l10ntools/scripts/tool/pseudo.py
new file mode 100644
index 000000000000..0956325e31db
--- /dev/null
+++ b/l10ntools/scripts/tool/pseudo.py
@@ -0,0 +1,184 @@
+#*************************************************************************
+#
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# Copyright 2000, 2010 Oracle and/or its affiliates.
+#
+# OpenOffice.org - a multi-platform office productivity suite
+#
+# This file is part of OpenOffice.org.
+#
+# OpenOffice.org is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Lesser General Public License version 3
+# only, as published by the Free Software Foundation.
+#
+# OpenOffice.org is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Lesser General Public License version 3 for more details
+# (a copy is included in the LICENSE file that accompanied this code).
+#
+# You should have received a copy of the GNU Lesser General Public License
+# version 3 along with OpenOffice.org. If not, see
+# <http://www.openoffice.org/license.html>
+# for a copy of the LGPLv3 License.
+#
+#*************************************************************************
+
+# to support macosx baseline machines from Cretaceous period
+
+# incomplete set() class implementation of Python 2.4
+class PseudoSet:
+ _list = []
+
+ def __str__(self):
+ return str(self._list)
+
+ def __init__(self, newlist=[]):
+ self._list = self._remove_dupes(newlist)
+
+ def __or__(self, other):
+ tmplist = []
+ if self._list != None and other != None:
+ tmplist.extend(self._list)
+ tmplist.extend(other)
+ return PseudoSet(self._remove_dupes(tmplist))
+ else:
+ print "__or__(None)"
+
+ def __sub__(self,other):
+ tmplist = []
+ if self._list != None and other != None:
+ tmplist.extend(self._list)
+ [tmplist.remove(key) for key in other if key in tmplist]
+ else:
+ print "__sub__(none)"
+ return PseudoSet(tmplist)
+
+ def __and__(self, other):
+ tmplist = []
+ if other != None and self._list != None:
+ [tmplist.append(key) for key in self._list if key in other]
+ return PseudoSet(tmplist)
+ else:
+ print "__and__(None)"
+
+ def __iter__(self):
+ return self._list.__iter__()
+
+ def __items__(self):
+ return self._list.items()
+
+ def __keys__(self):
+ return keys(self._list)
+
+ def _remove_dupes(self, list):
+ tmpdict = {}
+ for key in list:
+ tmpdict[key] = 1
+ return tmpdict.keys()
+
+# incomplete OrderedDict() class implementation
+class PseudoOrderedDict(dict):
+ _keylist = []
+ _valuelist = []
+
+ def __init__(self, defaults={}):
+ dict.__init__(self)
+ for n,v in defaults.items():
+ self[n] = v
+
+ def __setitem__(self, key, value):
+ self._keylist.append(key)
+ self._valuelist.append(value)
+ return dict.__setitem__(self, key, value)
+
+ def __delattr__(self, key):
+ self._keylist.__delattr__(key)
+ self._valuelist.__delattr__(dict[key])
+ return dict.__delattr__(self, key)
+
+ def __delitem__(self, key):
+ self._keylist.__delitem__(key)
+ self._valuelist.__delitem__(dict[key])
+ return dict.__delitem__(self, key)
+
+ def __iter__(self):
+ raise NotImplementedError("__iter__")
+
+ def __iterkeys__(self):
+ return self._keylist
+
+ def iteritems(self):
+ #return self._valuelist
+ return zip(self._keylist, self._valuelist)
+
+ def items(self):
+ return zip(self._keylist,self._valuelist)
+
+ def __keys__(self):
+ return self._keylist
+
+ def keys(self):
+ return self._keylist
+
+ def __keysattr__(self):
+ return self._keylist
+
+ def pop(self, key):
+ self._keylist.pop(key)
+ self._valuelist.pop(key)
+ return dict.__pop__(self, key)
+
+ def popitem(self):
+ raise NotImplementedError("popitem")
+
+def _testdriver_set():
+ list, list1 = [] ,[]
+ list.append("a")
+ list.append("b")
+ list.append("c")
+
+ list1.append("a")
+ list1.append("b")
+ list1.append("d")
+ list1.append("e")
+ list1.append("e")
+
+ if "a" in list:
+ print "YEAH!"
+
+ a = PseudoSet(list)
+ b = PseudoSet(list1)
+
+ print "a="+str(a)
+ print "b="+str(b)
+ print "a|b=" + str(a|b)
+ print "a="+str(a)
+ print "b="+str(b)
+ print "a&b=" + str(a&b)
+ print "a="+str(a)
+ print "b="+str(b)
+ print "a-b" + str(a-b)
+
+ for key in a:
+ print key
+
+def _testdriver_dict():
+ d = PseudoOrderedDict()
+ d["a"] = 1
+ d["b"] = 2
+ d["c"] = 3
+ d["d"] = 4
+ d["e"] = 5
+ d["f"] = 6
+
+ print "a="+str(d["a"])
+ print "e="+str(d["e"])
+ for key,value in d.iteritems():
+ print "d["+key+"]="+str(d[key])
+ print "key="+str(key)+" value="+str(value)
+
+ print "keys="+str(d.keys())
+
+#_testdriver_dict()
diff --git a/l10ntools/scripts/tool/sdf.py b/l10ntools/scripts/tool/sdf.py
new file mode 100644
index 000000000000..96afbed1452c
--- /dev/null
+++ b/l10ntools/scripts/tool/sdf.py
@@ -0,0 +1,170 @@
+#*************************************************************************
+#
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# Copyright 2000, 2010 Oracle and/or its affiliates.
+#
+# OpenOffice.org - a multi-platform office productivity suite
+#
+# This file is part of OpenOffice.org.
+#
+# OpenOffice.org is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Lesser General Public License version 3
+# only, as published by the Free Software Foundation.
+#
+# OpenOffice.org is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Lesser General Public License version 3 for more details
+# (a copy is included in the LICENSE file that accompanied this code).
+#
+# You should have received a copy of the GNU Lesser General Public License
+# version 3 along with OpenOffice.org. If not, see
+# <http://www.openoffice.org/license.html>
+# for a copy of the LGPLv3 License.
+#
+#*************************************************************************
+
+from pseudo import PseudoSet,PseudoOrderedDict
+from time import gmtime, strftime
+
+class SdfData:
+ _filename = "";
+ _dict = PseudoOrderedDict()
+ _languages_found = [];
+
+ def __init__ (self, filename=""):
+ self._filename = filename
+
+ def __getitem__(self, key):
+ if self._dict.has_key(key):
+ return self._dict[key]
+ else:
+ return None
+
+ def has_key(self, key):
+ return self._dict.has_key(key)
+
+ def __setitem__(self, key, value):
+ self._dict[key] = value
+
+ def get_languages_found_in_sdf(self):
+ return PseudoSet(self._languages_found)
+
+ def read(self):
+ try:
+ f = open(self._filename, "r")
+ lines = [line.rstrip('\n') for line in f.readlines()]
+ except IOError:
+ print "ERROR: Trying to read "+ self._filename
+ raise
+ else:
+ f.close()
+ for line in lines:
+ entity = SdfEntity()
+ entity.set_properties(line)
+ self._dict[entity.get_id()] = entity
+ self._languages_found.append(entity.langid)
+
+ def write(self, filename):
+ try:
+ f = open(filename, "w+")
+ for value in self._dict.itervalues():
+ #f.write( repr(value)+"\n" )
+ f.write(value + "\n")
+ except IOError:
+ print "ERROR: Trying to write " + filename
+ raise
+ else:
+ f.close()
+
+import sys
+class SdfEntity:
+ # Sdf format columns
+ project = ""
+ source_file = ""
+ dummy1 = ""
+ resource_type = ""
+ gid = ""
+ lid = ""
+ helpid = ""
+ platform = ""
+ dummy2 = ""
+ langid = ""
+ text = ""
+ helptext = ""
+ quickhelptext = ""
+ title = ""
+ date = ""
+
+ import const
+ const._PROJECT_POS = 0
+ const._SOURCE_FILE_POS = 1
+ const._DUMMY1_POS = 2
+ const._RESOURCE_TYPE_POS = 3
+ const._GID_POS = 4
+ const._LID_POS = 5
+ const._HELPID_POS = 6
+ const._PLATFORM_POS = 7
+ const._DUMMY2_POS = 8
+ const._LANGID_POS = 9
+ const._TEXT_POS = 10
+ const._HELPTEXT_POS = 11
+ const._QUICKHELPTEXT_POS = 12
+ const._TITLE_POS = 13
+ const._DATE_POS = 14
+
+ def __init__(self, project="", source_file="", dummy1="0", resource_type="", gid="", lid="", helpid="", platform="", dummy2="0", langid="",
+ text="", helptext="", quickhelptext="", title="", date=""):
+ self.project = project;
+ self.source_file = source_file;
+ self.dummy1 = dummy1;
+ self.resource_type = resource_type;
+ self.gid = gid;
+ self.lid = lid;
+ self.helpid = helpid;
+ self.platform = platform;
+ self.dummy2 = dummy2;
+ self.langid = langid;
+ self.text = text;
+ self.helptext = helptext;
+ self.quickhelptext = quickhelptext;
+ self.title = title;
+ if date != "":
+ self.date = date;
+ else:
+ self.date = strftime("%Y-%m-%d %H:%M:%S",gmtime())
+
+
+ def set_properties(self, line):
+ splitted = line.split("\t")
+ if len(splitted) == 15:
+ self.project = splitted[ self.const._PROJECT_POS ]
+ self.source_file = splitted[ self.const._SOURCE_FILE_POS ]
+ self.dummy1 = splitted[ self.const._DUMMY1_POS ]
+ self.resource_type = splitted[ self.const._RESOURCE_TYPE_POS ]
+ self.gid = splitted[ self.const._GID_POS ]
+ self.lid = splitted[ self.const._LID_POS ]
+ self.helpid = splitted[ self.const._HELPID_POS ]
+ self.platform = splitted[ self.const._PLATFORM_POS ]
+ self.dummy2 = splitted[ self.const._DUMMY2_POS ]
+ self.langid = splitted[ self.const._LANGID_POS ]
+ self.text = splitted[ self.const._TEXT_POS ]
+ self.helptext = splitted[ self.const._HELPTEXT_POS ]
+ self.quickhelptext = splitted[ self.const._QUICKHELPTEXT_POS ]
+ self.title = splitted[ self.const._TITLE_POS ]
+ self.date = splitted[ self.const._DATE_POS ]
+
+ def get_file_id(self):
+ return self.project + "\\" + self.source_file
+
+ def get_resource_path(self):
+ return self.source_file[0:self.source_file.rfind( "\\" )-1]
+
+ def __str__(self):
+ return ''.join([self.project, "\t", self.source_file, "\t", self.dummy1, "\t", self.resource_type, "\t" ,
+ self.gid, "\t", self.lid, "\t", self.helpid, "\t", self.platform, "\t", self.dummy2, "\t" , self.langid,
+ "\t", self.text, "\t", self.helptext, "\t", self.quickhelptext, "\t" , self.title, "\t", self.date ])
+
+ def get_id(self):
+ return ''.join([self.project, self.gid, self.lid, self.source_file, self.resource_type, self.platform, self.helpid, self.langid])
diff --git a/l10ntools/scripts/tool/xhtex.py b/l10ntools/scripts/tool/xhtex.py
new file mode 100644
index 000000000000..d916fc675944
--- /dev/null
+++ b/l10ntools/scripts/tool/xhtex.py
@@ -0,0 +1,136 @@
+#*************************************************************************
+#
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# Copyright 2000, 2010 Oracle and/or its affiliates.
+#
+# OpenOffice.org - a multi-platform office productivity suite
+#
+# This file is part of OpenOffice.org.
+#
+# OpenOffice.org is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Lesser General Public License version 3
+# only, as published by the Free Software Foundation.
+#
+# OpenOffice.org is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Lesser General Public License version 3 for more details
+# (a copy is included in the LICENSE file that accompanied this code).
+#
+# You should have received a copy of the GNU Lesser General Public License
+# version 3 along with OpenOffice.org. If not, see
+# <http://www.openoffice.org/license.html>
+# for a copy of the LGPLv3 License.
+#
+#*************************************************************************
+
+from l10ntool import AbstractL10nTool
+from sdf import SdfEntity
+import sys
+import xml.dom.minidom
+
+class Xhtex(AbstractL10nTool):
+ _resource_type = "xht"
+ _sdfdata = ()
+ _lang = ""
+
+ # Extract methods
+ def extract_topic(self, list, inputfile):
+ topics = []
+ for elem in list:
+ if elem.childNodes[0].nodeType == elem.TEXT_NODE and len(elem.childNodes[0].data.strip()):
+ topics.append(self.prepare_sdf_line(id=elem.getAttribute("id").strip(), text=elem.childNodes[0].data, inputfile=inputfile))
+ return topics
+
+ def extract_title(self, list, inputfile):
+ titles = []
+ for elem in list:
+ if len(elem.getAttribute("title").strip()):
+ titles.append(self.prepare_sdf_line(id=elem.getAttribute("id").strip(), text=elem.getAttribute("title").strip(), inputfile=inputfile))
+ return titles
+
+ # Merge methods
+ def merge_topic(self, list, sdfdata, lang, inputfilename, dom):
+ for elem in list:
+ if elem.childNodes[0].nodeType == elem.TEXT_NODE and elem.getAttribute("id").strip():
+ obj = self.prepare_sdf_line(inputfile=inputfilename, lang=lang, id=elem.getAttribute("id").strip())
+ if sdfdata[obj.get_id()]:
+ elem.childNodes[0].data = unicode(str(sdfdata[obj.get_id()].text),"utf8")
+
+
+ def merge_title(self, list, sdfdata, lang, inputfilename):
+ for elem in list:
+ obj = self.prepare_sdf_line(inputfile=inputfilename, lang=lang, id=elem.getAttribute("id").strip())
+ if elem.getAttribute("id").strip() and sdfdata[obj.get_id()]:
+ elem.setAttribute("title", unicode(str(sdfdata[obj.get_id()].text),"utf8"))
+
+ # L10N tool
+ def __init__(self):
+ AbstractL10nTool.__init__(self)
+
+ def parse_file(self, filename):
+ document = ""
+ try:
+ f = open(filename, "r+")
+ document = f.read()
+ except IOError:
+ print "ERROR: Can not read file " + filename
+ sys.exit(-1)
+ else:
+ f.close()
+ return xml.dom.minidom.parseString(document)
+
+
+ def merge_file(self, inputfilename, outputfilename, parsed_file_ref, lang,is_forced_lang, sdfdata):
+ if lang == "en-US":
+ mod_outputfilename = outputfilename.replace("_en-US",'')
+ self.make_dirs(mod_outputfilename)
+ self.copy_file(inputfilename, mod_outputfilename)
+ return
+ dom = parsed_file_ref.cloneNode(True)
+ #dom = self.parse_file(inputfilename) # in case cloneNode is buggy just parse it always
+
+ self.merge_topic(dom.getElementsByTagName("topic"), sdfdata, lang, inputfilename, dom)
+ self.merge_title(dom.getElementsByTagName("node"), sdfdata, lang, inputfilename)
+ self.merge_title(dom.getElementsByTagName("help_section"), sdfdata, lang, inputfilename)
+ self.make_dirs(outputfilename)
+ try:
+ f = open(outputfilename, "w+")
+ str = dom.toxml()
+ f.write(str.encode("utf-8"))
+ except IOError:
+ print "ERROR: Can not write file " + outputfilename
+ sys.exit(-1)
+ else:
+ f.close()
+
+ ##### Helper for parse-once-use-often like parsing a xml file is needed implement it here
+ def parse_file(self, filename):
+ document = ""
+ try:
+ f = open(filename,"r")
+ document = f.read()
+ except IOError:
+ print "ERROR: Can not read file " + filename
+ else:
+ f.close()
+ return xml.dom.minidom.parseString(document)
+
+ ##### Extract a single File
+ def extract_file(self, inputfile):
+ sdf_data = []
+ dom = self.parse_file(inputfile)
+ sdf_data.extend(self.extract_topic(dom.getElementsByTagName("topic"), inputfile))
+ sdf_data.extend(self.extract_title(dom.getElementsByTagName("help_section"), inputfile))
+ sdf_data.extend(self.extract_title(dom.getElementsByTagName("node"), inputfile))
+ return ''.join([str(line)+"\n" for line in sdf_data])
+
+ def prepare_sdf_line(self, inputfile="", lang="" , id="" , text=""):
+ if lang == "":
+ lang = self._source_language
+ return SdfEntity(project=self._options.project_name, source_file=self.get_filename_string(inputfile),
+ resource_type=self._resource_type, gid=id, lid="", langid=lang,text=text)
+
+run = Xhtex()
+
diff --git a/l10ntools/scripts/tool/xtxex.py b/l10ntools/scripts/tool/xtxex.py
new file mode 100644
index 000000000000..96912754b7df
--- /dev/null
+++ b/l10ntools/scripts/tool/xtxex.py
@@ -0,0 +1,94 @@
+#*************************************************************************
+#
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# Copyright 2000, 2010 Oracle and/or its affiliates.
+#
+# OpenOffice.org - a multi-platform office productivity suite
+#
+# This file is part of OpenOffice.org.
+#
+# OpenOffice.org is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Lesser General Public License version 3
+# only, as published by the Free Software Foundation.
+#
+# OpenOffice.org is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Lesser General Public License version 3 for more details
+# (a copy is included in the LICENSE file that accompanied this code).
+#
+# You should have received a copy of the GNU Lesser General Public License
+# version 3 along with OpenOffice.org. If not, see
+# <http://www.openoffice.org/license.html>
+# for a copy of the LGPLv3 License.
+#
+#*************************************************************************
+
+from l10ntool import AbstractL10nTool
+from sdf import SdfEntity
+import sys
+import shutil
+
+class Xtxex(AbstractL10nTool):
+ _resource_type = "xtx"
+
+ def __init__(self):
+ AbstractL10nTool.__init__(self)
+
+ def merge_file(self, inputfilename, outputfilename, parsed_file_ref, lang, is_forced_lang, sdfdata):
+ # Special handling for en-US files
+ if lang == "en-US":
+ mod_outputfilename = outputfilename
+ # mod here if needed
+ self.copy_file(inputfilename, mod_outputfilename)
+ return
+ # merge usual lang
+ sdfline = self.prepare_sdf_line(inputfilename,lang)
+ if sdfdata.has_key(sdfline.get_id()):
+ line = sdfdata[sdfline.get_id()].text.replace("\\n", '\n')
+ self.make_dirs(outputfilename)
+ try:
+ f = open(outputfilename, "w+")
+ f.write(line)
+ except IOError:
+ print "ERROR: Can not write file " + outputfilename
+ sys.exit(-1)
+ else:
+ f.close()
+ return
+ # no sdf data found then copy en-US source file
+ if is_forced_lang:
+ self.copy_file(inputfilename, outputfilename)
+
+ ##### Extract a single File
+ def extract_file(self, inputfile):
+ lines = []
+ try:
+ f = open(inputfile, "r")
+ lines = f.readlines()
+ except IOError:
+ print "ERROR: Can not open file " + inputfile
+ sys.exit(-1)
+ else:
+ f.close()
+ # remove legal header
+ lines = [line for line in lines if len(line) > 0 and not line[0] == '#']
+ # escape all returns
+ lines = [line.replace('\n', "\\n") for line in lines]
+ line = ''.join(lines)
+ test = str(line)
+ if len(test.strip()):
+ sdf_entity = self.prepare_sdf_line(inputfile);
+ sdf_entity.text = line
+ return str(sdf_entity)
+ else:
+ return ""
+
+ def prepare_sdf_line(self, inputfile="", lang=""):
+ if lang == "":
+ lang = self._source_language
+ return SdfEntity(project=self._options.project_name, source_file=self.get_filename_string(inputfile),
+ resource_type=self._resource_type, gid="none", lid="none", langid=lang,text="")
+
+run = Xtxex()
diff --git a/l10ntools/scripts/xhtex b/l10ntools/scripts/xhtex
new file mode 100755
index 000000000000..d337694c589b
--- /dev/null
+++ b/l10ntools/scripts/xhtex
@@ -0,0 +1,38 @@
+#!/bin/sh
+#*************************************************************************
+#
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# Copyright 2000, 2010 Oracle and/or its affiliates.
+#
+# OpenOffice.org - a multi-platform office productivity suite
+#
+# This file is part of OpenOffice.org.
+#
+# OpenOffice.org is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Lesser General Public License version 3
+# only, as published by the Free Software Foundation.
+#
+# OpenOffice.org is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Lesser General Public License version 3 for more details
+# (a copy is included in the LICENSE file that accompanied this code).
+#
+# You should have received a copy of the GNU Lesser General Public License
+# version 3 along with OpenOffice.org. If not, see
+# <http://www.openoffice.org/license.html>
+# for a copy of the LGPLv3 License.
+#
+#*************************************************************************
+
+if [ x${SOLARENV}x = xx ]; then
+ echo No environment found, please use 'setsolar'
+exit 1
+fi
+
+if [ x${SOLARVER}x = xx -o x${UPDMINOREXT}x = xx ]; then
+ exec python $SOLARVERSION/$INPATH/bin/xhtex.py "$@"
+else
+ exec python $SOLARVERSION/$INPATH/bin$UPDMINOREXT/xhtex.py "$@"
+fi
diff --git a/l10ntools/scripts/xtxex b/l10ntools/scripts/xtxex
new file mode 100755
index 000000000000..01a70ae57d80
--- /dev/null
+++ b/l10ntools/scripts/xtxex
@@ -0,0 +1,39 @@
+#!/bin/sh
+#*************************************************************************
+#
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# Copyright 2000, 2010 Oracle and/or its affiliates.
+#
+# OpenOffice.org - a multi-platform office productivity suite
+#
+# This file is part of OpenOffice.org.
+#
+# OpenOffice.org is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Lesser General Public License version 3
+# only, as published by the Free Software Foundation.
+#
+# OpenOffice.org is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Lesser General Public License version 3 for more details
+# (a copy is included in the LICENSE file that accompanied this code).
+#
+# You should have received a copy of the GNU Lesser General Public License
+# version 3 along with OpenOffice.org. If not, see
+# <http://www.openoffice.org/license.html>
+# for a copy of the LGPLv3 License.
+#
+#*************************************************************************
+
+if [ x${SOLARENV}x = xx ]; then
+ echo No environment found, please use 'setsolar'
+exit 1
+fi
+
+if [ x${SOLARVER}x = xx -o x${UPDMINOREXT}x = xx ]; then
+ exec python $SOLARVERSION/$INPATH/bin/xtxex.py "$@"
+else
+ exec python $SOLARVERSION/$INPATH/bin$UPDMINOREXT/xtxex.py "$@"
+fi
+