Translated Config Override should default to original language values if there are no translations

Created on 21 August 2018, over 6 years ago
Updated 27 January 2025, 2 days ago

Situation

Assume the following configuration

my_module.settings.yml, containing the following structure (according to the schema, a field with type label and a field with type text_format):

langcode: en
some_label: 'This is a test'
some_ckeditor_text_field: 
  value: "<p>This is a long text field</p>"
  format: basic_html

Now I enable translation on this node (a great guide on how to do this can be found here: https://antistatique.net/en/we/blog/2018/05/01/drupal-8-how-to-translate... ).

The translator only translates the label, because he does not know how to translate the text field (for some reason). The translation file, let's say german, (language/de/my_module.settings.yml) will look like this:

some_label: 'Ein deutscher Text'

You note that the key "some_ckeditor_text_field" is missing, because the translation form was saved without a change on it, so it won't get extra added in the german config file.

The Problem

Having now a partially translation, I'd like to have my texts selected in the user language. If a key does not exist, I'd expect it to default to the default configuration language.

I currently have no way of doing this, because I either get the original language config or the set of translations, which may be missing a few keys.


// original language (EN)
$config = \Drupal::config('my_module.settings');
$label = $config->get('some_label'); // contains the english label
$text = $config->get('some_ckeditor_text_field'); // contains an array with the text and the text format

// translation (DE)
$config = \Drupal::languageManager()->getLanguageConfigOverride('de', 'my_module.settings');
$label = $config->get('some_label'); // contains the german label
$text = $config->get('some_ckeditor_text_field'); // is empty!

Wanting to achieve a complete set of keys, I'd have to merge all keys manually and check if they're translated, and if not, take the original.

Proposed resolution

Add a parameter to "getLanguageConfigOverride" to set prefilled values with original language keys (must default to false to not change existing behavior) in core/modules/language/src/ConfigurableLanguageManager.php:

public function getLanguageConfigOverride($langcode, $name, $include_default = false) { ... }
Feature request
Status

Active

Version

11.0 🔥

Component

configuration system

Created by

🇨🇭Switzerland florianmuellerch Aarau, Switzerland

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024