Community Documentation

International menus

Last updated October 18, 2011. Created by ugerhard on June 24, 2005.
Edited by MGParisi, ronald_istos, add1sun, Amazon. Log in to edit this page.

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

About this page

Audience
Themers

Archive

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. Comments on documentation pages are used to improve content and then deleted.
nobody click here