#!/usr/bin/perl # This script will test with all messages are present in a translation file # The original messages are allways from english.txt file # # Copyright (C) 2004 Alceu Rodrigues de Freitas Jr. (glasswalk3r@yahoo.com.br) # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program 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 General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. use warnings; use strict; use Getopt::Std; my $version = '0.2'; my %opts; getopts('b:t:hv',\%opts); if ( ( exists($opts{h}) ) and ($opts{h} == 1) ) { print < -t Where: -b identifies the complete pathname to a file that will be used as base to check messages. Usually this is the english.txt file. -t identifies the complete pathname to a file that messages will be checked against the -h shows this help message -v prints program information BLOCK exit; } if ( ( exists($opts{v}) ) and ($opts{v} == 1) ) { print <; close(FILE); # reading original messages while () { next if /^\#/; next unless /=/; chomp; s/\s+=\s+/=/; my @temp = split(/=/,$_); $list{$temp[0]} = [ '0',$temp[1] ]; } close(SOURCE); foreach (@file_content) { next if (/^#/); next unless (/[\w]+/); my @temp = split(/=/,$_); $temp[0] =~ s/\s//g; unless ( exists( $list{$temp[0]} ) ) { print "The message $temp[0] is not valid\n"; $flag++; } else { unless ( $temp[1] =~ /[\w]+/ ) { print "Message $temp[0] has no value\n"; $flag++; # the message exists and have a translated message } else { $list{$temp[0]}->[0] = 1; } } } foreach ( keys(%list) ) { if ($list{$_}->[0] == 0) { print "Message \"$_\" was not found in this translation file\n"; $flag++; $new_messages{$_} = $list{$_}->[1]; } } if ($flag == 0) { print "No errors found: translation file is OK\n"; } else { print "$flag errors where found in the translation file\n"; print "Do you want to create a new file with the missing messages? (y/n) "; my $answer = ; chomp($answer); if ($answer eq 'y') { rename $translationfile,"$translationfile.old"; open(NEW,">$translationfile") || die "Cannot create new translation file $translationfile: $!\n"; foreach (@file_content) { print NEW; } my $key; print NEW <