portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Enrique Lara" <enriquelara_6...@hotmail.com>
Subject simple localization diff
Date Thu, 11 Mar 2004 15:31:39 GMT
Hello all,
    Sorry about the blank post:  I was having attachment woes with my e-mail 
account.
    In working through the spanish localization file I wanted a way to  
determine which keys were missing/extraneous.
    I tried a quick googling but didn't find anything - so I wrote up a 
quick & dirty perl script to 'diff' two localization files.  FYI the output 
is more of a report than a true diff.

Peace,
Enrique


Usage:
   localization-diff.pl file1 file2

-------------------------------- BEGIN SCRIPT

#!/usr/bin/perl
#
# Copyright 2000-2004 The Apache Software Foundation.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#--------------------------------------------------------------------
#  Purpose : Give a simple "diff" between two turbine localization files.
#            Just tells what keys are missing in the 2nd file
#--------------------------------------------------------------------
# Author: EnriqueLara_6009@hotmail.com
#--------------------------------------------------------------------
use strict;

#----------------------------------------------------------%%%
#Globals
#-------------------------------------------------------------
$| = 1;


my $USAGE ="perl $0 file1 file2\n";
my $file1;
my $file2;

#----------------------------------------------------------%%%
sub parseInput {
	if(scalar(@ARGV) > 1) {
		$file1 = shift(@ARGV);
		$file2 = shift(@ARGV);
	} else {
		return -1;
	}
	return 0;
}

#-----------------------------------------------------------------%%%
sub slurp {
	my ($filename, $hash_ref) = @_;

	open(IN,$filename) || die("Couldn't open $filename for input\n");

	while(<IN>) {
		chomp(my $str = $_);

		my $lineNo = $.;

		if($str =~ /^\#/) { next; }
		($str =~ /.+=.+/) or next;
		my ($key, $value) = split(/=/,$str);
		$key = uc($key);

		if(exists $$hash_ref{$key}) {
			print STDERR "$filename:$lineNo: $key already defined at line 
$$hash_ref{$key}\n";
		} else {
			$$hash_ref{$key} = $lineNo;
		}
	}


	close(IN);
}

#-----------------------------------------------------------------%%%
sub main {
	if(parseInput() != 0) {
		print $USAGE;
		exit(-1);
	}

	my %KEYS1 = ();
	my %KEYS2 = ();

	slurp($file1, \%KEYS1);
	slurp($file2, \%KEYS2);

	print "Analysis of $file2\n";
	foreach my $key1 (sort keys %KEYS1) {
		if(exists $KEYS2{$key1}) {
			#ok
		} else {
			print STDERR "Missing key $key1, See $file1:$KEYS1{$key1}\n";
		}
	}


	foreach my $key2 (sort keys %KEYS2) {
		if(exists $KEYS1{$key2}) {
			#ok
		} else {
			print STDERR "Extra key $key2, $file2:$KEYS2{$key2}\n";
		}
	}

}

main();

1;

__END__

_________________________________________________________________
Las mejores tiendas, los precios mas bajos y las mejores ofertas en MSN 
Latino.   http://latino.msn.com/compras


---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jetspeed-dev-help@jakarta.apache.org


Mime
View raw message