ConfigOverrideLanguage gets set to CurrentLanguage too late, leading to hard to debug wrong entity labels

Created on 25 January 2023, over 2 years ago
Updated 14 February 2023, over 2 years ago

Problem/Motivation

(Re-reading this, i do not see the relation to entity labels. The difffering ConfitOverrideLanguage is correct thouth.)

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

🐛 Bug report
Status

Active

Version

10.1

Component
Language system 

Last updated about 10 hours ago

  • Maintained by
  • 🇩🇪Germany @sun
Created by

🇩🇪Germany geek-merlin Freiburg, Germany

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

Comments & Activities

Production build 0.71.5 2024