The site I am working on uses i18n and is bilingual: english and french.

The nodeasblock module could be a very interesting option on multilingual sites, because it allows to use multilingual workflow control that i18n excellently implements for nodes but not for blocks.

Currently, the nodeasblock/i18n duo completely ignores multilinguality: If I assign the english node "About" as block to the bottom bar of my site, the About node shows up also on the french version of the site. The french translation "A propos" does not show up at all.

Desired behaviour would be

1) block from node should show on specific languages according to the settings of the i18n module (language selector).

The next level would be

2) if translation of node is available in current language, show the translation of the node. This could require some user interface adjustment, because it _could_ be confusing for the user that suddenly a node shows up as block shows that has not been configured to do so. But this could be a major workflow improvement: once a node is assigned as block to some website real estate, the site can grow organically. If you add another language to the site, you just create a translation of the node you use as block. The new translation automatically pops up at the right place. No need to go to the block admin page.

I need to get this done somehow, I appreciate any thoughts or suggestions.

Comments

jose reyero’s picture

I think this simple one line patch may work (last line).

As we have nid, using db_rewrite_sql should add the language conditions for nodes there and only select the blocks for the current language.

If you just set both blocks in the same place, the right one will show. The other option may be using i18nblocks.module metablocks to show whatever block depending on language.

function nodeasblock_block($op = 'list', $delta = 0, $edit = array()) {
  if ($op == 'list') {
    // get list of nodeblock nodes from db...
    $result = db_query(db_rewrite_sql('SELECT n.nid FROM {nodeasblock} n'));
alex_b’s picture

Thanks Jose, will try that. Do you see a chance how to implement 2) ?

alex_b’s picture

Jose,

The patch you suggested has no impact on viewing a nodeasblock block, it alters a query that is being called on listing nodes as blocks. I think there needs sth. to happen a couple of lines further down:

else if ($op == 'view') {
  if ($node = node_load($delta)) {
    return theme('nodeasblock', $node);
  }
}
jose reyero’s picture

Status: Active » Needs review
StatusFileSize
new1.32 KB

Here's a patch for i18n integration. It shouldn't break anything if i18n is not enabled.

It replaces the node by its translation on the fly. Further explanation on the code comments

Also, this 'nodeasblock_translate' function could be used inside the theme function if you don't want to patch the module..

alex_b’s picture

Jose,

Thanks for the patch, great! I am worried about the performance tax of an additional node load.

Instead of

if ($node = nodeasblock_translate(node_load($delta))) {
      return theme('nodeasblock', $node);
    }

Should we...

if (module_exists('translation')) {
  if ($trans_nid = translation_node_nid($nid, i18n_get_lang())) {
    $delta = $trans_nid;
  }
} 

...?

jose reyero’s picture

StatusFileSize
new758 bytes

Alex,

Yes, I think your code is better. I've tried it and works fine. The only change in behaviour is that it shows the original node if no translation exists, that is also all right I guess

So I've recreated the patch using your code and fixing a small typo ($nid)

Plus, maybe a workaround if you dont have too many of these blocks, you can use block visibility settings for blocks to display only for given languages, using paths like: en/*, es/*, etc..

mfredrickson’s picture

Status: Needs review » Fixed

Oops. I applied this patch but forgot to update the issue queue.

Thank you Jose and Alex for writing and testing these patches. Like most module developers, I want to be int'l compatible, but I'm not entirely clear when I need to be.

Cheers,
-mark

Anonymous’s picture

Status: Fixed » Closed (fixed)
makangus’s picture

For anyone trying to use the same patch for 6.x-1.0-beta1 and i18n 6.x-1.9, do the following instead

   else if ($op == 'view') {
+    // Integration with i18n-translation
+    if (module_exists('translation')) {
+      if ($translations = translation_node_get_translations($delta)) {
+        $delta = $translations[i18n_get_lang()]->nid;
+      }
+    } 
     // Don't show on own node page
    if (arg(0) == 'node' && arg(1) == $delta) {
      return;
    }