From: scyrma Date: Fri, 26 Sep 2008 01:56:12 +0000 (+0000) Subject: MDL-15688: Keep local modifications in language files - only import new strings.... X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=a6c1407820dda9d1f44804f03320c74d5f12640d;p=moodle.git MDL-15688: Keep local modifications in language files - only import new strings. This also fix a few display bug and prevent use from the web. --- diff --git a/lib/editor/tinymce/create_langfiles.php b/lib/editor/tinymce/create_langfiles.php index 534f6789b1..921f653a41 100755 --- a/lib/editor/tinymce/create_langfiles.php +++ b/lib/editor/tinymce/create_langfiles.php @@ -1,6 +1,10 @@ #!/usr/bin/php 'sr_lt', + 'nb' => 'no', + //'sr' => 'sr_lt', // ignore the Serbian translation 'zh' => 'zh_tw', ); @@ -43,7 +48,7 @@ if (isset($_SERVER['REMOTE_ADDR'])) { // if the script is accessed via the web. } // Do it. -import_language_files(); +build_language_files(); /**************************************************************************** * Everything's a function. @@ -93,8 +98,12 @@ function read_language_file($lang) { } if (file_exists($langfile)) { include($langfile); - } - return $string; + } + $encodedstrings = array(); + foreach($string as $key => $value) { + $encodedstrings[strtr($key, array('\\\'' =>'\\\'', '\'' => '\\\''))] = strtr($value, array('\\\'' =>'\\\'', '\'' => '\\\'')); + } + return $encodedstrings; } /** @@ -111,20 +120,25 @@ function write_language_file($lang, $langdata) { } $file = fopen(find_language_file($lang), 'w'); - fwrite($file, " $line) { - // the next two lines are there to make you enjoy how php deals with backslashes - $line = preg_replace_callback('/\\\\u([0-9A-F]{4})/', 'unichr', $line); // we're matching something like \u00E9 - // we're only escaping single quotes, but we gotta prevent escaping those that have already been escaped. - fwrite($file, '$string[\''. $id ."']='". strtr($line, array('\\\'' => '\\\'', '\'' => '\\\'', '%' => '%%', '$' => '\$')) ."';\n"); + fwrite($file, '$string[\''. $id ."'] = '". $line ."';\n"); } - fwrite($file, "?>"); + fwrite($file, "\n?>\n"); fclose($file); } +function encode_text($text) { + // the next two lines are there to make you enjoy how php deals with backslashes + $text = preg_replace_callback('/\\\\u([0-9A-F]{4})/', 'unichr', $text); // we're matching something like \u00E9 + // we're only escaping single quotes, but we gotta prevent escaping those that have already been escaped. + $text = strtr($text, array('\\\'' => '\\\'', '\'' => '\\\'', '%' => '%%', '$' => '\$')); + return $text; +} + /** * Unicode aware version of chr, while we wait for PHP to reach the 21st century. * Taken on http://au.php.net/manual/en/function.chr.php#77911 @@ -151,7 +165,7 @@ function unichr($c) { return $s; } -function import_language_files() { +function build_language_files() { // build file list $languagefiles = array(); $langfolders = array( @@ -174,6 +188,15 @@ function import_language_files() { } } + // process English first - it's necessary to compare other languages later on + import_language_files($languagefiles); + + global $sec; + print("\nIt is suggested you run this script twice. This will include() \nthe generated files once and detect parse errors before you \ncommit the files and wreach havoc on every Moodle site out there. \n\nReally. \n\nIt's quick (this script only took ". (time() - $sec) ." seconds to run), so do it!\n\nThe english translation file was only saved in HEAD. You will need \nto copy it to any other necessary checkout manually.\n\n"); +} + +function import_language_files($languagefiles) { + // process the files and import strings foreach ($languagefiles as $currentlang => $filepaths) { @@ -184,7 +207,7 @@ function import_language_files() { continue; } - print($filename .' - '); + print($currentlang .' - '); if (!empty($strings)) { print('loaded '. count($strings) .' current strings - '); @@ -193,6 +216,7 @@ function import_language_files() { } $importedstrings = 0; + $addedstrings = 0; foreach ($filepaths as $currentpath => $moduletypes) { foreach ($moduletypes as $moduletype => $filenames) { foreach ($filenames as $filename) { @@ -232,7 +256,17 @@ function import_language_files() { if (!empty($moduletype)) { $modulestring = $moduletype .'/'; } - $strings[$modulestring . $section . $subsection . $stringid] = $stringvalue; + + $key = $modulestring . $section . $subsection . $stringid; + $value = encode_text($stringvalue); + + // we're only adding new strings. No removals, no updates. + if (!array_key_exists($key, $strings)) { + $strings[$key] = $value; + //echo "added $key:$value\n"; + $addedstrings++; + } + $importedstrings++; } else { // wrong line !? @@ -246,11 +280,8 @@ function import_language_files() { } write_language_file($currentlang, $strings); - print("imported $importedstrings strings.\n"); + print("imported $importedstrings strings, added $addedstrings.\n"); } - global $sec; - print("\nIt is suggested you run this script twice. This will include() \nthe generated files once and detect parse errors before you \ncommit the files and wreach havoc on every Moodle site out there. \n\nReally. \n\nIt's quick (this script only took ". (time() - $sec) ." seconds to run), so do it!\n\nThe english translation file was only saved in head. You will need \n\nto copy it to any other necessary checkout manually.\n\n"); } - ?>