Problem/Motivation

I built the Language Install Audit module to find and measure fixing issues in how content and config gets created in the installation of core and Drupal CMS in particular. When installing Drupal core with German as an example, it is almost perfect. The "errors" noted are configuration that do not have translatable pieces. While this looks logical on the surface, it quickly falls apart :)

A great example is the two text editors that get created. One has 14 source strings and is German. The other has 0 source strings and is English. However on a German site English is not a known language. This is not a problem until the editor gets something that is translatable. Once it gets something that is translatable, which is easy to achieve on the UI, that is not possible to translate and the config translation UI produces an exception.

That the config as shipped did not contain translatable things do not mean it will not need to be translatable shortly after. Config has various dynamic parts, plugins, etc. Such as the CKEditor example shows.

This also potentially causes problems if any module wants to add 3rd party settings to the config, as the langcode of the config will be not known to the site and the 3rd party settings will not be possible translate even if they would be translatable.

Steps to reproduce

Note: Language Install Audit module has been superseded by Language Audit, which has slightly different screenshots and is located in "Configuration > Region and language" instead of "Reports"

  • Install Drupal in German. Install the config translation module.
  • Either install Language Install Audit or export the configuration as-is.
  • Note that there are two editor configs, one is German, the other is English.
  • Now add the code block feature to the basic HTML editor using the core UI.
  • Export the config again or look at the Language Install Audit screen again. Now the basic HTML editor has translatable strings but is still English.
  • Go to config translation to translate it. As English is not known, and the two config entities involved in the editor are different language, they cannot be translated.

UI of config translation after the steps above (prior to the MR):

Language Install Audit for editor config after the above steps (prior to the MR):

Caveat: if you install a module after doing the above steps, it "fixes itself" because the config langcode update / translation update runs. However that should not be a suggested solution to install a random module to fix a configuration issue.

Proposed resolution

Due to 3rd party settings support config entities should always have a langcode even if they do not have translatable items at install time. That means config entities installed from extensions should always have a valid langcode and be in the site default langcode unless otherwise specified.

Language Install Audit output after the MR:

Remaining tasks

Reviews welcome!

User interface changes

None.

Introduced terminology

None.

API changes

None.

Data model changes

None.

Release notes snippet

Default configuration entities imported now always has a language code to support later changes to configuration especially third party settings. For existing sites this means configuration entities that were originally installed by extensions and that lack a language code in active storage will receive the site default language code on the next extension install even for configuration entities that had no translatable elements directly.

Issue fork drupal-3600904

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

gábor hojtsy created an issue. See original summary.

gábor hojtsy’s picture

Issue summary: View changes

gábor hojtsy’s picture

Issue summary: View changes

Correct the steps to install config translation BEFORE changing the editor, as doing it after will "fix" the config. Doing it in the other order results in the bugos config.

gábor hojtsy’s picture

Issue summary: View changes

Added an explicit question to the remaining steps and expanded release note snippet for current state.

gábor hojtsy’s picture

Issue summary: View changes
StatusFileSize
new205.73 KB
new133.49 KB
gábor hojtsy’s picture

Issue summary: View changes
Status: Active » Needs review
StatusFileSize
new1.04 MB

Language Install Audit is all green after this MR on core installing in German.

gábor hojtsy’s picture

Issue summary: View changes

More explicit description of screenshots.

gábor hojtsy’s picture

Title: Shipped configuration that does not have translatable elements is not set to the site default langcode » Shipped configuration entities that do not have translatable elements are not set to the site default langcode

Let's limit this to configuration entities as those can get third party settings. Other configuration theoretically can's get data from outside the module that manages them. At least limiting to configuration entities will limit the scope for now.

gábor hojtsy’s picture

Created a parent issue to collect related issues.

gábor hojtsy’s picture

Issue summary: View changes

Updated issue summary for new scope with configuration entities.

roderik’s picture

TL/DR: reviewed + tested; next comment will contain some questions about context. This comment is just a log plus a question about Language Audit at the very bottom bullet.

Reviewed:

  • proposed resolution ('fix' at install time) sounds logical
  • code looks good
  • The 'behavior change' fixes things; I can't imagine it having real adverse effects.
  • (I think I understand) any update function to 'fix' current wrong config is practically impossible, because we don't know existing configs' language code vs. actual language of strings.

Reproduce STR to see if anything pops out:

