Translations of message missing format.

Created on 14 May 2025, 9 days ago

Problem/Motivation

When message template is translated in another language, for example zh-hans,
render the message in that language will missing the format setting in the text field of the message template.

Steps to reproduce

1. Create a message template config entity, set the text format to use a non-default format.
2. Translate the template to another language, for example: zh-hans.
3. Create a message of the template.
4. Render the message in zh-hans language.
5. We will see the message is rendered in zh-hans language, but not the format set in the message template.

Proposed resolution

This is because the \Drupal\language\Config\LanguageConfigOverride object
only contain the language overrided properties values, doesn't contain the non-translatable properties values.

We need to merge to the original config values manually, there is a contrib module translated_config
focus on this task, but the code is very simple, we don't need to make dependency on it.

$config_translation_override = $language_manager->getLanguageConfigOverride($langcode, 'message.template.' . $this->id());
$config_translation = array_replace_recursive($this->toArray(), $config_translation_override->get());
$translated_text = $config_translation['text'];

Remaining tasks

none.

User interface changes

none.

API changes

none.

Data model changes

none.

🐛 Bug report
Status

Active

Version

1.0

Component

Code

Created by

🇨🇳China 司南

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024