3

Coder says:

The $message argument to watchdog() should NOT be enclosed within t(), so that it can be properly translated at display time.

Does this mean that $message will be translated by watchdog() by default?

3

As 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:

| improve this answer | |
1

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.

| improve this answer | |
0

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;
  }
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.