Provides a helper to get one translated and complete configuration set on a localized configuration set.
This module is necessary as long as Drupal Core does not provide a way to get one complete dataset of configuration in a specified language, while all keys that are not translated remain original. Triggering issue was Issue #2993984 "Translated Config Override should default to original language values if there are no translations".
How does it work?
You just call the service to get your localized configuration:
\Drupal::service('translated_config.helper')->getTranslatedConfig('system.site','de')->get('name');
You will get the translated site name in your specified language. Leave the language empty, and it automatically takes the current language (\Drupal::languageManager()->getCurrentLanguage()->getId()
).
Get your entire configuration array by leaving the last key empty:
\Drupal::service('translated_config.helper')->getTranslatedConfig('system.site')->get();
You will recieve your entire configuration, with those values that have a translation automatically included.
Example
System Language: English (en). Current Language: German (de).
Basic configuration file my_module.settings.yml
:
some_label: 'This is a test'
some_ckeditor_text_field:
value: "<p>This is a long text field</p>"
format: basic_html
Translated file my_module.settings.yml
in language/de folder:
some_label: 'Ein deutscher Text'
Get entire configuration set in german:
\Drupal::service('translated_config.helper')->getTranslatedConfig('my_module.settings')->get();
Output (Array) with merged translations, but original keys that have no translation, remain in the collection:
some_label: 'Ein deutscher Text'
some_ckeditor_text_field:
value: "<p>This is a long text field</p>"
format: basic_html
Project information
- Maintenance fixes only
Considered feature-complete by its maintainers. - Module categories: Content Display, Developer Tools, Multilingual
- Ecosystem: Drupal core
- 283 sites report using this module
- Created by florianmuellerCH on , updated
- Stable releases for this project are covered by the security advisory policy.
Look for the shield icon below.
Releases
Development version: 8.x-1.x-dev updated 13 Oct 2022 at 11:47 UTC