Wordpress Themes - WP Forum at BFA

Wordpress Themes - WP Forum at BFA (http://forum.bytesforall.com/index.php)
-   Atahualpa 3 Wordpress theme (http://forum.bytesforall.com/forumdisplay.php?f=2)
-   -   SwitchLang Function (http://forum.bytesforall.com/showthread.php?t=5664)

Lyryanne Feb 2, 2010 04:46 AM

SwitchLang Function
 
Hi all ^^,

I've a little problem with a function SwitchLang, for my website I have two languages, French and English.

All the pages on my site have the same name in french and english and the only distinction is :
website.com/fr/about/
website.com/en/about/

So I've search on the Internet and I've found this piece of code :

Code:

<?php
function switchLang ($mode) {
        if($mode==="fr"){
          $posfr = strpos($_SERVER['REDIRECT_URL'],"/fr/");
          $part1=substr($_SERVER['REDIRECT_URL'],0,$posfr);
          $part2=substr($_SERVER['REDIRECT_URL'],$posfr+4);
          $link2=$part1."/en/".$part2;
          $return="<li><a href=\"".$part1."/fr\">Fr</a></li>";
          $return.="<li><a href=\"".$link2."\">En</a></li>";
       
          } elseif($mode==="en") {
          $posen = strpos($_SERVER['PHP_SELF'],"/en/");
          $part1=substr($_SERVER['PHP_SELF'],0,$posen);
          $part2=substr($_SERVER['PHP_SELF'],$posen+4);
          $link=$part1."/fr/".$part2;
          $return="<li><a href=\"".$link."\">Fr</a></li>";
          $return.="<li><a href=\"".$part1."/en\">En</a></li>";
       
        } else {
                $return="<li><a href=\"/fr\">Fr</a></li>";
            $return.="<li><a href=\"/en\">En</a></li>";

        }

        return $return;
       
}
?>

I've make a switchLang.php file and when I want to make an include in header.php or another file, I've a white page instead of the site.

The other problem is that my flag button for switch is in the $logo_area in the bfa_header_config.php, so when I put the code :
Code:

<a href="<?php echo switchLang(\'fr\'); ?>"><img src="/flag.png"></a>
and when I mouse over the flag I see a link like : website.com/en/about/<?php echo switchLang('fr') ?> so, when I click it, I have a 404.

Can somebody help me to solve this problem?

Regards, Lyryanne =).

PS : Sorry for my poor English I'm French ^^.


All times are GMT -6. The time now is 07:30 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.