]> git.mjollnir.org Git - moodle.git/commitdiff
Fix for Bug #4910 - stringnames with - . and / don't show up in translation editor
authorvyshane <vyshane>
Wed, 5 Apr 2006 04:07:16 +0000 (04:07 +0000)
committervyshane <vyshane>
Wed, 5 Apr 2006 04:07:16 +0000 (04:07 +0000)
Modified /admin/lang.php to allow us to still use periods in language string keys. The lang.php script just replaces the periods with ##46# for the form inputs and then puts the periods back in before saving to the language file.

This means that there is no need to update language files at all. They will just work even with periods in the string keys.

admin/lang.php

index c87caf312554b2eb7d412e8bb6fee9884d3f9bbb..dd4c9fba3c236308130af1f70d46faf1cb3e4daa 100644 (file)
             if (!confirm_sesskey()) {
                 error(get_string('confirmsesskeybad', 'error'));
             }
-            $newstrings = $_POST;
+            
+            $newstrings = array();
+            
+            foreach ($_POST as $postkey => $postval) {
+                $stringkey = lang_file_string_key($postkey);
+                $newstrings[$stringkey] = $postval;
+            }
+            
             unset($newstrings['currentfile']);
             if (lang_save_file($langdir, $currentfile, $newstrings)) {
                 notify(get_string("changessaved")." ($langdir/$currentfile)", "green");
                 $cols=50;
                 if (strstr($value, "\r") or strstr($value, "\n") or $valuelen > $cols) {
                     $rows = ceil($valuelen / $cols);
-                    echo '<textarea name="stringXXX'.$key.'" cols="'.$cols.'" rows="'.$rows.'">'.$value.'</textarea>'."\n";
+                    echo '<textarea name="stringXXX'.lang_form_string_key($key).'" cols="'.$cols.'" rows="'.$rows.'">'.$value.'</textarea>'."\n";
                 } else {
                     if ($valuelen) {
                         $cols = $valuelen + 2;
                     }
-                    echo '<input type="text" name="stringXXX'.$key.'" value="'.$value.'" size="'.$cols.'" />';
+                    echo '<input type="text" name="stringXXX'.lang_form_string_key($key).'" value="'.$value.'" size="'.$cols.'" />';
                 }
                 echo '</td>';
 
@@ -343,4 +350,19 @@ function lang_save_file($path, $file, $strings) {
     return true;
 }
 
-?>
+
+
+/// Following functions are required because '.' in form input names
+/// get replaced by '_' by PHP.
+
+function lang_form_string_key($keyfromfile) {
+    return str_replace('.', '##46#', $keyfromfile);  /// Derived from &#46, the ascii value for a period.
+}
+
+
+function lang_file_string_key($keyfromform) {
+    return str_replace('##46#', '.', $keyfromform);
+}
+
+
+?>
\ No newline at end of file