From 774ab660025296641d924193bbc73e7e5040d922 Mon Sep 17 00:00:00 2001 From: martin Date: Sat, 7 Sep 2002 14:57:33 +0000 Subject: [PATCH] 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. --- admin/lang.php | 183 +++++++++++++++++++++++++++++++-------------- lang/en/moodle.php | 6 ++ lib/moodlelib.php | 10 ++- 3 files changed, 137 insertions(+), 62 deletions(-) diff --git a/admin/lang.php b/admin/lang.php index 43de5e3ed7..82c2482370 100644 --- a/admin/lang.php +++ b/admin/lang.php @@ -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 = "$strchecklanguage -> $strmissingstrings"; + break; + case "compare": + $navigation = "$strchecklanguage -> $strcomparelanguage"; + break; + default: + $navigation = $strchecklanguage; + break; + } print_header("$site->fullname", "$site->fullname", - "$stradministration - -> $strchecklanguage -> $CFG->lang"); - - - // Get a list of all the files in the English directory + "$stradministration -> $navigation"); + + if (!$mode) { + print_heading("$strcurrentlanguage: $CFG->lang"); + print_heading("$strmissingstrings"); + print_heading("$strcomparelanguage"); + 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 "

".get_string("filemissing", "", "$langdir/$file")."

"; - 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 "

".get_string("filemissing", "", "$langdir/$file")."

"; + 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 "

".get_string("stringsnotset","","$langdir/$file")."

";
+                        $first = false;
+                        $somethingfound = true;
+                    }
+                    echo "$"."string[$key] = \"$value\";
"; + } + } + } + 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 "

".get_string("filemissing", "", "$langdir/help/$file")."

"; + $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 "

".get_string("filemissing", "", "$langdir/docs/$file")."

"; + $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 "

".get_string("filemissing", "", "$langdir/$file")."

"; + continue; + } + + unset($string); + include("$enlangdir/$file"); + $enstring = $string; + + unset($string); + include("$langdir/$file"); + + echo ""; + foreach ($enstring as $key => $value) { $value = htmlentities($value); $value = str_replace("$"."a", "\\$"."a", $value); - if ($first) { - echo "

".get_string("stringsnotset","","$langdir/$file")."

";
-                    $first = false;
-                    $somethingfound = true;
+                echo "
"; + echo ""; + echo ""; + if (isset($string[$key])) { + $value = htmlentities($string[$key]); + $value = str_replace("$"."a", "\\$"."a", $value); + echo ""; + } else { + echo ""; } - echo "$"."string[$key] = \"$value\";
"; } + echo "
$key$value$value-
"; } - } - 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 "

".get_string("filemissing", "", "$langdir/help/$file")."

"; - $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 "

".get_string("filemissing", "", "$langdir/docs/$file")."

"; - $somethingfound = true; - continue; - } - } - if (!$somethingfound) { - notice(get_string("languagegood"), "index.php"); - } else { - print_continue("index.php"); + print_continue("lang.php"); + } print_footer(); diff --git a/lang/en/moodle.php b/lang/en/moodle.php index 6f29822feb..8c66bbb934 100644 --- a/lang/en/moodle.php +++ b/lang/en/moodle.php @@ -1,5 +1,7 @@ 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"; diff --git a/lib/moodlelib.php b/lib/moodlelib.php index 41f61c8823..5703f82f77 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -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; } -- 2.39.5