Problem/Motivation

Drupal allows using a different (admin) interface language than the (frontend) content language. This allows to administer all pages in English while users (and editor) can select content language to use in the language selection form by URL (/de for example).

When using these different settings, the block title is displayed in interface language while block content is displayed in content language:

Expected would be to have both displayed in content language!

In this example the interface language is German (de), the URL is English (/en).
The strings are translated to contain the language identifier of the translation:
...de... is the German translation
...en... is the English translation

both in title and content.
interface vs content language for block title and content
As the selected content language is /en you'd expect "block test en" here for the title. Block content is correct!

Steps to reproduce

  1. Enable at least two languages
  2. Enable content language in admin/config/regional/language/detection
  3. Configure as in the screenshot below
  4. Set one language in your user profile (interface language) e.g. English
  5. Select a different language in the language selector block (Drupal core) so that the the URL changes to that language (e. g. "/de")
  6. Place a custom block somewhere and translate content and title. Enable "Display title".
  7. Switch languages and see content in content language and title in interface language!

I'm using a configuration like this:
translation settings

Proposed resolution

Show block title in content language just like the content.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

CommentFileSizeAuthor
#2 block-title-vs-content-language.PNG18.36 KBanybody

Comments

Anybody created an issue. See original summary.

anybody’s picture

Issue summary: View changes
StatusFileSize
new18.36 KB
anybody’s picture

Issue summary: View changes
berdir’s picture

This is the same discussion as field labels vs field content. config translation is deeply baked into the system and done automatically on loading config. There is no easy way to override that and the place that loads block configs is detached from where we decide to display it in the frontend.

There's not going to be an easy fix for this. We only use the admin language for config and not the user language negotiatior, while that has its own issues (like toolbar not being translated without other patches), it's far more consistent.

Not saying that this isn't a bug, just that the chances of it being improved/fixed are... slim.

anybody’s picture

Thank you very much for your detailed reply @Berdir. I guess the consequences are that using the functionality to have a different interface language from content language, e.g. administration language, is not really usable if it's not consistently implemented everywhere (if not even in core). That's sad as It would be really really helpful as other solutions like administration_language or similar never really worked great and I was happy there was a core solution now. :(

I totally understand that it won't be easy and things won't change in the near future, as there are many other TODOs, but I ask myself why this separation was made in core then without ensuring it's possible. No offense and no criticism, it's just unclear to me, and perhaps you might agree. Thank you very very much for your remarkable work on Drupal each day!

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

anybody’s picture

anybody’s picture

quietone credited bahuma20.

quietone credited make77.

quietone’s picture

Closed earlier issue as a duplicate, #2810457: custom block title translation not displayed and adding credit.

That issue has this workaround which 3 comments state is working.

function my_theme_preprocess_block(&$variables) {
  if ($variables['elements']['#base_plugin_id'] == 'block_content') {
    if ($variables['label'] !== '') {
      $variables['label'] = $variables['content']['#block_content']->label();
    }
  }
}

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

recrit’s picture

Some more info regarding this pain point...
This ultimately comes down to \Drupal\language\EventSubscriber\LanguageRequestSubscriber:setLanguageOverrides that sets the language config override language to the interface language type (LanguageInterface::TYPE_INTERFACE).
This causes the disconnect for the frontend facing configurations.
Examples:

  • block - The title is rendered in the interface language, but the content of the block is rendered in the content language.
  • View exposed form blocks - The exposed form field labels and descriptions are rendered in the interface language.

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

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

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.