BEFORE MR:

  • -> drush si --locale=de
  • -> drush en language_audit config_translation # important to do this before editing
  • at admin/config/regional/audit
    • I see a warning for 'editor' entities
    • basic_html displays with error / is 'en'; has 0 translatable strings
  • drush cget editor.editor.full_html shows me the 14 strings at > plugins > ckeditor5_codeBlock
  • drush cget editor.editor.basic_html does not have those yet.
  • at admin/config/content/formats/manage/basic_html,
    • I see the "textformat übersetzen" tab, with the 2 lanuages "Deutsch" (not editable) + "Keine (original)"
  • -> add code block to active toolbar, and save.
  • drush cget editor.editor.basic_html now contains the 14 translatable strings.
  • admin/config/regional/audit/config/editor: still shows the same warning
    • A note: basic_html still shows 0 translatable strings, despite them being present in the config object. (See below.)
  • admin/config/content/formats/manage/basic_html: still the same <<<<<-- error reproduced.
  • -> drush en ban # or any other module
  • admin/config/regional/audit:
    • both editor configs are now 'de'; no warning shown
    • basic_html still shows 0 translatable strings here
  • drush cget editor.editor.basic_html now has "language: de", though the labels contain English text (notably: "Plain text", while editor.full_text has "Klartext") <<<<<

AFTER MR:

  • drush cget editor.editor.basic_html is immediately 'de' and the reported issues in admin/config/regional/audit are gone. <<<<< fixed.
  • After I enable the Code Block in the basic_html editor:
    • drush cget editor.editor.basic_html again shows the labels
    • The supposedly-German label for "plaintext" still says "Plain text", not "Klartext".
    • admin/config/regional/audit/config/editor still shows 0 translatable strings for basic_html.

So, the error is gone. But, just noting some related things that I don't know about:

  • I guess it's normal that, when 3rd party settings-labels are imported into the basic_html editor config, we never get label translations automatically and it is up to the admin to translate them. Because there's no default translation available for editor.basic_html anywhere. If so: ignore this.
  • The 0 translatable strings for the basic_html in the Language Audit screen differ from the above screenshot (which was Language Install Audit module). Also, admin/config/regional/audit/config/editor/basic_html/strings shows 0 strings. The configuration _is_ translatable at admin/config/content/formats/manage/basic_html/translate though (after adding another language).

I see the called LaunguageAuditController::getLocaleTranslatableDefaultConfig() -> $locale_config_manager->getTranslatableDefaultConfig() still returns 0. I don't know this code; my first guess would be it is the "Default" part, and Language Audit does not show the current translations? Is this... intended?

roderik’s picture

This is a 'cautious review', because I understand what's going on in this MR and why - but likely not the wider context of config translation code.

So... I have one main question before RTBC:

This solves things for config entities. Can we fix the equivalent situation for simple config, which I encountered for samlauth in #3611776: samlauth.authentication config object must specify a language code?

Either in this issue (I will leave an MR comment with some context)...

Or in a followup? In which case... do I need to create a separate followup, or is work going to continue in #3337864: Introduce a dedicated "Configuration default language" different from "Site default language", which would also solve that? I'm not sure of its status. I'll just note it looks like it will solve my #3611776 issue by forcing language code 'lazily', at save time whenever a translatable value is first introduced, while this MR explicitly chooses to solve the equivalent thing (for config entities) at install time.

Or: is any module just required to prevent this situation for simple config? (I imagine not.)

roderik’s picture

Status: Needs review » Reviewed & tested by the community

OK. I'm going to set this RTBC, because

---

I do not know for 100% sure, whether the changes introduced here, influence #3337864. My current guess is "no", because

  • this issue == "change the rule for whether a config entity gets a langcode
  • #3337864 == "change when a config object can get a langcode"

My previous guess was that #3337864 supersedes this issue, because it does things on Config::save() which means this wouldn't be needed anymore. (@alexpott also suggests something similar on Slack. Then again... wouldn't that suggest that code in LocaleConfigManager::updateDefaultConfigLangcodes() is going to be not needed anymore?)

But I think that's for #3337864 to figure out. It has current activity by people more knowledgeable than me. This is reviewed/tested, so I'm going to leave it to the others to merge or close-as-duplicate.

roderik’s picture

alexpott’s picture

Version: main » 11.4.x-dev
Status: Reviewed & tested by the community » Fixed

This needs an update path but I'm going to defer that until we solve #3337864: Introduce a dedicated "Configuration default language" different from "Site default language" as that needs an upgrade path too. The other thing that should be investigated is that this bug suggests entities are being created without \Drupal\Core\Config\Entity\ConfigEntityStorage::doCreate() being called - which sure guarantee a langcode is set on entities as we need to work out why that is.

Committed and pushed 73847ce09f3 to main and f84b6e6b030 to 11.x and a5d3407d021 to 11.4.x. Thanks!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

  • alexpott committed a5d3407d on 11.4.x
    fix: #3600904 Shipped configuration entities that do not have...

  • alexpott committed f84b6e6b on 11.x
    fix: #3600904 Shipped configuration entities that do not have...

  • alexpott committed 73847ce0 on main
    fix: #3600904 Shipped configuration entities that do not have...
alexpott’s picture

Okay I've just merged this issue with #3337864: Introduce a dedicated "Configuration default language" different from "Site default language" and re-run the core/tests/Drupal/FunctionalTests/Installer/InstallerTranslationMultipleLanguageForeignTest.php test - it passed - which surprised me. So I then went and re-ran the test without the fix and it also passed. So I don't think this has solved the issue completely but I think it is still worth doing so leaving in.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.