Problem/Motivation

I want to configure the language detection behavior to be different for content language and interface language.
Therefore I check the checkbox "Customize Content language detection to differ from Interface text language detection settings" on the language detection settings (/admin/config/regional/language/detection). For the Interface text language I configure the Users selected language (Follow the user's language preference.) to be top priority for language detection as the admins want to have the toolbar, edit forms and so on to be in the language they chose, so that they can understand every field and function.

For the content language detection, I choose URL (Language from the URL (Path prefix or domain).) to be the top priority.
But now the dropdown language switcher isn't working anymore to switch between different content translations and it doesn't show the current content language because it seems to be using the interface language instead of the content language.

Proposed resolution

Change the module code, so that the dropdown language switcher depends on the content language (which you normally want to change with such a language switcher) instead of interface language.

Command icon 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

Guido_S created an issue. See original summary.

anybody’s picture

Indeed I can confirm this!

anybody’s picture

Priority: Normal » Major
anybody’s picture

Status: Active » Closed (works as designed)

Trying to fix this in code I found the important part: The maintainer already solved this VERY smart:

  /**
   * {@inheritdoc}
   */
  public function getDerivativeDefinitions($base_plugin_definition) {
    $language_manager = \Drupal::languageManager();

    if ($language_manager instanceof ConfigurableLanguageManagerInterface) {
      $info = $language_manager->getDefinedLanguageTypesInfo();
      $configurable_types = $language_manager->getLanguageTypes();
      foreach ($configurable_types as $type) {
        $this->derivatives[$type] = $base_plugin_definition;
        $this->derivatives[$type]['admin_label'] = $this->t('Dropdown Language (@type)', ['@type' => $info[$type]['name']]);
      }
      // If there is just one configurable type then change the title of the
      // block.
      if (count($configurable_types) == 1) {
        $this->derivatives[reset($configurable_types)]['admin_label'] = $this->t('Dropdown Language');
      }
    }

    return parent::getDerivativeDefinitions($base_plugin_definition);
  }

So you simply have to use the other dropdown language block "Dropdown language (Content)". There's one for each language type! :)

skaught’s picture

Derivatives in the Block API are a interesting little treat.

This seems like the very discovery that is the cause of v1-v2 progression for this module.

noting (contrib releasing): a flaw in the Block API happens to be if you have already initialized a block definition, you can not add a deriver after..

skaught’s picture

guido_s’s picture

So you simply have to use the other dropdown language block "Dropdown language (Content)". There's one for each language type!

Thank you very much for this hint!
This module should definitely have some documentation on this.
Because different blocks for different language types are only available AFTER checking "Customize Content language detection to differ from Interface text language detection settings". And the default dropdown language block uses the interface language.
I didn't expect new available blocks in the list. I expected the dropdown language block that I already placed before to work as I expected it or to have some settings in the block or in the module configuration for it, but not that I can place a new block now and have to remove the dropdown language block I already placed.

skaught’s picture

Title: Interface language is used instead of content language » [doc] Interface language is used instead of content language
Component: Code » Documentation
Status: Closed (works as designed) » Needs review

#7

Because different blocks for different language types are only available AFTER checking "Customize Content language detection to differ from Interface text language detection settings".

skaught’s picture

Status: Needs review » Needs work
anybody’s picture

Title: [doc] Interface language is used instead of content language » Document Interface language vs. content language block
Version: 8.x-2.x-dev » 4.0.x-dev
skaught’s picture

Status: Needs work » Closed (outdated)

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.