1
<?PHP // $Id: lang.php,v 1.42.4.3 2004/11/30 03:47:13 moodler Exp $
1
<?PHP // $Id: lang.php,v 1.55.2.1 2005/07/14 16:01:23 moodler Exp $
3
3
require_once("../config.php");
5
optional_variable($mode, "");
6
optional_variable($currentfile, "moodle.php");
5
$mode = optional_param('mode', '', PARAM_ALPHA);
6
$currentfile = optional_param('currentfile', 'moodle.php', PARAM_FILE);
20
20
$strlanguage = get_string("language");
21
21
$strcurrentlanguage = get_string("currentlanguage");
22
22
$strmissingstrings = get_string("missingstrings");
23
$strcomparelanguage = get_string("comparelanguage");
23
$streditstrings = get_string("editstrings", 'admin');
24
$stredithelpdocs = get_string("edithelpdocs", 'admin');
24
25
$strthislanguage = get_string("thislanguage");
28
$navigation = "<A HREF=\"lang.php\">$strlanguage</A> -> $strmissingstrings";
29
$navigation = "<a href=\"lang.php\">$strlanguage</a> -> $strmissingstrings";
29
30
$title = $strmissingstrings;
30
$button = '<form target="'.$CFG->framename.'" method="get" action="'.$CFG->wwwroot.'/admin/lang.php">'.
31
$button = '<form target="'.$CFG->framename.'" method="get" action="'.$CFG->wwwroot.'/'.$CFG->admin.'/lang.php">'.
31
32
'<input type="hidden" name="mode" value="compare" />'.
32
'<input type="hidden" name="sesskey" value="'.$USER->sesskey.'" />'.
33
'<input type="submit" value="'.$strcomparelanguage.'" /></form>';
33
'<input type="submit" value="'.$streditstrings.'" /></form>';
36
$navigation = "<A HREF=\"lang.php\">$strlanguage</A> -> $strcomparelanguage";
37
$title = $strcomparelanguage;
38
$button = '<form target="'.$CFG->framename.'" method="get" action="'.$CFG->wwwroot.'/admin/lang.php">'.
36
$navigation = "<a href=\"lang.php\">$strlanguage</a> -> $streditstrings";
37
$title = $streditstrings;
38
$button = '<form target="'.$CFG->framename.'" method="get" action="'.$CFG->wwwroot.'/'.$CFG->admin.'/lang.php">'.
39
39
'<input type="hidden" name="mode" value="missing" />'.
40
'<input type="hidden" name="sesskey" value="'.$USER->sesskey.'" />'.
41
40
'<input type="submit" value="'.$strmissingstrings.'" /></form>';
58
57
$currlang = current_language();
59
58
$langs = get_list_of_languages();
60
echo "<table align=center><tr><td align=\"right\">";
59
echo "<table align=\"center\"><tr><td align=\"right\">";
61
60
echo "<b>$strcurrentlanguage:</b>";
63
echo popup_form ("$CFG->wwwroot/admin/lang.php?lang=", $langs, "chooselang", $currlang, "", "", "", true);
64
echo "</td></tr></table>";
65
print_heading("<a href=\"lang.php?mode=missing&sesskey=$USER->sesskey\">$strmissingstrings</a>");
66
print_heading("<a href=\"lang.php?mode=compare&sesskey=$USER->sesskey\">$strcomparelanguage</a>");
67
echo "<center><hr noshade size=1>";
62
echo popup_form ("$CFG->wwwroot/$CFG->admin/lang.php?lang=", $langs, "chooselang", $currlang, "", "", "", true);
63
echo '</td></tr><tr><td colspan="2">';
68
64
$options["lang"] = $currentlang;
69
65
print_single_button("http://moodle.org/download/lang/", $options, get_string("latestlanguagepack"));
66
echo "</td></tr></table>";
67
print_heading("<a href=\"lang.php?mode=missing\">$strmissingstrings</a>");
68
print_heading("<a href=\"lang.php?mode=compare\">$streditstrings</a>");
69
print_heading("<a href=\"langdoc.php\">$stredithelpdocs</a>");
90
if ($mode == "missing" and confirm_sesskey()) {
89
if ($mode == "missing") {
91
90
// For each file, check that a counterpart exists, then check all the strings
93
92
foreach ($stringfiles as $file) {
94
if (!file_exists("$langdir/$file")) {
95
if (!touch("$langdir/$file")) {
96
echo "<p><font color=red>".get_string("filemissing", "", "$langdir/$file")."</font></p>";
102
94
include("$enlangdir/$file");
103
95
$enstring = $string;
106
include("$langdir/$file");
99
if (file_exists("$langdir/$file")) {
100
include("$langdir/$file");
102
notify(get_string("filemissing", "", "$langdir/$file"));
109
107
foreach ($enstring as $key => $value) {
110
if (!isset($string[$key]) or $string[$key] == "") {
108
if (empty($string[$key])) {
111
109
$value = htmlspecialchars($value);
112
110
$value = str_replace("$"."a", "\\$"."a", $value);
113
111
$value = str_replace("%%","%",$value);
131
129
foreach ($files as $filekey => $file) { // check all the help files.
132
130
if (!file_exists("$langdir/help/$file")) {
133
echo "<p><font color=red>".get_string("filemissing", "", "$langdir/help/$file")."</font></p>";
131
echo "<p><font color=\"red\">".get_string("filemissing", "", "$langdir/help/$file")."</font></p>";
134
132
$somethingfound = true;
142
140
foreach ($files as $filekey => $file) { // check all the docs files.
143
141
if (!file_exists("$langdir/docs/$file")) {
144
echo "<P><FONT COLOR=red>".get_string("filemissing", "", "$langdir/docs/$file")."</FONT></P>";
142
echo "<p><font color=\"red\">".get_string("filemissing", "", "$langdir/docs/$file")."</font></p>";
145
143
$somethingfound = true;
153
151
notice(get_string("languagegood"), "lang.php");
156
} else if ($mode == "compare" and confirm_sesskey()) {
154
} else if ($mode == "compare") {
158
156
if (isset($_POST['currentfile'])){ // Save a file
157
if (!confirm_sesskey()) {
158
error(get_string('confirmsesskeybad', 'error'));
159
160
$newstrings = $_POST;
160
161
unset($newstrings['currentfile']);
161
162
if (lang_save_file($langdir, $currentfile, $newstrings)) {
162
163
notify(get_string("changessaved")." ($langdir/$currentfile)", "green");
164
error("Could not save the file '$currentfile'!", "lang.php?mode=compare¤tfile=$currentfile&sesskey=$USER->sesskey");
165
error("Could not save the file '$currentfile'!", "lang.php?mode=compare&currentfile=$currentfile");
168
print_heading_with_help($strcomparelanguage, "langedit");
169
print_heading_with_help($streditstrings, "langedit");
170
171
print_simple_box_start("center", "80%");
171
172
echo '<center><font size="2">';
173
174
if ($file == $currentfile) {
174
175
echo "<b>$file</b> ";
176
echo "<a href=\"lang.php?mode=compare¤tfile=$file&sesskey=$USER->sesskey\">$file</a> ";
177
echo "<a href=\"lang.php?mode=compare&currentfile=$file\">$file</a> ";
179
180
echo '</font></center>';
185
186
if (!file_exists("$langdir/$currentfile")) {
186
187
if (!touch("$langdir/$currentfile")) {
187
echo "<p><font color=red>".get_string("filemissing", "", "$langdir/$currentfile")."</font></p>";
188
echo "<p><font color=\"red\">".get_string("filemissing", "", "$langdir/$currentfile")."</font></p>";
218
219
echo "<form name=\"$currentfile\" action=\"lang.php\" method=\"post\">";
219
echo '<input type="hidden" name="sesskey" value="'.$USER->sesskey.'" />';
221
echo "<table width=\"100%\" cellpadding=2 cellspacing=3 border=0>";
221
echo "<table width=\"100%\" cellpadding=\"2\" cellspacing=\"3\" border=\"0\" class=\"generalbox\">";
222
222
foreach ($enstring as $key => $envalue) {
223
223
$envalue = nl2br(htmlspecialchars($envalue));
224
224
$envalue = preg_replace('/(\$a\-\>[a-zA-Z0-9]*|\$a)/', '<b>$0</b>', $envalue); // Make variables bold.
225
225
$envalue = str_replace("%%","%",$envalue);
226
226
$envalue = str_replace("\\","",$envalue); // Delete all slashes
229
echo "<td dir=ltr lang=en width=20% bgcolor=\"$THEME->cellheading\" nowrap valign=top>$key</td>\n";
230
echo "<td dir=ltr lang=en width=40% bgcolor=\"$THEME->cellheading\" valign=top>$envalue</td>\n";
229
echo '<td dir="ltr" lang="en" width="20%" nowrap="nowrap" valign="top">'.$key.'</td>'."\n";
230
echo '<td dir="ltr" lang="en" width="40%" valign="top">'.$envalue.'</td>'."\n";
232
232
$value = $string[$key];
233
233
$value = str_replace("\r","",$value); // Bad character caused by Windows
239
239
$value = str_replace(">",">",$value);
240
240
$value = str_replace('"',""",$value);
242
$cellcolour = $value ? $THEME->cellcontent: $THEME->highlight;
242
$cellcolour = $value ? '': 'class="highlight"';
245
echo "<td width=40% bgcolor=\"$cellcolour\" valign=top>\n";
245
echo '<td width="40%" '.$cellcolour.' valign="top">'."\n";
246
246
if (isset($string[$key])) {
247
247
$valuelen = strlen($value);
252
252
if (strstr($value, "\r") or strstr($value, "\n") or $valuelen > $cols) {
253
253
$rows = ceil($valuelen / $cols);
254
echo "<textarea name=\"string-$key\" cols=\"$cols\" rows=\"$rows\">$value</textarea>\n";
254
echo '<textarea name="stringXXX'.$key.'" cols="'.$cols.'" rows="'.$rows.'">'.$value.'</textarea>'."\n";
257
257
$cols = $valuelen + 2;
259
echo "<input type=\"text\" name=\"string-$key\" value=\"$value\" size=\"$cols\"></td>";
259
echo '<input type="text" name="stringXXX'.$key.'" value="'.$value.'" size="'.$cols.'" />';
264
echo "<td width=40% bgcolor=\"$cellcolour\" valign=top>$value</td>\n";
264
echo '<td width="40%" bgcolor="'.$cellcolour.'" valign="top">'.$value.'</td>';
268
echo "<tr><td colspan=2> <td><br />";
269
echo " <input type=\"hidden\" name=\"currentfile\" value=\"$currentfile\">";
270
echo " <input type=\"hidden\" name=\"mode\" value=\"compare\">";
271
echo " <input type=\"submit\" name=\"update\" value=\"".get_string("savechanges").": $currentfile\">";
268
echo '<tr><td colspan="2"> <td><br />';
269
echo '<input type="hidden" name="sesskey" value="'.$USER->sesskey.'" />';
270
echo ' <input type="hidden" name="currentfile" value="'.$currentfile.'" />';
271
echo ' <input type="hidden" name="mode" value="compare" />';
272
echo ' <input type="submit" name="update" value="'.get_string('savechanges').': '.$currentfile.'" />';
305
306
foreach ($strings as $key => $value) {
306
list($id, $stringname) = explode("-",$key);
307
list($id, $stringname) = explode('XXX',$key);
307
308
if ($CFG->lang != "zh_hk" and $CFG->lang != "zh_tw") { // Some MB languages include backslash bytes
308
309
$value = str_replace("\\","",$value); // Delete all slashes