diff options
Diffstat (limited to 'doublecheck.pl')
-rwxr-xr-x | doublecheck.pl | 176 |
1 files changed, 176 insertions, 0 deletions
diff --git a/doublecheck.pl b/doublecheck.pl new file mode 100755 index 0000000..12a8e97 --- /dev/null +++ b/doublecheck.pl @@ -0,0 +1,176 @@ +: +eval 'exec perl -wS $0 ${1+"$@"}' + if 0; +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* +# +# doublecheck - Checks sdf files for identical translations where they have to be unique. +# + +use strict; + +my ($source); +my (%languages, %languages_seen, %Stores, $smodule, $help, $lineOK, $module, $gid, $lid, $lang, $found, $text, $Store_ref, $error, $file, $line, $sfile, $sgid, $slid, $goodlangs ); + +# this string should contain only languages that are known to be well translated i.e. no newly translated languages or even in pregress +$goodlangs = "de fr ja es ko"; + +%languages = (); +%languages_seen = (); +%Stores = (); + +if ( !exists $ENV{ "WITH_LANG" } || !$ENV{ "WITH_LANG" } ) +{ + print "\$WITH_LANG not set or empty: nothing to do\n"; + exit 0; +} + +foreach ( split( " ", $ENV{ "WITH_LANG" } ) ) +{ + $languages{ $_ } = 1; +} + +$smodule = $sfile = $sgid = $slid = ".*"; + + +&get_options; + +if ( ! $source ) +{ + print "Error: No sdf_filename defined\n\n"; + $help = "Yes"; +} +if ( !$help ) +{ + + $found = 0; + open SOURCE, "<$source"; + while ( <SOURCE> ) + { + analyze_line( $_ ); + + $languages_seen{ $lang } = 1 if ( $lineOK ); + + if ( $lineOK && $module =~ $smodule && $file =~ $sfile && $gid =~ $sgid && $lid =~ $slid ) + { + $found += 1; + if ( exists $languages{ $lang } ) + { + if ( !exists $Stores{ $lang } ) + { + my %S = (); + $Stores{ $lang } = \%S; + } + $Store_ref = $Stores{ $lang }; + if ( exists $$Store_ref{ $text } ) + { + print "Entry double for LANG=$lang in file $source\n"; + print $$Store_ref{ $text }; + print $line; + $error = 1; + } + else + { + $$Store_ref{ $text } = $line; + } + } + } + } + close SOURCE; + +# print "$found strings found in $source for -m $smodule -f $sfile -g $sgid -l $slid\n"; + foreach my $goodlang ( split( " ", $goodlangs ) ) + { + if ( exists $languages_seen{ $goodlang } && exists $languages{ $goodlang } && !exists $Stores{ $goodlang } ) + { + die "no sting found to check for language $lang in $source for -m $smodule -f $sfile -g $sgid -l $slid. Maybe the strings have been relocated."; + } + } + die "errors found" if ( $error ); + +} +else +{ + print "\n\n"; + print "doubleckeck v.1.0\n"; + print "---------------------\n"; + print "Usage:\n"; + print "doubleckeck [-m <module>] [-f <filepath>] [-g <GID>] [-l <LID>] <sdf_filename>\n"; + print "doubleckeck --help\n"; + print "\n"; + print "------------------------------------------------------------------------------\n"; + print "Checks sdf files for identical translations where they have to be unique.\n"; + print "The switches -m, -f, -g and -l are treated as perl regular expressions.\n"; + print "They default to .*\n"; + print "All Languages in \$WITH_LANG are checked.\n"; + print "\n\n"; +} + + + +sub get_options { + my ($arg,$has_source); + $has_source = 0; + while ($arg = shift @ARGV) { + $arg =~ /^-m$/ and $smodule = shift @ARGV and next; + $arg =~ /^-f$/ and $sfile = shift @ARGV and next; + $arg =~ /^-g$/ and $sgid = shift @ARGV and next; + $arg =~ /^-l$/ and $slid = shift @ARGV and next; + $arg =~ /^--help$/ and $help = 1 and next; #show help + + if ( !$has_source ) + { + $source = $arg; + $has_source = 1; + } + else + { + die "only one file can be parsed"; + } + } +} + + +sub analyze_line { + + ($line) = @_; + + $lineOK = 0; + if ( $line =~ /^([^\t]*)\t([^\t]*)\t[^\t]*\t[^\t]*\t([^\t]*)\t([^\t]*)\t[^\t]*\t[^\t]*\t[^\t]*\t([^\t]*)\t([^\t]*)\t[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*/ ) + { + $module = $1; + $file = $2; + $gid = $3; + $lid = $4; + + $lang = $5; + $text = $6; + + $lineOK = 1; + } +} + |