修改 "The changes have been saved." 消息 - Drupal 9

Modify "The changes have been saved." message - Drupal 9

修改和保存账户信息时,drupal显示“更改已保存”。消息,来自 Drupal 核心用户模块。有没有办法修改这条消息?

由于使用 status-messages 主题显示状态消息,您可以编写一个预处理函数来更改它们:

/**
 * Implements hook_preprocess_HOOK().
 *
 * @param $variables
 */
function YOUR_MODULE_preprocess_status_messages(&$variables) {
  $route = \Drupal::routeMatch()->getRouteName();

  // Only handle user edit form
  if ($route === 'entity.user.edit_form' && isset($variables['message_list']['status'])) {
    $status_messages = $variables['message_list']['status'];
    foreach ($status_messages as $delta => $message) {
      // Find the message and replace it
      if ((string) $message === (string) t('The changes have been saved.')) {
        $variables['message_list']['status'][$delta] = t('Your message text');
      }
    }
  }
}