mirror of
https://github.com/moodle/moodle.git
synced 2025-01-19 06:18:28 +01:00
Very very quick checking of new lang doc editing script from David Mudrak,
with significant cleanups Needs some testing.
This commit is contained in:
parent
4f805fe9d0
commit
2bb407f51d
@ -20,7 +20,8 @@
|
||||
$strlanguage = get_string("language");
|
||||
$strcurrentlanguage = get_string("currentlanguage");
|
||||
$strmissingstrings = get_string("missingstrings");
|
||||
$strcomparelanguage = get_string("comparelanguage");
|
||||
$streditstrings = get_string("editstrings", 'admin');
|
||||
$stredithelpdocs = get_string("edithelpdocs", 'admin');
|
||||
$strthislanguage = get_string("thislanguage");
|
||||
|
||||
switch ($mode) {
|
||||
@ -29,11 +30,11 @@
|
||||
$title = $strmissingstrings;
|
||||
$button = '<form target="'.$CFG->framename.'" method="get" action="'.$CFG->wwwroot.'/'.$CFG->admin.'/lang.php">'.
|
||||
'<input type="hidden" name="mode" value="compare" />'.
|
||||
'<input type="submit" value="'.$strcomparelanguage.'" /></form>';
|
||||
'<input type="submit" value="'.$streditstrings.'" /></form>';
|
||||
break;
|
||||
case "compare":
|
||||
$navigation = "<a href=\"lang.php\">$strlanguage</a> -> $strcomparelanguage";
|
||||
$title = $strcomparelanguage;
|
||||
$navigation = "<a href=\"lang.php\">$strlanguage</a> -> $streditstrings";
|
||||
$title = $streditstrings;
|
||||
$button = '<form target="'.$CFG->framename.'" method="get" action="'.$CFG->wwwroot.'/'.$CFG->admin.'/lang.php">'.
|
||||
'<input type="hidden" name="mode" value="missing" />'.
|
||||
'<input type="submit" value="'.$strmissingstrings.'" /></form>';
|
||||
@ -59,13 +60,13 @@
|
||||
echo "<b>$strcurrentlanguage:</b>";
|
||||
echo "</td><td>";
|
||||
echo popup_form ("$CFG->wwwroot/$CFG->admin/lang.php?lang=", $langs, "chooselang", $currlang, "", "", "", true);
|
||||
echo "</td></tr></table>";
|
||||
print_heading("<a href=\"lang.php?mode=missing\">$strmissingstrings</a>");
|
||||
print_heading("<a href=\"lang.php?mode=compare\">$strcomparelanguage</a>");
|
||||
echo "<center><hr noshade=\"noshade\" size=\"1\" />";
|
||||
echo '</tr><td colspan="2">';
|
||||
$options["lang"] = $currentlang;
|
||||
print_single_button("http://moodle.org/download/lang/", $options, get_string("latestlanguagepack"));
|
||||
echo "</center>";
|
||||
echo "</td></tr></table>";
|
||||
print_heading("<a href=\"lang.php?mode=missing\">$strmissingstrings</a>");
|
||||
print_heading("<a href=\"lang.php?mode=compare\">$streditstrings</a>");
|
||||
print_heading("<a href=\"langdoc.php\">$stredithelpdocs</a>");
|
||||
print_footer();
|
||||
exit;
|
||||
}
|
||||
@ -166,7 +167,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
print_heading_with_help($strcomparelanguage, "langedit");
|
||||
print_heading_with_help($streditstrings, "langedit");
|
||||
|
||||
print_simple_box_start("center", "80%");
|
||||
echo '<center><font size="2">';
|
||||
|
189
admin/langdoc.php
Executable file
189
admin/langdoc.php
Executable file
@ -0,0 +1,189 @@
|
||||
<?php // $Id$
|
||||
|
||||
/***
|
||||
This script enables Moodle translators to edit /docs and /help language
|
||||
files directly via WWW interface.
|
||||
|
||||
Author: mudrd8mz@it.pedf.cuni.cz (http://moodle.cz)
|
||||
Based on: lang.php in 1.4.3+ release
|
||||
*/
|
||||
|
||||
//
|
||||
// Some local configuration
|
||||
//
|
||||
$fileeditorrows = 12; // number of textareas' rows
|
||||
$fileeditorcols = 100; // dtto cols
|
||||
$fileeditorinline = 1; // shall be textareas put in one row?
|
||||
$filemissingmark = ' (!)'; // a mark to be added to non-existing filenames in selection form
|
||||
// or to filenames with filesize() == 0
|
||||
|
||||
require_once("../config.php");
|
||||
|
||||
$currentfile = optional_param('currentfile', 'docs/README.txt', PARAM_PATH);
|
||||
|
||||
require_login();
|
||||
|
||||
if (!isadmin()) {
|
||||
error("You need to be admin to edit this page");
|
||||
}
|
||||
|
||||
if (! $site = get_site()) {
|
||||
error("Site not defined!");
|
||||
}
|
||||
|
||||
$stradministration = get_string("administration");
|
||||
$strconfiguration = get_string("configuration");
|
||||
$strlanguage = get_string("language");
|
||||
$strcurrentlanguage = get_string("currentlanguage");
|
||||
$strthislanguage = get_string("thislanguage");
|
||||
$stredithelpdocs = get_string('edithelpdocs', 'admin');
|
||||
|
||||
print_header("$site->shortname: $stredithelpdocs: $currentfile", "$site->fullname",
|
||||
"<a href=\"index.php\">$stradministration</a> -> ".
|
||||
"<a href=\"configure.php\">$strconfiguration</a> ->
|
||||
<a href=\"lang.php\">$strlanguage</a> -> $stredithelpdocs",
|
||||
'choosefile.popup', '', true);
|
||||
|
||||
$currentlang = current_language();
|
||||
$langdir = "$CFG->dirroot/lang/$currentlang";
|
||||
$enlangdir = "$CFG->dirroot/lang/en";
|
||||
|
||||
error_reporting(0); // Error reporting turned off due to non-existing files
|
||||
|
||||
// Generate selection for all help and documentation files
|
||||
|
||||
// Get all files from /docs directory
|
||||
|
||||
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.
|
||||
$options["docs/$file"] = "docs/$file";
|
||||
// add (!) if file doesn't exists or is empty
|
||||
if (( !file_exists("$langdir/docs/$file")) || (filesize("$langdir/docs/$file") == 0)) {
|
||||
$options["docs/$file"] .= "$filemissingmark";
|
||||
}
|
||||
}
|
||||
|
||||
// Get all files from /help directory
|
||||
|
||||
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.
|
||||
$options["help/$file"] = "help/$file";
|
||||
if (!file_exists("$langdir/help/$file")) {
|
||||
$options["help/$file"] .= "$filemissingmark";
|
||||
}
|
||||
}
|
||||
|
||||
echo "<table align=\"center\"><tr><td align=\"center\">";
|
||||
echo $prevfile;
|
||||
echo popup_form ("$CFG->wwwroot/$CFG->admin/langdoc.php?sesskey=$USER->sesskey&currentfile=", $options, "choosefile", $currentfile, "", "", "", true);
|
||||
echo $nextfile;
|
||||
echo "</td></tr></table>";
|
||||
|
||||
// Shall I save POSTed data?
|
||||
|
||||
if (isset($_POST['currentfile'])) {
|
||||
if (confirm_sesskey()) {
|
||||
if (langdoc_save_file($langdir, $currentfile, $_POST['filedata'])) {
|
||||
notify(get_string("changessaved")." ($langdir/$currentfile)", "green");
|
||||
} else {
|
||||
error("Could not save the file '$currentfile'!", "langdoc.php?currentfile=$currentfile&sesskey=$USER->sesskey");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Generate textareas
|
||||
|
||||
if (!empty($currentfile)) {
|
||||
|
||||
if (!file_exists("$langdir/$currentfile")) {
|
||||
if (!touch("$langdir/$currentfile")) {
|
||||
echo "<p align=\"center\"><font color=red>".get_string("filemissing", "", "$langdir/$currentfile")."</font></p>";
|
||||
}
|
||||
}
|
||||
|
||||
if ($f = fopen("$langdir/$currentfile","r+")) {
|
||||
$editable = true;
|
||||
fclose($f);
|
||||
} else {
|
||||
$editable = false;
|
||||
echo "<p><font size=1>".get_string("makeeditable", "", "$langdir/$currentfile")."</font></p>";
|
||||
}
|
||||
|
||||
echo "<table align=\"center\"><tr valign=\"center\"><td align=\"center\">\n";
|
||||
echo "<textarea rows=\"$fileeditorrows\" cols=\"$fileeditorcols\" name=\"\">\n";
|
||||
include("$enlangdir/$currentfile");
|
||||
echo "</textarea>\n";
|
||||
link_to_popup_window("/lang/en/$currentfile", "popup", get_string("preview"));
|
||||
echo "</td>\n";
|
||||
if ($fileeditorinline == 1) {
|
||||
echo "</tr>\n<tr valign=\"center\">\n";
|
||||
}
|
||||
echo "<td align=\"center\">\n";
|
||||
|
||||
if ($editable) {
|
||||
echo "<form name=\"$currentfile\" action=\"langdoc.php\" method=\"post\">";
|
||||
echo '<input type="hidden" name="sesskey" value="'.$USER->sesskey.'" />';
|
||||
echo '<input type="hidden" name="currentfile" value="'.$currentfile.'" />';
|
||||
}
|
||||
|
||||
echo "<textarea rows=\"$fileeditorrows\" cols=\"$fileeditorcols\" name=\"filedata\">\n";
|
||||
include("$langdir/$currentfile");
|
||||
echo "</textarea>\n";
|
||||
link_to_popup_window("/lang/$currentlang/$currentfile", "popup", get_string("preview"));
|
||||
echo "</td>\n</tr>\n</table>";
|
||||
|
||||
if ($editable) {
|
||||
echo '<div align="center"><input type="submit" value="'.get_string('savechanges').': lang/'.$currentlang.'/'.$currentfile.'" /></div>';
|
||||
echo '</form>';
|
||||
}
|
||||
|
||||
error_reporting($CFG->debug);
|
||||
}
|
||||
|
||||
print_footer();
|
||||
|
||||
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
function langdoc_save_file($path, $file, $content) {
|
||||
|
||||
// $path is a full pathname to the file
|
||||
// $file is the file to overwrite.
|
||||
// $content are data to write
|
||||
|
||||
global $CFG, $USER;
|
||||
|
||||
error_reporting(0);
|
||||
if (!$f = fopen("$path/$file","w")) {
|
||||
return false;
|
||||
}
|
||||
error_reporting(7);
|
||||
|
||||
$content = str_replace("\r", "",$content); // Remove linefeed characters
|
||||
$content = preg_replace("/\n{3,}/", "\n\n", $content); // Collapse runs of blank lines
|
||||
$content = trim($content, "\n"); // Delete leading/trailing lines
|
||||
$content = str_replace("\\","",$content); // Delete all slashes
|
||||
$content = str_replace("%%","%",$content);
|
||||
|
||||
fwrite($f, $content);
|
||||
|
||||
fclose($f);
|
||||
|
||||
// Remove file if its empty
|
||||
|
||||
if (filesize("$path/$file") == 0) {
|
||||
unlink("$path/$file");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
?>
|
@ -90,6 +90,8 @@ $string['dstisforcedto'] = 'Force all users to use';
|
||||
$string['dstpresets'] = 'DST Presets';
|
||||
$string['emptydstlist'] = 'There are currently no DST presets defined. You can add one by clicking on the Add button.';
|
||||
$string['editingdstpreset'] = 'Editing a DST preset';
|
||||
$string['edithelpdocs'] = 'Edit help documents';
|
||||
$string['editstrings'] = 'Edit strings';
|
||||
$string['errordstpresetactivateearlier'] = 'The month of activation must be earlier than the month of deactivation';
|
||||
$string['errordstpresetnameempty'] = 'The preset name cannot be empty';
|
||||
$string['errordstpresetnameexists'] = 'Another preset with that name already exists';
|
||||
|
Loading…
x
Reference in New Issue
Block a user