]> git.mjollnir.org Git - moodle.git/commitdiff
Improvements to the language checker. As well as checking for missing
authormartin <martin>
Sat, 7 Sep 2002 14:57:33 +0000 (14:57 +0000)
committermartin <martin>
Sat, 7 Sep 2002 14:57:33 +0000 (14:57 +0000)
strings, you can now see the current language compared side-by-side
with English.

admin/lang.php
lang/en/moodle.php
lib/moodlelib.php

index 43de5e3ed7a162fff2ec7dcc4c3b88d4b164fb7e..82c2482370be77669e23e89eab52e11899e69fcd 100644 (file)
@@ -2,6 +2,8 @@
 
        require("../config.php");
 
+    optional_variable($mode, "");
+
     require_login();
 
     if (!isadmin()) {
 
     $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();
index 6f29822febb97230db99251af36f2d5e583e30b8..8c66bbb9349c722230b2029053303e8fefd17bd8 100644 (file)
@@ -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[chooselogs] = "Choose which logs you want to see";
 $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[courses] = "Courses";
 $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[logout] = "Logout";
 $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[missingpassword] = "Missing password";
 $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";
index 41f61c8823e885dc0b680fb21c77df6b3b91c36d..5703f82f7757fdc8877242cb1036f45125a1e659 100644 (file)
@@ -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;
 }