I found the Nodes In Block module very useful, but would like to use it inside a multi-language site.
To add this feature, I think the best way is to add template_preprocess_node() and hook_theme_registry_alter() functions.
Then a new theme files node-nodesinblock-default.tpl.php

I will base my work on the Node Block module which have the translation enable. But the new module is still on development !

If you have already think about adding this multilanguage feature, please contact me: dsnoeck [the email character] gmail [you know the last 4 characters]
Otherwise, I will keep you updated

Comments

swentel’s picture

Multilangual support should be included indeed, not sure about the preprocess_node solution though, wouldn't it be more handy to check on tnid in the node object ? Haven't done any work on that though, so if you have any patches, feel free to post!

dsnoeck’s picture

StatusFileSize
new1.35 KB

Hi swentel,

You are right it wasn't the correct way to use preprocess_node. I have found the right way. Had some check for translation available etc.
We can do some more test to check the translation setting define for the website.
See below the added code in the function _nodesinblock_show() after the node_load() function.
I alse have attached the diff patch.

	    // if the node type is translatable, try to load the node with the appropriate
	    // language from the translation set.
	    if (module_exists('translation') && translation_supported_type($node->type)) {
	      global $language;
	      $translations = translation_node_get_translations($node->tnid);
	      if ($translations[$language->language]) {
	        $node = node_load($translations[$language->language]->nid);
	      }
	      elseif (!$node->nodeblock_translation_fallback) {
	        // if no translation was found, and not using the fallback option
	        // return nothing, so the block doesn't display.
	        // TODO: check the default translation settings to load default language
	        // if the current language isn't available
	        return;
	      }
	      // otherwise we just use the main node
	    }
dsnoeck’s picture

StatusFileSize
new1.32 KB

Here is a new patch to check against the site default language value. I use the function language_default() to get the default language.

swentel’s picture

