Translate log only on display

Created on 27 August 2025, 10 days ago

Problem/Motivation

Do not store translated strings as builder logs.

Only translate it when displaying it.

📌 Task
Status

Active

Version

1.0

Component

Main / Misc.

Created by

🇫🇷France Grimreaper France 🇫🇷

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @Grimreaper
  • 🇫🇷France Grimreaper France 🇫🇷
  • 🇫🇷France Grimreaper France 🇫🇷

    core/modules/dblog/src/Controller/DbLogController.php::formatMessage

    public function formatMessage($row) {
        // Check for required properties.
        if (isset($row->message, $row->variables)) {
          $variables = @unserialize($row->variables);
          // Messages without variables or user specified text.
          if ($variables === NULL) {
            $message = Xss::filterAdmin($row->message);
          }
          elseif (!is_array($variables)) {
            $message = $this->t('Log data is corrupted and cannot be unserialized: @message', ['@message' => Xss::filterAdmin($row->message)]);
          }
          // Message to translate with injected variables.
          else {
            // Ensure backtrace strings are properly formatted.
            if (isset($variables['@backtrace_string'])) {
              $variables['@backtrace_string'] = new FormattableMarkup(
                '<pre class="backtrace">@backtrace_string</pre>', $variables
              );
              // Save a reference so the backtrace can be displayed separately.
              if (!str_contains($row->message, '@backtrace_string')) {
                $row->backtrace = $variables['@backtrace_string'];
              }
            }
            // phpcs:ignore Drupal.Semantics.FunctionT.NotLiteralString
            $message = $this->t(Xss::filterAdmin($row->message), $variables);
          }
        }
        else {
          $message = FALSE;
        }
        return $message;
      }
    
  • 🇫🇷France Grimreaper France 🇫🇷

    Need to store the string variables serialized.

    Or display only in english.

  • Pipeline finished with Success
    10 days ago
    Total: 145s
    #583184
  • 🇫🇷France Grimreaper France 🇫🇷

    Draft because not what was initially expected.

    To be able to translate on display, variables needs to be serialized for later rendering.

  • 🇫🇷France pdureau Paris

    OK for review. We may talk about this serialization later in beta phase.

Production build 0.71.5 2024