Skip to content

Commit

Permalink
Fix for Bug #4910 - stringnames with - . and / don't show up in trans…
Browse files Browse the repository at this point in the history
…lation editor

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.
  • Loading branch information
vyshane committed Apr 5, 2006
1 parent 9c9aeef commit 5723bc6
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions admin/lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,14 @@
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");
Expand Down Expand Up @@ -272,12 +279,12 @@
$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>';

Expand Down Expand Up @@ -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);
}


?>

0 comments on commit 5723bc6

Please sign in to comment.