Unexpected text showed when the translated text in a split has the same value as the default language text in that split

Created on 25 March 2024, 9 months ago
Updated 5 April 2024, 9 months ago

Problem/Motivation

There is a case in which the value of some translatable config text in some language is the same as in the default language. For example, when your website's name is a proper noun.
In that case, Drupal does not save any config translation for that language (https://git.drupalcode.org/project/drupal/-/commit/cc7cae5fe14ac9abe62e8...).
It's nice because if for example you made a typo in the website's name, it will be fixed in the other language if you simply fix it in the default language (no duplicate data).
Since #2488302, you even get a special message when trying to translate with the default value.

BUT! When you use config splits in addition to config translation, this can cause an unexpected behavior.

Steps to reproduce

Let's say that your default site name (in your sync/ folder) is set to "My cool website", translated in french (sync/language/fr) with "Mon super site web".
In a split (for example on one website in some kind of multisite installation where you share most of the config between websites), you override the site name to "John Doe" (through Drupal UI). Then translate in french to "John Doe" (same value). It will work as expected: "John Doe" is shown in both languages.
When you export your split, you'll get a config override file for the default language in mysplit/ (because in DB for default language you have "John Doe" which is not the same as "My cool website").

But you won't* get any config override file for french (in mysplit/language/fr), although "John Doe" is not the same as "Mon super site web".
Why? Because, as explained above, there is no translation saved when a text is unchanged. So that in DB, there is no config translation to french for the website's name. And thus, as Config split loops on existing config entities in the language collection when trying to detect overrides at export, it does not detect the override for french.

The consequence is that, when you import again, you still see "John Doe" in english mode, but you see "Mon super site web" in french. The override is gone.

*I only tested in partial mode but I guess it's the same in other modes.

Proposed resolution

I'm currently trying to find a fix for that. It's clear for me that in such a case, we should get some sort of override in mysplit/language/fr. So that the files state is different in the case you want "the same as default language" and the case you want "the same as default config" (which could also be a legitimate use case).

I see two ways to have this:
- on export, find a way to get a config override file very similar to the one you'd get if you had changed the value on translation,
- or, on export, detect the fact that a config which exists in default config (french translation) does not exist anymore in splitted DB, and generate some file indicating a "config removal" in mysplit/language/fr.
The last one seems harder to me, but I may be wrong. On the other side, the first one seems less "clean", as it will create a config translation on next import.

Remaining tasks

Implement some way to fix the bug.

User interface changes

None.

API changes

None?

Data model changes

None?

🐛 Bug report
Status

Active

Version

2.0

Component

Code

Created by

🇫🇷France GaëlG Lille, France

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

Merge Requests

Comments & Activities

  • Issue created by @GaëlG
  • Merge request !47Fix proposal for #3435910 → (Open) created by GaëlG
  • Open in Jenkins → Open on Drupal.org →
    Core: 10.2.x + Environment: php8.3_mysql8
    last update 9 months ago
    36 pass, 8 fail
  • Pipeline finished with Failed
    9 months ago
    Total: 183s
    #138856
  • Open in Jenkins → Open on Drupal.org →
    Core: 10.2.x + Environment: php8.3_mysql8
    last update 9 months ago
    75 pass
  • Pipeline finished with Success
    9 months ago
    #138878
  • Issue was unassigned.
  • Status changed to Needs review 9 months ago
  • 🇫🇷France GaëlG Lille, France

    Actually my second idea seemed easier to do: if a config exists by default (in sync) but not when the split is active, we config-split:export that config as an empty array yaml file. Then on config import, we delete this config if it exists, in case we detect an empty array.

    I made some manual testing, for my use case but also for a "normal" config entity (not a translation one). It seems to work well. But I would not be surprised if my code has problems I did not expect. This code seems complex to me and I think it's the first time I contribute to it. I was not always sure of the meaning of every line, some where sort-of copy-pasted.

    Anyway, I made a merge request. But even if the idea is OK and the implementation is OK too, I guess tests would be needed?

    The good news is that this would give a new feature: remove a config only in a split.

  • Status changed to Needs work 8 months ago
  • 🇨🇭Switzerland bircher 🇨🇿

    we should definitely have a test for that! It would help me step through the code and find more edge cases.

  • Pipeline finished with Failed
    5 months ago
    Total: 193s
    #241875
  • Pipeline finished with Failed
    about 2 months ago
    Total: 201s
    #319566
  • Pipeline finished with Canceled
    about 2 months ago
    Total: 53s
    #320412
  • Pipeline finished with Canceled
    about 2 months ago
    Total: 126s
    #320414
  • Pipeline finished with Failed
    about 2 months ago
    Total: 266s
    #320417
  • Pipeline finished with Failed
    about 2 months ago
    Total: 255s
    #320482
  • Pipeline finished with Failed
    about 1 month ago
    Total: 218s
    #332844
  • Pipeline finished with Failed
    about 1 month ago
    Total: 208s
    #339714
  • Status changed to Needs review about 1 month ago
  • 🇫🇷France GaëlG Lille, France

    Hello bircher, I made tests and added some comments to the MR.

Production build 0.71.5 2024