From cb011cfd0a7d4797f2c5a9fc6c2fde3b498b54a5 Mon Sep 17 00:00:00 2001 From: martin Date: Wed, 25 Sep 2002 07:33:04 +0000 Subject: [PATCH] In compare mode you can now EDIT language files directly. This should make language development much easier. Based on code sent to me by Petri Asikainen --- admin/lang.php | 128 +++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 108 insertions(+), 20 deletions(-) diff --git a/admin/lang.php b/admin/lang.php index 82c2482370b..a39c68e7ab5 100644 --- a/admin/lang.php +++ b/admin/lang.php @@ -24,33 +24,31 @@ switch ($mode) { case "missing": $navigation = "$strchecklanguage -> $strmissingstrings"; + $title = $strmissingstrings; break; case "compare": $navigation = "$strchecklanguage -> $strcomparelanguage"; + $title = $strcomparelanguage; break; default: $navigation = $strchecklanguage; break; } - print_header("$site->fullname", "$site->fullname", + print_header("$site->fullname: $title", "$site->fullname", "$stradministration -> $navigation"); if (!$mode) { - print_heading("$strcurrentlanguage: $CFG->lang"); + print_heading("$strcurrentlanguage: $USER->lang - ".get_string("thislanguage")); print_heading("$strmissingstrings"); print_heading("$strcomparelanguage"); print_footer(); exit; } - if ($CFG->lang == "en") { - notice("Nothing to check - you are using the English language pack!", "lang.php"); - } - // Get a list of all the root files in the English directory - $langdir = "$CFG->dirroot/lang/$CFG->lang"; + $langdir = "$CFG->dirroot/lang/$USER->lang"; $enlangdir = "$CFG->dirroot/lang/en"; if (! $stringfiles = get_directory_list($enlangdir, "", false)) { @@ -93,7 +91,6 @@ } } } - closedir($dir); if (! $files = get_directory_list("$CFG->dirroot/lang/en/help", "CVS")) { error("Could not find English language help files!"); @@ -126,7 +123,19 @@ } 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"); + } + } + foreach ($stringfiles as $file) { + print_heading("$file", "LEFT", 4); if (!file_exists("$langdir/$file")) { @@ -134,29 +143,71 @@ continue; } + error_reporting(0); + if ($f = fopen("$langdir/$file","r+")) { + $editable = true; + } 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"); - - echo ""; - foreach ($enstring as $key => $value) { - $value = htmlentities($value); - $value = str_replace("$"."a", "\\$"."a", $value); + + if ($editable) { + echo ""; + } + echo "
"; + foreach ($enstring as $key => $envalue) { + $envalue = nl2br(htmlentities($envalue)); + $envalue = str_replace("$"."a", "\\$"."a", $envalue); echo ""; - echo ""; - echo ""; - if (isset($string[$key])) { - $value = htmlentities($string[$key]); - $value = str_replace("$"."a", "\\$"."a", $value); - echo ""; + echo ""; + echo ""; + + $value = htmlentities($string[$key]); + $value = str_replace("$"."a", "\\$"."a", $value); + if ($editable) { + echo ""; + } + echo ""; + } else { - echo ""; + if (isset($string[$key])) { + echo ""; + } else { + echo ""; + } } } + if ($editable) { + echo ""; + } echo "
$key$value$valuecellheading\" NOWRAP VALIGN=TOP>$keycellheading\" VALIGN=TOP>$envalue"; + if (isset($string[$key])) { + $valuelen = strlen($value); + } else { + $valuelen = strlen($envalue); + } + $cols=50; + if (strstr($value, "\r") or strstr($value, "\n") or $valuelen > $cols) { + $rows = ceil($valuelen / $cols); + echo ""; + } else { + $cols = $valuelen + 2; + echo "-$value-
 "; + echo " "; + echo " "; + echo " "; + echo "
"; + echo ""; } print_continue("lang.php"); @@ -165,4 +216,41 @@ 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); + if ($id == "string"){ + fwrite($f,"\$string['$stringname'] = \"$value\";\n"); + } + } + fwrite($f,"\n?>\n"); + fclose($f); + + return true; +} + ?>