diff --git a/e107_admin/language.php b/e107_admin/language.php index 86513e30f..dd77c3085 100644 --- a/e107_admin/language.php +++ b/e107_admin/language.php @@ -75,21 +75,23 @@ if (isset($_POST['del_existing']) && $_POST['lang_choices']) { if ($sql->db_Table_exists($lang."_".$del_table,TRUE)) { - echo $del_table." exists
"; + // echo $del_table." exists
"; $qry = "DROP TABLE ".$mySQLprefix."lan_".$lang."_".$del_table; if (mysql_query($qry)) { - $message .= sprintf(LANG_LAN_100, $_POST['lang_choices'].' '.$del_table).'[!br!]'; // can be removed? - $mes->addSuccess(sprintf(LANG_LAN_100, $_POST['lang_choices'].' '.$del_table)); + $msg = $tp->lanVars(LANG_LAN_100, $_POST['lang_choices'].' '.$del_table); + $message .= $msg.'[!br!]'; + $mes->addSuccess($msg); } else { - $message .= sprintf(LANG_LAN_101, $_POST['lang_choices'].' '.$del_table).'[!br!]'; // can be removed? - $mes->addWarning(sprintf(LANG_LAN_101, $_POST['lang_choices'].' '.$del_table)); + $msg = $tp->lanVars(LANG_LAN_101, $_POST['lang_choices'].' '.$del_table); + $message .= $msg.'[!br!]'; + $mes->addWarning($msg); } } } - $admin_log->log_event('LANG_02', $message, E_LOG_INFORMATIVE, ''); + $admin_log->log_event('LANG_02', $message.'[!br!]', E_LOG_INFORMATIVE, ''); $sql->db_ResetTableList(); if ($action == 'modify') @@ -108,20 +110,23 @@ if (isset($_POST['create_tables']) && $_POST['language']) $copdata = ($_POST['copydata_'.$value]) ? 1 : 0; if ($sql->db_CopyTable($value, "lan_".$lang."_".$value, $_POST['drop'], $copdata)) { - $message .= sprintf(LANG_LAN_103, $_POST['language'].' '.$value).'[!br!]'; // can be removed? - $mes->addSuccess(sprintf(LANG_LAN_103, $_POST['language'].' '.$value)); + $msg = $tp->lanVars(LANG_LAN_103, $_POST['language'].' '.$value); + $message .= $msg . '[!br!]'; // Used in admin log. + $mes->addSuccess($msg); } else { if (!$_POST['drop']) { - $message .= sprintf(LANG_LAN_00, $_POST['language'].' '.$value).'[!br!]'; // can be removed? - $mes->addWarning(sprintf(LANG_LAN_00, $_POST['language'].' '.$value)); + $msg = $tp->lanVars(LANG_LAN_00, $_POST['language'].' '.$value); + $message .= $msg . '[!br!]'; + $mes->addWarning($msg); } else { - $message .= sprintf(LANG_LAN_01, $_POST['language'].' '.$value).'[!br!]'; // can be removed? - $mes->addWarning(sprintf(LANG_LAN_01, $_POST['language'].' '.$value)); + $msg = $tp->lanVars(LANG_LAN_01, $_POST['language'].' '.$value); + $message .= $msg . '[!br!]'; + $mes->addWarning($msg); } } } @@ -137,15 +142,18 @@ if (isset($_POST['create_tables']) && $_POST['language']) } else { - $message .= sprintf(LANG_LAN_02, $_POST['language'].' '.$value).'[!br!]'; // can be removed? - $mes->addWarning(sprintf(LANG_LAN_02, $_POST['language'].' '.$value)); + $msg = $tp->lanVars(LANG_LAN_02, $_POST['language'].' '.$value); + $message .= $msg . '[!br!]'; + $mes->addWarning($msg); } } else { // leave table. LANG_LAN_104 - $message .= sprintf(LANG_LAN_104, $_POST['language'].' '.$value).'[!br!]'; // can be removed? - $mes->addInfo(sprintf(LANG_LAN_104, $_POST['language'].' '.$value)); + + $msg = $tp->lanVars(LANG_LAN_104, $_POST['language'].' '.$value); + $message .= $msg . '[!br!]'; + $mes->addInfo($msg); } } } @@ -583,12 +591,12 @@ if (isset($_POST['edit_existing'])) // Drop tables ? isset() if (varset($_POST['create_edit_existing'])) { - $baction = 'btn create'; + $baction = 'create'; $bcaption = LANG_LAN_06; } else { - $baction = 'btn update'; + $baction = 'update'; $bcaption = LAN_UPDATE; } $text .= " @@ -611,7 +619,6 @@ if (isset($_POST['edit_existing']))
".$frm->admin_button('create_tables','no-value',$baction,$bcaption)." -
@@ -857,9 +864,9 @@ function multilang_db() "; if (count($installed)) { - //FIXME sprintf + $text .= " - "; + "; } elseif ($e_language != $pref['sitelanguage']) { diff --git a/e107_admin/newspost.php b/e107_admin/newspost.php index d5828ade8..ad44eeee4 100644 --- a/e107_admin/newspost.php +++ b/e107_admin/newspost.php @@ -1852,7 +1852,7 @@ class admin_newspost $tmp = NWSLAN_43; if(vartrue($_GET['srch'])) { - $tmp = sprintf(NWSLAN_121, '"'.$_GET['srch'])."" « ".LAN_BACK.""; + $tmp = sprintXXXf(NWSLAN_121, '"'.$_GET['srch'])."" « ".LAN_BACK.""; } $text = "
{$tmp}
"; } diff --git a/e107_core/shortcodes/single/nextprev.php b/e107_core/shortcodes/single/nextprev.php index 5cb2b3401..857306a94 100644 --- a/e107_core/shortcodes/single/nextprev.php +++ b/e107_core/shortcodes/single/nextprev.php @@ -199,8 +199,8 @@ function nextprev_shortcode($parm = '') } // Advanced multilingual support: 'Page [x] of [y]' -> match the exact argument, result would be 'Page 1 of 20' - $e_vars->caption = $tp->lanVars(defset($e_vars->caption, $e_vars->caption),array('x'=>$current_page, 'y'=>$total_pages)); - // sprintf(defset($e_vars->caption, $e_vars->caption), $current_page, $total_pages); + $e_vars->caption = $tp->lanVars(defset($e_vars->caption, $e_vars->caption), array('x'=>$current_page, 'y'=>$total_pages)); + // sprintXX(defset($e_vars->caption, $e_vars->caption), $current_page, $total_pages); // urldecoded by parse_str() $pagetitle = explode('|', vartrue($parm['pagetitle'])); diff --git a/e107_handlers/admin_ui.php b/e107_handlers/admin_ui.php index 6be43b1a7..b52f15189 100644 --- a/e107_handlers/admin_ui.php +++ b/e107_handlers/admin_ui.php @@ -1920,7 +1920,7 @@ class e_admin_controller if(!method_exists($this, $method)) { $this->getRequest()->setAction('e404'); - $message = e107::getParser()->lanVars(LAN_UI_404_METHOD_ERROR, array('x'=>$method), true); + $message = e107::getParser()->lanVars(LAN_UI_404_METHOD_ERROR, $method, true); e107::getMessage()->add($message, E_MESSAGE_ERROR); } } @@ -3036,8 +3036,9 @@ class e_admin_controller_ui extends e_admin_controller if (!isset($e_userclass->class_tree[$id]) || !$user->checkClass($e_userclass->class_tree[$id])) { // TODO lan - $this->getTreeModel()->addMessageWarning(sprintf('You don\'t have management permissions on %1$s ', $label)); - unset($classes[$id]); + $msg = $tp->lanVars("You don't have management permissions on [x]",$label); + $this->getTreeModel()->addMessageWarning($msg); + unset($classes[$id],$msg); } } $this->handleCommaBatch($selected, $field, array_keys($classes), $trigger[0] === 'ucdelall' ? 'clearAll' : 'addAll'); @@ -3970,6 +3971,9 @@ class e_admin_ui extends e_admin_controller_ui */ protected function handleListDeleteBatch($selected) { + + $tp = e107::getParser(); + if(!$this->getBatchDelete()) { e107::getMessage()->add(LAN_UI_BATCHDEL_ERROR, E_MESSAGE_WARNING); @@ -4028,8 +4032,8 @@ class e_admin_ui extends e_admin_controller_ui { $this->getTreeModel()->setMessages(); // FIXME lan - if($delcount) e107::getMessage()->addSuccess(sprintf('%1$d records successfully deleted.', $delcount)); - if($nfcount) e107::getMessage()->addError(sprintf('%1$d records not found and not deleted.', $nfcount)); + if($delcount) e107::getMessage()->addSuccess($tp->lanVars('[x] record(s) successfully deleted.', $delcount, true)); + if($nfcount) e107::getMessage()->addError($tp->lanVars('[x] records not found and not deleted.', $nfcount,true)); } //$this->redirect(); @@ -4253,7 +4257,7 @@ class e_admin_ui extends e_admin_controller_ui $cnt = $this->getTreeModel()->update($field, $value, $selected, $value, false); if($cnt) { - $caption = e107::getParser()->lanVars(LAN_UI_BATCH_BOOL_SUCCESS, array('x'=>$cnt), true); + $caption = e107::getParser()->lanVars(LAN_UI_BATCH_BOOL_SUCCESS, $cnt, true); $this->getTreeModel()->addMessageSuccess($caption); } $this->getTreeModel()->setMessages(); @@ -4270,7 +4274,7 @@ class e_admin_ui extends e_admin_controller_ui $cnt = $tree->update($field, "1-{$field}", $selected, null, false); if($cnt) { - $caption = e107::getParser()->lanVars(LAN_UI_BATCH_REVERSED_SUCCESS, array('x'=>$cnt), true); + $caption = e107::getParser()->lanVars(LAN_UI_BATCH_REVERSED_SUCCESS, $cnt, true); $tree->addMessageSuccess($caption); //sync models $tree->load(true); @@ -4439,7 +4443,8 @@ class e_admin_ui extends e_admin_controller_ui if($cnt) { $vttl = $this->getUI()->renderValue($field, $value, $this->getFieldAttr($field)); - $this->getTreeModel()->addMessageSuccess(sprintf(LAN_UI_BATCH_UPDATE_SUCCESS, $vttl, $cnt)); + $msg = e107::getParser()->lanVars(LAN_UI_BATCH_UPDATE_SUCCESS, array('x' => $vttl, 'y' => $cnt), true); + $this->getTreeModel()->addMessageSuccess($msg); // force reload the collection from DB, fix some issues as 'observer' is executed before the batch handler $this->getTreeModel()->setParam('db_query', $this->_modifyListQry(false, false, false, false, $this->listQry))->load(true); } @@ -5120,7 +5125,7 @@ class e_admin_form_ui extends e_form $request = $controller->getRequest(); if($controller->getId()) { - $legend = e107::getParser()->lanVars(LAN_UI_EDIT_LABEL, array('x'=>$controller->getId())); // sprintf(LAN_UI_EDIT_LABEL, $controller->getId()); + $legend = e107::getParser()->lanVars(LAN_UI_EDIT_LABEL, $controller->getId()); // sprintXXX(LAN_UI_EDIT_LABEL, $controller->getId()); $form_start = vartrue($controller->headerUpdateMarkup); $form_end = vartrue($controller->footerUpdateMarkup); } diff --git a/e107_handlers/e_parse_class.php b/e107_handlers/e_parse_class.php index 7f3416805..9ef01371e 100644 --- a/e107_handlers/e_parse_class.php +++ b/e107_handlers/e_parse_class.php @@ -2580,12 +2580,17 @@ class e_parser return sprintf("%0".$numDigits."d",$num); } -/** + /** * Generic variable translator for LAN definitions. + * @param $lan - string LAN + * @param $vals - either a single value, which will replace '[x]' or an array with key=>value pairs. * @example $tp->lanVars("My name is [x] and I own a [y]", array('x'=>"John", 'y'=>"Cat")); */ - function lanVars($lan, $array= array(), $bold=false) + function lanVars($lan, $vals, $bold=false) { + + $array = (!is_array($vals)) ? array('x'=>$vals) : $vals; + foreach($array as $k=>$v) { $search[] = "[".$k."]"; diff --git a/e107_handlers/model_class.php b/e107_handlers/model_class.php index f22cb8bbc..3978a31b3 100644 --- a/e107_handlers/model_class.php +++ b/e107_handlers/model_class.php @@ -2342,7 +2342,7 @@ class e_front_model extends e_model /** * Add custom validation message. - * $field_type and $error_code will be inserted via sprintf() + * $field_type and $error_code will be inserted via $tp->lanVars() * in the $message string * Example: * diff --git a/e107_handlers/validator_class.php b/e107_handlers/validator_class.php index 0f38fae05..adf3d3d18 100644 --- a/e107_handlers/validator_class.php +++ b/e107_handlers/validator_class.php @@ -771,6 +771,12 @@ class e_validator */ function addValidateMessage($field_title, $err_code = 0, $err_message = '', $custom = '') { + $lanVars = array( + 'x' => $field_title, + 'y' => $err_code, + 'z' => $this->getErrorByCode($err_code) + ); + if($custom) { e107::getMessage()->addStack(sprintf($err_message, $err_code, $field_title), $this->_message_stack, (true === $custom ? E_MESSAGE_ERROR : $custom)); @@ -782,26 +788,36 @@ class e_validator $dbgmsg = false; if($err_message) { - $lan = (!$field_title || strpos($err_message, '%1$s') !== false ? '' : '"%1$s" - ').$err_message; // custom, e.g. // default '"%1$s" field error: Custom error message. ' + $lan = (!$field_title || strpos($err_message, '[x]') !== false ? '' : '[x] - ').$err_message; // custom, e.g. // default '"%1$s" field error: Custom error message. ' $dbgmsg = LAN_VALIDATE_FAILMSG; } //Core message + /* $msg = sprintf( $lan, // default '"%1$s" validation error: [#%2$d] %3$s. ' $field_title, $err_code, $this->getErrorByCode($err_code) ); + */ + + //NEW - removes need for using sprintf() + $msg = $tp->lanVars($lan,$lanVars,true); // '[x] validation error: [y] [z].' if($dbgmsg && defset('e107_DEBUG_LEVEL')) { + + e107::getMessage()->addDebug($tp->lanVars($dbgmsg,$lanVars)); + + /* e107::getMessage()->addDebug(sprintf( $dbgmsg, $field_title, $err_code, $this->getErrorByCode($err_code) )); + */ } e107::getMessage()->addStack($msg, $this->_message_stack, E_MESSAGE_ERROR); diff --git a/e107_languages/English/admin/lan_language.php b/e107_languages/English/admin/lan_language.php index 2e70f9113..882967896 100644 --- a/e107_languages/English/admin/lan_language.php +++ b/e107_languages/English/admin/lan_language.php @@ -6,9 +6,9 @@ * */ -define("LANG_LAN_00", "%s could not be created (already exists)."); // FIXME HTML in LAN -define("LANG_LAN_01", "%s was deleted (if existing) and created."); // FIXME HTML in LAN -define("LANG_LAN_02", "%s couldn't be deleted."); // FIXME HTML in LAN +define("LANG_LAN_00", "[x] could not be created (already exists)."); +define("LANG_LAN_01", "[x] was deleted (if existing) and created."); +define("LANG_LAN_02", "[x] couldn't be deleted."); define("LANG_LAN_03", "Tables"); define("LANG_LAN_05", "Not Installed"); @@ -35,8 +35,6 @@ define("LANG_LAN_25", "Language-Pack Creation Status"); define("LANG_LAN_26", "Load language files only for current language"); define("LANG_LAN_27", "If checked, and a required language cannot be found, there will be an error"); -//FIXME - LAN conflict & HTML IN LAN -//0.8 - in conflict with 0.7. define("LANG_LAN_PAGE_TITLE", "Languages"); define("LANG_LAN_AGR", "Note: By using these tools you agree to share your language pack(s) with the e107 community."); @@ -59,12 +57,12 @@ define("LANG_LAN_34", "Please verify and correct the remaining [x] error(s) befo define("LANG_LAN_50", "Admin-Area Interface Language"); // e107 v2 -//FIXME Remove use of sprintf() and replace with [x] -define("LANG_LAN_100", "%s deleted."); -define("LANG_LAN_101", "%s could not be deleted."); -define("LANG_LAN_103", "%s created."); + +define("LANG_LAN_100", "[x] deleted."); +define("LANG_LAN_101", "[x] could not be deleted."); +define("LANG_LAN_103", "[x] created."); // define("LANG_LAN_31", "%s couldn\"t be deleted."); -define("LANG_LAN_104", "%s was disabled but left intact."); -define("LANG_LAN_105", "Delete all tables in %s?"); +define("LANG_LAN_104", "[x] was disabled but left intact."); +define("LANG_LAN_105", "Delete all tables in [x]?"); ?> \ No newline at end of file diff --git a/e107_languages/English/admin/lan_validator.php b/e107_languages/English/admin/lan_validator.php index 7e191ba12..ea6cc842c 100644 --- a/e107_languages/English/admin/lan_validator.php +++ b/e107_languages/English/admin/lan_validator.php @@ -41,4 +41,8 @@ define('LAN_VALIDATE_204', 'File size lower than allowed minimal file size'); * %2$d - validation error code (number) * %3$s - validation error message (string) */ -define('LAN_VALIDATE_FAILMSG', '"%1$s" validation error: [#%2$d] %3$s.'); \ No newline at end of file + +// define('LAN_VALIDATE_FAILMSG', '"%1$s" validation error: [#%2$d] %3$s.'); + + //FIXME - use this instead: +define('LAN_VALIDATE_FAILMSG', '[x] validation error: [y] [z].'); \ No newline at end of file