3 # This tool helps with the translation into other languages by verifying that
4 # all text specified in translate(), etranslate() and etooltip()
5 # within the application has a corresponding entry in the translation
6 # data file. In short, this makes sure all text has a correspoding
10 # check_translation.pl languagefile
11 # ... or to check the most recently modified translation file
12 # check_translation.pl
14 # check_translation.pl ../translations/English-US.txt
16 # Note: this utility should be run from this directory (tools).
18 ###########################################################################
20 $trans_dir = "../translations";
24 if ( $infile eq "" ) {
25 opendir ( DIR, $trans_dir ) || die "error opening $trans_dir";
26 @files = grep ( /\.txt$/, readdir ( DIR ) );
29 foreach $f ( @files ) {
30 ( $mtime ) = ( stat ( "../translations/$f" ) )[9];
31 if ( $mtime > $last_mtime ) {
33 $infile = "../translations/$f";
38 if ( $infile ne "" && ! -f $infile && -f "$trans_dir/$infile" ) {
39 $infile = "$trans_dir/$infile";
42 if ( $infile ne "" && ! -f $infile && -f "$trans_dir/$infile.txt" ) {
43 $infile = "$trans_dir/$infile.txt";
47 # First get the list of .php and .inc files.
48 opendir ( DIR, ".." ) || die "Error opening ..";
49 @files = grep ( /\.php$/, readdir ( DIR ) );
52 opendir ( DIR, "../includes" ) || die "Error opening ../includes";
53 @incfiles = grep ( /\.php$/, readdir ( DIR ) );
55 foreach $f ( @incfiles ) {
56 push ( @files, "includes/$f" );
58 opendir ( DIR, "../includes/js" ) || die "Error opening ../includes/js";
59 @incfiles = grep ( /\.php$/, readdir ( DIR ) );
61 foreach $f ( @incfiles ) {
62 push ( @files, "includes/js/$f" );
64 push ( @files, "tools/send_reminders.php" );
67 foreach $f ( @files ) {
69 open ( F, $file ) || die "Error reading $file";
70 #print "Checking $f for text.\n";
73 while ( $data =~ /(translate|tooltip)\s*\(\s*"/ ) {
75 if ( $data =~ /"\s*\)/ ) {
85 #print "Found the following entries:\n";
86 #foreach $text ( sort { uc($a) cmp uc($b) } keys ( %text ) ) {
90 # Now load the translation file
92 die "Usage: $0 translation-file\n";
94 open ( F, $infile ) || die "Error opening $infile";
100 $trans{$abbrev} = $';
106 foreach $text ( sort { uc($a) cmp uc($b) } keys ( %text ) ) {
107 if ( ! defined ( $trans{$text} ) ) {
109 print "The following text did not have a translation in $infile:\n\n";
117 # Check for translations that are not used...
119 foreach $text ( sort { uc($a) cmp uc($b) } keys ( %trans ) ) {
120 if ( ! defined ( $text{$text} ) ) {
122 print "\nThe following translation text is not needed in $infile:\n\n";
130 print "All text was found in $infile. Good job :-)\n";
132 printf "\n$notfound of $total translation(s) missing. (%1.1f%% complete)\n",
133 ( 100 * ( $total - $notfound ) / $total );