Permalink
Browse files

Improvements to the language checker. As well as checking for missing

strings, you can now see the current language compared side-by-side
with English.
  • Loading branch information...
1 parent 7fb8331 commit 774ab660025296641d924193bbc73e7e5040d922 martin committed Sep 7, 2002
Showing with 137 additions and 62 deletions.
  1. +125 −58 admin/lang.php
  2. +6 −0 lang/en/moodle.php
  3. +6 −4 lib/moodlelib.php
View
@@ -2,6 +2,8 @@
require("../config.php");
+ optional_variable($mode, "");
+
require_login();
if (!isadmin()) {
@@ -14,86 +16,151 @@
$stradministration = get_string("administration");
$strchecklanguage = get_string("checklanguage");
+ $strcurrentlanguage = get_string("currentlanguage");
+ $strmissingstrings = get_string("missingstrings");
+ $strcomparelanguage = get_string("comparelanguage");
+ $strthislanguage = get_string("thislanguage");
+
+ switch ($mode) {
+ case "missing":
+ $navigation = "<A HREF=\"lang.php\">$strchecklanguage</A> -> $strmissingstrings";
+ break;
+ case "compare":
+ $navigation = "<A HREF=\"lang.php\">$strchecklanguage</A> -> $strcomparelanguage";
+ break;
+ default:
+ $navigation = $strchecklanguage;
+ break;
+ }
print_header("$site->fullname", "$site->fullname",
- "<A HREF=\"index.php\">$stradministration</A>
- -> $strchecklanguage -> $CFG->lang");
-
-
- // Get a list of all the files in the English directory
+ "<A HREF=\"index.php\">$stradministration</A> -> $navigation");
+
+ if (!$mode) {
+ print_heading("$strcurrentlanguage: $CFG->lang");
+ print_heading("<A HREF=\"lang.php?mode=missing\">$strmissingstrings</A>");
+ print_heading("<A HREF=\"lang.php?mode=compare\">$strcomparelanguage</A>");
+ print_footer();
+ exit;
+ }
- if (! $files = get_directory_list("$CFG->dirroot/lang/en", "CVS")) {
- error("Could not find English language pack!");
+ if ($CFG->lang == "en") {
+ notice("Nothing to check - you are using the English language pack!", "lang.php");
}
- // For each file, check that a counterpart exists, then check all the strings
+ // Get a list of all the root files in the English directory
$langdir = "$CFG->dirroot/lang/$CFG->lang";
$enlangdir = "$CFG->dirroot/lang/en";
- $dir = opendir($enlangdir);
-
+ if (! $stringfiles = get_directory_list($enlangdir, "", false)) {
+ error("Could not find English language pack!");
+ }
- while ($file = readdir($dir)) {
- if ($file == "." or $file == ".." or $file == "CVS" or $file == "README" or $file == "help" or $file == "docs") {
- continue;
+ foreach ($stringfiles as $key => $file) {
+ if ($file == "README" or $file == "help" or $file == "docs") {
+ unset($stringfiles[$key]);
}
+ }
- if (!file_exists("$langdir/$file")) {
- echo "<P><FONT COLOR=red>".get_string("filemissing", "", "$langdir/$file")."</FONT></P>";
- continue;
+ if ($mode == "missing") {
+ // For each file, check that a counterpart exists, then check all the strings
+
+ foreach ($stringfiles as $file) {
+ if (!file_exists("$langdir/$file")) {
+ echo "<P><FONT COLOR=red>".get_string("filemissing", "", "$langdir/$file")."</FONT></P>";
+ continue;
+ }
+
+ unset($string);
+ include("$enlangdir/$file");
+ $enstring = $string;
+
+ unset($string);
+ include("$langdir/$file");
+
+ $first = true;
+ foreach ($enstring as $key => $value) {
+ if (!isset($string[$key])) {
+ $value = htmlentities($value);
+ $value = str_replace("$"."a", "\\$"."a", $value);
+ if ($first) {
+ echo "</PRE><HR><P><B>".get_string("stringsnotset","","$langdir/$file")."</B></P><PRE>";
+ $first = false;
+ $somethingfound = true;
+ }
+ echo "$"."string[$key] = \"$value\";<BR>";
+ }
+ }
+ }
+ closedir($dir);
+
+ if (! $files = get_directory_list("$CFG->dirroot/lang/en/help", "CVS")) {
+ error("Could not find English language help files!");
+ }
+
+ foreach ($files as $filekey => $file) { // check all the help files.
+ if (!file_exists("$langdir/help/$file")) {
+ echo "<P><FONT COLOR=red>".get_string("filemissing", "", "$langdir/help/$file")."</FONT></P>";
+ $somethingfound = true;
+ continue;
+ }
+ }
+
+ if (! $files = get_directory_list("$CFG->dirroot/lang/en/docs", "CVS")) {
+ error("Could not find English language docs files!");
+ }
+ foreach ($files as $filekey => $file) { // check all the docs files.
+ if (!file_exists("$langdir/docs/$file")) {
+ echo "<P><FONT COLOR=red>".get_string("filemissing", "", "$langdir/docs/$file")."</FONT></P>";
+ $somethingfound = true;
+ continue;
+ }
+ }
+
+ if ($somethingfound) {
+ print_continue("lang.php");
+ } else {
+ notice(get_string("languagegood"), "lang.php");
}
- unset($string);
- include("$enlangdir/$file");
- $enstring = $string;
+ } else if ($mode == "compare") {
- unset($string);
- include("$langdir/$file");
+ foreach ($stringfiles as $file) {
+ print_heading("$file", "LEFT", 4);
- $first = true;
- foreach ($enstring as $key => $value) {
- if (!isset($string[$key])) {
+ if (!file_exists("$langdir/$file")) {
+ echo "<P><FONT COLOR=red>".get_string("filemissing", "", "$langdir/$file")."</FONT></P>";
+ continue;
+ }
+
+ unset($string);
+ include("$enlangdir/$file");
+ $enstring = $string;
+
+ unset($string);
+ include("$langdir/$file");
+
+ echo "<TABLE WIDTH=\"100%\" BORDER=1>";
+ foreach ($enstring as $key => $value) {
$value = htmlentities($value);
$value = str_replace("$"."a", "\\$"."a", $value);
- if ($first) {
- echo "</PRE><HR><P><B>".get_string("stringsnotset","","$langdir/$file")."</B></P><PRE>";
- $first = false;
- $somethingfound = true;
+ echo "<TR>";
+ echo "<TD WIDTH=20% BGCOLOR=white NOWRAP VALIGN=TOP>$key</TD>";
+ echo "<TD WIDTH=40% VALIGN=TOP>$value</TD>";
+ if (isset($string[$key])) {
+ $value = htmlentities($string[$key]);
+ $value = str_replace("$"."a", "\\$"."a", $value);
+ echo "<TD WIDTH=40% BGCOLOR=white VALIGN=TOP>$value</TD>";
+ } else {
+ echo "<TD WIDTH=40% BGCOLOR=white ALIGN=CENTER VALIGN=TOP>-</TD>";
}
- echo "$"."string[$key] = \"$value\";<BR>";
}
+ echo "</TABLE>";
}
- }
- closedir($dir);
-
- if (! $files = get_directory_list("$CFG->dirroot/lang/en/help", "CVS")) {
- error("Could not find English language help files!");
- }
-
- foreach ($files as $filekey => $file) { // check all the help files.
- if (!file_exists("$langdir/help/$file")) {
- echo "<P><FONT COLOR=red>".get_string("filemissing", "", "$langdir/help/$file")."</FONT></P>";
- $somethingfound = true;
- continue;
- }
- }
-
- if (! $files = get_directory_list("$CFG->dirroot/lang/en/docs", "CVS")) {
- error("Could not find English language docs files!");
- }
- foreach ($files as $filekey => $file) { // check all the docs files.
- if (!file_exists("$langdir/docs/$file")) {
- echo "<P><FONT COLOR=red>".get_string("filemissing", "", "$langdir/docs/$file")."</FONT></P>";
- $somethingfound = true;
- continue;
- }
- }
- if (!$somethingfound) {
- notice(get_string("languagegood"), "index.php");
- } else {
- print_continue("index.php");
+ print_continue("lang.php");
+
}
print_footer();
View
@@ -1,5 +1,7 @@
<?PHP // $Id$
+$string[thislanguage] = "English"; // Francais, Italiano, etc etc
+
$string[action] = "Action";
$string[activity] = "Activity";
$string[activities] = "Activities";
@@ -38,6 +40,7 @@
$string[choosetheme] = "Choose theme";
$string[chooseuser] = "Choose a user";
$string[city] = "City/town";
+$string[comparelanguage] = "Compare language to English";
$string[confirmed] = "Your registration has been confirmed";
$string[courseupdates] = "Course updates";
$string[cookiesenabled] = "Cookies must be enabled in your browser";
@@ -51,6 +54,7 @@
$string[createaccount] = "Create my new account";
$string[createuserandpass] = "Create a new username and password to log in with";
$string[createziparchive] = "Create zip archive";
+$string[currentlanguage] = "Current language";
$string[currentlocaltime] = "your current local time";
$string[databasechecking] = "Upgrading Moodle database from version \$a->oldversion to \$a->newversion...";
$string[databasesetup] = "Setting up database";
@@ -209,6 +213,7 @@
$string[logs] = "Logs";
$string[makeafolder] = "Make a folder";
$string[mainmenu] = "Main menu";
+$string[managedatabase] = "Manage database";
$string[markthistopic] = "Mark this topic as the current topic";
$string[maximumchars] = "Maximum of \$a characters";
$string[maximumgrade] = "Maximum grade";
@@ -227,6 +232,7 @@
$string[missingshortsitename] = "Missing short site name";
$string[missingsitedescription] = "Missing site description";
$string[missingsitename] = "Missing site name";
+$string[missingstrings] = "Check for missing strings";
$string[missingstudent] = "Must choose something";
$string[missingsummary] = "Missing summary";
$string[missingteacher] = "Must choose something";
View
@@ -1363,7 +1363,7 @@ function get_max_upload_file_size() {
}
-function get_directory_list($rootdir, $excludefile="") {
+function get_directory_list($rootdir, $excludefile="", $descend=true) {
// Returns an array with all the filenames in
// all subdirectories, relative to the given rootdir.
// If excludefile is defined, then that file/directory is ignored
@@ -1373,10 +1373,10 @@ function get_directory_list($rootdir, $excludefile="") {
$dir = opendir($rootdir);
while ($file = readdir($dir)) {
- if ($file != "." and $file != ".." and $file != $excludefile) {
+ if ($file != "." and $file != ".." and $file != "CVS" and $file != $excludefile) {
$fullfile = $rootdir."/".$file;
- if (filetype($fullfile) == "dir") {
- $subdirs = get_directory_list($fullfile, $excludefile);
+ if ($descend and filetype($fullfile) == "dir") {
+ $subdirs = get_directory_list($fullfile, $excludefile, $descend);
foreach ($subdirs as $subdir) {
$dirs[] = $file."/".$subdir;
}
@@ -1387,6 +1387,8 @@ function get_directory_list($rootdir, $excludefile="") {
}
closedir($dir);
+ asort($dirs);
+
return $dirs;
}

0 comments on commit 774ab66

Please sign in to comment.