International menus

Last modified: August 26, 2009 - 23:53

I wanted to have the "links" menu on my site be contextual to the language the user was browsing in. The below maybe a bit of a hack, but it seems to work quite well.

This little php chunk can be inserted into the theme template, eg themes/themeName/page.tpl.php

Basically two text files define the names of the links in each language. Then i prepend "en" or "ja" to each link to get eg:
   example.com/en/dev
   example.com/ja/dev

when using the internationalisation module translated versions of these pages appear remapped under these URLs. so you can just go nuts and create pages!

Its working on my site here:
Pikkle.com

<?php

   
//todo: change settings here to read JP file - unicode doesnt work!

   
$urlList = array("", "corp", "prod", "dev", "commu" );
   
$nameList = array(
                   
"en" => file("sites/default/links_en.txt"),
                   
"ja" => file("sites/default/links_ja.txt"),
                    );

    echo(
"<ul>");

   
$c=0;
    foreach (
$urlList as $url) {
       
$name = $nameList[$language][$c];
        echo (
"<li><A href='$language/$url' >$name</A></li>");
       
$c++;
    }

   
// language toggle
   
if ($language == "ja") {
       
$url = "en";
       
$name = "english";
    } else {
       
$url = "ja";
       
$name = "日本語";
    }

    echo (
"<li><A href='$url' >$name</A></li>");

    echo(
"</ul>");

?>

Author: dc3 at pikkle.com

 
 

Drupal is a registered trademark of Dries Buytaert.