Hi, I tested and committed your patch (see http://drupal.org/cvs?commit=196138), works perfectly. Can you try out the next development build, if all is ok, I'll roll out a new release this week.

dsnoeck’s picture

I will test it during the next week and will probably send you others patch to add more functionalities.
- Damien

swentel’s picture

Status: Active » Fixed

Cool, looking forward to that. I've had some discussion with a few colleagues too about the multilingual support and I think it needs some more finegraining before I roll out another release, eg:

  • An option in the fieldset which lets you choose if you want to fallback to the original language if no translation is found or not show at at all
  • Some sort of warning to notify the user an existing translated node exists which is configured already so you don't need to enter the info twice - otherwhise you end up with 2 nodes on the same page

I'm going to think about this some more and post other patches myself. I'm marking this one as fixed for now, I'll let you know when I have other patches too by posting the links in this thread.

Status: Fixed » Closed (fixed)

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

miruoss’s picture

Status: Closed (fixed) » Active

Hi there

I took over Damien's work so I will continue this discussion. :) I'm still running into multilanguage problems, even with Damien's patch. I therefore reverted it and added a db_rewrite_sql() around the $query on line 203. It now reads:

function _nodesinblock_show($delta) {
  $output = '';
  $query = "SELECT nib.nid, visibility, render, delta FROM {nodes_in_block} nib
    LEFT JOIN {node} n on n.nid = nib.nid
    WHERE n.status = 1 AND nib.status > 0 AND delta = %d
    ORDER BY weight
  ";
  $result = db_query(db_rewrite_sql($query), $delta);
  $path = drupal_get_path_alias($_GET['q']);
[...]

This should solve the question about language fallback and in the same time checks if the current user has access to the node being shown. Using the module i18n, the admin can already define the language fallback policy at admin/settings/language/i18n so why add another fallback policy selection. This fallback setting is then used by i18n using hook_db_rewrite_sql() to rewrite the node selection query.
I personally use the module active_translation (http://drupal.org/project/active_translation) by now. It comes with another hook_db_rewrite_sql() and another language fallback policy.

swentel’s picture

Hmm makes much more sense indeed! I'll test it this weekend, probably commit it too :)

swentel’s picture

Status: Active » Needs review

Ok, it took me a while to commit this, sorry about that. Can you test the new dev/cvs version to see if all goes well ?

miruoss’s picture

Status: Needs review » Fixed

I tested the CVS version which looks good to me.

Cheers,
Michael

Status: Fixed » Closed (fixed)

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

tlangford’s picture

Hi. I really like this module and too have a multilingual site. I'm having problems actually getting Drupal to display two different nodes depending on the current language. Can someone write a step-by-step guide to adding this please?

Keep up the good work!

netsensei’s picture

Version: 6.x-1.2 » 7.x-1.x-dev
Status: Closed (fixed) » Active
StatusFileSize
new999 bytes

Not sure if I should open a new issue. In 7.x this does not work.

Installed: i18n, locale, nodesinblock. The node which was added to the block is shown, not the translated node for the current language. I've created a patch which allows translated nodes using Translation Helpers (http://drupal.org/project/translation_helpers) rather then writing a function in nodesinblock which essentially would do the same.

Patch will translate all nodes in a block. No exceptions. We might want more finegrained control (on a block level: which get translated, which don't) but such a feature might add more complexity in the wilderness of block contexts (i.e. show block on language x, blocks in panels,...)

swentel’s picture

Status: Active » Fixed

committed and pushed.

Status: Fixed » Closed (fixed)

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

rudins’s picture

Status: Closed (fixed) » Fixed

Line 430:
$tnode = translation_helpers_get_translation($node, $language->language);

should be:

$tnode = translation_helpers_get_translation($node, $language);

Status: Fixed » Closed (fixed)

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

remaye’s picture

Sorry to re-open this issue, but is NodesInBlock really working now with multilingual site and how ?

I enabled : locale / content translation / i18n / block translation

I created a Nodes In Block block and "block translation" module allow me to enabled my different languages in theblock settings.

When I select the block in Nodes in Block tab, for a node form and its translations, I would expect it display the block in all selected languages, with the corresponding translated content in it.
Instead, it creates as many instances of the block than the number of languages and display all of them in the page regardless of the language of the page.

The only solution I have is to create one Nodes in Block per language, enable it only for its language and select it in the node form for the correct translation.

Is it designed like this or did I miss something somewhere...?

Thanks for your help.

NB: the same issue has also been reported here : http://drupal.org/node/1608350

drzraf’s picture

Assigned: dsnoeck » drzraf
Category: feature » task
Priority: Normal » Major
Status: Closed (fixed) » Needs review
StatusFileSize
new1.71 KB

Why a dep on translation_helpers.module 's translation_node_get_translations ?
This function is here: http://drupalcode.org/project/translation_helpers.git/blob/refs/heads/7....
And is a very simple wrapper around http://api.drupal.org/api/drupal/modules!translation!translation.module/...

Here is a patch.
But... it does not fix the main issue which is that all blocks (each per translation) for a given node are displayed one below the other.

I'll come up with a workaround later.

drzraf’s picture

StatusFileSize
new3.27 KB

here it is.
please review and/or enhance, commit and enjoy

hkirsman’s picture

#21 didn't work for me. Applied the patch, deleted cache

drzraf’s picture

I'm using it in a production environment, maybe your issue comes from another cause
(patch applies ? theme support i18n ? ... what does not works ?)

hkirsman’s picture

It still showed both nodes in the block. I'm not aware that there are any patches applied. Does it work for other people?

neerajskydiver’s picture

Issue summary: View changes
StatusFileSize
new1.08 KB

In #20 comment, the patch is using the function "translation_helpers_get_translation" which is part Translation helpers(https://www.drupal.org/project/translation_helpers), and this module is not added as a dependency for the module. This patch will add this and a $language global variable usage in module, which will fix the issue.

drzraf’s picture

Assigned: drzraf » Unassigned