I am going to implement the multi-language support for the website using php
The default language is chinese
I have selected en as british English one.
the webpage link is set as www.abc.com/index.php?lang=en
When it comes to selecting the other menu items,
the query string ?lang=en is gone and resume to chinese language
Would you please tell me how to pass the 'en' and ?lang= to other menu so as to maintain the selection of language desired through the browsing ?
The below is my code
<html>
<body>...
<div id="languages">
<?php $string = basename(__FILE__); ?>
<?php echo "<a href=".$string.'?lang=en >'; $_SESSION['lang']= 'en'; ?><img src="images/en.png" /></a>
<?php echo "<a href=".$string.'?lang=hk >'; $_SESSION['lang']= 'hk'; ?><img src="images/hk.png" /></a>
<?php echo "<a href=".$string.'?lang=cn >'; $_SESSION['lang']= 'cn'; ?><img src="images/cn.png" /></a>
</div>
...
<div class="navigation">
<div id="smoothmenu1" class="ddsmoothmenu">
<ul>
<li><a href="index.php"><?php echo $lang['MENU_HOME']; ?></a></li>
<!--<li><a href="#">About Club</a></li>-->
<li><a href="news.php"><?php echo $lang['MENU_NEWS']; ?> </a></li>
<li><a href="gallery.php"><?php echo $lang['MENU_GALLERY']; ?></a></li>
<!--<li><a href="reservation.php">Make Reservation</a></li>-->
<li><a href="contact.php"><?php echo $lang['MENU_CONTACTS']; ?></a></li>
<!--<li class="dropdown"><a href="#">Pages</a>
<ul>
<li><a href="index.php">Home</a> </li>
<li><a href="news.php">News</a></li>
<li><a href="blog.php">Blog</a></li>
<li><a href="blogpost.php">Blog Post</a></li>
<li><a href="gallery.php">Gallery</a></li>
<li><a href="reservation.php">Reservation</a></li>
<li class="nbbdr"><a href="contact.php">Contact Us </a></li>
</ul>
</li>-->
</ul>
</div>
</div>
This fragment of code:
Will always set your
$_SESSION['lang']
tocn
value, not only when you click certain anchor. Instead you should change it to:And also at the beginning of the file you should add:
Don't forget to add
session_start()
at the beginning, before previously mentioned block of code aswell, if you don't have it yet.From now on, if you won't have
?lang=...
in your URL, you will have your last lang set in$_SESSION['lang']
.To change links in the other menu (
<li><a href="index.php"><?php echo $lang['MENU_HOME']; ?></a></li>
and so on), you should change theirhref's
from:To: