Community Documentation

i18n custom frontpage

Last updated January 13, 2012. Created by ugerhard on May 4, 2007.
Edited by Kristen Pol, macm. Log in to edit this page.

Hi Folks

I was trying custom my frontpage with i18n. (with tpl.php files) I read a lot of things in special http://drupal.org/node/134003

But unfortunately didn't work for me.

So I created this snippet to use in page.tpl.php . I am not sure will work in production site because my website isn't finished.

I will appreciate comments and know if is working well.

<?php
if (arg(0)=="admin" && i18n_get_lang() == 'en') {
  include(
'page-default.tpl.php');
  return;
}
elseif (
arg(0)=="admin" && i18n_get_lang() == 'it') {
  include(
'page-default.tpl.php');
  return;
}
/* repeat to all languages */
elseif (arg(0)=="node" && arg(1)=="add" && arg(2)=="mycck" && i18n_get_lang() == 'en') {
  include(
'page-mycck.tpl.php');
  return;
}
elseif (
arg(0)=="node" && arg(1)=="add" && arg(2)=="mycck" && i18n_get_lang() == 'pt') {
  include(
'page-mycck.tpl.php');
  return;
}
elseif (
arg(0)=="node" && arg(1)=="add" && arg(2)=="mycck" && i18n_get_lang() == 'it') {
  include(
'page-mycck.tpl.php');
  return;
}
/* repeat to all languages, and insert all paths of drupal */

elseif (i18n_get_lang() == 'en') {include('front-en.tpl.php');return;}
elseif (
i18n_get_lang() == 'it') {include('front-it.tpl.php');return;}
elseif (
i18n_get_lang() == 'pt') {include('front-pt.tpl.php');return;}
elseif (
i18n_get_lang() == 'fr') {include('front-fr.tpl.php');return;}
else
include
'page-default.tpl.php'; /*if none of the above applies, load the page-default.tpl.php by macm */
   
return;
?>

Regards

macm
Mario

Comments

try panels2

http://drupal.org/node/256558

greets,
Drupal Berlin
________________
http://www.drupalberlin.com

It's actualy far easier than this

You can include in your settings.php (sites/default)

'site_frontpage' in your $conf['i18n_variables']

then go to: /admin/settings/site-information and apply a different node per language by switching languages within this page. Works as expected, and no need for coding anything.

Greetings from Barcelona

thats a great solution!

thats a great solution! thanks!

--

keine zeit für spielkonsolen mein leben ist jump n run!

valderama.net

Custom page-front.tpl.php

In my page-front.tpl.php i'm using this:

<?php
global $language;
if(
arg(0) == 'node' && is_numeric(arg(1))) {
   
$fnid = arg(1); #get current nid (frontpage nid)
    #$fnid = '12';
   
$nl = $node; # replace with node_load($fnid);
   
$nt = module_invoke('translation', 'node_get_translations', $nl->tnid);
    foreach(
$nt as $l)
        if (
$l->language == $language->language) $t_fnid = $l->nid;
   
$fpath = drupal_lookup_path('alias', 'node/'.$t_fnid);
   
#print '$nid = '.$t_fnid.'//'.$fnid.' // $fpath = '.$fpath;
   
if ($fnid != $t_fnid) {
       
drupal_goto($fpath);
    } else {
        require_once(
"page.tpl.php");
    }
} else {
    require_once(
"page.tpl.php");
}
?>

If you are on the front page node (main frontpage declared in site-configuration), it displays the content of page.tpl.php, else you are redirected to the translated version of the that node.

this snippet is dynamic, and you simply add it to any theme and it works, you have a drupal i18n front-page

--
Walter S.

About this page

Drupal version
Drupal 5.x

Multilingual Guide

Drupal’s online documentation is © 2000-2012 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License.