Fatal error when combined with i18n module

jackmaninov - July 15, 2008 - 23:34
Project:E-Publish
Version:6.x-1.x-dev
Component:Code
Category:bug report
Priority:normal
Assigned:jerdiggity
Status:closed
Description

I'm using the 6.x i18n module, and get the following error when trying to view an edition:

Fatal error: Call to undefined function translation_node_nid() in /foo/bar/epublish/epublish_layout_nodes.inc on line 53

There's a few other places where translation_node_nid seems to be called, but it doesn't appear to be in the i18n api anymore. I've been able to fix it by manually adding an old version of the function to the i18n code, but this should probably be fixed here.

#1

jackmaninov - July 17, 2008 - 19:03

Adding this code to the .module solves the issue, but the functionality of the i18n API should really be used instead:

function translation_node_nid($nid, $language = NULL, $default = NULL) {
  $translation = db_result(db_query("SELECT n.nid FROM {node} n INNER JOIN {node} a ON n.tnid = a.tnid AND n.nid != a.nid WHERE a.nid = %d AND n.language = '%s' AND n.tnid", $nid, $language ? $language : i18n_get_lang()));
  return $translation ? $translation : $default;
}

(sorry, I'd make a patch, but I'm not on a good computer at the moment).

#2

Anselm Heaton - July 29, 2008 - 16:33

mmmm... I'm having this problem too.

The problem itself is that the module is calling a function that does not exist. What the module is trying to do is work out which translation to display to the user. Unfortunately, there isn't an easy way to do this.

  • i18n rewrites queries, such that when nodes are listed it applies it's own content selection algorithm to it. However this does not apply here, since the nodes are from a list, not queried.
  • There are views filters that can be used for selecting the right translation when listing nodes. Again, this doesn't apply here as epublish doesn't use views, as it saves it's node list

What would be needed is a function (or even better, a hook) that lets module writers asks which translation to use given a node id. Unfortunately, core (the 'translation' module) doesn't provide such a function, and neither does i18n. It's up to each module writer to deal with this (as in the patch provided above), which makes it difficult to have a consistent site.

I am not suggesting the following is a proper solution - it isn't ; a proper solution should be more generic - but until there is one and in case you are using the select translation module for your views, that module also provides an API for selecting nodes ; as you'd be using select_translation everywhere then it would be consistent.

The following patch does this :

--- epublish/epublish_layout_regular.inc        (revision 1215)
+++ epublish/epublish_layout_regular.inc        (working copy)
@@ -32,13 +32,9 @@
         $output .= '<div class="topic">' . $topic->name . "</div>\n";
       }
       foreach ($topic->nodes as $nid) {
-       if (module_exists('i18n')) {
-         $lang = i18n_get_lang();
-         $transnid .= translation_node_nid($nid, $lang);
-         if ($transnid) {
-           $nid = $transnid; $transnid = '';
-         }
-       }
+        if (module_exists('select_translation')) {
+          $nid = select_translation_of_node($nid, 'default');
+        }
         $node = node_load($nid);
         $output .= '<div class="title">' . l(t($node->title), "node/$nid") . "</div>\n";
         $output .= '<div class="user">' . t('by') . ' ' . l($node->name, "blog/" . $node->uid) . "</div>\n";

You can use 'original' instead of 'default' in the call to select_translation_of_node() to change the algorithm used (see the select translation project page).

#3

Anselm Heaton - August 14, 2008 - 16:46

Having now worked on a multilingual site with many editions, I realise none of the patches above are satisfying. Either the whole of epublish should work with translations, either none of it should (which is the route we went down - manually create an edition per language). Just patching this part of epublish in isolation does not help.

Of course it does need patching since it acually generate an error ! It will be different depending on each site, but for us the best option was to not translate the items in edition listing - so remove the lines "if (module_exitsts('18n')) { .... }" completely.

#4

meruthecat - October 16, 2008 - 15:43

Is there some way for a client to pay to get epublish to work properly with Drupal 6 & i18n? If so how much and any takers?

#5

ica - November 16, 2008 - 14:17

Hi,
Just to confirm for a bug record that I got the similar fatal error of the epublish.module not functioning with the i18n.module -albeit the error I got on different layout as below

Fatal error: Call to undefined function translation_node_nid() in /home/sites/all/modules/epublish/epublish_layout_regular.inc on line 41

afaik- since the module developer specialized on multilingual sites at www.gloscon.com
I wonder if there are example sites that epublish.module functions in a multilingual setting?

~ If there is no fix/patch for the module to solve this problem for the sake of the saving people from a going to same process until they find the same problem- would not be useful if its mentioned on the module project page info? -that the module does not work with the i18n.module/multilingual setting -until its fixed

-thanks

#6

meruthecat - December 15, 2008 - 07:53

I get the same error as ica:

Fatal error: Call to undefined function translation_node_nid() in /home/sites/all/modules/epublish/epublish_layout_regular.inc on line 41

#7

TomChiverton - March 16, 2009 - 19:06

This occurs in my own link_node module - has something changed in the API module authors should know about, maybe ?

#8

chris_five - April 27, 2009 - 20:38

The problem is that epublish is not using Drupal 6 i18n API. The code below does:

      foreach ($topic->nodes as $nid) {
        if (module_exists('i18n')) {
          $lang = i18n_get_lang();
+          $transnids = translation_node_get_translations($nid);
+          if ($transnids[$lang]) {
+            $nid = $transnids[$lang];
+          }

-          $transnid .= translation_node_nid($nid, $lang);
-          if ($transnid) {
-           $nid = $transnid; $transnid = '';
-          }

        }

I'm not using the beta so didn't create a proper patch, but you get the general idea. The following files also reference the missing function "translation_node_nid()" so the fix also applies:

grep -r 'translation_node_nid(' *
epublish_layout_indexed.inc: $transnid .= translation_node_nid($nid, $lang);
epublish_layout_list.inc: $transnid .= translation_node_nid($nid, $lang);
epublish_layout_nodes.inc: $transnid .= translation_node_nid($nid, $lang);
epublish_layout_nodes.inc: $transnid = translation_node_nid($nid, $lang);
epublish_layout_one_two.inc: $transnid .= translation_node_nid($nid, $lang);
epublish_layout_one_two.inc: $transnid = translation_node_nid($nid, $lang);
epublish_layout_regular.inc: $transnid .= translation_node_nid($nid, $lang);

#9

havran - June 24, 2009 - 10:22

Small correction - $transnids[$lang] is object:

      foreach ($topic->nodes as $nid) {
        if (module_exists('i18n')) {
          $lang = i18n_get_lang();
+          $transnids = translation_node_get_translations($nid);
+          if ($transnids[$lang]) {
+            $nid = $transnids[$lang]->nid;
+          }

-          $transnid .= translation_node_nid($nid, $lang);
-          if ($transnid) {
-           $nid = $transnid; $transnid = '';
-          }

        }

#10

cronix - September 23, 2009 - 20:26

Will this be solved in the current (of future) dev?

#11

jerdiggity - September 26, 2009 - 12:54
Version:6.x-1.0-beta2» 6.x-1.x-dev
Assigned to:Anonymous» jerdiggity
Status:active» needs review
AttachmentSize
epublish_layout_indexed.inc_D6.patch 819 bytes

#12

jerdiggity - September 27, 2009 - 08:47
Status:needs review» fixed

Committed to dev version... Thanks to everyone for their input. :)
Seems to work fine on my end, but please let me know if more needs to be done.

#13

System Message - October 11, 2009 - 08:50
Status:fixed» closed

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

 
 

Drupal is a registered trademark of Dries Buytaert.