Revision: 1600
http://mrbs.svn.sourceforge.net/mrbs/?rev=1600&view=rev
Author: jberanek
Date: 2010-11-15 00:01:36 +0000 (Mon, 15 Nov 2010)
Log Message:
-----------
* Updated checklang.php script, with ideas from P?\195?\165l Monstad.
Modified Paths:
--------------
mrbs/trunk/checklang.php
Modified: mrbs/trunk/checklang.php
===================================================================
--- mrbs/trunk/checklang.php 2010-11-14 19:54:27 UTC (rev 1599)
+++ mrbs/trunk/checklang.php 2010-11-15 00:01:36 UTC (rev 1600)
@@ -7,10 +7,6 @@
<h1>Language File Checker</h1>
<p>
This will report missing or untranslated strings in the language files.
- Access this script with a parameter lang=xx to see the results for
- language xx only (for example,
- http://localhost/mrbs/checklang.php?lang=fr).
- If you do not supply a lang=xx parameter, all languages will be checked.
</p>
<?php
@@ -22,65 +18,161 @@
require_once "$path_to_mrbs/systemdefaults.inc.php";
require_once "$path_to_mrbs/config.inc.php";
-// Checklang 2001-01-28 ljb - Check MRBS language files for completeness.
-// This is a rather straightforward job. For each language file, report
-// on any missing or untranslated strings with respect to the reference
-// file.
-// Parameter lang=xx can be supplied, to just check that language; by
-// default all languages are checked.
-
unset($lang);
+$lang = array();
if (!empty($_GET))
{
$lang = $_GET['lang'];
+ $update = $_GET['update'];
}
else if (!empty($HTTP_GET_VARS))
{
- $lang = $HTTP_GET_VARS['lang'];
+ $lang = (array)$HTTP_GET_VARS['lang'];
+ $update = $HTTP_GET_VARS['update'];
}
+
// Language file prefix
$langs = "lang.";
// Reference language:
$ref_lang = "en";
-if (isset($lang))
+// Make a list of language files to check. This is similar to glob() in
+// PEAR File/Find.
+$dh = opendir($path_to_mrbs);
+while (($filename = readdir($dh)) !== false)
{
- $check[0] = $lang;
- unset($lang);
+ $files[] = $filename;
}
-else
+closedir($dh);
+
+sort($files);
+
+?>
+
+<form method="get" action="checklang.php">
+<select multiple="multiple" size=5 name="lang[]">
+<?php
+foreach ($files as $filename)
{
- // Make a list of language files to check. This is similar to glob() in
- // PEAR File/Find.
- $dh = opendir($path_to_mrbs);
- while (($filename = readdir($dh)) !== false)
+ if (preg_match('/^lang\.(.*)/', $filename, $name) && $name[1] != $ref_lang)
{
- $files[] = $filename;
- }
- closedir($dh);
-
- sort($files);
-
- foreach ($files as $filename)
- {
- if (ereg("^lang\\.(.*)", $filename, $name) && $name[1] != $ref_lang)
+ if (preg_match('/~|\.bak|\.swp\$/', $name[1]))
{
- $check[] = $name[1];
+ continue;
}
+ print "<option";
+ if (array_search($name[1], $lang) !== FALSE)
+ {
+ print " selected=\"selected\"";
+ }
+ print ">$name[1]</option>\n";
}
}
+?>
+</select>
+<br>
+<input type="checkbox" name="update">
+Update file(s) with new token lines (web server user requires write permission
+on files and directory)
+<br>
+<input type="submit" name="submit" value="Go">
+</form>
+
+<?php
include "$path_to_mrbs/$langs$ref_lang";
$ref = $vocab;
-reset($check);
-while (list(,$l) = each($check))
+foreach ($lang as $l)
{
unset($vocab);
include "$path_to_mrbs/$langs$l";
+ if ($update)
+ {
+ $ref_lines = array();
+ $in = fopen("$path_to_mrbs/$langs$ref_lang", "r")
+ or die("Failed to open $path_to_mrbs/$langs$ref_lang for reading\n");
+ while (!feof($in))
+ {
+ $line = fgets($in);
+ if (preg_match('/^\$vocab\["([^"]+)"\]/', $line, $matches))
+ {
+// DEBUG print "MATCH $matches[1]<br>\n";
+ $ref_lines[$matches[1]] = $line;
+ }
+ }
+ fclose($in);
+ $in = fopen("$path_to_mrbs/$langs$l", "r") or
+ die("Failed to open $path_to_mrbs/$langs$l for reading");
+ $out = fopen("$path_to_mrbs/$langs$l.new", "w") or
+ die("Failed to open $path_to_mrbs/$langs$l.new for writing");
+
+ $seen = array();
+ $added = array();
+// DEBUG print "<table>\n";
+ while (!feof($in))
+ {
+ $line = fgets($in);
+ if (preg_match('/^\$vocab\["([^"]+)"\]/', $line, $matches))
+ {
+// DEBUG print "<tr><td>$matches[1]</td><td>".key($ref_lines);
+
+ if (!array_key_exists($matches[1], $ref_lines))
+ {
+ fwrite($out, "// REMOVED - ".$line);
+ continue;
+ }
+ while (($matches[1] != key($ref_lines)) &&
+ (!array_key_exists(key($ref_lines), $vocab)))
+ {
+ if (array_key_exists(key($ref_lines), $seen))
+ {
+ break;
+ }
+ $seen[key($ref_lines)] = 1;
+ fwrite($out, current($ref_lines));
+ $added[] = key($ref_lines);
+ $ret = next($ref_lines);
+// DEBUG print " ".key($ref_lines);
+ if (!$ret)
+ {
+ break;
+ }
+ }
+ next($ref_lines);
+ }
+ $seen[$matches[1]] = 1;
+ fwrite($out, $line);
+// DEBUG print "</td></tr>\n";
+ }
+ fclose($in);
+ fclose($out);
+// DEBUG print "</table>\n";
+
+ if (count($added))
+ {
+ print "Added the following tokens:\n<ul>\n<li>".
+ implode("</li>\n<li>",$added)."</li>\n</ul>\n";
+ rename("$path_to_mrbs/$langs$l", "$path_to_mrbs/$langs$l.old") or
+ die("Failed to rename $path_to_mrbs/$langs$l to
$path_to_mrbs/$langs$l.old");
+ rename("$path_to_mrbs/$langs$l.new", "$path_to_mrbs/$langs$l") or
+ die("Failed to rename $path_to_mrbs/$langs$l.new to
$path_to_mrbs/$langs$l");
+
+ // Re-read the updated file
+ unset($vocab);
+ include "$path_to_mrbs/$langs$l";
+ }
+ else
+ {
+ print "No token lines added.";
+ unlink("$path_to_mrbs/$langs$l.new") or
+ print "<span style=\"color: red; font-weight: bold\">
+ Failed to delete $path_to_mrbs/$langs$l.new</span>.\n";
+ }
+ }
?>
<h2>Language: <?php echo $l ?></h2>
<table border="1">
@@ -129,6 +221,7 @@
{
echo "missing: $nmissing, untranslated: $nunxlate.\n";
}
+ print "<hr>\n";
}
?>
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Centralized Desktop Delivery: Dell and VMware Reference Architecture
Simplifying enterprise desktop deployment and management using
Dell EqualLogic storage and VMware View: A highly scalable, end-to-end
client virtualization framework. Read more!
http://p.sf.net/sfu/dell-eql-dev2dev
_______________________________________________
Mrbs-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mrbs-commits