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
Comment #2
geek-merlinComment #3
geek-merlinComment #4
geek-merlinComment #5
geek-merlin