From 8df3db566a3a937b45ebf11adb90d265e6f5e2d4 Mon Sep 17 00:00:00 2001 From: Andreas Baumann Date: Sun, 17 Nov 2019 20:45:02 +0100 Subject: initial checking of customized version 1.0rc9 --- scripts/langedit.php | 329 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 329 insertions(+) create mode 100644 scripts/langedit.php (limited to 'scripts/langedit.php') diff --git a/scripts/langedit.php b/scripts/langedit.php new file mode 100644 index 0000000..20ba4a8 --- /dev/null +++ b/scripts/langedit.php @@ -0,0 +1,329 @@ + +perms('manage_project')) { + Flyspray::show_error(28); +} + +// Make it possible to reload page after updating language +// Don't want to send form data again if user reloads the page +ob_start(); +?> + +\n"; +} +if(!file_exists('en.php')) { + $fail .= "The english language file en.php is missing. Make sure this script is run from the same directory as the language files .../flyspray/lang/
\n"; +} +if($fail) { + die($fail."Usage: <lang code> where <lang code> should be replaced by your language, e.g. de for German."); +} +// Read english language file in array $language (assumed to be UTF-8 encoded) +require('en.php'); +if(!is_array(@$language)){ + die("Invalid language file for english"); +} +$count = count($language); + +// Read the translation file in array $translation (assumed to be UTF-8 encoded) +$working_copy = false; +if(!file_exists($lang.'.php') && !file_exists('.'.$lang.'.php.work')) { + echo '

A new language file will be created: '.$lang.'.php

