Checking Language Files

This php-script can be used to display the lines in the language file that don't exist:

<?php
 
// Lang check
//
// by: Legolas
//
// 
// Parameters:
//   string lang    -> language to check
//   string langdir -> language dir (standard the same dir as where this script is)
//   string english -> language to compare with (standard english)
//   bool table     -> set true if you want the output in a table (standard false)
//
//
 
function langCheck($lang, $langdir = "", $english = "english", $table = false) {
 
   // English (orginal lang) can't be nothing
   if ($english == null) {
      $english = "english";
   }
 
   // Files gone?
   if (!file_exists($langdir . $english . ".php") || !file_exists($langdir . $lang . ".php")) {
      die("<b>Error:</b> One of the files doesn't exist<br />\n");
   }
 
   // Load lang-files
   $englishlines = file($langdir . $english . ".php");
   $dutchlines = file($langdir . $lang . ".php");
 
   // set variables (safety)
   $output = null;
   $textfilecontents = null;
 
   // Load the language file that needs to be tested
   $dutch = array();
   for ($i = 0; $i < count($dutchlines); $i++) {
      // Take only the lines where some lang thing is defined
      if (substr($dutchlines[$i], 0, 6) == "define") {
         // Build the array
         $dutch[] = array("text" => $dutchlines[$i], "line" => $i + 1);
      }
   }
 
   // Now the standard language
   $english = array();
   for ($i = 0; $i < count($englishlines); $i++) {
      // The same goes here
      if (substr($englishlines[$i], 0, 6) == "define") {
         // Create the array
         $english[] = array("text" => $englishlines[$i], "line" => $i + 1);
      }
   }
 
   // Build table headers if set
   if ($table == true) {
      $output .= "<table>\n<tr>\n<td><b>NO.</b></td>\n<td><b>LINE</b></td>\n</tr>\n";
   }
 
   // Loop through the file
   for ($i = 0; $i < count($english); $i++) {
      // Explode it to take the names out
      $tmpa = explode("'", $english[$i]["text"]);
      // Set test var false
      $inc = false;
      for ($j = 0; $j < count($dutch); $j++) {
         // Also take 'em out here
         $tmpb = explode("'", $dutch[$j]["text"]);
         // If the var in both langs exists set the test var true
         if ($tmpa[1] == $tmpb[1]) {
            $inc = true;
         }
      }
      // What if it isn't found?
      if ($inc == false) {
         // Table?
         if ($table == true) {
            $outputline = "<tr>\n<td>" . $english[$i]["line"] . ". </td>\n<td>" . htmlentities($english[$i]["text"]) . "</td>\n</tr>\n";
            $output .= $outputline;
         }
         else {
            $outputline = $english[$i]["line"] . ". " . htmlentities($english[$i]["text"]);
            $output .= nl2br($outputline);
         }
      }
   }
 
   // Table?
   if ($table == true) {
      $output .= "</table>\n";
   }
 
   // Output ^^
   return($output);
}
 
 
 
 
// Run the function
echo(langCheck("nederlands"));
 
?>
langcheck.txt · Last modified: 2006/07/05 13:03 (external edit)
 
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Noncommercial-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki