Problem/Motivation

Some blocks in the block layout library are grouped under the label "System", some under the translation of "System"

Steps to reproduce

  1. Install in another language than english
  2. Login as admin
  3. Go to the block layout page admin/structure/block

Alternative:

  1. Login as admin
  2. Enable multilanguage modules
  3. Add another language
  4. Interface-translate "System"
  5. Go to the block layout page admin/structure/block

Multiple instances of "System" are not translated while some are. See the screenshots below, where "System" was translated to "TEST" in German.

Noticed in #2019511: Explain why the language switcher would not show under some configurations

Proposed resolution

Remaining tasks

User interface changes

Before


After


All system blocks are now in translatable categories.

API changes

No.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

YesCT’s picture

Issue summary: View changes
Status: Needs work » Active
FileSize
614.41 KB

Maybe there is a t() missing from some?

YesCT’s picture

Those two that go into Systema, have explicit category set in their annotations with @Translation

For example, in LanguageBlock.php

/**
 * Provides a 'Language switcher' block.
 *
 * @Block(
 *   id = "language_block",
 *   admin_label = @Translation("Language switcher"),
 *   category = @Translation("System"),
 *   deriver = "Drupal\language\Plugin\Derivative\LanguageBlock"
 * )
 */
class LanguageBlock extends BlockBase implements ContainerFactoryPluginInterface {

compare to SystemMailBlock.php

/**
 * Provides a 'Main page content' block.
 *
 * @Block(
 *   id = "system_main_block",
 *   admin_label = @Translation("Main page content")
 * )
 */
class SystemMainBlock extends BlockBase implements MainContentBlockPluginInterface {

but... how does it know that is system? is system the default category?

\Drupal\Core\Block\Annotation\Block

says

  /**
   * The category in the admin UI where the block will be listed.
   *
   * @var \Drupal\Core\Annotation\Translation
   *
   * @ingroup plugin_translatable
   */
  public $category = '';

which looks like it is not setting a default category...

----

Here is one not in system, just for additional comparison, SearchBlock.php:

/**
 * Provides a 'Search form' block.
 *
 * @Block(
 *   id = "search_form_block",
 *   admin_label = @Translation("Search form"),
 *   category = @Translation("Forms")
 * )
 */
class SearchBlock extends BlockBase {
axooh’s picture

@dschenk and me are working on this, while sprinting at DrupalCon in Barcelona.

dschenk’s picture

Issue summary: View changes
FileSize
158.73 KB
101.5 KB
axooh’s picture

Component: language.module » system.module
Status: Active » Needs review
FileSize
2.95 KB

In this patch we added the category explicitly to the corresponding blocks in the system module, to make them translatable.

dschenk’s picture

Issue summary: View changes
FileSize
331.22 KB

I helped in the creation of the patch.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

dschenk’s picture

Version: 8.1.x-dev » 8.2.x-dev
maxocub’s picture

Status: Needs review » Reviewed & tested by the community

I was able to reproduce the issue and confirm that the patch in #5 works.

xjm’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs tests

Nice find! I noticed this once before but did not track down why it was happening. The fix seems correct.

I think we could provide test coverage to this to make sure future system blocks also get the correct category. The test might load the translated admin listing, assert that expected blocks are displayed, and assert that the untranslated word "system" does not appear.

Alternately (or additionally), is declaring a block without a category even valid? Should we warn developers of this somehow?

maxocub’s picture

I think that declaring a block without a category is valid, at least that's what I understand from the default empty value in the annotation. I haven't found out why and how (and I would like know if someone can illuminate me), but when we don't declare a category, it uses the module's name.

What's happening here is that the 5 blocks from the system module don't declared a category (so it uses 'System' as a fall back), and that two blocks from other modules declared there category as 'System' and made it translatable. I think the module's name fall back is OK.

On a different note, the admin label too is optional, and it doesn't have a fall back, so when you don't declare one it stays blank. Shouldn't we use the block's ID in that case for the admin label?

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.0-beta1 was released on August 3, 2016, which means new developments and disruptive changes should now be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Gábor Hojtsy’s picture

Sounds like a backwards incompatible change to require categories. But fixing this problem by adding categories sounds fine. So maybe we should test that all core blocks provide a category as a best practice, but not as a requirement.

Gábor Hojtsy’s picture

Issue tags: +sprint

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

maxocub’s picture

Title: some blocks in system are in system, some in translated-system label when install in another language » Some blocks don't have a category, and thus we cannot translate it
Component: system.module » block.module
Status: Needs work » Needs review
Issue tags: -Needs tests
FileSize
962 bytes
5.53 KB
2.59 KB

Here's a test to check that every core block have a category.

The last submitted patch, 16: 2500607-test-only.patch, failed testing.

maxocub’s picture

Title: Some blocks don't have a category, and thus we cannot translate it » Some block categories are not translatable
FileSize
7.72 KB
2.19 KB

Hmm, it seems like my test does not catch all blocks without a category.
I guess it's because the namespaces array is only filled with enabled modules.
Is there a way to get ALL namespaces?

maxocub’s picture

Here's a way to find all block plugins: loading every (non-test) modules to fill the namespaces array.

maxocub’s picture

Just found a better way to get a list of all modules, thanks to @heddn!

maxocub’s picture

Issue tags: +Baltimore2017
John Cook’s picture

I started out by testing the patch from #20 using the Korean translation.

Before:

After:

So I would say that the patch works as designed.

Then I followed the code a bit down the call stack and made a new patch. The only change is in core/lib/Drupal/Core/Plugin/CategorizingPluginManagerTrait.php:processDefinitionCategory() where I've passed the retrieved module name into t(). This would allow all categories that haven't been set to be translatable.

Status: Needs review » Needs work

The last submitted patch, 22: 2500607-22.patch, failed testing.

John Cook’s picture

Changed the test to expect a TranslatableMarkup object instead of a string as default category.

John Cook’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 24: 2500607-24.patch, failed testing.

John Cook’s picture

Status: Needs work » Needs review
FileSize
9.97 KB
1.08 KB

The category was accidentally removed from PageTitleBlock.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

ethomas08’s picture

Uploading re-rolled patch. It fixes the bug (see attached screenshot), but I haven't ran the tests to see if anything breaks. Lots of changes between 8.4.x and 8.7.x!

ethomas08’s picture

Status: Needs review » Reviewed & tested by the community

Ran tests -- the 2 that had been altered passed. All the reroll changes were the same as in the 8.4.x patch so marking this RTBC. Great job on this, looks great!

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/lib/Drupal/Core/Plugin/CategorizingPluginManagerTrait.php
@@ -31,7 +31,7 @@ protected function processDefinitionCategory(&$definition) {
-      $definition['category'] = $this->getProviderName($definition['provider']);
+      $definition['category'] = $this->t($this->getProviderName($definition['provider'])); ¶

I'm not sure this is correct. The @translation should pass a TranslationMarkup object into the definition.

Also we should have the test that ensures all the blocks have categories that was in #27.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

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

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

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.

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.

quietone’s picture

Issue tags: +Bug Smash Initiative

This is still relevant and the patch applies to 9.5.x.

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.