Problem/Motivation

(Re-reading this, i do not see the relation to entity labels. The difffering ConfitOverrideLanguage is correct thouth.)
This is one of the "we get wrong translations" issues, which manifests itself mainly in wrong entity labels, because those are created when entity info is collected, which may be quite early. What makes that even harder to debug is that when entity info is collected depends highly on which modules exactly are doing what during the bootstrap.

Note that there are other issue which lead to the same outcome (wrong entity labels), but have different reasons.

Long story short, we found situations where CurrentLanguage is negotiated, but NOT yet copied to ConfigOverrideLanguage. That should not be.

Steps to reproduce

It's some time ago, but here's the note i made in that MultiLangNG commit:

  /**
   * Get configuration target language.
   *
   * This should in fact use LanguageManagerInterface::getConfigOverrideLanguage,
   * but this leads to nasty and hard debug issues. How to reproduce:
   * - Set 'de' as negotiation default.
   * - (Maybe it's relevant to enable search_api and webform_views)
   * Then on `drush cr`, english labels are cached for 'de'.
   * This is because EntityTypeManager caches field definitions for
   * currentLanguage, which is "de", but configOverrideLanguage is "en",
   * because it defaults to defaultLanguage and seems to not have been set yet.
   *
   * Maybe the reason is that sometimes the listener calls currentLanguage
   * before it's initialized, in which case it falls back to 'system', but
   * later when it is initialized, configOverrideLanguage is not updated.
   * If that is the case, finishing initialization of LanguageManager should
   * trigger syncing configOverrideLanguage somehow.
   *
   * And in the end, do we need configOverrideLanguage as a separate concept
   * from currentLanguage (i.e. interface_language) at all?
   *
   * @see \Drupal\Core\Language\LanguageManagerInterface::getConfigOverrideLanguage
   * @see \Drupal\language\EventSubscriber\LanguageRequestSubscriber::setLanguageOverrides
   * @see \Drupal\language\ConfigurableLanguageManager::getCurrentLanguage
   *
   * @todo Find a fix upstream and get rid of this hack.
   */
  protected function getTargetLanguage(): LanguageInterface {
-    return $this->getLanguageManager()->getConfigOverrideLanguage();
+    return $this->getLanguageManager()->getCurrentLanguage();

Proposed resolution

Change the copy-over logic in a way that avoids the diverging situation.

Remaining tasks

Think, code, review, commit

User interface changes

None

API changes

TBD

Data model changes

TBD

Release notes snippet

TBD

Comments

geek-merlin created an issue. See original summary.

geek-merlin’s picture

Issue summary: View changes
geek-merlin’s picture

geek-merlin’s picture

geek-merlin’s picture

Issue summary: View changes

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.