'; +} else { + if($lang != 'en') { + if(file_exists('.'.$lang.'.php.work')) { + $working_copy = true; + include_once('.'.$lang.'.php.work'); // Read the translation array (work in progress) + } else{ + include($lang.'.php'); // Read the original translation array - maybe again, no _once here! + } + } else if(file_exists('.en.php.work')){ + $working_copy = true; + $tmp = $language; + include_once('.en.php.work'); // Read the language array (work in progress) + $translation = $language; // Edit the english language file + $language = $tmp; + } else{ + $translation = $language; // Edit the english language file + } + + if(!is_array(@$translation)){ + echo "Warning: the translation file does not contain the \$translation array, a new file will be created: $lang.php\n"; + } +} + +$limit = 30; +$begin = isset($_GET['begin']) ? (int)($_GET['begin'] / $limit) * $limit : 0; + +// Was show missing pressed? +$show_empty = (!isset($_POST['search']) && isset($_REQUEST['empty'])); // Either POST or URL +// Any text in search box? +if(!$show_empty && isset($_POST['search_for'])) { + $search = trim($_POST['search_for']); +} else if(!$show_empty && isset($_GET['search_for'])) { + $search = trim(urldecode($_GET['search_for'])); +} else { + $search = ""; +} +// Path to this file +$self = "{$_SERVER['SCRIPT_NAME']}?do=langedit&lang=$lang"; + +if(isset($_POST['confirm'])) { + // Make a backup + unlink(".$lang.php.bak"); + rename("$lang.php", ".$lang.php.bak"); + rename(".$lang.php.work", "$lang.php"); + // Reload page, so that form data won't get posted again on refresh + header("location: $self&begin=$begin" . ($search? "&search_for=".urlencode($search): "") . ($show_empty? "&empty=": "")); + exit; +} else if(isset($_POST['submit']) && isset($_POST['L'])) { + // Save button was pressed + update_language($lang, $_POST['L'], @$_POST['E']); + // Reload page, so that form data won't get posted again on refresh + header("location: $self&begin=$begin" . ($search? "&search_for=".urlencode($search): "") . ($show_empty? "&empty=": "")); + exit; +} + +// One form for all buttons and inputs +echo 'Overview'; +echo "
\n"; +echo "\n + + $val){ + $trans = @$translation[$key]; + if((!$search && !$show_empty && $i >= $begin) || + ($search && (stristr($key, $search) || stristr($val, $search) || stristr($trans, $search))) || + ($show_empty && !$trans)){ + $bg = ($j++ & 1)? '#fff': '#eed'; + // Key + echo ''; + // English (underline leading and trailing spaces) + $space = '_'; + echo '\n"; + echo '\n"; + + if(--$limit == 0 && !$search && !$show_empty){ + break; + } + } + $i++; +} +?> +
"; +// Make page links +for($p = 0; $p < $count; $p += $limit){ + if($p){ + echo " | "; + } + $bgn = $p+1; + $end = min($p+$limit, $count); + if($p != $begin || $search || $show_empty) { + echo "$bgn…$end\n"; // Show all links when searching or display all missing strings + } else { + echo "$bgn…$end\n"; + } +} +?> + + + title="Confirm all changes and replace the original language file"> +
+.$lang.php.work until you press 'Confirm all changes'
"; +} +// Search +echo ''; +// List empty +if($lang != 'en') { + echo ''; +} +?> +
KeyEnglishTranslation:
'.($i+1).''.$key.''. (preg_match("/^[ \t]/",$val)? $space: "") . nl2br(htmlentities($val)). (preg_match("/[ \t]$/",$val)? $space: "") ."'; + echo ''; + echo ''; + // Count lines in both english and translation + $lines = 1 + max(preg_match_all("/\n/", $val, $matches), preg_match_all("/\n/", $trans, $matches)); + // Javascript call on some input events + $onchange = 'onchange="set(\''.$key.'\');" onkeypress="set(\''.$key.'\');"'; + // \ is displayed as \\ in edit fields to allow \n as line feed + $trans = str_replace("\\", "\\\\", $trans); + if($lines > 1 || strlen(utf8_decode($val)) > 60 || strlen(utf8_decode($trans)) > 60){ + // Format long texts for '; + } else{ + // Format short texts for + $trans = str_replace(array("\n", "\""), array("\\n", """), $trans); + echo ''; + } + echo "
+
+ + + + + +
The language files are UTF-8 encoded, avoid manual editing if You are not sure that your editor supports UTF-8
+Syntax for \ is \\ and for line feed type \\n in single line edit fields
langedit by larserik@softpoint.nu
+uses('content'); +$page->pushTpl('admin.translation.tpl'); + +// Parse string for \n and \\ to be replaced by and \ +function parseNL($str) { + $pos = 0; + while(($pos = strpos($str, "\\", $pos)) !== false){ + switch(substr($str, $pos, 2)){ + case "\\n": + $str = substr_replace($str, "\n", $pos, 2); + break; + case "\\\\": + $str = substr_replace($str, "\\", $pos, 2); + break; + } + $pos++; + } + return $str; +} + +function update_language($lang, &$strings, $edit) { + global $language, $translation; + + if(!is_array($edit)) { + return; + } + // Form data contains UTF-8 encoded text + foreach($edit as $key => $dummy){ + if(@$strings[$key]) { + $translation[$key] = parseNL($strings[$key]); + } else { + unset($translation[$key]); + } + } + // Make a backup just in case! + if(!file_exists(".$lang.php.safe")){ + // Make one safe backup that will NOT be changed by this script + copy("$lang.php", ".$lang.php.safe"); + } + if(file_exists(".$lang.php.work")){ + // Then make ordinary backups + copy(".$lang.php.work", ".$lang.php.bak"); + } + // Write the translation array to file with UNIX style line endings + $file = fopen(".$lang.php.work", "w"); + // Write the UTF-8 BOM, Byte Order Marker + //fprintf($file, chr(0xef).chr(0xbb).chr(0xbf)); + // Header + fprintf($file, " \\ + // " => \" + // $ => \$ + // => \n + // are removed if any + $pattern = array("\\", "\"", "\$", "\n", "\r"); + $replace = array("\\\\", "\\\"", "\\\$", "\\n", ""); + // Write the array to the file, ordered as the english language file + foreach($language as $key => $val){ + $trans = @$translation[$key]; + if(!$trans) { + continue; + } + if(strstr($trans, "\n")) { // Use double quotes for multiline + fprintf($file, "%-26s=> \"%s\",\n", "'$key'", str_replace($pattern, $replace, $trans)); + } else { // Use single quotes for single lines, only \ and ' needs escaping + fprintf($file, "%-26s=> '%s',\n", "'$key'", str_replace(array("\\","'"), array("\\\\", "\\'"), $trans)); + } + } + fprintf($file, ");\n\n?".">\n"); // PHP end tag currupts some syntax color coders + fclose($file); +} + +?> -- cgit v1.2.3-54-g00ecf