[ PHPXref.com ] [ Generated: Sun Jul 20 19:39:24 2008 ] [ PhpGedView 4.0 ]
[ Index ]     [ Variables ]     [ Functions ]     [ Classes ]     [ Constants ]     [ Statistics ]

title

Body

[close]

/ -> checklang.php (source)

   1  <?php
   2  /**
   3   * Check lang files
   4   *
   5   * phpGedView: Genealogy Viewer
   6   * Copyright (C) 2002 to 2005  John Finlay and Others
   7   *
   8   * This program is free software; you can redistribute it and/or modify
   9   * it under the terms of the GNU General Public License as published by
  10   * the Free Software Foundation; either version 2 of the License, or
  11   * (at your option) any later version.
  12   *
  13   * This program is distributed in the hope that it will be useful,
  14   * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16   * GNU General Public License for more details.
  17   *
  18   * You should have received a copy of the GNU General Public License
  19   * along with this program; if not, write to the Free Software
  20   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  21   *
  22   * @package PhpGedView
  23   * @subpackage Languages
  24   * @version $Id: checklang.php,v 1.2.2.2 2006/01/13 23:00:13 yalnifj Exp $
  25   */
  26  // -- include config file
  27  require ("config.php");
  28  require( $factsfile["english"]);
  29  if (file_exists( $factsfile[$LANGUAGE])) require  $factsfile[$LANGUAGE];
  30  
  31  print_header("checklang");
  32  
  33  // args
  34  $lang=@$HTTP_GET_VARS["lang"];
  35  if (!isset($lang)) $lang="";
  36  
  37  // reading flags directory
  38  $flags = array();
  39  $rep = opendir('./images/flags/');
  40  while ($file = readdir($rep)) {
  41      if (stristr($file, ".gif") and $file!="new.gif" and $file!="en.gif") {
  42          $flags[] = substr($file, 0, strlen($file)-4);
  43      }
  44  }
  45  
  46  // show menu
  47  print "<center>";
  48  print "<h2>Check lang files</h2>";
  49  
  50  echo <<< END1
  51  This tool performs a check between english files and
  52  <br />
  53  selected language(s) files to help translators keeping files up-to-date.
  54  <br />
  55  The table shows <i>translated vars / english vars</i> ratio.
  56  <br />
  57  <span class="warning">Results files (*.NEW.php) have to be carefully verified before use.</span>
  58  <br /><br />
  59  END1;
  60  
  61  print "<form action=\"?\">";
  62  print "Select a lang code : <select name=\"lang\">";
  63  print "<option value=\"\">Select...</option>";
  64  print "<option value=\"all\">all</option>";
  65  foreach ($flags as $indexval => $flag) {
  66      print "<option value=\"$flag\"";
  67      if ($flag==$lang) print " selected";
  68      print ">$flag</option>";
  69  }
  70  print "</select>";
  71  print " <input type=\"submit\" value=\"Check\" />";
  72  print "</form>";
  73  print "<br />";
  74  closedir($rep);
  75  clearstatcache();
  76  
  77  // show empty table
  78  print "<table border=\"0\" class=\"facts_table\">";
  79  //print "<table class=\"list_table $TEXT_DIRECTION\">";
  80  print "<tr class=\"facts_label03\">";
  81  print "<td width=\"20%\">lang</td>";
  82  print "<td width=\"20%\">facts</td>";
  83  print "<td width=\"20%\">lang</td>";
  84  print "<td width=\"20%\">configure_help</td>";
  85  print "<td width=\"20%\">help_text</td>";
  86  print "</tr>";
  87  
  88  
  89  if ($lang!="all") {
  90      unset($flags);
  91      if ($lang!="") $flags[] = $lang;
  92  }
  93  if (isset($flags)) foreach ($flags as $indexval => $flag) {
  94      print "<tr class=\"facts_label\"><td><img src=\"images/flags/$flag.gif\" width=\"32\" border=0 alt=\"$flag\" align=\"middle\" /> $flag</td>";
  95      print "<td id=\"$flag.f\" class=\"facts_value\">...</td>";
  96      print "<td id=\"$flag.l\" class=\"facts_value\">...</td>";
  97      print "<td id=\"$flag.c\" class=\"facts_value\">...</td>";
  98      print "<td id=\"$flag.h\" class=\"facts_value\">...</td>";
  99      print "</tr>";
 100  }
 101  print "</table>";
 102  print "</center>";
 103  print "<br /><br />";
 104  print_footer();
 105  flush();
 106  
 107  // process each lang
 108  $path = "languages";
 109  //chdir($path);
 110  if (isset($flags)) foreach ($flags as $indexval => $flag) {
 111      unset($target);
 112      checkfile("$path/facts.en.php");
 113      checkfile("$path/lang.en.php");
 114      checkfile("$path/configure_help.en.php");
 115      checkfile("$path/help_text.en.php");
 116  }
 117  
 118  exit;
 119  
 120  function checkfile($filename) {
 121      global $flag;
 122      global $target;
 123  
 124      set_time_limit(0); //
 125  
 126      // loading source data
 127      if (!$fd = fopen($filename, 'r')) die("Cannot open $filename");
 128      while ($data = fgets($fd)) $source[] = $data;
 129      fclose($fd);
 130  
 131      // loading target data
 132      $filename = str_replace(".en.", ".$flag.", $filename);
 133      if (!$fd = fopen($filename, 'r')) print("Cannot open $filename");
 134      while ($data = @fgets($fd)) {
 135          if (substr($data, 0, 1) == "\$") $target[] = $data; //smart_utf8_decode($data);
 136      }
 137      @fclose($fd);
 138      $target[] = ""; // DO NOT DELETE THIS
 139  
 140      // output file
 141      $filename = str_replace(".php", ".NEW.php", $filename);
 142      if (!$fd = fopen($filename, 'w')) die("Cannot open $filename");
 143  
 144      // process source data
 145      $ok = 0;
 146      $nok = 0;
 147      foreach($source as $indexval => $english) {
 148          if (substr($english, 0, 1) == "\$") {
 149              // print "<br />$english";
 150              $p = strpos($english, "]");
 151              $keyword = substr($english, 0, $p + 1);
 152  
 153              // search for existing translation
 154              foreach($target as $indexval => $translated) {
 155                  if (stristr($translated, $keyword)) break;
 156              }
 157              if ($translated == "") {
 158                  $nok++;
 159                  $translated = "#" . substr($english, 1);
 160              } else $ok++;
 161  
 162              // delete comment
 163  //            $p = @strpos($translated, "//");
 164  //            if ($p > 5) $translated = trim(substr($translated, 0, $p-1));
 165  
 166              // output record
 167              $z = $translated;
 168          } else $z = str_replace(".en.", ".$flag.", $english);
 169  
 170          // output string
 171  //        $z = utf8_encode($z);
 172          $z = str_replace("\r", "", $z);
 173          $z = str_replace("\n", "", $z);
 174          $z = set_tab($z);
 175          $z = $z . "\r\n";
 176          if (strlen($z) > 0) {
 177              if (!fputs($fd, $z, strlen($z))) die("Cannot write to $filename");
 178          }
 179      }
 180      fclose($fd);
 181      ?>
 182     <script type="text/javascript">
 183          var OK = <?php print $ok;?>;
 184          var TOT = <?php print ($ok + $nok);?>;
 185          var ELT = "<?php print "$flag." . substr(basename($filename), 0, 1);?>";
 186          //alert(ELT);
 187          perc = Math.round(100*(OK / TOT));
 188          progress = document.getElementById(ELT);
 189          progress.innerHTML = perc+"%";
 190      </script>
 191      <?php
 192      flush();
 193  }
 194  
 195  function set_tab($z) {
 196      $p = strpos($z, "]");
 197      if ($p < 5) return $z;
 198      if ($p > 50) return $z;
 199  
 200      $q = strpos($z, "=");
 201      if ($q < $p) return $z;
 202  
 203      $label = substr($z, 0, $p + 1);
 204      $value = substr($z, $q);
 205  
 206  //    $space = str_repeat("\t", max(0, (40 - $p) / 4));
 207      $space = str_repeat(" ", max(0, (39 - $p)));
 208  
 209      return $label . $space . $value;
 210  }
 211  
 212  ?>


[ Powered by PHPXref - Served by Debian GNU/Linux ]