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