$strchecklanguage -> $strmissingstrings"; $title = $strmissingstrings; break; case "compare": $navigation = "$strchecklanguage -> $strcomparelanguage"; $title = $strcomparelanguage; break; default: $title = $strchecklanguage; $navigation = $strchecklanguage; break; } if ($USER->lang) { $currentlang = $USER->lang; } else { $currentlang = $CFG->lang; } print_header("$site->shortname: $title", "$site->fullname", "$stradministration -> $navigation"); if (!$mode) { print_heading("$strcurrentlanguage: $currentlang - ".get_string("thislanguage")); print_heading("$strmissingstrings"); print_heading("$strcomparelanguage"); print_footer(); exit; } // Get a list of all the root files in the English directory $langdir = "$CFG->dirroot/lang/$currentlang"; $enlangdir = "$CFG->dirroot/lang/en"; if (! $stringfiles = get_directory_list($enlangdir, "", false)) { error("Could not find English language pack!"); } foreach ($stringfiles as $key => $file) { if ($file == "README" or $file == "help" or $file == "docs") { unset($stringfiles[$key]); } } 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\";
";
}
}
}
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");
}
} else if ($mode == "compare") {
if (isset($HTTP_POST_VARS['file'])){ // Save a file
$newstrings = $HTTP_POST_VARS;
$file = $newstrings['file'];
unset($newstrings['file']);
if (lang_save_file($langdir, $file, $newstrings)) {
notify(get_string("changessaved")." ($langdir/$file)");
} else {
error("Could not save the file '$file'!", "lang.php?mode=compare");
}
}
print_heading($strcomparelanguage);
echo "";
helpbutton("langedit",$strcomparelanguage);
echo " ";
foreach ($stringfiles as $file) {
print_heading("$file", "LEFT", 4);
if (!file_exists("$langdir/$file")) {
echo "".get_string("filemissing", "", "$langdir/$file")."
";
continue;
}
error_reporting(0);
if ($f = fopen("$langdir/$file","r+")) {
$editable = true;
fclose($f);
} else {
$editable = false;
echo "".get_string("makeeditable", "", "$langdir/$file")."
";
}
error_reporting(7);
unset($string);
include("$enlangdir/$file");
$enstring = $string;
ksort($enstring);
unset($string);
include("$langdir/$file");
if ($editable) {
echo "";
}
print_continue("lang.php");
}
print_footer();
//////////////////////////////////////////////////////////////////////
function lang_save_file($path, $file, $strings) {
// Thanks to Petri Asikainen for the original version of code
// used to save language files.
//
// $path is a full pathname to the file
// $file is the file to overwrite.
// $strings is an array of strings to write
global $CFG;
error_reporting(0);
if (!$f = fopen("$path/$file","w")) {
return false;
}
error_reporting(7);
fwrite($f, "release ($CFG->version)\n\n\n");
ksort($strings);
foreach ($strings as $key => $value) {
list($id, $stringname) = explode("-",$key);
$value = str_replace("\\","",$value); // Delete all slashes
$value = str_replace("$"."a", "\\$"."a", $value); // Add slashes for $a
$value = str_replace("\"", "\\\"", $value); // Add slashes for "
if ($id == "string"){
fwrite($f,"\$string['$stringname'] = \"$value\";\n");
}
}
fwrite($f,"\n?>\n");
fclose($f);
return true;
}
?>