diff --git a/e107_core/shortcodes/single/nextprev.php b/e107_core/shortcodes/single/nextprev.php index 304ab8c64..5cb2b3401 100644 --- a/e107_core/shortcodes/single/nextprev.php +++ b/e107_core/shortcodes/single/nextprev.php @@ -59,6 +59,7 @@ function nextprev_shortcode($parm = '') { $e107 = e107::getInstance(); $pref = e107::getPref(); + $tp = e107::getParser(); e107::coreLan('np'); @@ -196,8 +197,10 @@ function nextprev_shortcode($parm = '') { $e_vars->caption = 'LAN_NP_CAPTION'; } - // Advanced multilingual support: 'Page %1$d of %2$d' -> match the exact argument, result would be 'Page 1 of 20' - $e_vars->caption = sprintf(defset($e_vars->caption, $e_vars->caption), $current_page, $total_pages); + + // 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); // urldecoded by parse_str() $pagetitle = explode('|', vartrue($parm['pagetitle'])); @@ -321,7 +324,7 @@ function nextprev_shortcode($parm = '') else { $e_vars_loop->url_label = $label ? $tp->toAttribute($label) : LAN_NP_GOTO; - $e_vars_loop->url_label = sprintf($e_vars_loop->url_label, ($c + 1)); + $e_vars_loop->url_label = str_replace("[x]", ($c + 1), $e_vars_loop->url_label); $ret_items[] = $tp->simpleParse($tmpl[$tprefix.'item'], $e_vars_loop); } } diff --git a/e107_handlers/admin_ui.php b/e107_handlers/admin_ui.php index cbe2215f9..6be43b1a7 100644 --- a/e107_handlers/admin_ui.php +++ b/e107_handlers/admin_ui.php @@ -1920,7 +1920,8 @@ class e_admin_controller if(!method_exists($this, $method)) { $this->getRequest()->setAction('e404'); - e107::getMessage()->add(sprintf(LAN_UI_404_METHOD_ERROR, $method), E_MESSAGE_ERROR); + $message = e107::getParser()->lanVars(LAN_UI_404_METHOD_ERROR, array('x'=>$method), true); + e107::getMessage()->add($message, E_MESSAGE_ERROR); } } @@ -4252,7 +4253,8 @@ class e_admin_ui extends e_admin_controller_ui $cnt = $this->getTreeModel()->update($field, $value, $selected, $value, false); if($cnt) { - $this->getTreeModel()->addMessageSuccess(sprintf(LAN_UI_BATCH_BOOL_SUCCESS, $cnt)); + $caption = e107::getParser()->lanVars(LAN_UI_BATCH_BOOL_SUCCESS, array('x'=>$cnt), true); + $this->getTreeModel()->addMessageSuccess($caption); } $this->getTreeModel()->setMessages(); } @@ -4268,7 +4270,8 @@ class e_admin_ui extends e_admin_controller_ui $cnt = $tree->update($field, "1-{$field}", $selected, null, false); if($cnt) { - $tree->addMessageSuccess(sprintf(LAN_UI_BATCH_REVERSED_SUCCESS, $cnt)); + $caption = e107::getParser()->lanVars(LAN_UI_BATCH_REVERSED_SUCCESS, array('x'=>$cnt), true); + $tree->addMessageSuccess($caption); //sync models $tree->load(true); } @@ -4391,12 +4394,14 @@ 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)); + $caption = e107::getParser()->lanVars(LAN_UI_BATCH_UPDATE_SUCCESS, array('x'=>$vttl, 'y'=>$cnt), true); + $this->getTreeModel()->addMessageSuccess($caption); } elseif($rcnt) { $vttl = $this->getUI()->renderValue($field, $value, $this->getFieldAttr($field)); - $this->getTreeModel()->addMessageSuccess(sprintf(LAN_UI_BATCH_DEATTACH_SUCCESS, $vttl, $rcnt)); + $caption = e107::getParser()->lanVars(LAN_UI_BATCH_DEATTACH_SUCCESS, array('x'=>$vttl, 'y'=>$cnt), true); + $this->getTreeModel()->addMessageSuccess($caption); } $this->getTreeModel()->setMessages(); } @@ -4869,7 +4874,8 @@ class e_admin_ui extends e_admin_controller_ui // Option for working with tables having no PID if(!varset($this->pid) && vartrue($this->fields) && false !== $this->pid) { - e107::getMessage()->add(LAN_UI_NOPID_ERROR, E_MESSAGE_WARNING); + $message = e107::getParser()->toHtml(LAN_UI_NOPID_ERROR,true); + e107::getMessage()->add($message, E_MESSAGE_WARNING); } return $this->pid; @@ -5081,7 +5087,8 @@ class e_admin_form_ui extends e_form // check form custom methods if(vartrue($foptions['type']) === 'method' && method_exists('e_form', $field)) // check even if type is not method. - just in case of an upgrade later by 3rd-party. { - e107::getMessage()->addError(sprintf(LAN_UI_FORM_METHOD_ERROR, $field)); + $message = e107::getParser()->lanVars(LAN_UI_FORM_METHOD_ERROR, array('x'=>$field), true); + e107::getMessage()->addError($message); $err = true; } } @@ -5113,7 +5120,7 @@ class e_admin_form_ui extends e_form $request = $controller->getRequest(); if($controller->getId()) { - $legend = sprintf(LAN_UI_EDIT_LABEL, $controller->getId()); + $legend = e107::getParser()->lanVars(LAN_UI_EDIT_LABEL, array('x'=>$controller->getId())); // sprintf(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 5b6d75822..7f3416805 100644 --- a/e107_handlers/e_parse_class.php +++ b/e107_handlers/e_parse_class.php @@ -2580,7 +2580,20 @@ class e_parser return sprintf("%0".$numDigits."d",$num); } - +/** + * Generic variable translator for LAN definitions. + * @example $tp->lanVars("My name is [x] and I own a [y]", array('x'=>"John", 'y'=>"Cat")); + */ + function lanVars($lan, $array= array(), $bold=false) + { + foreach($array as $k=>$v) + { + $search[] = "[".$k."]"; + $replace[] = ($bold===true) ? "".$v."" : $v; + } + + return str_replace($search, $replace, $lan); + } /** * Return an Array of all specific tags found in an HTML document and their attributes. diff --git a/e107_handlers/language_class.php b/e107_handlers/language_class.php index ab7059ad1..96ab6dbe9 100644 --- a/e107_handlers/language_class.php +++ b/e107_handlers/language_class.php @@ -335,6 +335,7 @@ class language{ /** * Generic variable translator for LAN definitions. * @example $lng->translate("My name is [x] and I own a [y]", array('x'=>"John", 'y'=>"Cat")); + * @deprecated Use $tp->lanVars() instead. */ function translate($lan, $array= array()) { diff --git a/e107_languages/English/admin/lan_admin.php b/e107_languages/English/admin/lan_admin.php index 849253002..5606ed0d0 100644 --- a/e107_languages/English/admin/lan_admin.php +++ b/e107_languages/English/admin/lan_admin.php @@ -362,22 +362,21 @@ define("LAN_FILTER_LABEL_CLEAR", "Clear Filter"); define("LAN_FILTER_LABEL_TYPED", "(typed)"); //FIXME Remove html -define("LAN_UI_NOPID_ERROR", "There is no Primary ID set"); +define("LAN_UI_NOPID_ERROR", "There is no [b]Primary ID[/b] set"); define("LAN_UI_BATCHDEL_ERROR", "Batch delete not allowed!"); define("LAN_UI_404_BODY_ERROR", "Requested page was not found!"); define("LAN_UI_404_TITLE_ERROR", "Page Not Found"); -define("LAN_UI_404_METHOD_ERROR", "Action %1\$s not found!"); +define("LAN_UI_404_METHOD_ERROR", "Action [x] not found!"); define("LAN_UI_403_BODY_ERROR", "Access to the requested page is denied."); define("LAN_UI_403_TITLE_ERROR", "Access denied"); -define("LAN_UI_FORM_METHOD_ERROR", "FATAL ERROR: The field name %1\$s is not allowed. Please rename the key %1\$s to something else in your fields array and database table (if required)."); +define("LAN_UI_FORM_METHOD_ERROR", "FATAL ERROR: The field name [x] is not allowed. Please rename the key [x] to something else in your fields array and database table (if required)."); -//FIXME - remove % code and HTML from LANS below and replace with "[x]" and bbcode. -define("LAN_UI_BATCH_UPDATE_SUCCESS", "%1\$s set for %2\$d record(s)."); -define("LAN_UI_BATCH_REVERSED_SUCCESS", "%1\$d records successfully reversed."); -define("LAN_UI_BATCH_BOOL_SUCCESS", "%1\$d records successfully updated."); -define("LAN_UI_BATCH_DEATTACH_SUCCESS", "%1\$s removed from %2\$d record(s)."); +define("LAN_UI_BATCH_UPDATE_SUCCESS", "[x] set for [y] record(s)."); +define("LAN_UI_BATCH_REVERSED_SUCCESS", "[x] records successfully reversed."); +define("LAN_UI_BATCH_BOOL_SUCCESS", "[x] records successfully updated."); +define("LAN_UI_BATCH_DEATTACH_SUCCESS", "[x] removed from [y] record(s)."); -define("LAN_UI_EDIT_LABEL", "Update record #%1\$s"); +define("LAN_UI_EDIT_LABEL", "Update record #[x]"); define("LAN_UI_CREATE_LABEL", "Create new record"); define("LAN_UI_PREF_LABEL", "Settings"); define("LAN_UI_DELETE_LABEL", "Confirm Delete"); diff --git a/e107_languages/English/lan_np.php b/e107_languages/English/lan_np.php index 3de35a0e2..b3376d31c 100644 --- a/e107_languages/English/lan_np.php +++ b/e107_languages/English/lan_np.php @@ -18,11 +18,11 @@ define('LAN_NP_NEXT', 'next'); define('LAN_NP_URLNEXT', 'Go to the next page'); define('LAN_NP_LAST', 'last'); define('LAN_NP_URLLAST', 'Go to the last page'); -define('LAN_NP_GOTO', 'Go to page %s'); +define('LAN_NP_GOTO', 'Go to page [x]'); define('LAN_NP_URLCURRENT', 'Currently viewed'); // WARNING - USE SINGLE QUOTES!!! // Replacement: '%1$d' - current page; '%2$d' - total pages -define('NP_CAPTION', 'Page %1$d of %2$d'); +define('NP_CAPTION', 'Page [x] of [y]'); ?> \ No newline at end of file