Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

4885: Message.printAbstract() should indicate when additional message parameters are not used #5

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 24 additions & 10 deletions include/classes/Message/Message.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,16 +97,30 @@ function printAbstract($type) {

/* this is an array with terms to replace */
$first = array_shift($item);
$result = _AT($first); // lets translate the code

if ($result == '') { // if the code is not in the db lets just print out the code for easier trackdown
$result = '[' . $first . ']';
$format_specifier = _AT($first); // lets translate the code

if ($format_specifier == '') { // if the code is not in the db lets just print out the code for easier trackdown
$format_specifier = '[' . $first . ']';
}

/* replace the format-specifier tokens in DB language_text.text field with the terms */
$result = vsprintf($format_specifier, $item);
/* Improve code quality. Detect specifiers that are not used.
This will highlight language_text.term entries that are missing format-specifiers */
$match_fs = array();
$count_fs = preg_match_all('/(%.*?[a-zA-Z])/', $format_specifier, $match_fs);
$count_item = count($item);
if (strcmp($result, $format_specifier) == 0 || $count_item != $count_fs) {
// $item array has elements that appear to have been ignored so give a warning
trigger_error('ERROR: language_text term '.$first.' is missing one or more format specifiers. Expected '
.$count_item.' but got '.$count_fs);
// now add the missed elements to the message
$idx = 0;
foreach($item as $element) {
if ($idx++ >= $count_fs)
$result .= ' ' . $element;
}
}

$terms = $item;

/* replace the tokens with the terms */
$result = vsprintf($result, $terms);

} else {
$result = _AT($item);
Expand Down Expand Up @@ -469,4 +483,4 @@ function deleteHelp($code) {



?>
?>