Problem/Motivation
Some blocks in the block layout library are grouped under the label "System", some under the translation of "System"
Steps to reproduce
- Install in another language than english
- Login as admin
- Go to the block layout page admin/structure/block
Alternative:
- Login as admin
- Enable multilanguage modules
- Add another language
- Interface-translate "System"
- 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.
Comment | File | Size | Author |
---|---|---|---|
#31 | Screen Shot 2018-11-30 at 9.57.51 AM.png | 55.86 KB | ethomas08 |
#31 | 2500607-8.7.x-reroll.patch | 8.39 KB | ethomas08 |
#27 | interdiff-24-26.txt | 1.08 KB | John Cook |
#27 | 2500607-26.patch | 9.97 KB | John Cook |
#24 | interdiff-22-24.txt | 1.56 KB | John Cook |
Comments
Comment #1
YesCT CreditAttribution: YesCT commentedMaybe there is a t() missing from some?
Comment #2
YesCT CreditAttribution: YesCT commentedThose two that go into Systema, have explicit category set in their annotations with @Translation
For example, in LanguageBlock.php
compare to SystemMailBlock.php
but... how does it know that is system? is system the default category?
\Drupal\Core\Block\Annotation\Block
says
which looks like it is not setting a default category...
----
Here is one not in system, just for additional comparison, SearchBlock.php:
Comment #3
axooh CreditAttribution: axooh commented@dschenk and me are working on this, while sprinting at DrupalCon in Barcelona.
Comment #4
dschenk CreditAttribution: dschenk commentedComment #5
axooh CreditAttribution: axooh commentedIn this patch we added the category explicitly to the corresponding blocks in the system module, to make them translatable.
Comment #6
dschenk CreditAttribution: dschenk commentedI helped in the creation of the patch.
Comment #8
dschenk CreditAttribution: dschenk commentedComment #9
maxocub CreditAttribution: maxocub commentedI was able to reproduce the issue and confirm that the patch in #5 works.
Comment #10
xjmNice 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?
Comment #11
maxocub CreditAttribution: maxocub commentedI 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?
Comment #13
Gábor HojtsySounds 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.
Comment #14
Gábor HojtsyComment #16
maxocub CreditAttribution: maxocub commentedHere's a test to check that every core block have a category.
Comment #18
maxocub CreditAttribution: maxocub commentedHmm, 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?
Comment #19
maxocub CreditAttribution: maxocub commentedHere's a way to find all block plugins: loading every (non-test) modules to fill the namespaces array.
Comment #20
maxocub CreditAttribution: maxocub commentedJust found a better way to get a list of all modules, thanks to @heddn!
Comment #21
maxocub CreditAttribution: maxocub commentedComment #22
John Cook CreditAttribution: John Cook at Creode commentedI 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 intot()
. This would allow all categories that haven't been set to be translatable.Comment #24
John Cook CreditAttribution: John Cook at Creode commentedChanged the test to expect a TranslatableMarkup object instead of a string as default category.
Comment #25
John Cook CreditAttribution: John Cook at Creode commentedComment #27
John Cook CreditAttribution: John Cook at Creode commentedThe category was accidentally removed from PageTitleBlock.
Comment #31
ethomas08 CreditAttribution: ethomas08 as a volunteer commentedUploading 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!
Comment #32
ethomas08 CreditAttribution: ethomas08 as a volunteer commentedRan 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!
Comment #33
alexpottI'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.
Comment #41
quietone CreditAttribution: quietone at PreviousNext commentedThis is still relevant and the patch applies to 9.5.x.