Coder says:
The
$message
argument towatchdog()
should NOT be enclosed withint()
, so that it can be properly translated at display time.
Does this mean that $message
will be translated by watchdog()
by default?
Drupal Answers is a question and answer site for Drupal developers and administrators. It only takes a minute to sign up.
Sign up to join this communityAs per the core documentation we should use the watchdog function without the t()
because it is translating when reading and outputing the log message.
Watchdog invokes dblog_watchdog()
in "modules/dblog/dblog.module" and dblog_watchdog() is not translating anything before writing into the database BUT it is translating when reading and outputing the log message.
Reference:
Might be if we store the translated string in the database(tokens replaced with real values), it will make it non translatable while displaying it to the user.So storing the string with tokens directly and replacing those at the time of display makes more sense as translation seems to be taken care of at presentation layer.
and I consider the same reason responsible for title in menu as they are kept untranslated as well.
No, watchdog()
doesn't translate the message. The message will be translated when the message is shown to the users, for example, in admin/reports/event/%, which is the page output from dblog_event()
.
$severity = watchdog_severity_levels();
$result = db_query('SELECT w.*, u.name, u.uid FROM {watchdog} w INNER JOIN {users} u ON w.uid = u.uid WHERE w.wid = :id', array(
':id' => $id,
))->fetchObject();
if ($dblog = $result) {
$rows = array(
array(
array(
'data' => t('Type'),
'header' => TRUE,
),
t($dblog->type),
),
array(
array(
'data' => t('Date'),
'header' => TRUE,
),
format_date($dblog->timestamp, 'long'),
),
array(
array(
'data' => t('User'),
'header' => TRUE,
),
theme('username', array(
'account' => $dblog,
)),
),
array(
array(
'data' => t('Location'),
'header' => TRUE,
),
l($dblog->location, $dblog->location),
),
array(
array(
'data' => t('Referrer'),
'header' => TRUE,
),
l($dblog->referer, $dblog->referer),
),
array(
array(
'data' => t('Message'),
'header' => TRUE,
),
theme('dblog_message', array(
'event' => $dblog,
)),
),
array(
array(
'data' => t('Severity'),
'header' => TRUE,
),
$severity[$dblog->severity],
),
array(
array(
'data' => t('Hostname'),
'header' => TRUE,
),
check_plain($dblog->hostname),
),
array(
array(
'data' => t('Operations'),
'header' => TRUE,
),
$dblog->link,
),
);
$build['dblog_table'] = array(
'#theme' => 'table',
'#rows' => $rows,
'#attributes' => array(
'class' => array(
'dblog-event',
),
),
);
return $build;
}