1cdf0e10cSrcweir: 2cdf0e10cSrcweireval 'exec perl -wS $0 ${1+"$@"}' 3cdf0e10cSrcweir if 0; 4cdf0e10cSrcweir 5cdf0e10cSrcweir 6*7e90fac2SAndrew Rist#************************************************************** 7*7e90fac2SAndrew Rist# 8*7e90fac2SAndrew Rist# Licensed to the Apache Software Foundation (ASF) under one 9*7e90fac2SAndrew Rist# or more contributor license agreements. See the NOTICE file 10*7e90fac2SAndrew Rist# distributed with this work for additional information 11*7e90fac2SAndrew Rist# regarding copyright ownership. The ASF licenses this file 12*7e90fac2SAndrew Rist# to you under the Apache License, Version 2.0 (the 13*7e90fac2SAndrew Rist# "License"); you may not use this file except in compliance 14*7e90fac2SAndrew Rist# with the License. You may obtain a copy of the License at 15*7e90fac2SAndrew Rist# 16*7e90fac2SAndrew Rist# http://www.apache.org/licenses/LICENSE-2.0 17*7e90fac2SAndrew Rist# 18*7e90fac2SAndrew Rist# Unless required by applicable law or agreed to in writing, 19*7e90fac2SAndrew Rist# software distributed under the License is distributed on an 20*7e90fac2SAndrew Rist# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 21*7e90fac2SAndrew Rist# KIND, either express or implied. See the License for the 22*7e90fac2SAndrew Rist# specific language governing permissions and limitations 23*7e90fac2SAndrew Rist# under the License. 24*7e90fac2SAndrew Rist# 25*7e90fac2SAndrew Rist#************************************************************** 26*7e90fac2SAndrew Rist 27*7e90fac2SAndrew 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". 276cdf0e10cSrcweir"#*************************************************************************\n". 277cdf0e10cSrcweir"#\n". 278cdf0e10cSrcweir"# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.\n". 279cdf0e10cSrcweir"# \n". 280cdf0e10cSrcweir"# Copyright 2000, 2010 Oracle and/or its affiliates.\n". 281cdf0e10cSrcweir"#\n". 282cdf0e10cSrcweir"# OpenOffice.org - a multi-platform office productivity suite\n". 283cdf0e10cSrcweir"#\n". 284cdf0e10cSrcweir"# This file is part of OpenOffice.org.\n". 285cdf0e10cSrcweir"#\n". 286cdf0e10cSrcweir"# OpenOffice.org is free software: you can redistribute it and/or modify\n". 287cdf0e10cSrcweir"# it under the terms of the GNU Lesser General Public License version 3\n". 288cdf0e10cSrcweir"# only, as published by the Free Software Foundation.\n". 289cdf0e10cSrcweir"#\n". 290cdf0e10cSrcweir"# OpenOffice.org is distributed in the hope that it will be useful,\n". 291cdf0e10cSrcweir"# but WITHOUT ANY WARRANTY; without even the implied warranty of\n". 292cdf0e10cSrcweir"# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n". 293cdf0e10cSrcweir"# GNU Lesser General Public License version 3 for more details\n". 294cdf0e10cSrcweir"# (a copy is included in the LICENSE file that accompanied this code).\n". 295cdf0e10cSrcweir"#\n". 296cdf0e10cSrcweir"# You should have received a copy of the GNU Lesser General Public License\n". 297cdf0e10cSrcweir"# version 3 along with OpenOffice.org. If not, see\n". 298cdf0e10cSrcweir"# <http://www.openoffice.org/license.html>\n". 299cdf0e10cSrcweir"# for a copy of the LGPLv3 License.\n". 300cdf0e10cSrcweir"#\n". 301cdf0e10cSrcweir"#*************************************************************************\n"; 302cdf0e10cSrcweir} 303cdf0e10cSrcweir######## Check input sdf file and use only the correct part 304cdf0e10cSrcweirsub merge_gsicheck{ 305cdf0e10cSrcweir my $command = ''; 306cdf0e10cSrcweir my ( $TMPHANDLE , $tmpfile ) = File::Temp::tempfile(); 307cdf0e10cSrcweir close ( $TMPHANDLE ); 308cdf0e10cSrcweir 309cdf0e10cSrcweir $command = "$ENV{WRAPCMD} " if( $ENV{WRAPCMD} ); 310cdf0e10cSrcweir $command .= "$ENV{SOLARVER}/$ENV{INPATH}/bin/gsicheck"; 311cdf0e10cSrcweir 312cdf0e10cSrcweir my $errfile = $sdffile.".err"; 313cdf0e10cSrcweir $command .= " -k -c -wcf $tmpfile -wef $errfile -l \"\" $sdffile"; 314cdf0e10cSrcweir #my $rc = system( $command ); 315cdf0e10cSrcweir my $output = `$command`; 316cdf0e10cSrcweir my $rc = $? << 8; 317cdf0e10cSrcweir if ( $output ne "" ){ 318cdf0e10cSrcweir print STDOUT "### gsicheck ###\n"; 319cdf0e10cSrcweir print STDOUT "### The file $errfile have been written containing the errors in your sdf file. Those lines will not be merged: ###\n\n"; 320cdf0e10cSrcweir print STDOUT "$output\n"; 321cdf0e10cSrcweir print STDOUT "################\n"; 322cdf0e10cSrcweir 323cdf0e10cSrcweir }else{ 324cdf0e10cSrcweir # Remove the 0 Byte file 325cdf0e10cSrcweir unlink $errfile; 326cdf0e10cSrcweir } 327cdf0e10cSrcweir $sdffile = $tmpfile; 328cdf0e10cSrcweir} 329cdf0e10cSrcweir######################################################### 330cdf0e10cSrcweir# find search function 331cdf0e10cSrcweirsub wanted 332cdf0e10cSrcweir{ 333cdf0e10cSrcweir my $file = $File::Find::name; 334cdf0e10cSrcweir if( -f $file && $file =~ /.*localize.sdf$/ && !( $file =~ /.*\.svn.*/ ) ) { 335cdf0e10cSrcweir push @sdfparticles , $file; 336cdf0e10cSrcweir if( $bVerbose eq "1" ) { print STDOUT "$file\n"; } 337cdf0e10cSrcweir else { print "."; } 338cdf0e10cSrcweir } 339cdf0e10cSrcweir} 340cdf0e10cSrcweir 341cdf0e10cSrcweirsub add_paths 342cdf0e10cSrcweir{ 343cdf0e10cSrcweir my $langhash_ref = shift; 344cdf0e10cSrcweir my $root_dir = $ENV{ SRC_ROOT }; 345cdf0e10cSrcweir my $ooo_l10n_dir = "$root_dir/l10n/source"; 346cdf0e10cSrcweir my $so_l10n_dir = "$root_dir/l10n_so/source"; 347cdf0e10cSrcweir 348cdf0e10cSrcweir if( -e $ooo_l10n_dir ) 349cdf0e10cSrcweir { 350cdf0e10cSrcweir foreach my $lang ( keys( %{ $langhash_ref } ) ) 351cdf0e10cSrcweir { 352cdf0e10cSrcweir my $loc_file = "$ooo_l10n_dir/$lang/localize.sdf"; 353cdf0e10cSrcweir if( -e $loc_file ) 354cdf0e10cSrcweir { 355cdf0e10cSrcweir push @sdfparticles , "$ooo_l10n_dir/$lang/localize.sdf"; 356cdf0e10cSrcweir } 357cdf0e10cSrcweir else { print "WARNING: $loc_file not found ....\n"; } 358cdf0e10cSrcweir } 359cdf0e10cSrcweir } 360cdf0e10cSrcweir else { die "ERROR: Can not find directory $ooo_l10n_dir!!!" } 361cdf0e10cSrcweir if( -e $so_l10n_dir ) 362cdf0e10cSrcweir { 363cdf0e10cSrcweir foreach my $lang ( keys( %{ $langhash_ref } ) ) 364cdf0e10cSrcweir { 365cdf0e10cSrcweir my $loc_file = "$so_l10n_dir/$lang/localize.sdf"; 366cdf0e10cSrcweir if( -e $loc_file ) 367cdf0e10cSrcweir { 368cdf0e10cSrcweir push @sdfparticles , "$ooo_l10n_dir/$lang/localize.sdf"; 369cdf0e10cSrcweir } 370cdf0e10cSrcweir else { #print "WARNING: $loc_file not found ....\n"; 371cdf0e10cSrcweir } 372cdf0e10cSrcweir } 373cdf0e10cSrcweir 374cdf0e10cSrcweir } 375cdf0e10cSrcweir} 376cdf0e10cSrcweirsub collectfiles{ 377cdf0e10cSrcweir print STDOUT "### Localize\n"; 378cdf0e10cSrcweir my $localizehash_ref; 379cdf0e10cSrcweir my ( $bAll , $bUseLocalize, $langhash_ref , $bHasSourceLanguage , $bFakeEnglish ) = parseLanguages(); 380cdf0e10cSrcweir 381cdf0e10cSrcweir # Enable autoflush on STDOUT 382cdf0e10cSrcweir # $| = 1; 383cdf0e10cSrcweir STDOUT->autoflush( 1 ); 384cdf0e10cSrcweir 385cdf0e10cSrcweir my $working_path = getcwd(); 386cdf0e10cSrcweir chdir $ENV{SOURCE_ROOT_DIR}, if defined $ENV{SOURCE_ROOT_DIR}; 387cdf0e10cSrcweir add_paths( $langhash_ref ); 388cdf0e10cSrcweir 389cdf0e10cSrcweir my ( $LOCALIZEPARTICLE , $localizeSDF ) = File::Temp::tempfile(); 390cdf0e10cSrcweir close( $LOCALIZEPARTICLE ); 391cdf0e10cSrcweir 392cdf0e10cSrcweir my ( $ALLPARTICLES_MERGED , $particleSDF_merged ) = File::Temp::tempfile(); 393cdf0e10cSrcweir close( $ALLPARTICLES_MERGED ); 394cdf0e10cSrcweir my ( $LOCALIZE_LOG , $my_localize_log ) = File::Temp::tempfile(); 395cdf0e10cSrcweir close( $LOCALIZE_LOG ); 396cdf0e10cSrcweir 397cdf0e10cSrcweir ## Get the localize en-US extract 398cdf0e10cSrcweir if( $bAll || $bUseLocalize ){ 399cdf0e10cSrcweir print "### Fetching source language strings\n"; 400cdf0e10cSrcweir my $command = ""; 401cdf0e10cSrcweir my $args = ""; 402cdf0e10cSrcweir 403cdf0e10cSrcweir if( $ENV{WRAPCMD} ){ 404cdf0e10cSrcweir $command = $ENV{WRAPCMD}.$binpath."localize_sl"; 405cdf0e10cSrcweir }else{ 406cdf0e10cSrcweir $command = $binpath."localize_sl"; 407cdf0e10cSrcweir } 408cdf0e10cSrcweir print $command; 409cdf0e10cSrcweir # -e 410cdf0e10cSrcweir # if ( -x $command ){ 411cdf0e10cSrcweir if( $command ){ 412cdf0e10cSrcweir if( !$bVerbose ){ $args .= " "; } 413cdf0e10cSrcweir $args .= " -e -f $localizeSDF -l "; 414cdf0e10cSrcweir my $bFlag=""; 415cdf0e10cSrcweir if( $bAll ) {$args .= " en-US";} 416cdf0e10cSrcweir else{ 417cdf0e10cSrcweir my @list; 418cdf0e10cSrcweir foreach my $isokey ( keys( %{ $langhash_ref } ) ){ 419cdf0e10cSrcweir push @list , $isokey; 420cdf0e10cSrcweir if( $langhash_ref->{ $isokey } ne "" ){ 421cdf0e10cSrcweir push @list , $langhash_ref->{ $isokey }; 422cdf0e10cSrcweir } 423cdf0e10cSrcweir } 424cdf0e10cSrcweir remove_duplicates( \@list ); 425cdf0e10cSrcweir foreach my $isokey ( @list ){ 426cdf0e10cSrcweir switch :{ 427cdf0e10cSrcweir ( $isokey=~ /^en-US$/i ) 428cdf0e10cSrcweir && do{ 429cdf0e10cSrcweir if( $bFlag eq "TRUE" ){ $args .= ",en-US"; } 430cdf0e10cSrcweir else { 431cdf0e10cSrcweir $args .= "en-US"; $bFlag = "TRUE"; 432cdf0e10cSrcweir } 433cdf0e10cSrcweir }; 434cdf0e10cSrcweir 435cdf0e10cSrcweir } #switch 436cdf0e10cSrcweir } #foreach 437cdf0e10cSrcweir } # if 438cdf0e10cSrcweir } # if 439cdf0e10cSrcweir if ( $bVerbose ) { print STDOUT $command.$args."\n"; } 440cdf0e10cSrcweir 441cdf0e10cSrcweir my $rc = system( $command.$args ); 442cdf0e10cSrcweir 443cdf0e10cSrcweir if( $rc < 0 ){ print STDERR "ERROR: localize rc = $rc\n"; exit( -1 ); } 444cdf0e10cSrcweir ( $localizehash_ref ) = read_file( $localizeSDF , $langhash_ref ); 445cdf0e10cSrcweir 446cdf0e10cSrcweir } 447cdf0e10cSrcweir ## Get sdf particles 448cdf0e10cSrcweir#***************** 449cdf0e10cSrcweir open ALLPARTICLES_MERGED , "+>> $particleSDF_merged" 450cdf0e10cSrcweir or die "Can't open $particleSDF_merged"; 451cdf0e10cSrcweir 452cdf0e10cSrcweir ## Fill fackback hash 453cdf0e10cSrcweir my( $fallbackhashhash_ref ) = fetch_fallback( \@sdfparticles , $localizeSDF , $langhash_ref ); 454cdf0e10cSrcweir my %block; 455cdf0e10cSrcweir my $cur_fallback; 456cdf0e10cSrcweir if( !$bAll) { 457cdf0e10cSrcweir foreach my $cur_lang ( keys( %{ $langhash_ref } ) ){ 458cdf0e10cSrcweir #print STDOUT "DBG: G1 cur_lang=$cur_lang\n"; 459cdf0e10cSrcweir $cur_fallback = $langhash_ref->{ $cur_lang }; 460cdf0e10cSrcweir if( $cur_fallback ne "" ){ 461cdf0e10cSrcweir # Insert fallback strings 462cdf0e10cSrcweir #print STDOUT "DBG: Renaming $cur_fallback to $cur_lang in fallbackhash\n"; 463cdf0e10cSrcweir rename_language( $fallbackhashhash_ref , $cur_fallback , $cur_lang ); 464cdf0e10cSrcweir } 465cdf0e10cSrcweir foreach my $currentfile ( @sdfparticles ){ 466cdf0e10cSrcweir if ( open MYFILE , "< $currentfile" ) { 467cdf0e10cSrcweir while(<MYFILE>){ 468cdf0e10cSrcweir if( /$sdf_regex/ ){ 469cdf0e10cSrcweir my $line = defined $_ ? $_ : ''; 470cdf0e10cSrcweir my $prj = defined $3 ? $3 : ''; 471cdf0e10cSrcweir my $file = defined $4 ? $4 : ''; 472cdf0e10cSrcweir my $type = defined $6 ? $6 : ''; 473cdf0e10cSrcweir my $gid = defined $7 ? $7 : ''; 474cdf0e10cSrcweir my $lid = defined $8 ? $8 : ''; 475cdf0e10cSrcweir my $lang = defined $12 ? $12 : ''; 476cdf0e10cSrcweir my $plattform = defined $10 ? $10 : ''; 477cdf0e10cSrcweir my $helpid = defined $9 ? $9 : ''; 478cdf0e10cSrcweir 479cdf0e10cSrcweir chomp( $line ); 480cdf0e10cSrcweir 481cdf0e10cSrcweir if ( $lang eq $cur_lang ){ 482cdf0e10cSrcweir # Overwrite fallback strings with collected strings 483cdf0e10cSrcweir #if( ( !has_two_sourcelanguages( $cur_lang) && $cur_lang eq "de" ) || $cur_lang ne "en-US" ){ 484cdf0e10cSrcweir $fallbackhashhash_ref->{ $cur_lang }{ $prj.$gid.$lid.$file.$type.$plattform.$helpid } = $line ; 485cdf0e10cSrcweir #} 486cdf0e10cSrcweir 487cdf0e10cSrcweir } 488cdf0e10cSrcweir } 489cdf0e10cSrcweir } 490cdf0e10cSrcweir }else { print STDERR "WARNING: Can't open file $currentfile"; } 491cdf0e10cSrcweir } 492cdf0e10cSrcweir 493cdf0e10cSrcweir foreach my $line ( keys( %{$fallbackhashhash_ref->{ $cur_lang } } )) { 494cdf0e10cSrcweir if( #$cur_lang ne "de" && 495cdf0e10cSrcweir $cur_lang ne "en-US" ){ 496cdf0e10cSrcweir print ALLPARTICLES_MERGED ( $fallbackhashhash_ref->{ $cur_lang }{ $line }, "\n" ); 497cdf0e10cSrcweir } 498cdf0e10cSrcweir } 499cdf0e10cSrcweir } 500cdf0e10cSrcweir } else { 501cdf0e10cSrcweir foreach my $currentfile ( @sdfparticles ){ 502cdf0e10cSrcweir if ( open MYFILE , "< $currentfile" ) { 503cdf0e10cSrcweir while( <MYFILE> ){ 504cdf0e10cSrcweir print ALLPARTICLES_MERGED ( $_, "\n" ); # recheck de / en-US ! 505cdf0e10cSrcweir } 506cdf0e10cSrcweir } 507cdf0e10cSrcweir else { print STDERR "WARNING: Can't open file $currentfile"; } 508cdf0e10cSrcweir } 509cdf0e10cSrcweir } 510cdf0e10cSrcweir close ALLPARTICLES_MERGED; 511cdf0e10cSrcweir 512cdf0e10cSrcweir # Hash of array 513cdf0e10cSrcweir my %output; 514cdf0e10cSrcweir my @order; 515cdf0e10cSrcweir 516cdf0e10cSrcweir ## Join both 517cdf0e10cSrcweir if( $outputfile ){ 518cdf0e10cSrcweir if( open DESTFILE , "+> $outputfile" ){ 519cdf0e10cSrcweir if( !open LOCALIZEPARTICLE , "< $localizeSDF" ) { print STDERR "ERROR: Can't open file $localizeSDF\n"; } 520cdf0e10cSrcweir if( !open ALLPARTICLES_MERGED , "< $particleSDF_merged" ) { print STDERR "ERROR: Can't open file $particleSDF_merged\n"; } 521cdf0e10cSrcweir 522cdf0e10cSrcweir # Insert localize 523cdf0e10cSrcweir my $extract_date=""; 524cdf0e10cSrcweir while ( <LOCALIZEPARTICLE> ){ 525cdf0e10cSrcweir if( /$sdf_regex/ ){ 526cdf0e10cSrcweir my $leftpart = defined $2 ? $2 : ''; 527cdf0e10cSrcweir my $lang = defined $12 ? $12 : ''; 528cdf0e10cSrcweir my $rightpart = defined $13 ? $13 : ''; 529cdf0e10cSrcweir my $timestamp = defined $18 ? $18 : ''; 530cdf0e10cSrcweir 531cdf0e10cSrcweir my $prj = defined $3 ? $3 : ''; 532cdf0e10cSrcweir my $file = defined $4 ? $4 : ''; 533cdf0e10cSrcweir my $type = defined $6 ? $6 : ''; 534cdf0e10cSrcweir my $gid = defined $7 ? $7 : ''; 535cdf0e10cSrcweir my $lid = defined $8 ? $8 : ''; 536cdf0e10cSrcweir #my $lang = defined $12 ? $12 : ''; 537cdf0e10cSrcweir my $plattform = defined $10 ? $10 : ''; 538cdf0e10cSrcweir my $helpid = defined $9 ? $9 : ''; 539cdf0e10cSrcweir 540cdf0e10cSrcweir 541cdf0e10cSrcweir if( $use_default_date ) 542cdf0e10cSrcweir { 543cdf0e10cSrcweir $extract_date = "$default_date\n" ; 544cdf0e10cSrcweir } 545cdf0e10cSrcweir elsif( $extract_date eq "" ) { 546cdf0e10cSrcweir $extract_date = $timestamp ; 547cdf0e10cSrcweir $extract_date =~ tr/\r\n//d; 548cdf0e10cSrcweir $extract_date .= "\n"; 549cdf0e10cSrcweir } 550cdf0e10cSrcweir 551cdf0e10cSrcweir if( $bAll ){ print DESTFILE $leftpart."\t".$lang."\t".$rightpart.$extract_date ; } 552cdf0e10cSrcweir else { 553cdf0e10cSrcweir foreach my $sLang ( keys( %{ $langhash_ref } ) ){ 554cdf0e10cSrcweir if( $sLang=~ /all/i ) { 555cdf0e10cSrcweir push @{ $output{ $prj.$gid.$lid.$file.$type.$plattform.$helpid } } , $leftpart."\t".$lang."\t".$rightpart.$extract_date ; 556cdf0e10cSrcweir #print DESTFILE $leftpart."\t".$lang."\t".$rightpart.$extract_date; 557cdf0e10cSrcweir } 558cdf0e10cSrcweir #if( $sLang eq "de" && $lang eq "de" ) { 559cdf0e10cSrcweir # push @{ $output{ $prj.$gid.$lid.$file.$type.$plattform.$helpid } } , $leftpart."\t".$lang."\t".$rightpart.$extract_date ; 560cdf0e10cSrcweir #print DESTFILE $leftpart."\t".$lang."\t".$rightpart.$extract_date; 561cdf0e10cSrcweir #} 562cdf0e10cSrcweir if( $sLang eq "en-US" && $lang eq "en-US" ) { 563cdf0e10cSrcweir push @order , $prj.$gid.$lid.$file.$type.$plattform.$helpid; 564cdf0e10cSrcweir if( !$bFakeEnglish ){ push @{ $output{ $prj.$gid.$lid.$file.$type.$plattform.$helpid } } , $leftpart."\t".$lang."\t".$rightpart.$extract_date ; } 565cdf0e10cSrcweir #print DESTFILE $leftpart."\t".$lang."\t".$rightpart.$extract_date; 566cdf0e10cSrcweir } 567cdf0e10cSrcweir 568cdf0e10cSrcweir } 569cdf0e10cSrcweir } 570cdf0e10cSrcweir } 571cdf0e10cSrcweir } 572cdf0e10cSrcweir # Insert particles 573cdf0e10cSrcweir while ( <ALLPARTICLES_MERGED> ){ 574cdf0e10cSrcweir if( /$sdf_regex/ ){ 575cdf0e10cSrcweir my $leftpart = defined $2 ? $2 : ''; 576cdf0e10cSrcweir my $prj = defined $3 ? $3 : ''; 577cdf0e10cSrcweir my $lang = defined $12 ? $12 : ''; 578cdf0e10cSrcweir my $rightpart = defined $13 ? $13 : ''; 579cdf0e10cSrcweir my $timestamp = defined $18 ? $18 : ''; 580cdf0e10cSrcweir 581cdf0e10cSrcweir #my $prj = defined $3 ? $3 : ''; 582cdf0e10cSrcweir my $file = defined $4 ? $4 : ''; 583cdf0e10cSrcweir my $type = defined $6 ? $6 : ''; 584cdf0e10cSrcweir my $gid = defined $7 ? $7 : ''; 585cdf0e10cSrcweir my $lid = defined $8 ? $8 : ''; 586cdf0e10cSrcweir #my $lang = defined $12 ? $12 : ''; 587cdf0e10cSrcweir my $plattform = defined $10 ? $10 : ''; 588cdf0e10cSrcweir my $helpid = defined $9 ? $9 : ''; 589cdf0e10cSrcweir 590cdf0e10cSrcweir 591cdf0e10cSrcweir if( $use_default_date ) 592cdf0e10cSrcweir { 593cdf0e10cSrcweir $extract_date = "$default_date\n" ; 594cdf0e10cSrcweir } 595cdf0e10cSrcweir elsif( $extract_date eq "" ) 596cdf0e10cSrcweir { 597cdf0e10cSrcweir $extract_date = $timestamp; 598cdf0e10cSrcweir } 599cdf0e10cSrcweir 600cdf0e10cSrcweir if( ! ( $prj =~ /binfilter/i ) ) { 601cdf0e10cSrcweir push @{ $output{ $prj.$gid.$lid.$file.$type.$plattform.$helpid } } , $leftpart."\t".$lang."\t".$rightpart.$extract_date ; 602cdf0e10cSrcweir #print DESTFILE $leftpart."\t".$lang."\t".$rightpart.$extract_date ; 603cdf0e10cSrcweir } 604cdf0e10cSrcweir } 605cdf0e10cSrcweir } 606cdf0e10cSrcweir 607cdf0e10cSrcweir # Write! 608cdf0e10cSrcweir foreach my $curkey ( @order ){ 609cdf0e10cSrcweir foreach my $curlist ( $output{ $curkey } ){ 610cdf0e10cSrcweir foreach my $line ( @{$curlist} ){ 611cdf0e10cSrcweir print DESTFILE $line; 612cdf0e10cSrcweir } 613cdf0e10cSrcweir } 614cdf0e10cSrcweir } 615cdf0e10cSrcweir 616cdf0e10cSrcweir }else { print STDERR "Can't open $outputfile";} 617cdf0e10cSrcweir } 618cdf0e10cSrcweir close DESTFILE; 619cdf0e10cSrcweir close LOCALIZEPARTICLE; 620cdf0e10cSrcweir close ALLPARTICLES_MERGED; 621cdf0e10cSrcweir chdir $working_path; 622cdf0e10cSrcweir 623cdf0e10cSrcweir #print STDOUT "DBG: \$localizeSDF $localizeSDF \$particleSDF_merged $particleSDF_merged\n"; 624cdf0e10cSrcweir unlink $localizeSDF , $particleSDF_merged , $my_localize_log; 625cdf0e10cSrcweir 626cdf0e10cSrcweir #sort_outfile( $outputfile ); 627cdf0e10cSrcweir #remove_obsolete( $outputfile ) , if $bHasSourceLanguage ne ""; 628cdf0e10cSrcweir } 629cdf0e10cSrcweir 630cdf0e10cSrcweir######################################################### 631cdf0e10cSrcweirsub remove_obsolete{ 632cdf0e10cSrcweir my $outfile = shift; 633cdf0e10cSrcweir my @lines; 634cdf0e10cSrcweir my $enusleftpart; 635cdf0e10cSrcweir my @good_lines; 636cdf0e10cSrcweir 637cdf0e10cSrcweir print STDOUT "### Removing obsolete strings\n"; 638cdf0e10cSrcweir 639cdf0e10cSrcweir # Kick out all strings without en-US reference 640cdf0e10cSrcweir if ( open ( SORTEDFILE , "< $outfile" ) ){ 641cdf0e10cSrcweir while( <SORTEDFILE> ){ 642cdf0e10cSrcweir if( /$sdf_regex/ ){ 643cdf0e10cSrcweir my $line = defined $_ ? $_ : ''; 644cdf0e10cSrcweir my $language = defined $12 ? $12 : ''; 645cdf0e10cSrcweir my $prj = defined $3 ? $3 : ''; 646cdf0e10cSrcweir my $file = defined $4 ? $4 : ''; 647cdf0e10cSrcweir my $type = defined $6 ? $6 : ''; 648cdf0e10cSrcweir my $gid = defined $7 ? $7 : ''; 649cdf0e10cSrcweir my $lid = defined $8 ? $8 : ''; 650cdf0e10cSrcweir my $plattform = defined $10 ? $10 : ''; 651cdf0e10cSrcweir my $helpid = defined $9 ? $9 : ''; 652cdf0e10cSrcweir 653cdf0e10cSrcweir my $leftpart = $prj.$gid.$lid.$file.$type.$plattform.$helpid; 654cdf0e10cSrcweir 655cdf0e10cSrcweir if( $language eq "en-US" ){ # source string found, 1. entry 656cdf0e10cSrcweir $enusleftpart = $leftpart; 657cdf0e10cSrcweir push @good_lines , $line; 658cdf0e10cSrcweir }else{ 659cdf0e10cSrcweir if( !defined $enusleftpart or !defined $leftpart ){ 660cdf0e10cSrcweir print STDERR "BADLINE: $line\n"; 661cdf0e10cSrcweir print STDERR "\$enusleftpart = $enusleftpart\n"; 662cdf0e10cSrcweir print STDERR "\$leftpart = $leftpart\n"; 663cdf0e10cSrcweir } 664cdf0e10cSrcweir if( $enusleftpart eq $leftpart ){ # matching language 665cdf0e10cSrcweir push @good_lines , $line; 666cdf0e10cSrcweir } 667cdf0e10cSrcweir #else{ 668cdf0e10cSrcweir # print STDERR "OUT: \$enusleftpart=$enusleftpart \$leftpart=$leftpart \$line=$line\n"; 669cdf0e10cSrcweir #} 670cdf0e10cSrcweir } 671cdf0e10cSrcweir } 672cdf0e10cSrcweir } 673cdf0e10cSrcweir close SORTEDFILE; 674cdf0e10cSrcweir } else { print STDERR "ERROR: Can't open file $outfile\n";} 675cdf0e10cSrcweir 676cdf0e10cSrcweir # Write file 677cdf0e10cSrcweir if ( open ( SORTEDFILE , "> $outfile" ) ){ 678cdf0e10cSrcweir foreach my $newline ( @good_lines ) { 679cdf0e10cSrcweir print SORTEDFILE $newline; 680cdf0e10cSrcweir } 681cdf0e10cSrcweir close SORTEDFILE; 682cdf0e10cSrcweir } else { print STDERR "ERROR: Can't open file $outfile\n";} 683cdf0e10cSrcweir 684cdf0e10cSrcweir} 685cdf0e10cSrcweir######################################################### 686cdf0e10cSrcweirsub sort_outfile{ 687cdf0e10cSrcweir my $outfile = shift; 688cdf0e10cSrcweir print STDOUT "### Sorting ... $outfile ..."; 689cdf0e10cSrcweir my @lines; 690cdf0e10cSrcweir my @sorted_lines; 691cdf0e10cSrcweir 692cdf0e10cSrcweir 693cdf0e10cSrcweir #if ( open ( SORTEDFILE , "< $outputfile" ) ){ 694cdf0e10cSrcweir if ( open ( SORTEDFILE , "< $outfile" ) ){ 695cdf0e10cSrcweir my $line; 696cdf0e10cSrcweir while ( <SORTEDFILE> ){ 697cdf0e10cSrcweir $line = $_; 698cdf0e10cSrcweir if( $line =~ /^[^\#]/ ){ 699cdf0e10cSrcweir push @lines , $line; 700cdf0e10cSrcweir } 701cdf0e10cSrcweir } 702cdf0e10cSrcweir close SORTEDFILE; 703cdf0e10cSrcweir @sorted_lines = sort { 704cdf0e10cSrcweir my $xa_lang = ""; 705cdf0e10cSrcweir my $xa_left_part = ""; 706cdf0e10cSrcweir my $xa_right_part = ""; 707cdf0e10cSrcweir my $xa_timestamp = ""; 708cdf0e10cSrcweir my $xb_lang = ""; 709cdf0e10cSrcweir my $xb_left_part = ""; 710cdf0e10cSrcweir my $xb_right_part = ""; 711cdf0e10cSrcweir my $xb_timestamp = ""; 712cdf0e10cSrcweir my $xa = ""; 713cdf0e10cSrcweir my $xb = ""; 714cdf0e10cSrcweir my @alist; 715cdf0e10cSrcweir my @blist; 716cdf0e10cSrcweir 717cdf0e10cSrcweir if( $a=~ /$sdf_regex/ ){ 718cdf0e10cSrcweir $xa_left_part = defined $2 ? $2 : ''; 719cdf0e10cSrcweir $xa_lang = defined $12 ? $12 : ''; 720cdf0e10cSrcweir $xa_right_part = defined $13 ? $13 : ''; 721cdf0e10cSrcweir $xa_left_part = remove_last_column( $xa_left_part ); 722cdf0e10cSrcweir 723cdf0e10cSrcweir } 724cdf0e10cSrcweir if( $b=~ /$sdf_regex/ ){ 725cdf0e10cSrcweir $xb_left_part = defined $2 ? $2 : ''; 726cdf0e10cSrcweir $xb_lang = defined $12 ? $12 : ''; 727cdf0e10cSrcweir $xb_right_part = defined $13 ? $13 : ''; 728cdf0e10cSrcweir $xb_left_part = remove_last_column( $xb_left_part ); 729cdf0e10cSrcweir 730cdf0e10cSrcweir 731cdf0e10cSrcweir } 732cdf0e10cSrcweir if( ( $xa_left_part cmp $xb_left_part ) == 0 ){ # Left part equal 733cdf0e10cSrcweir if( ( $xa_lang cmp $xb_lang ) == 0 ){ # Lang equal 734cdf0e10cSrcweir return ( $xa_right_part cmp $xb_right_part ); # Right part compare 735cdf0e10cSrcweir } 736cdf0e10cSrcweir elsif( $xa_lang eq "en-US" ) { return -1; } # en-US wins 737cdf0e10cSrcweir elsif( $xb_lang eq "en-US" ) { return 1; } # en-US wins 738cdf0e10cSrcweir else { return $xa_lang cmp $xb_lang; } # lang compare 739cdf0e10cSrcweir } 740cdf0e10cSrcweir else { 741cdf0e10cSrcweir return $xa_left_part cmp $xb_left_part; # Left part compare 742cdf0e10cSrcweir } 743cdf0e10cSrcweir } @lines; 744cdf0e10cSrcweir 745cdf0e10cSrcweir if ( open ( SORTEDFILE , "> $outfile" ) ){ 746cdf0e10cSrcweir print SORTEDFILE get_license_header(); 747cdf0e10cSrcweir foreach my $newline ( @sorted_lines ) { 748cdf0e10cSrcweir print SORTEDFILE $newline; 749cdf0e10cSrcweir #print STDOUT $newline; 750cdf0e10cSrcweir } 751cdf0e10cSrcweir } 752cdf0e10cSrcweir close SORTEDFILE; 753cdf0e10cSrcweir } else { print STDERR "WARNING: Can't open file $outfile\n";} 754cdf0e10cSrcweir print "done\n"; 755cdf0e10cSrcweir 756cdf0e10cSrcweir} 757cdf0e10cSrcweir######################################################### 758cdf0e10cSrcweirsub remove_last_column{ 759cdf0e10cSrcweir my $string = shift; 760cdf0e10cSrcweir my @alist = split ( "\t" , $string ); 761cdf0e10cSrcweir pop @alist; 762cdf0e10cSrcweir return join( "\t" , @alist ); 763cdf0e10cSrcweir} 764cdf0e10cSrcweir 765cdf0e10cSrcweir######################################################### 766cdf0e10cSrcweirsub rename_language{ 767cdf0e10cSrcweir my $fallbackhashhash_ref = shift; 768cdf0e10cSrcweir my $cur_fallback = shift; 769cdf0e10cSrcweir my $cur_lang = shift; 770cdf0e10cSrcweir my $line; 771cdf0e10cSrcweir 772cdf0e10cSrcweir foreach my $key( keys ( %{ $fallbackhashhash_ref->{ $cur_fallback } } ) ){ 773cdf0e10cSrcweir $line = $fallbackhashhash_ref->{ $cur_fallback }{ $key }; 774cdf0e10cSrcweir if( $line =~ /$sdf_regex/ ){ 775cdf0e10cSrcweir my $leftpart = defined $2 ? $2 : ''; 776cdf0e10cSrcweir my $lang = defined $12 ? $12 : ''; 777cdf0e10cSrcweir my $rightpart = defined $13 ? $13 : ''; 778cdf0e10cSrcweir 779cdf0e10cSrcweir $fallbackhashhash_ref->{ $cur_lang }{ $key } = $leftpart."\t".$cur_lang."\t".$rightpart; 780cdf0e10cSrcweir } 781cdf0e10cSrcweir } 782cdf0e10cSrcweir} 783cdf0e10cSrcweir 784cdf0e10cSrcweir############################################################ 785cdf0e10cSrcweirsub remove_duplicates{ 786cdf0e10cSrcweir my $list_ref = shift; 787cdf0e10cSrcweir my %tmphash; 788cdf0e10cSrcweir foreach my $key ( @{ $list_ref } ){ $tmphash{ $key } = '' ; } 789cdf0e10cSrcweir @{$list_ref} = keys( %tmphash ); 790cdf0e10cSrcweir} 791cdf0e10cSrcweir 792cdf0e10cSrcweir############################################################## 793cdf0e10cSrcweirsub fetch_fallback{ 794cdf0e10cSrcweir my $sdfparticleslist_ref = shift; 795cdf0e10cSrcweir my $localizeSDF = shift; 796cdf0e10cSrcweir my $langhash_ref = shift; 797cdf0e10cSrcweir my %fallbackhashhash; 798cdf0e10cSrcweir my $cur_lang; 799cdf0e10cSrcweir my @langlist; 800cdf0e10cSrcweir 801cdf0e10cSrcweir foreach my $key ( keys ( %{ $langhash_ref } ) ){ 802cdf0e10cSrcweir $cur_lang = $langhash_ref->{ $key }; 803cdf0e10cSrcweir if ( $cur_lang ne "" ) { 804cdf0e10cSrcweir push @langlist , $cur_lang; 805cdf0e10cSrcweir } 806cdf0e10cSrcweir } 807cdf0e10cSrcweir remove_duplicates( \@langlist ); 808cdf0e10cSrcweir foreach $cur_lang ( @langlist ){ 809cdf0e10cSrcweir if( $cur_lang eq "en-US" ){ 810cdf0e10cSrcweir read_fallbacks_from_source( $localizeSDF , $cur_lang , \%fallbackhashhash ); 811cdf0e10cSrcweir } 812cdf0e10cSrcweir } 813cdf0e10cSrcweir 814cdf0e10cSrcweir # remove de / en-US 815cdf0e10cSrcweir my @tmplist; 816cdf0e10cSrcweir foreach $cur_lang( @langlist ){ 817cdf0e10cSrcweir if( $cur_lang ne "en-US" ){ 818cdf0e10cSrcweir push @tmplist , $cur_lang; 819cdf0e10cSrcweir 820cdf0e10cSrcweir } 821cdf0e10cSrcweir } 822cdf0e10cSrcweir @langlist = @tmplist; 823cdf0e10cSrcweir if ( $#langlist +1 ){ 824cdf0e10cSrcweir read_fallbacks_from_particles( $sdfparticleslist_ref , \@langlist , \%fallbackhashhash ); 825cdf0e10cSrcweir 826cdf0e10cSrcweir } 827cdf0e10cSrcweir return (\%fallbackhashhash); 828cdf0e10cSrcweir} 829cdf0e10cSrcweir 830cdf0e10cSrcweir######################################################### 831cdf0e10cSrcweirsub write_file{ 832cdf0e10cSrcweir 833cdf0e10cSrcweir my $localizeFile = shift; 834cdf0e10cSrcweir my $index_ref = shift; 835cdf0e10cSrcweir 836cdf0e10cSrcweir if( open DESTFILE , "+> $localizeFile" ){ 837cdf0e10cSrcweir foreach my $key( %{ $index_ref } ){ 838cdf0e10cSrcweir print DESTFILE ($index_ref->{ $key }, "\n" ); 839cdf0e10cSrcweir } 840cdf0e10cSrcweir close DESTFILE; 841cdf0e10cSrcweir }else { 842cdf0e10cSrcweir print STDERR "Can't open/create '$localizeFile'"; 843cdf0e10cSrcweir } 844cdf0e10cSrcweir} 845cdf0e10cSrcweir 846cdf0e10cSrcweir######################################################### 847cdf0e10cSrcweirsub read_file{ 848cdf0e10cSrcweir 849cdf0e10cSrcweir my $sdffile = shift; 850cdf0e10cSrcweir my $langhash_ref = shift; 851cdf0e10cSrcweir my %block = (); 852cdf0e10cSrcweir 853cdf0e10cSrcweir open MYFILE , "< $sdffile" 854cdf0e10cSrcweir or die "Can't open '$sdffile'\n"; 855cdf0e10cSrcweir while( <MYFILE>){ 856cdf0e10cSrcweir if( /$sdf_regex/ ){ 857cdf0e10cSrcweir my $line = defined $_ ? $_ : ''; 858cdf0e10cSrcweir my $prj = defined $3 ? $3 : ''; 859cdf0e10cSrcweir my $file = defined $4 ? $4 : ''; 860cdf0e10cSrcweir my $type = defined $6 ? $6 : ''; 861cdf0e10cSrcweir my $gid = defined $7 ? $7 : ''; 862cdf0e10cSrcweir my $lid = defined $8 ? $8 : ''; 863cdf0e10cSrcweir my $plattform = defined $10 ? $10 : ''; 864cdf0e10cSrcweir my $lang = defined $12 ? $12 : ''; 865cdf0e10cSrcweir my $helpid = defined $9 ? $9 : ''; 866cdf0e10cSrcweir 867cdf0e10cSrcweir foreach my $isolang ( keys ( %{ $langhash_ref } ) ){ 868cdf0e10cSrcweir if( $isolang=~ /$lang/i || $isolang=~ /all/i ) { $block{$prj.$gid.$lid.$file.$type.$plattform.$helpid } = $line ; } 869cdf0e10cSrcweir } 870cdf0e10cSrcweir } 871cdf0e10cSrcweir } 872cdf0e10cSrcweir return (\%block); 873cdf0e10cSrcweir} 874cdf0e10cSrcweir 875cdf0e10cSrcweir######################################################### 876cdf0e10cSrcweirsub read_fallbacks_from_particles{ 877cdf0e10cSrcweir 878cdf0e10cSrcweir my $sdfparticleslist_ref = shift; 879cdf0e10cSrcweir my $isolanglist_ref = shift; 880cdf0e10cSrcweir my $fallbackhashhash_ref = shift; 881cdf0e10cSrcweir my $block_ref; 882cdf0e10cSrcweir foreach my $currentfile ( @{ $sdfparticleslist_ref } ){ 883cdf0e10cSrcweir if ( open MYFILE , "< $currentfile" ) { 884cdf0e10cSrcweir while(<MYFILE>){ 885cdf0e10cSrcweir if( /$sdf_regex/ ){ 886cdf0e10cSrcweir my $line = defined $_ ? $_ : ''; 887cdf0e10cSrcweir my $prj = defined $3 ? $3 : ''; 888cdf0e10cSrcweir my $file = defined $4 ? $4 : ''; 889cdf0e10cSrcweir my $type = defined $6 ? $6 : ''; 890cdf0e10cSrcweir my $gid = defined $7 ? $7 : ''; 891cdf0e10cSrcweir my $lid = defined $8 ? $8 : ''; 892cdf0e10cSrcweir my $lang = defined $12 ? $12 : ''; 893cdf0e10cSrcweir my $plattform = defined $10 ? $10 : ''; 894cdf0e10cSrcweir my $helpid = defined $9 ? $9 : ''; 895cdf0e10cSrcweir 896cdf0e10cSrcweir chomp( $line ); 897cdf0e10cSrcweir 898cdf0e10cSrcweir foreach my $isolang ( @{$isolanglist_ref} ){ 899cdf0e10cSrcweir if( $isolang=~ /$lang/i ) { 900cdf0e10cSrcweir $fallbackhashhash_ref->{ $isolang }{ $prj.$gid.$lid.$file.$type.$plattform.$helpid } = $line ; 901cdf0e10cSrcweir } 902cdf0e10cSrcweir } 903cdf0e10cSrcweir } 904cdf0e10cSrcweir } 905cdf0e10cSrcweir }else { print STDERR "WARNING: Can't open file $currentfile"; } 906cdf0e10cSrcweir } 907cdf0e10cSrcweir} 908cdf0e10cSrcweir 909cdf0e10cSrcweir######################################################### 910cdf0e10cSrcweirsub read_fallbacks_from_source{ 911cdf0e10cSrcweir 912cdf0e10cSrcweir my $sdffile = shift; 913cdf0e10cSrcweir my $isolang = shift; 914cdf0e10cSrcweir my $fallbackhashhash_ref = shift; 915cdf0e10cSrcweir my $block_ref; 916cdf0e10cSrcweir # read fallback for single file 917cdf0e10cSrcweir open MYFILE , "< $sdffile" 918cdf0e10cSrcweir or die "Can't open '$sdffile'\n"; 919cdf0e10cSrcweir 920cdf0e10cSrcweir while( <MYFILE>){ 921cdf0e10cSrcweir if( /$sdf_regex/ ){ 922cdf0e10cSrcweir my $line = defined $_ ? $_ : ''; 923cdf0e10cSrcweir my $prj = defined $3 ? $3 : ''; 924cdf0e10cSrcweir my $file = defined $4 ? $4 : ''; 925cdf0e10cSrcweir my $type = defined $6 ? $6 : ''; 926cdf0e10cSrcweir my $gid = defined $7 ? $7 : ''; 927cdf0e10cSrcweir my $lid = defined $8 ? $8 : ''; 928cdf0e10cSrcweir my $helpid = defined $9 ? $9 : ''; 929cdf0e10cSrcweir my $lang = defined $12 ? $12 : ''; 930cdf0e10cSrcweir my $plattform = defined $10 ? $10 : ''; 931cdf0e10cSrcweir 932cdf0e10cSrcweir chomp( $line ); 933cdf0e10cSrcweir if( $isolang=~ /$lang/i ) { $fallbackhashhash_ref->{ $isolang }{ $prj.$gid.$lid.$file.$type.$plattform.$helpid } = $line ; 934cdf0e10cSrcweir } 935cdf0e10cSrcweir } 936cdf0e10cSrcweir } 937cdf0e10cSrcweir} 938cdf0e10cSrcweir 939cdf0e10cSrcweir######################################################### 940cdf0e10cSrcweirsub parseLanguages{ 941cdf0e10cSrcweir 942cdf0e10cSrcweir my $bAll; 943cdf0e10cSrcweir my $bUseLocalize; 944cdf0e10cSrcweir my $bHasSourceLanguage=""; 945cdf0e10cSrcweir my $bFakeEnglish=""; 946cdf0e10cSrcweir my %langhash; 947cdf0e10cSrcweir my $iso=""; 948cdf0e10cSrcweir my $fallback=""; 949cdf0e10cSrcweir 950cdf0e10cSrcweir #### -l all 951cdf0e10cSrcweir if( $languages=~ /all/ ){ 952cdf0e10cSrcweir $bAll = "TRUE"; 953cdf0e10cSrcweir $bHasSourceLanguage = "TRUE"; 954cdf0e10cSrcweir } 955cdf0e10cSrcweir ### -l fr=de,de 956cdf0e10cSrcweir elsif( $languages=~ /.*,.*/ ){ 957cdf0e10cSrcweir my @tmpstr = split "," , $languages; 958cdf0e10cSrcweir for my $lang ( @tmpstr ){ 959cdf0e10cSrcweir if( $lang=~ /([a-zA-Z]{2,3}(-[a-zA-Z\-]*)*)(=([a-zA-Z]{2,3}(-[a-zA-Z\-]*)*))?/ ){ 960cdf0e10cSrcweir $iso = $1; 961cdf0e10cSrcweir $fallback = $4; 962cdf0e10cSrcweir 963cdf0e10cSrcweir if( ( $iso && $iso=~ /(en-US)/i ) || ( $fallback && $fallback=~ /(en-US)/i ) ) { 964cdf0e10cSrcweir $bUseLocalize = "TRUE"; 965cdf0e10cSrcweir } 966cdf0e10cSrcweir if( ( $iso && $iso=~ /(en-US)/i ) ) { 967cdf0e10cSrcweir $bHasSourceLanguage = "TRUE"; 968cdf0e10cSrcweir } 969cdf0e10cSrcweir if( $fallback ) { $langhash{ $iso } = $fallback; } 970cdf0e10cSrcweir else { $langhash{ $iso } = ""; } 971cdf0e10cSrcweir } 972cdf0e10cSrcweir } 973cdf0e10cSrcweir } 974cdf0e10cSrcweir ### -l de 975cdf0e10cSrcweir else{ 976cdf0e10cSrcweir if( $languages=~ /([a-zA-Z]{2,3}(-[a-zA-Z\-]*)*)(=([a-zA-Z]{2,3}(-[a-zA-Z\-]*)*))?/ ){ 977cdf0e10cSrcweir $iso = $1; 978cdf0e10cSrcweir $fallback = $4; 979cdf0e10cSrcweir 980cdf0e10cSrcweir if( ( $iso && $iso=~ /(en-US)/i ) || ( $fallback && $fallback=~ /(en-US)/i ) ) { 981cdf0e10cSrcweir $bUseLocalize = "TRUE"; 982cdf0e10cSrcweir 983cdf0e10cSrcweir } 984cdf0e10cSrcweir if( ( $iso && $iso=~ /(en-US)/i ) ) { 985cdf0e10cSrcweir $bHasSourceLanguage = "TRUE"; 986cdf0e10cSrcweir } 987cdf0e10cSrcweir 988cdf0e10cSrcweir if( $fallback ) { $langhash{ $iso } = $fallback; } 989cdf0e10cSrcweir else { $langhash{ $iso } = ""; } 990cdf0e10cSrcweir } 991cdf0e10cSrcweir } 992cdf0e10cSrcweir # HACK en-US always needed! 993cdf0e10cSrcweir if( !$bHasSourceLanguage ){ 994cdf0e10cSrcweir #$bHasSourceLanguage = "TRUE"; 995cdf0e10cSrcweir $bUseLocalize = "TRUE"; 996cdf0e10cSrcweir $bFakeEnglish = "TRUE"; 997cdf0e10cSrcweir $langhash{ "en-US" } = ""; 998cdf0e10cSrcweir } 999cdf0e10cSrcweir return ( $bAll , $bUseLocalize , \%langhash , $bHasSourceLanguage, $bFakeEnglish); 1000cdf0e10cSrcweir} 1001cdf0e10cSrcweir 1002cdf0e10cSrcweir######################################################### 1003cdf0e10cSrcweirsub parse_options{ 1004cdf0e10cSrcweir 1005cdf0e10cSrcweir my $help; 1006cdf0e10cSrcweir my $merge; 1007cdf0e10cSrcweir my $extract; 1008cdf0e10cSrcweir my $success = GetOptions('f=s' => \$sdffile , 'l=s' => \$languages , 's=s' => \$srcpath , 'h' => \$help , 'v' => \$bVerbose , 1009cdf0e10cSrcweir 'm' => \$merge , 'e' => \$extract , 'x' => \$no_sort , 'd' => \$use_default_date , 'c' => \$create_dirs , 1010cdf0e10cSrcweir 'n' => \$no_gsicheck , 'o' => \$force_ooo_module ); 1011cdf0e10cSrcweir $outputfile = $sdffile; 1012cdf0e10cSrcweir 1013cdf0e10cSrcweir #print STDOUT "DBG: lang = $languages\n"; 1014cdf0e10cSrcweir if( !$srcpath ){ 1015cdf0e10cSrcweir $srcpath = "$ENV{SRC_ROOT}"; 1016cdf0e10cSrcweir if( !$srcpath ){ 1017cdf0e10cSrcweir print STDERR "No path to the source root found!\n\n"; 1018cdf0e10cSrcweir usage(); 1019cdf0e10cSrcweir exit(1); 1020cdf0e10cSrcweir } 1021cdf0e10cSrcweir } 1022cdf0e10cSrcweir if( $help ){ 1023cdf0e10cSrcweir usage(); 1024cdf0e10cSrcweir exit(0); 1025cdf0e10cSrcweir } 1026cdf0e10cSrcweir if( !$success || $#ARGV > 1 || ( !$sdffile ) ){ 1027cdf0e10cSrcweir usage(); 1028cdf0e10cSrcweir exit(1); 1029cdf0e10cSrcweir } 1030cdf0e10cSrcweir if( $merge && $sdffile && ! ( -r $sdffile)){ 1031cdf0e10cSrcweir print STDERR "Can't open file '$sdffile'\n"; 1032cdf0e10cSrcweir exit(1); 1033cdf0e10cSrcweir } 1034cdf0e10cSrcweir 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\-]*)*)?)*/ ) ){ 1035cdf0e10cSrcweir print STDERR "Please check the -l iso code\n"; 1036cdf0e10cSrcweir exit(1); 1037cdf0e10cSrcweir } 1038cdf0e10cSrcweir if( ( !$merge && !$extract ) || ( $merge && $extract ) ){ usage();exit( -1 );} 1039cdf0e10cSrcweir if( $extract ){ $mode = "extract"; } 1040cdf0e10cSrcweir else { $mode = "merge"; } 1041cdf0e10cSrcweir} 1042cdf0e10cSrcweir#my $multi_localize_files = ''; h 1043cdf0e10cSrcweir#my $module_to_merge = ''; i 1044cdf0e10cSrcweir#my $sort_sdf_before = ''; g 1045cdf0e10cSrcweir 1046cdf0e10cSrcweir######################################################### 1047cdf0e10cSrcweirsub usage{ 1048cdf0e10cSrcweir 1049cdf0e10cSrcweir print STDERR "Usage: localize.pl\n"; 1050cdf0e10cSrcweir print STDERR "Split or collect SDF files\n"; 1051cdf0e10cSrcweir print STDERR " merge: -m -f <sdffile> -l l1[=f1][,l2[=f2]][...] [ -s <sourceroot> ] [ -c ]\n"; 1052cdf0e10cSrcweir print STDERR " extract: -e -f <outputfile> -l <lang> [ -s <sourceroot> ] [-d]\n"; 1053cdf0e10cSrcweir print STDERR "Options:\n"; 1054cdf0e10cSrcweir print STDERR " -h help\n"; 1055cdf0e10cSrcweir print STDERR " -m Merge mode\n"; 1056cdf0e10cSrcweir print STDERR " -e Extract mode\n"; 1057cdf0e10cSrcweir print STDERR " -f <sdffile> To split a big SDF file into particles\n"; 1058cdf0e10cSrcweir print STDERR " <outputfile> To collect and join all particles to one big file\n"; 1059cdf0e10cSrcweir print STDERR " -s <sourceroot> Path to the modules, if no \$SRC_ROOT is set\n"; 1060cdf0e10cSrcweir print STDERR " -l ( all | <isocode> | <isocode>=fallback ) comma seperated languages\n"; 1061cdf0e10cSrcweir print STDERR " -d Use default date in extracted sdf file\n"; 1062cdf0e10cSrcweir print STDERR " -c Create needed directories\n"; 1063cdf0e10cSrcweir print STDERR " -g Sort sdf file before mergeing\n"; 1064cdf0e10cSrcweir print STDERR " -h File with localize.sdf's\n!"; 1065cdf0e10cSrcweir print STDERR " -n No gsicheck\n"; 1066cdf0e10cSrcweir print STDERR " -i Module to merge\n"; 1067cdf0e10cSrcweir print STDERR " -o force using ooo localization from the l10n module instead of l10n_so; \n"; 1068cdf0e10cSrcweir print STDERR " useful if the type can't be detected by the .svn tags; \n"; 1069cdf0e10cSrcweir print STDERR " -v Verbose\n"; 1070cdf0e10cSrcweir print STDERR "\nExample:\n"; 1071cdf0e10cSrcweir 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"; 1072cdf0e10cSrcweir print STDERR "\nlocalize -m -l cs -f my.sdf\n( Merge cs translation into the sourcecode ) \n"; 1073cdf0e10cSrcweir} 1074cdf0e10cSrcweir 1075