Problem/Motivation
RecipeConfigTranslationInstaller saves each override with
LanguageConfigOverride::save(). Normally that fires
LanguageConfigOverrideEvents::SAVE_OVERRIDE, and
LocaleConfigSubscriber::onOverrideChange() records the values in locale's
string storage as customized = 1, which is what makes them survive later
translation refreshes.
During a site install that subscriber early-returns:
if (!InstallerKernel::installationAttempted() && !$this->localeConfigManager->isUpdatingTranslationsFromLocale()) {
Recipes are applied inside the installer, so RecipeAppliedEvent, and
therefore this module, always runs while installationAttempted() is TRUE.
The overrides land in config, but locale never learns they are authoritative.
The first drush locale:update afterwards calls
LocaleConfigManager::updateConfigTranslations(), whose
filterOverride() strips every translatable key from the existing override and
refills only what it can match in the .po catalogue. Everything the recipe
shipped is gone, silently.
This is install-only: drush cim goes through
ConfigImporter::importConfig(), which builds the override via the collection's
override service, so the event fires and the values stick. Sites deployed with
drush deploy are unaffected; freshly installed ones are not.
Steps to reproduce
- Install a profile whose recipe carries
config/language/nl/some.config.yml. - Confirm the override is present, e.g. via
\Drupal::languageManager()->getLanguageConfigOverride('nl', 'some.config'). - Run
drush locale:check && drush locale:update. - The override now contains only the keys locale could translate from
.po. Anything the recipe shipped that has no.pomatch is
back to English.
Proposed resolution
After saving an override, when running under the installer, register the values
with locale directly. LocaleConfigSubscriber::updateLocaleStorage() is public
and locale.config_subscriber is a public service; it takes the override plus
the active config as reference:
$subscriber->updateLocaleStorage($override, $langcode, $reference_config);
Guard it on locale being installed, and skip it when locale itself is
driving the write.
Remaining tasks
- Agree on the approach.
- Patch
RecipeConfigTranslationInstaller. - Add a kernel or functional test covering install followed by
locale:update, the existing fixtures assert the override is written,
not that it survives.
Related
The deeper cause is core's: the installationAttempted() guard predates
recipes, and isUpdatingTranslationsFromLocale() already covers the case its
docblock describes. Worth revisiting in
#3453331 when core
applies config language overrides natively.
Issue fork recipe_config_translation-3617792
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
Comment #2
f0ns commentedHappy to write the patch and a test for this if you're open to the approach.
I'd treat it as an interim fix, once core handles this natively (#3453331) it can probably be dropped again.
Let me know and I'll get it done.
Comment #4
f0ns commentedPatch pushed to the issue fork.
The installer now calls
LocaleConfigSubscriber::updateLocaleStorage()after saving an override, guarded three ways: only during installation (outside it locale's own subscriber already handles the save), only when locale is installed (both locale services injected as optional@?arguments), and skipped whenisUpdatingTranslationsFromLocale()is TRUE. The active config is passed as$reference_config, matching core's subscriber.New
RecipeConfigTranslationLocaleTestcovers the install-time apply survivingupdateConfigTranslations(), the value being stored as customized, and the non-install path. Verified on 11.4.5: all tests pass, and with the new call removed the two install-path tests fail, so they do reproduce the loss. phpcs clean.Comment #5
f0ns commented