[ Index ]
 

Code source de WebCalendar 1.0.5

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables | Statistiques

title

Body

[fermer]

/tools/ -> check_translation.pl (source)

   1  #!/usr/bin/perl
   2  #
   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
   7  # translation.
   8  #
   9  # Usage:
  10  #    check_translation.pl languagefile
  11  #      ... or to check the most recently modified translation file
  12  #    check_translation.pl
  13  # Example:
  14  #    check_translation.pl ../translations/English-US.txt
  15  #
  16  # Note: this utility should be run from this directory (tools).
  17  #
  18  ###########################################################################
  19  
  20  $trans_dir = "../translations";
  21  
  22  $infile = $ARGV[0];
  23  
  24  if ( $infile eq "" ) {
  25    opendir ( DIR, $trans_dir ) || die "error opening $trans_dir";
  26    @files = grep ( /\.txt$/, readdir ( DIR ) );
  27    closedir ( DIR );
  28    $last_mtime = 0;
  29    foreach $f ( @files ) {
  30      ( $mtime ) = ( stat ( "../translations/$f" ) )[9];
  31      if ( $mtime > $last_mtime ) {
  32        $last_mtime = $mtime;
  33        $infile = "../translations/$f";
  34      }
  35    }
  36  }
  37  
  38  if ( $infile ne "" && ! -f $infile && -f "$trans_dir/$infile" ) {
  39    $infile = "$trans_dir/$infile";
  40  }
  41  
  42  if ( $infile ne "" && ! -f $infile && -f "$trans_dir/$infile.txt" ) {
  43    $infile = "$trans_dir/$infile.txt";
  44  }
  45  
  46  
  47  # First get the list of .php and .inc files.
  48  opendir ( DIR, ".." ) || die "Error opening ..";
  49  @files = grep ( /\.php$/, readdir ( DIR ) );
  50  closedir ( DIR );
  51  
  52  opendir ( DIR, "../includes" ) || die "Error opening ../includes";
  53  @incfiles = grep ( /\.php$/, readdir ( DIR ) );
  54  closedir ( DIR );
  55  foreach $f ( @incfiles ) {
  56    push ( @files, "includes/$f" );
  57  }
  58  opendir ( DIR, "../includes/js" ) || die "Error opening ../includes/js";
  59  @incfiles = grep ( /\.php$/, readdir ( DIR ) );
  60  closedir ( DIR );
  61  foreach $f ( @incfiles ) {
  62    push ( @files, "includes/js/$f" );
  63  }
  64  push ( @files, "tools/send_reminders.php" );
  65  
  66  
  67  foreach $f ( @files ) {
  68    $file = "../$f";
  69    open ( F, $file ) || die "Error reading $file";
  70    #print "Checking $f for text.\n";
  71    while ( <F> ) {
  72      $data = $_;
  73      while ( $data =~ /(translate|tooltip)\s*\(\s*"/ ) {
  74        $data = $';
  75        if ( $data =~ /"\s*\)/ ) {
  76          $text = $`;
  77          $text{$text} = 1;
  78          $data = $';
  79        }
  80      }
  81    }
  82    close ( F );
  83  }
  84  
  85  #print "Found the following entries:\n";
  86  #foreach $text ( sort { uc($a) cmp uc($b) } keys ( %text ) ) {
  87  #  print "$text\n";
  88  #}
  89  
  90  # Now load the translation file
  91  if ( ! -f $infile ) {
  92    die "Usage: $0 translation-file\n";
  93  }
  94  open ( F, $infile ) || die "Error opening $infile";
  95  while ( <F> ) {
  96    chop;
  97    next if ( /^#/ );
  98    if ( /\s*:/ ) {
  99      $abbrev = $`;
 100      $trans{$abbrev} = $';
 101    }
 102  }
 103  
 104  $notfound = 0;
 105  $total = 0;
 106  foreach $text ( sort { uc($a) cmp uc($b) } keys ( %text ) ) {
 107    if ( ! defined ( $trans{$text} ) ) {
 108      if ( ! $notfound ) {
 109        print "The following text did not have a translation in $infile:\n\n";
 110      }
 111      print "$text\n";
 112      $notfound++;
 113    }
 114    $total++;
 115  }
 116  
 117  # Check for translations that are not used...
 118  $extra = 0;
 119  foreach $text ( sort { uc($a) cmp uc($b) } keys ( %trans ) ) {
 120    if ( ! defined ( $text{$text} ) ) {
 121      if ( ! $extra ) {
 122        print "\nThe following translation text is not needed in $infile:\n\n";
 123      }
 124      print "$text\n";
 125      $extra++;
 126    }
 127  }
 128  
 129  if ( ! $notfound ) {
 130    print "All text was found in $infile.  Good job :-)\n";
 131  } else {
 132    printf "\n$notfound of $total translation(s) missing. (%1.1f%% complete)\n", 
 133     ( 100 * ( $total - $notfound ) / $total );
 134  }
 135  
 136  exit 0;


Généré le : Fri Nov 30 19:09:19 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics