Blocks are shown untranslated, if placed in Panels. Was it fixed in dev?

Comments

juves’s picture

Title: Translated Blocks » Custom text blocks are shown untranslated
Version: 7.x-3.0-alpha3 » 7.x-3.x-dev
Component: Miscellaneous » Panel pages
Category: support » bug

Views blocks on a panel-page are translated, custom blocks are not.

merlinofchaos’s picture

Status: Active » Closed (works as designed)

Views does its own translating. Panels doesn't have a facility for translating its custom content.

You can use visibility rules to put in translations of custom content.

juves’s picture

Category: bug » support
Status: Closed (works as designed) » Active

It's not panels custom content, it's one with i18n translated custom drupal block.

Do you mean, Panels respect the language definition for nodes, views, menu-blocks, ect., but not for custom drupal blocks and I need to make additional settings to get it work?

#784648: Block multilingual settings ignored by panels layout

juves’s picture

Title: Custom text blocks are shown untranslated » Custom drupal blocks are shown untranslated
Category: support » bug
merlinofchaos’s picture

I don't know how i18n handles translating the blocks. It's possible that it does it in the theme layer or something, and it doesn't recognize that panels is using the block.

Here's an idea: Change the style on your block to "System block" -- that forces it to go through normal block theming. At that point it's very nearly the same as rendering a block normally. If that works, it tells us that i18n only translates through theme('block').

juves’s picture

Title: Custom drupal blocks are shown untranslated » Drupal blocks are shown untranslated

I'm probably using the wrong terminology, it's not a self coded block, it's a normal Drupal text block, created via "Add Block" und localized/translated with i18n. I called it custom, because it's not a view or Drupal predefined block.

merlinofchaos’s picture

Right right, I understand what you mean now.

I still don't know how i18n actually handles translating it, so we need to figure that out. Sometimes things not handled by core are done awkwardly, and going through different services (like a panel pane) means the system doing the translation does not recognize that it needs to.

juves’s picture

Should I crosspost this issue to the i18n queue, so that i18n folk can explain this?

merlinofchaos’s picture

Try my suggestion in #5 first, see if it has any effect. If it does not, then yes, ask in the proper i18n queue.

juves’s picture

I don't know how to change a block style :D

merlinofchaos’s picture

In panels, when you click on the gear for a pane, there's a bunch of possible links. One of them should say change style. Select it, change it to system block, submit and then save and update. Then try viewing your panel.

juves’s picture

Nothing happened

merlinofchaos’s picture

Ok, then I guess ask the i18n folks if there's something special we have to do.

webflo’s picture

i18n_block translates blocks in hook_block_view. i18n_block only translates block title (and block content form drupal core blocks).

/**
 * Implements hook_block_view().
 */
function i18n_block_block_view_alter(&$data, $block) {
  if (!empty($block->i18n_mode)) {
    if ($block->title && $block->title != '<none>') {
      $block->title = i18n_string(array('blocks', $block->module, $block->delta, 'title'), $block->title);
    }
    if ($block->module == 'block' && isset($data['content'])) {
      $data['content'] = i18n_string(array('blocks', $block->module, $block->delta, 'body'), $data['content']);
    }
  }
}

There is also a new language condition for blocks. There is also a language condition for block (like path and user roles in core). But this affects only the block visibility and is independent from the translation. This done in hook_block_list_alter().

merlinofchaos’s picture

Interesting. Maybe we're just missing an alter on the CTools side that wasn't in D6. Will have to check this.

luckystrikerin’s picture

subscribing

guillaumev’s picture

subscribing

guillaumev’s picture

As a quick temporary fix, you can go into panels/templates/panels-pane.tpl.php and replace the following code:

  <?php if ($title): ?>
    <h2 class="pane-title"><?php print $title; ?></h2>
  <?php endif; ?>

by

  <?php if ($title): ?>
    <h2 class="pane-title"><?php print t($title); ?></h2>
  <?php endif; ?>
juves’s picture

If I wrap title and content with t(), I can translate it via 'translate interface', but it doesn't fetch translations, that I made via 'translate tab' on the block settings page.

But it works and it's usable as long as I have only two text-blocks in panels.

chriscalip’s picture

subscribe: note to self, translation of content pane (block) in panels

llribas’s picture

Suggestion in #5 work like a charm! (with panels 6.x-3.9)
Thank you merlinofchaos!

tuwebo’s picture

The workaround for me is create a new content type.
This content type will have Title, Body, and cck field called type.

Then I will create blocks with the content that I need through views, and add those views blocks to panels. Hope it works.

merlinofchaos’s picture

Status: Active » Needs review
StatusFileSize
new3.24 KB

Ok, i18n appears to be relying on altering the block as its loaded, and as it stands right now, CTools never actually loads data from the block table (except the title, which it loads specially later).

Try this patch. If nothing else, this patch actually saves some queries if you're displaying custom blocks (though it adds a query if you're displaying zero, so it's not a total improvement).

But it should allow i18n_block to function on these again.

merlinofchaos’s picture

Project: Panels » Chaos Tool Suite (ctools)
Version: 7.x-3.x-dev » 7.x-1.x-dev
Component: Panel pages » Code

Oh. This is a patch to CTOols, not Panels.

Moving queues.

merlinofchaos’s picture

Status: Needs review » Fixed

Committed.

Status: Fixed » Closed (fixed)

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

subhojit777’s picture

I am also having the same problem. The title of a custom block are not translated when they are kept in panels, but title gets translated when kept in theme region. I am using drupal 7.12, panels 7.x-3.0, ctools 7.x-1.0-rc1. I applied your patch file given in #23 and it gives the following error:

Notice: Trying to get property of non-object in menu_block_view_alter() (Zeile 501 von /var/www/proartadev/modules/menu/menu.module).
Notice: Trying to get property of non-object in i18n_menu_block_view_alter() (Zeile 62 von /var/www/proartadev/sites/all/modules/i18n/i18n_menu/i18n_menu.module).
Notice: Trying to get property of non-object in i18n_menu_block_view_alter() (Zeile 62 von /var/www/proartadev/sites/all/modules/i18n/i18n_menu/i18n_menu.module).
Notice: Trying to get property of non-object in ctools_block_content_type_render() (Zeile 158 von /var/www/proartadev/sites/all/modules/ctools/plugins/content_types/block/block.inc).

idflood’s picture

Status: Closed (fixed) » Needs work
StatusFileSize
new2.47 KB

Sorry to reopen this issue but this is exactly the issue I'm facing right now.

I'm having the same problem with the latest dev version of ctools (git 7.x-1.x) / panels / i18n on a drupal 7.12. Setting the style of the block to "system block" has no effects (untranslated block title and body). I tried to apply the patch in #23 since I wasn't able to find "_ctools_block_load_blocks" in ctools sources. Unfortunately the patch doesn't apply:

error: patch failed: plugins/content_types/block/block.inc:78
error: plugins/content_types/block/block.inc: patch does not apply

I've manually applied the patch proposed in #23 and it fixed the translation of the body but not the title and the title. The $block->title is correctly defined in ctools_block_content_type_render (translated) but the untranslated title is rendered.

With the patch it isn't required to select the "system block" style to have the block translated (the body). I have no idea of what is missing to get the title translated. Hopefully someone will have a solution.

edit: my bad, the untranslated title issue was simply caused by a "Override title" in the block panel setting. Unchecking this made the translation work, so the patch is perfect on my side.

idflood’s picture

Status: Needs work » Needs review

Needs review since the patch works as expected for me.

idflood’s picture

After some more tests I've found one edge case where the patch in #28 is causing an issue. In this case it simply displayed a warning about trying to access a property of a non-object (the $block->module in menu_block_view_alter, but I bet it can appear in other contributed block_view_alter hooks).

I selected an admin theme but the theme wasn't enabled. Pretty much everything was working so I didn't noticed that error before. In this situation the new _ctools_block_load_blocks() will return an empty $blocks array. Before the patch, the $block passed to hook_block_view_alter in ctools_block_content_type_render was constructed from scratch so this was not an issue.

Should I add a fallback to handle this situation in the patch?

tim.plunkett’s picture

Status: Needs review » Active

Yes, the error you found in #30 is exactly why this code was removed: #1275886-63: Error - Notice: Trying to get property of non-object in menu_block_view_alter().

We need a new solution.

dimitriseng’s picture

Hi, has anybody managed to find any solution for this yet? Thank you.

Cyclodex’s picture

Hey all, I have also this problem since some upgrading.
Everything worked well some months ago, updating to current version of ctools, i18n, panels seems still not solving my issue.
Blocks in panels are just not translated anymore :(

What could be the problem still ? I am missing something ?

skyredwang’s picture

which versions worked for you?

Cyclodex’s picture

Good question, because its some months ago, I am not sure when it was working well.
I will try to find it out.

Cyclodex’s picture

Ok, I got the working versions.

I created a drupal instance with the code and database from February. This shows me back the working blocks with translation.

I list some modules , which should influence this behavior, if you need further information just ask. What could we do? Diff the whole versions ?
Hope you see what causes the problem...

Drupal Version 7.9

ctools : 7.x-1.0-rc1
panels : 7.x-3.0-alpha3
i18n : 7.x-1.2

Cyclodex’s picture

Hey all

Ok, I tried to track it down. I could just reproduce the problem after update of ctools after my working setup I wrote in the previous comment.
I then compared the latest release with the one that worked (RC1).

I could track it down to some changes in the block.inc file (plugins/content_types/block/block.inc)

I do not understand what the code changes should do, but it looks like its not doing it well. So this patch will change the things back and implement it as in RC1.
If someone understand this better please have a look for how we could fix this with the new code.

Functions were removed which gave us the translated blocks. The changes also made something other not working as I think.
The title from blocks implemented in panels were also missing, with this change they are back again.

It seems that the patches from latest dev version and the 7.x-1.0 Release is not different, so could be applied to both of them.

Regards Cyclodex

Cyclodex’s picture

Oh dear, somehow I have overseen the comment #28, just saw that this patch is nearly or even exactly the same... arg...
sorry for that...

Hope someone finds a solution to have this working again in a new release.

merlinofchaos’s picture

This is frustrating, because there is some opinion that the i18n translation stuff we're relying on in the patch from #28 shouldn't actually work for Panels, and some other people feel it should. Unfortunately, I don't know who's right here.

The actual problem that removing the code was solving can probably be fixed just by testing that the $info actually exists, I imagine, and defaulting appropriately if it doesn't. But I'm not certain if:

1) We should go ahead and rely on i18n's block translation or
2) Ask i18n to have a special translation for Panels.

#2 is probably better in the long run, but requires someone from i18n world to actually do it.

merlinofchaos’s picture

Status: Active » Fixed

I've applied #28 with a safety to check for empty $info; if $info is empty, hook_block_view_alter won't be called, because it doesn't really exist as far as block_view is concerned.

ayalon’s picture

The patch works, but if you translate the blocktitle with i18n_blocks and you uncheck "override title" the block title still is not translated.

Tested with the latest ctools + panels version.

ayalon’s picture

Status: Fixed » Needs work

The error happens in function ctools_block_content_type_render
in plugins/content_types/block/block.inc

The variable $block contains the translated title.

But ctools loads the block itself in $info and overrides the translated table with an untranslated version.

if ($module == 'block') {
   /**************uncomment******/ 
   //$block->title = $info->title;
  }
  else if (isset($block->subject)) {
    $block->title = $block->subject;
  }
  else {
    $block->title = NULL;
  }

merlinofchaos’s picture

Status: Needs work » Fixed

Returning to fixed.

The code presented in #42 doesn't match either what's there now or what was already there -- specifically the "Uncomment this code" was never commented out.

merlinofchaos’s picture

Also, $info is what is sent to the alter function, and that is what should normally be translated by i18nblocks.

Status: Fixed » Closed (fixed)

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

richsky’s picture

Still not solved? Solved with Ctools 7.x-1.2 Thx.

Cyclodex’s picture

For me it is working fine with ctools version 7.x-1.2
But perhaps it depends how you are using or where you set the title.

Still not solved?

is also not a very detailed feedback.
Is it still not working for you? Did you tested it already on a dev server?

ayalon’s picture

Status: Closed (fixed) » Needs work

Hi all

Today I upgraded to the latest ctools and had my blocks untranslated again.

I think, I have tracked down the problem now.

1. Activate i18n_block translation
2. Add a custom block and and translate the title and the content
3. Create a panel page
4. Add the block to the panel page
5. Uncheck "Override title" in the pane settings
6. Switch the language and check it the block title translates in the frontend. It will not.

merlinofchaos said in #44 that the $info is altered. It's true, that drupal_alter is executed but $info os NOT altered:
plugins/content_types/block/block.inc line 148

drupal_alter(array('block_view', "block_view_{$module}_{$delta}"), $block, $info);

contains the unaltered $info;

then i18n_block_block_view_alter is executed:

function i18n_block_block_view_alter(&$data, $block) {
  if (!empty($block->i18n_mode)) {
    if (!empty($block->title) && $block->title != '<none>') {
      // Unfiltered, as $block->subject will be created later from the title.
      $data['title'] = i18n_string(array('blocks', $block->module, $block->delta, 'title'), $block->title, array('sanitize' => FALSE));
    }
    if ($block->module == 'block' && isset($data['content'])) {
      $data['content'] = i18n_string(array('blocks', $block->module, $block->delta, 'body'), $data['content']);
    }
  }
}

As you can see, the $info os not touched. Only the $block variable is translated.

