3 require_once("../config.php");
5 optional_variable($mode, "");
6 optional_variable($currentfile, "moodle.php");
11 error("You need to be admin to edit this page");
14 if (! $site = get_site()) {
15 error("Site not defined!");
18 $stradministration = get_string("administration");
19 $strconfiguration = get_string("configuration");
20 $strlanguage = get_string("language");
21 $strcurrentlanguage = get_string("currentlanguage");
22 $strmissingstrings = get_string("missingstrings");
23 $strcomparelanguage = get_string("comparelanguage");
24 $strthislanguage = get_string("thislanguage");
28 $navigation = "<A HREF=\"lang.php\">$strlanguage</A> -> $strmissingstrings";
29 $title = $strmissingstrings;
32 $navigation = "<A HREF=\"lang.php\">$strlanguage</A> -> $strcomparelanguage";
33 $title = $strcomparelanguage;
36 $title = $strlanguage;
37 $navigation = $strlanguage;
41 $currentlang = current_language();
43 print_header("$site->shortname: $title", "$site->fullname",
44 "<a href=\"index.php\">$stradministration</a> -> ".
45 "<a href=\"configure.php\">$strconfiguration</a> -> $navigation");
48 $currlang = current_language();
49 $langs = get_list_of_languages();
50 echo "<table align=center><tr><td align=\"right\">";
51 echo "<b>$strcurrentlanguage:</b>";
53 echo popup_form ("$CFG->wwwroot/admin/lang.php?lang=", $langs, "chooselang", $currlang, "", "", "", true);
54 echo "</td></tr></table>";
55 print_heading("<a href=\"lang.php?mode=missing\">$strmissingstrings</a>");
56 print_heading("<a href=\"lang.php?mode=compare\">$strcomparelanguage</a>");
57 echo "<center><hr noshade size=1>";
58 $options["lang"] = $currentlang;
59 print_single_button("http://moodle.org/download/lang/", $options, get_string("latestlanguagepack"));
65 // Get a list of all the root files in the English directory
67 $langdir = "$CFG->dirroot/lang/$currentlang";
68 $enlangdir = "$CFG->dirroot/lang/en";
70 if (! $stringfiles = get_directory_list($enlangdir, "", false)) {
71 error("Could not find English language pack!");
74 foreach ($stringfiles as $key => $file) {
75 if (substr($file, -4) != ".php") {
76 unset($stringfiles[$key]);
80 if ($mode == "missing") {
81 // For each file, check that a counterpart exists, then check all the strings
83 foreach ($stringfiles as $file) {
84 if (!file_exists("$langdir/$file")) {
85 if (!touch("$langdir/$file")) {
86 echo "<p><font color=red>".get_string("filemissing", "", "$langdir/$file")."</font></p>";
92 include("$enlangdir/$file");
96 include("$langdir/$file");
99 foreach ($enstring as $key => $value) {
100 if (!isset($string[$key]) or $string[$key] == "") {
101 $value = htmlspecialchars($value);
102 $value = str_replace("$"."a", "\\$"."a", $value);
103 $value = str_replace("%%","%",$value);
105 echo "</PRE><HR><P><B>".get_string("stringsnotset","","$langdir/$file")."</B></P><PRE>";
107 $somethingfound = true;
109 echo "$"."string['$key'] = \"$value\";<BR>";
114 if (! $files = get_directory_list("$CFG->dirroot/lang/en/help", "CVS")) {
115 error("Could not find English language help files!");
118 foreach ($files as $filekey => $file) { // check all the help files.
119 if (!file_exists("$langdir/help/$file")) {
120 echo "<p><font color=red>".get_string("filemissing", "", "$langdir/help/$file")."</font></p>";
121 $somethingfound = true;
126 if (! $files = get_directory_list("$CFG->dirroot/lang/en/docs", "CVS")) {
127 error("Could not find English language docs files!");
129 foreach ($files as $filekey => $file) { // check all the docs files.
130 if (!file_exists("$langdir/docs/$file")) {
131 echo "<P><FONT COLOR=red>".get_string("filemissing", "", "$langdir/docs/$file")."</FONT></P>";
132 $somethingfound = true;
137 if (!empty($somethingfound)) {
138 print_continue("lang.php");
140 notice(get_string("languagegood"), "lang.php");
143 } else if ($mode == "compare") {
145 if (isset($_POST['currentfile'])){ // Save a file
146 $newstrings = $_POST;
147 unset($newstrings['currentfile']);
148 if (lang_save_file($langdir, $currentfile, $newstrings)) {
149 notify(get_string("changessaved")." ($langdir/$currentfile)", "green");
151 error("Could not save the file '$currentfile'!", "lang.php?mode=compare¤tfile=$currentfile");
155 print_heading_with_help($strcomparelanguage, "langedit");
157 print_simple_box_start("center", "80%");
158 echo '<center><font size="2">';
159 foreach ($stringfiles as $file) {
160 if ($file == $currentfile) {
161 echo "<b>$file</b> ";
163 echo "<a href=\"lang.php?mode=compare¤tfile=$file\">$file</a> ";
166 echo '</font></center>';
167 print_simple_box_end();
170 print_heading("$currentfile", "center", 4);
172 if (!file_exists("$langdir/$currentfile")) {
173 if (!touch("$langdir/$currentfile")) {
174 echo "<p><font color=red>".get_string("filemissing", "", "$langdir/$currentfile")."</font></p>";
180 if ($f = fopen("$langdir/$currentfile","r+")) {
185 echo "<p><font size=1>".get_string("makeeditable", "", "$langdir/$currentfile")."</font></p>";
191 include("$enlangdir/$currentfile");
196 include("$langdir/$currentfile");
199 echo "<form name=\"$currentfile\" action=\"lang.php\" method=\"post\">";
201 echo "<table width=\"100%\" cellpadding=2 cellspacing=3 border=0>";
202 foreach ($enstring as $key => $envalue) {
203 $envalue = nl2br(htmlspecialchars($envalue));
204 $envalue = preg_replace('/(\$a\-\>[a-zA-Z0-9]*|\$a)/', '<b>$0</b>', $envalue); // Make variables bold.
205 $envalue = str_replace("%%","%",$envalue);
206 $envalue = str_replace("\\","",$envalue); // Delete all slashes
209 echo "<td width=20% bgcolor=\"$THEME->cellheading\" nowrap valign=top>$key</td>";
210 echo "<td width=40% bgcolor=\"$THEME->cellheading\" valign=top>$envalue</td>";
212 $value = $string[$key];
213 $value = str_replace("\r","",$value); // Bad character caused by Windows
214 $value = str_replace("\n\n\n\n\n\n","\n",$value); // Collapse runs of blank lines
215 $value = str_replace("\n\n\n\n\n","\n",$value);
216 $value = str_replace("\n\n\n\n","\n",$value);
217 $value = str_replace("\n\n\n","\n",$value);
218 $value = str_replace("\n\n\n","\n",$value);
219 $value = str_replace("\\","",$value); // Delete all slashes
220 $value = str_replace("%%","%",$value);
221 $value = htmlspecialchars($value);
223 $cellcolour = $value ?
$THEME->cellcontent
: $THEME->highlight
;
226 echo "<td width=40% bgcolor=\"$cellcolour\" valign=top>";
227 if (isset($string[$key])) {
228 $valuelen = strlen($value);
230 $valuelen = strlen($envalue);
233 if (strstr($value, "\r") or strstr($value, "\n") or $valuelen > $cols) {
234 $rows = ceil($valuelen / $cols);
235 echo "<textarea name=\"string-$key\" cols=\"$cols\" rows=\"$rows\">$value</textarea>";
238 $cols = $valuelen +
2;
240 echo "<input type=\"text\" name=\"string-$key\" value=\"$value\" size=\"$cols\"></td>";
245 echo "<td width=40% bgcolor=\"$cellcolour\" valign=top>$value</td>";
249 echo "<tr><td colspan=2> <td><br />";
250 echo " <input type=\"hidden\" name=\"currentfile\" value=\"$currentfile\">";
251 echo " <input type=\"hidden\" name=\"mode\" value=\"compare\">";
252 echo " <input type=\"submit\" name=\"update\" value=\"".get_string("savechanges").": $currentfile\">";
262 //////////////////////////////////////////////////////////////////////
264 function lang_save_file($path, $file, $strings) {
265 // Thanks to Petri Asikainen for the original version of code
266 // used to save language files.
268 // $path is a full pathname to the file
269 // $file is the file to overwrite.
270 // $strings is an array of strings to write
275 if (!$f = fopen("$path/$file","w")) {
281 fwrite($f, "<?PHP // \$Id\$ \n");
282 fwrite($f, " // $file - created with Moodle $CFG->release ($CFG->version)\n\n\n");
286 foreach ($strings as $key => $value) {
287 list($id, $stringname) = explode("-",$key);
288 if ($CFG->lang
!= "zh_hk" and $CFG->lang
!= "zh_tw") { // Some MB languages include backslash bytes
289 $value = str_replace("\\","",$value); // Delete all slashes
291 $value = str_replace("'", "\\'", $value); // Add slashes for '
292 $value = str_replace('"', "\\\"", $value); // Add slashes for "
293 $value = str_replace("%","%%",$value); // Escape % characters
294 $value = str_replace("\r", "",$value); // Remove linefeed characters
295 if ($id == "string" and $value != ""){
296 fwrite($f,"\$string['$stringname'] = '$value';\n");