From 7c1029bbcb0f020fa859ecc978ed8bffd8d9b6c1 Mon Sep 17 00:00:00 2001 From: bradymiller Date: Wed, 14 Apr 2010 06:35:31 +0000 Subject: [PATCH] Added support for language translation oustomization and logging --- interface/language/lang_constant.php | 5 ++ interface/language/lang_definition.php | 85 +++++++++++++++---- interface/language/lang_language.php | 8 +- interface/language/lang_manage.php | 151 +++++++++++++++++++++++++++++++++ interface/language/language.inc.php | 62 +++++++++++++- interface/language/language.php | 67 ++++++++------- 6 files changed, 327 insertions(+), 51 deletions(-) create mode 100644 interface/language/lang_manage.php diff --git a/interface/language/lang_constant.php b/interface/language/lang_constant.php index f67936a30..7754d9fd2 100644 --- a/interface/language/lang_constant.php +++ b/interface/language/lang_constant.php @@ -17,8 +17,13 @@ if ($_POST['add']){ if ($err=='y'){ $val_constant=strip_escape_custom($_POST['constant_name']); } else { + //insert into the main table $sql="INSERT INTO lang_constants SET constant_name='".formData('constant_name')."'"; SqlStatement ($sql); + + //insert into the log table - to allow persistant customizations + insert_language_log('','',formData('constant_name'),''); + echo xl('Constant','','',' ') . strip_escape_custom($_POST['constant_name']) . xl('added','',' ','
'); } diff --git a/interface/language/lang_definition.php b/interface/language/lang_definition.php index e1b8268a4..0942b825d 100644 --- a/interface/language/lang_definition.php +++ b/interface/language/lang_definition.php @@ -1,9 +1,35 @@ - +     + + + + + +
+
+ + " . xl($row['lang_description']) . " |"; + } + $string.='|'; + echo (xl('Edit definitions').": $string

"); if ($_POST['load']) { + // set up the mysql collation string to ensure case is sensitive in the mysql queries + if (!$disable_utf8_flag) { + $case_sensitive_collation = "COLLATE utf8_bin"; + } + else { + $case_sensitive_collation = "COLLATE latin_bin"; + } + // query for entering new definitions it picks the cons_id because is existant. - $sql = "INSERT INTO lang_definitions (`cons_id`,`lang_id`,`definition`) VALUES "; if (!empty($_POST['cons_id'])) { foreach ($_POST['cons_id'] as $key => $value) { $value = formDataCore($value,true); @@ -11,29 +37,54 @@ if ($_POST['load']) { // do not create new blank definitions if ($value == "") continue; - $sql .= " ('$key', "; + // insert into the main language tables + $sql = "INSERT INTO lang_definitions (`cons_id`,`lang_id`,`definition`) VALUES "; + $sql .= "('$key',"; $sql .= "'" . formData('lang_id') . "',"; - $sql .= "'" . $value . "'),"; + $sql .= "'" . $value . "')"; + SqlStatement($sql); + + // insert each entry into the log table - to allow persistant customizations + $sql = "SELECT lang_description, lang_code FROM lang_languages WHERE lang_id = '".formData('lang_id')."' LIMIT 1"; + $res = SqlStatement($sql); + $row_l = SqlFetchArray($res); + $sql = "SELECT constant_name FROM lang_constants WHERE cons_id = '".$key."' LIMIT 1"; + $res = SqlStatement($sql); + $row_c = SqlFetchArray($res); + insert_language_log(add_escape_custom($row_l['lang_description']), add_escape_custom($row_l['lang_code']), add_escape_custom($row_c['constant_name']), $value); + $go = 'yes'; - } + } } - if ($go=='yes') { - $sql=substr($sql,0,-1); - if (SqlStatement($sql)) { - xl ("New Definition set added",'e'); - } - } + // query for updating preexistant definitions uses def_id because there is no def yet. // echo ('
');	print_r($_POST['def_id']);	echo ('
'); if (!empty($_POST['def_id'])) { foreach ($_POST['def_id'] as $key => $value) { $value = formDataCore($value,true); - $sql = "UPDATE `lang_definitions` SET `definition` = '$value' WHERE `def_id`='$key' LIMIT 1"; - SqlStatement($sql); - $goMod = 'yes'; + + // only continue if the definition is new + $sql = "SELECT * FROM lang_definitions WHERE def_id = '".$key."' AND definition = '".$value."' ".$case_sensitive_collation; + $res_test = SqlStatement($sql); + if (!SqlFetchArray($res_test)) { + // insert into the main language tables + $sql = "UPDATE `lang_definitions` SET `definition` = '$value' WHERE `def_id`='$key' LIMIT 1"; + SqlStatement($sql); + + // insert each entry into the log table - to allow persistant customizations + $sql = "SELECT ll.lang_description, ll.lang_code, lc.constant_name "; + $sql .= "FROM lang_definitions AS ld, lang_languages AS ll, lang_constants AS lc "; + $sql .= "WHERE ld.def_id = '".$key."' "; + $sql .= "AND ll.lang_id = ld.lang_id AND lc.cons_id = ld.cons_id LIMIT 1"; + $res = SqlStatement($sql); + $row = SqlFetchArray($res); + insert_language_log(add_escape_custom($row['lang_description']), add_escape_custom($row['lang_code']), add_escape_custom($row['constant_name']), $value); + + $go = 'yes'; + } } - if ($goMod=='yes') xl("New Definition set added",'e'); } + if ($go=='yes') xl("New Definition set added",'e'); } if ($_GET['edit'] != ''){ @@ -99,5 +150,5 @@ if ($_GET['edit'] != ''){ echo (''); echo (''); } - + ?> diff --git a/interface/language/lang_language.php b/interface/language/lang_language.php index 0689d3a9a..8bf006b15 100644 --- a/interface/language/lang_language.php +++ b/interface/language/lang_language.php @@ -1,5 +1,4 @@ '); + + //insert into the log table - to allow persistant customizations + insert_language_log(formData('lang_name'),formData('lang_code'),'',''); + + xl('Language definition added','e','','
'); } } diff --git a/interface/language/lang_manage.php b/interface/language/lang_manage.php new file mode 100644 index 000000000..ebbb80ab1 --- /dev/null +++ b/interface/language/lang_manage.php @@ -0,0 +1,151 @@ +"; + if (!$checkOnly) { + // add the new language (first collect the language code) + $sql = "SELECT lang_code FROM lang_custom WHERE constant_name='' AND lang_description='".add_escape_custom($var)."' ".$case_sensitive_collation." LIMIT 1"; + $res = SqlStatement($sql); + $row = SqlFetchArray($res); + $sql="INSERT INTO lang_languages SET lang_code='".add_escape_custom($row['lang_code'])."', lang_description='".add_escape_custom($var)."'"; + SqlStatement($sql); + echo xl('Synchronized new custom language:')." ".$var."

"; + } + $difference = 1; + } + + // + // collect and display(synchronize) new custom constants + // + $sql = "SELECT constant_name FROM lang_constants"; + $res = SqlStatement($sql); + $row_main = array(); + while ($row=SqlFetchArray($res)){ + $row_main[] = $row['constant_name']; + } + $sql = "SELECT constant_name FROM lang_custom"; + $res = SqlStatement($sql); + $row_custom = array(); + while ($row=SqlFetchArray($res)){ + $row_custom[] = $row['constant_name']; + } + $custom_constants = array_diff(array_unique($row_custom),array_unique($row_main)); + foreach ($custom_constants as $var) { + if ($var=='') continue; + echo xl('Following is a new custom constant:')." ".$var."
"; + if (!$checkOnly) { + // add the new constant + $sql="INSERT INTO lang_constants SET constant_name='".add_escape_custom($var)."'"; + SqlStatement($sql); + echo xl('Synchronized new custom constant:')." ".$var."

"; + } + $difference = 1; + } + + // + // collect and display(synchronize) custom definitions + // + $sql = "SELECT lang_description, lang_code, constant_name, definition FROM lang_custom WHERE lang_description != '' AND constant_name != ''"; + $res = SqlStatement($sql); + while ($row=SqlFetchArray($res)){ + + // collect language id + $sql = "SELECT lang_id FROM lang_languages WHERE lang_description='".add_escape_custom($row['lang_description'])."' ".$case_sensitive_collation." LIMIT 1"; + $res2 = SqlStatement($sql); + $row2 = SqlFetchArray($res2); + $language_id=$row2['lang_id']; + + // collect constant id + $sql = "SELECT cons_id FROM lang_constants WHERE constant_name='".add_escape_custom($row['constant_name'])."' ".$case_sensitive_collation." LIMIT 1"; + $res2 = SqlStatement($sql); + $row2 = SqlFetchArray($res2); + $constant_id=$row2['cons_id']; + + // collect definition id (if it exists) + $sql = "SELECT def_id FROM lang_definitions WHERE cons_id='".add_escape_custom($constant_id)."' AND lang_id='".add_escape_custom($language_id)."' LIMIT 1"; + $res2 = SqlStatement($sql); + $row2 = SqlFetchArray($res2); + $def_id=$row2['def_id']; + + if ($def_id) { + //definition exist, so check to see if different + $sql = "SELECT * FROM lang_definitions WHERE def_id = '".add_escape_custom($def_id)."' AND definition = '".add_escape_custom($row['definition'])."' ".$case_sensitive_collation; + $res_test = SqlStatement($sql); + if (SqlFetchArray($res_test)) { + //definition not different + continue; + } + else { + //definition is different + echo xl('Following is a new definition (Language, Constant, Definition):')." ".$row['lang_description']." ".$row['constant_name']." ".$row['definition']."
"; + if (!$checkOnly) { + //add new definition + $sql = "UPDATE `lang_definitions` SET `definition` = '".add_escape_custom($row['definition'])."' WHERE `def_id`='".add_escape_custom($def_id)."' LIMIT 1"; + SqlStatement($sql); + echo xl('Synchronized new definition (Language, Constant, Definition):')." ".$row['lang_description']." ".$row['constant_name']." ".$row['definition']."

"; + } + $difference = 1; + } + } + else { + echo xl('Following is a new definition (Language, Constant, Definition):')." ".$row['lang_description']." ".$row['constant_name']." ".$row['definition']."
"; + if (!$checkOnly) { + //add new definition + $sql = "INSERT INTO lang_definitions (cons_id,lang_id,definition) VALUES ('".add_escape_custom($constant_id)."','".add_escape_custom($language_id)."','".add_escape_custom($row['definition'])."')"; + SqlStatement($sql); + echo xl('Synchronized new definition (Language, Constant, Definition):')." ".$row['lang_description']." ".$row['constant_name']." ".$row['definition']."

"; + } + $difference = 1; + } + } + if (!$difference) { + echo xl('The translation tables are synchronized.'); + } +} +?> + + + + + + + + + + + + + +
diff --git a/interface/language/language.inc.php b/interface/language/language.inc.php index e29a4167f..df9c39bce 100644 --- a/interface/language/language.inc.php +++ b/interface/language/language.inc.php @@ -10,12 +10,68 @@ if (!$thisauth) { exit(); } - - function check_pattern ($data,$pat) { if (ereg ($pat, $data)) { return TRUE ; } else { RETURN FALSE; } } -//$pat="^(19[0-9]{2}|20[0-1]{1}[0-9]{1})-(0[1-9]|1[0-2])-(0[1-9]{1}|1[0-9]{1}|2[0-9]{1}|3[0-1]{1})$"; +// Function to insert/modify items in the language log table, lang_custom +// NOTE THAT ALL PARAMETERS SHOULD ALREADY BE ESCAPED TO PREPARE FOR MYSQL QUERIES +// +function insert_language_log($lang_desc,$lang_code,$cons_name,$def) { + global $enable_custom_language_logging; + if (!$enable_custom_language_logging) return; + + // set up the mysql collation string to ensure case is sensitive in the mysql queries + if (!$disable_utf8_flag) { + $case_sensitive_collation = "COLLATE utf8_bin"; + } + else { + $case_sensitive_collation = "COLLATE latin_bin"; + } + + + if ($cons_name == '') { + // NEW LANGUAGE + // (ensure not a repeat log entry) + $sql = "SELECT * FROM lang_custom WHERE constant_name='' AND lang_description='".$lang_desc."' ".$case_sensitive_collation; + $res_test = SqlStatement($sql); + if (!SqlFetchArray($res_test)) { + $sql="INSERT INTO lang_custom SET lang_code='".$lang_code."', lang_description='".$lang_desc."'"; + SqlStatement ($sql); + } + } + elseif ($lang_desc == '') { + // NEW CONSTANT + // (ensure not a repeat entry) + $sql = "SELECT * FROM lang_custom WHERE lang_description='' AND constant_name='".$cons_name."' ".$case_sensitive_collation; + $res_test = SqlStatement($sql); + if (!SqlFetchArray($res_test)) { + $sql="INSERT INTO lang_custom SET constant_name='".$cons_name."'"; + SqlStatement ($sql); + } + } + else { + // FULL ENTRY + // (ensure not a repeat log entry) + $sql = "SELECT * FROM lang_custom WHERE lang_description='".$lang_desc."' AND constant_name='".$cons_name."' AND definition='".$def."' ".$case_sensitive_collation; + $res_test = SqlStatement($sql); + if (!SqlFetchArray($res_test)) { + // either modify already existing log entry or create a new one + $sql = "SELECT * FROM lang_custom WHERE lang_description='".$lang_desc."' AND constant_name='".$cons_name."' ".$case_sensitive_collation; + $res_test2 = SqlStatement($sql); + if (SqlFetchArray($res_test2)) { + // modify existing log entry(s) + $sql = "UPDATE lang_custom SET definition = '".$def."' WHERE lang_description='".$lang_desc."' AND constant_name='".$cons_name."' ".$case_sensitive_collation; + SqlStatement($sql); + } + else { + // create new log entry + $sql = "INSERT INTO lang_custom (lang_description,lang_code,constant_name,definition) VALUES "; + $sql .= "('".$lang_desc."','".$lang_code."','".$cons_name."','".$def."')"; + SqlStatement($sql); + } + } + } +} ?> diff --git a/interface/language/language.php b/interface/language/language.php index b57793777..f07190947 100644 --- a/interface/language/language.php +++ b/interface/language/language.php @@ -7,6 +7,20 @@ include_once("../../library/acl.inc"); require_once("language.inc.php"); require_once("$srcdir/formdata.inc.php"); +// Setting to enable custom logging of language translations +// (Note that the below mysql table is required for this function) +$enable_custom_language_logging=false; +/* Note that the table mysql lang_custom is required for this function, +which can ce accomplished with following script in mysql: +DROP TABLE IF EXISTS lang_custom; +CREATE TABLE lang_custom ( + lang_description varchar(100) NOT NULL default '', + lang_code char(2) NOT NULL default '', + constant_name varchar(255) NOT NULL default '', + definition mediumtext NOT NULL default '' +) ENGINE=MyISAM ; +*/ + //START OUT OUR PAGE.... ?> @@ -18,7 +32,7 @@ require_once("$srcdir/formdata.inc.php"); - -
+ + ' /> ' /> -    - - + + + + +
+ + | + + | + | + +
-
- -
-
- + " . xl($row['lang_description']) . " |"; -} -$string.='|'; - -echo ("".xl('Add Language')." or "); -echo ("".xl('Add Constant')." or "); -echo (xl('Edit definitions').": $string

"); - switch ($_GET['m']): case 'definition': include_once('lang_definition.php'); - break; + break; case 'constant': include_once('lang_constant.php'); - break; - case 'language': + break; + case 'language': include_once('lang_language.php'); - break; + break; + case 'manage': + include_once('lang_manage.php'); + break; endswitch; ?>
-
+ -- 2.11.4.GIT