From: mudrd8mz Date: Sat, 3 Feb 2007 12:23:53 +0000 (+0000) Subject: lang.php now keeps orphaned transaltions, i.e. string without English reference.... X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=dd43d3715210c0a7fcdc1dae7ecc1dd63d92c76a;p=moodle.git lang.php now keeps orphaned transaltions, i.e. string without English reference. Fixes MDL-8409. --- diff --git a/admin/lang.php b/admin/lang.php index 3da624d947..ec0084674e 100644 --- a/admin/lang.php +++ b/admin/lang.php @@ -1,38 +1,6 @@ 's - * 5) added error_reporting(E_ALL ^ E_NOTICE); in "compare" mode (even in debug environment - * we know that missing keys are missing strings here, not bugs ;-) */ require_once('../config.php'); @@ -47,6 +15,7 @@ define('LANG_LINK_MISSING_STRINGS', 1); // create links from "missing" page to "compare" page? define('LANG_DEFAULT_USELOCAL', 0); // should *_utf8_local be used by default? define('LANG_MISSING_TEXT_MAX_LEN', 60); // maximum length of the missing text to display + define('LANG_KEEP_ORPHANS', 1); // keep orphaned strings (i.e. strings w/o English reference) $mode = optional_param('mode', '', PARAM_ALPHA); $currentfile = optional_param('currentfile', LANG_DEFAULT_FILE, PARAM_FILE); @@ -529,6 +498,18 @@ */ function lang_save_file($path, $file, $strings, $local, $packstrings) { global $CFG, $USER; + if (LANG_KEEP_ORPHANS) { + // let us load the current content of the file + unset($string); + @include("$path/$file"); + if (isset($string)) { + $orphans = $string; + unset($string); + } else { + $orphans = array(); + } + } + // let us rewrite the file if (!$f = @fopen("$path/$file","w")) { return false; } @@ -542,27 +523,33 @@ function lang_save_file($path, $file, $strings, $local, $packstrings) { ksort($strings); foreach ($strings as $key => $value) { @list($id, $stringname) = explode('XXX',$key); - if ($CFG->lang != "zh_hk" and $CFG->lang != "zh_tw") { // Some MB languages include backslash bytes - $value = str_replace("\\","",$value); // Delete all slashes - } - $value = str_replace("'", "\\'", $value); // Add slashes for ' - $value = str_replace('"', "\\\"", $value); // Add slashes for " - $value = str_replace("%","%%",$value); // Escape % characters - $value = str_replace("\r", "",$value); // Remove linefeed characters - $value = trim($value); // Delete leading/trailing white space + $value = lang_fix_value_before_save($value); if ($id == "string" and $value != ""){ if ((!$local) || (lang_fix_value_from_file($packstrings[$stringname]) <> lang_fix_value_from_file($value))) { fwrite($f,"\$string['$stringname'] = '$value';\n"); + if (LANG_KEEP_ORPHANS && isset($orphans[$stringname])) { + unset($orphans[$stringname]); + } } } } + if (LANG_KEEP_ORPHANS) { + // let us add orphaned strings, i.e. already translated strings without the English referential source + foreach ($orphans as $key => $value) { + fwrite($f,"\$string['$key'] = '".lang_fix_value_before_save($value)."'; // ORPHANED\n"); + } + } fwrite($f,"\n?>\n"); fclose($f); return true; } /** - * Fix value of string to translate. + * Fix value of the translated string after it is load from the file. + * + * These modifications are typically necessary to work with the same string coming from two sources. + * We need to compare the content of these sources and we want to have e.g. "This string\r\n" + * to be the same as " This string\n". * * @param string $value Original string from the file * @return string Fixed value @@ -579,6 +566,26 @@ function lang_fix_value_from_file($value='') { return $value; } +/** + * Fix value of the translated string before it is saved into the file + * + * @uses $CFG + * @param string $value Raw string to be saved into the lang pack + * @return string Fixed value + */ +function lang_fix_value_before_save($value='') { + global $CFG; + if ($CFG->lang != "zh_hk" and $CFG->lang != "zh_tw") { // Some MB languages include backslash bytes + $value = str_replace("\\","",$value); // Delete all slashes + } + $value = str_replace("'", "\\'", $value); // Add slashes for ' + $value = str_replace('"', "\\\"", $value); // Add slashes for " + $value = str_replace("%","%%",$value); // Escape % characters + $value = str_replace("\r", "",$value); // Remove linefeed characters + $value = trim($value); // Delete leading/trailing white space + return $value; +} + /** * Try and create a new language directory. * @@ -598,15 +605,26 @@ function lang_make_directory($dir, $shownotices=true) { return $dir; } - - -/// Following functions are required because '.' in form input names -/// get replaced by '_' by PHP. - +/** + * Return the string key name for use in HTML form. + * + * Required because '.' in form input names get replaced by '_' by PHP. + * + * @param string $keyfromfile The key name containing '.' + * @return string The key name without '.' + */ function lang_form_string_key($keyfromfile) { return str_replace('.', '##46#', $keyfromfile); /// Derived from ., the ascii value for a period. } +/** + * Return the string key name for use in file. + * + * Required because '.' in form input names get replaced by '_' by PHP. + * + * @param string $keyfromfile The key name without '.' + * @return string The key name containing '.' + */ function lang_file_string_key($keyfromform) { return str_replace('##46#', '.', $keyfromform); }