It seems that, there is no where to do this.

I looked into the code
I believe it is something to do with this file.

Plugin/DisplayVariant/ContextBlockPageVariant.php

125   private function getBuildFromBlockLayout() {
126     $plugin_manager = \Drupal::service('plugin.manager.display_variant');
127     $display_variant = $plugin_manager->createInstance('block_page', $plugin_manager->getDefinition('block_page'));
128     $display_variant->setTitle($this->title);
129
130     return $display_variant->build();
131   }
132

If we put t() to line 128 in the setTitle
The problem will be solved by using the Drupal8 UI Translation tool to translate it.
If we are going to do this, I suggest we put optional context parameter to t function, so this translation is limited only for Context Module.

I don't know anything else about how core Drupal8 store translation for Block Title, we can also do that. but it means you need to link the dropbutton to the translate button and etc..

Please discuss, I can provide a very simple patch if we are going for the first option.. which is adding t() to line 128 with the context parameter.

Issue fork context-2922368

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

vorapoap created an issue. See original summary.

Priyanka.addweb’s picture

You can make block twig file and use t() function for translation. For label use {{ label|t }} in twig file.

tahiticlic’s picture

Hi,

this solution is not perfect since it's not applicable in all cases. For instance, for a wysiwyg field, it won't work.

Perhaps a proper solution would have the translate link through Context UI.

Regards

boshtian’s picture

What kind of block do you have? Is this a Custom block, something out of Views or you made your own block in code?

The point is that some block types are translatable, so we would need more information so we can determine what would be the best solution that would cover all cases.

s.thiru.raju’s picture

I'm using custom block and using Panels. Not able to translate block title. I could find some solutions about translating Description. But would require a solution for translating custom block title. Thank you

thirstysix’s picture

Overriding the block title in panels:

  • Home > Administration > Configuration > Regional and language
  • Go to Configuration translation > Page Variant (/admin/config/regional/config-translation/page_variant)
  • Select the variant name to translate
  • Select the language to translate to and set translation content.
rooby’s picture

Priority: Critical » Normal

See https://www.drupal.org/node/45111 for priority descriptions.

This one doesn't seem to be critical.

sutharsan’s picture

Category: Feature request » Bug report

Changing to Bug as it is for the multilingual use of the Context module.

strozx’s picture

Status: Active » Postponed (maintainer needs more info)
deaom’s picture

I tested this one out, and it seems to be working. Not sure if I completely understand the issue tough. I could translate the title of the block in the UI by searching that string (tested with core's Recent content, which is a view block), but that then applies to blocks added via context or via block structure. The custom block is then translated via Configuration translation, and it's also working and displaying the correct translation depending on the language.
Leaving this status to postponed, but if no additional steps to reproduce are added, it will be assumed it's working correctly.

marcvangend’s picture

Status: Postponed (maintainer needs more info) » Active

If I understand correctly and the original issue is about the same problem I'm facing right now, here are the steps to reproduce:

  1. Set up a clean standard install of Drupal 9.2.4. Enable Context UI, Configuration Translation and Language modules.
  2. Create a sitewide context. Add a blocks reaction.
  3. Place the "Main navigation" menu block in the "Content" region, set its block title to "Primary" and make sure "Display title" is checked.
  4. Note that you now see the main menu in the content region, with a label "Primary" above it.
  5. Enable a second language. Let's choose French. Confirm you can switch to French by adding /fr to the URL.
  6. Now try to find a way to translate the "Primary" label to "Primaire" in the French interface. You can't. That is the problem.
marcvangend’s picture

OK, I lied a little when I said "You can't". There seems to be a workaround if you don't mind manually editing configuration Yaml files:

  1. Export your configuration.
  2. Find the default configuration file of your context, eg. config/sync/context.context.sitewide.yml if the machine name is "sitewide".
  3. Check if a file of the same name already exists in your translated config directory, eg. config/sync/language/fr/context.context.sitewide.yml. If not, create it.
  4. In the default context yml file, find the block label you want to translate. You should see a structure like this:
    reactions:
      blocks:
        blocks:
          cfc3ee1c-4ade-4978-b958-5f67f1c6aa79:
            [ ...properties of some other block ]
          dae52d3c-91e9-4c89-b7ff-ee2e54a0a680:
            id: 'menu_block:main'
            label: Primary
            [ ...more properties of the block you were looking for ]
          af990167-0822-4a31-8a57-0c17e45ea5b6:
            [ ...properties of yet another block ]
    
  5. Now add the following to your French configuration yml, using the structure and UUID you found in the default config file:
    reactions:
      blocks:
        blocks:
          dae52d3c-91e9-4c89-b7ff-ee2e54a0a680:
            label: Primaire
    

    You can leave out all other properties, only add the label property you need to translate and the parent keys that lead to it (reactions>blocks>blocks>[UUID]). Take care because Yaml is indentation-sensitive.

  6. Finally, import your configuration.

Disclaimer: Even though this works (at the moment, for me) this is not an officially supported method. It comes without guarantees and may break at any moment.

vlad.dancer made their first commit to this issue’s fork.

vlad.dancer’s picture

Status: Active » Needs review

Hey @DeaOm
I can't reproduce translating block title via `User interface translation`.
The Recent Content block's title isn't translated via t() function. Instead you've might translated strings with `Recent content` for other sources, like from: core/modules/help_topics/help_topics/tracker.tracking_changed_content.html.twig

Ha! You've found some bug. This block shouldn't be translatable in such way.

@marcvangend

There seems to be a workaround if you don't mind manually editing configuration Yaml files

I'm too lazy for it :)

I've looked into the context's schema definitions and found that we could translate block's title.
We need just to change value for the `reaction.plugin.mapping.blocks.sequence.mapping.label.type` property to the `label` type.
I checked translating various block provides: content blocks, user blocks, powered by, search block.

So for anyone who can't wait you could alter schema definition yourself:

function mymodule_config_schema_info_alter(&$definitions) {
  if (isset($definitions['reaction.plugin']['mapping']['blocks'])) {
    $blocks =& $definitions['reaction.plugin']['mapping']['blocks'];
    $blocks['sequence']['mapping']['label']['type'] = 'label';
  }
} 

Clear the caches.
Then go to admin/structure/context/[your_context]/translate and it under: reactions > reaction > blocks > your_block
Note: don't forget to disable Override title in a context block's settings page.

marcvangend’s picture

Thanks for the merge request, Vlad! Myself, I was too lazy to figure out how to make that label translatable... So I was happy to learn from your commit :-D

sutharsan’s picture

Status: Needs review » Reviewed & tested by the community

This is indeed the right way to translate the configuration. Patch looks good. Have not tested it, but this can't go wrong (famous last words ;) )

paulocs made their first commit to this issue’s fork.

paulocs’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.