In plugins/content_types/block/block.inc line 160 happens the failure:

  if ($module == 'block' && !empty($info) && isset($info->title)) {
    $block->title = $info->title;
  }

$block->title contains the translated title and is overridden by $info->title which contains the untranslated unaltered title.

merlinofchaos, do you see now, what I mean?

berdir’s picture

Status: Needs work » Needs review
StatusFileSize
new935 bytes

Confirmed.

i18n alters &$data (as that's what is passed by reference), which is $block, the naming of the variables here is partially switched.

The attached patch only attempts to set $block->title if it's not already set. This seems to be working fine here, so please test.

ayalon’s picture

Hi Berdir

Thanks for confirming. I test your patch and it works as expected.

@merlinofchaos: Could you have a look at this and also confirm, that this is an issue? We provided a detailed bug report including patch.

ayalon’s picture

Status: Needs review » Reviewed & tested by the community

Testes, forgot to change the status

berdir’s picture

Discussion and some more research lead my to the conclusion that the current code probably worked at some point because older versions of i18n did set $block->title, which is $info->title here: http://api.drupalize.me/api/drupal/function/i18n_block_block_view_alter/7

However, this was changed and now it assigns the translation to $data['title'], which is $block->title here.

There is nothing that sets $block->title other than a possible hook_block_view_alter() implementation and my patch should work with both the new and old i18n_block implementation.

dimitriseng’s picture

@merlinofchaos - any chance of reviewing the patch? Thank you.

podarok’s picture

Assigned: Unassigned » merlinofchaos

#49 looks good for me
RTBC

raulmuroc’s picture

+1 confirm patch in #49 works.

dshields’s picture

I can confirm that #49 solved the problem for me too :-)

sam0971’s picture

I also can confirm that #49 solved my problem!

berdir’s picture

japerry’s picture

Issue summary: View changes
Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

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

Jeffrey C.’s picture

Priority: Normal » Major
Status: Closed (fixed) » Active

Reopening this issue. Marking #784648: Block multilingual settings ignored by panels layout as duplicate. Here's how to reproduce the issue (using the latest stable release of ctools and i18n):

  1. Create a custom block on admin/structure/block/add.
  2. Set the block to translatable and translate it.
  3. Important! Place the block in a theme region.
  4. Add the block to a panel page.

Ta-da. The block is shown untranslated.
In my case, the block is always shown in Chinese even though there is a translated English version available. But as soon as I remove the block from the theme region, the translation is displayed correctly.

Jeffrey C.’s picture

Also, a temporary workaround would be: implementing PHP code for your block. Yes, I know, it's a horrible practice, but might be the only way to do this before a fix is proposed. Sample code below:

<?php
global $language;
$content = array();
$content['en'] = 'Here is some content in English.';
$content['fr'] = 'Here is some content in French.';
$content['zh-hant'] = 'Here is some content in Chinese.';
print $content[$language->language];
?>
franz’s picture

Confirm #49 fixed for me. This is a must, since it fixes an unexpected behavior (i.e. ignoring block title translations)

  • merlinofchaos committed bc898cf on 8.x-3.x
    Issue #1168272: Retool block.inc to support block_list_alter and thus...
  • merlinofchaos committed 169c6b8 on 8.x-3.x authored by idflood
    Issue #1168272 by merlinofchaos, idflood, Cyclodex | juves: Fixed Drupal...
  • japerry committed b2b05fe on 8.x-3.x authored by Berdir
    Issue #1168272 by juves, Berdir: blocks are shown untranslated
    
jjsanz’s picture

The same isue as #61. If i place the block in a theme region the panel shows block untranslated.

darrenwh’s picture

Status: Active » Reviewed & tested by the community

Setting this as RTBC going by general consensus

rivimey’s picture

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

I tried to verify this against current ctools 7.x-1.x-dev (~1.13).

First I tried to reproduce it. The 'i18n_block' module mentioned above is a submodule of 'i18n'. This was downloaded, enabled, and French was added as a site language. A block created with both site-default English and then a French translation. That block was placed in the 'content' region. I used the 'default translation' control on the block to request the French version, but whether the default translation was English or the default was French, the same (English) content was displayed.

So, the bug seems to exist. The confusing part is that the patch in #49 doesn't apply, because it is already present in this version of ctools, (although now at line 167).

I guess something else has broken it again. Given it seems quite fragile, I think it reasonable to require some automated tests this time :-)

joelpittet’s picture

Status: Needs work » Closed (outdated)

I'm closing this for triage it's been a while since anybody has asked about it and the patches are not in a state that can be committed. LMK and I'll re-open it if there is something to do.