How can we set a per language 404 error page? It does not seem to be a variable.

Comments

mtsanford’s picture

I don't think you can get away without using a little PHP for this, but I could be wrong. One way would be to make a node to use as 404 page, and use PHP filter. e.g:

<?php global $language; ?>
<?php if ($language->language == 'en') : ?>
  <div>Can't find what you're looking for</div>
<?php elseif ($language->language == 'es') : ?>
  <div>No se puede encontrar que usted está buscando</div>
<?php endif; ?>

You could also do something similar using the customerror module.

jmlavarenne’s picture

But I'm concerned my client will want to be able to edit the page but will not have access to the PHP input filter.

mtsanford’s picture

In that case you can create two (unpublished) nodes, and use the customerror module with PHP code similar to this that loads one of those nodes and displays it:

  global $language;
  
  switch ($language->language) {
    case 'es':
      $nid_404 = 45;  // node id of the spanish 404 page
    case 'en':
    default:
      $nid_404 = 46; // node id of the english 404 page
  }
  
  $node = node_load($nid_404);
  if (!empty($node)) {
    $node = (object)$node;
    $node = node_build_content($node, FALSE, FALSE);
    drupal_set_title($node->title);
    return $node->body;
  else {
    return '<div>Error page not found!  Please notify site admin.</div>';
  }
jmlavarenne’s picture

Thanks!

Nico_Drup’s picture

I have tried your code but it doesn't work...

Fist : there a little mistake, "}" is missing just before the "else".

Secondly, when I put your code I get this error (I use Drupal 7) :

Trying to get property of non-object dans eval() (ligne 13 dans /home/marylin/public_html/nicolas/modules/php/php.module(74) : eval()'d code)
Trying to get property of non-object dans eval() (ligne 14 dans /home/marylin/public_html/nicolas/modules/php/php.module(74) : eval()'d code)

Thanks if someone can help... I understand globaly the code but I don't knnow enough Drupal to do modifications...

adamevertsson’s picture

Use the i18n module, https://drupal.org/project/i18n, and follow this guide https://drupal.org/node/1216132

// Adam Evertsson

-----------------------------------------------------
www.adamevertsson.se - Blogging about Drupal...