Jump to content


This topic is now archived and is closed to further replies.


Multi language site

Recommended Posts

I am trying to create a multi language site which open the index page in the users' browser language but allows the user to change it if needed.

My file tree is:

I have the following main files: index.php and select.php
Working versions at: [URL=http://webwhiz.co.uk/lang12/index.php]index.php[/URL] [URL=http://webwhiz.co.uk/lang12/select.php]select.php[/URL]

They both work fine as they are. Index.php displays the correct language page, calling up the appropriate content from the language folders. select.php, displays the content according to the language selected.
What I want to do, is merge the code somehow so that the user initially arrives at the page apropriate to their browser as in index.php but has the option of changing their language preference as in select.php. I like the 'on select' method used here as it keeps the interface clean. How can I get the script to redirect to for instance; http://www.webwhiz.co.uk/lang12/index.php?language=en if the user selects English from the list?

The code I have so far is:
class object {};
$config = new object;
$config->dir    = "/home_path/lang12/lang_sets/";
if (! isset($lang)) {
$lang = "en";
$lang = "pt";
$lang = "sp";
$lang = "lv";
else if ($lang == "pt-br" ) { $_SESSION["lang"] = "pt"; }
else if ($lang == "en" ) { $_SESSION["lang"] = "en"; }
else if ($lang == "sp" ) { $_SESSION["lang"] = "sp"; }
else if ($lang == "lv" ) { $_SESSION["lang"] = "lv"; }
else { $_SESSION["lang"] = "en"; }
$config->global = $config->dir.$lang."/language.php";
include ($config->global);


$lang = $_GET["language"];
if ($lang=="") {
    $lang = 1;
<select onChange="window.location='select.php?language='+this.value">

$language = array(






for ($i = 1; $i <= 4; $i++)



<option value="<?=$i?>" <? if ($lang == $i) { print "SELECTED";}?>> <?=$language[$i]?></option>




<!-- content here -  Just to show it works! -->

<img src = " <?=$lang?>.gif"><!--posibly a flag here?-->
?><br />
<? if ($lang==1) { ?>
<? }
elseif ($lang==2) { ?>
<? }
elseif ($lang==3) { ?>
<? }
elseif ($lang==4) { ?>
<? }
else ($lang==1) ?>[/CODE]
I think this way would make updating and adding new files very easy as I could use a similar method for all the other pages including language specific menus and content from the other pages (I think)

The typical content for the language.php file could be:
[CODE]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>webwhiz lang12 lv</title>


$content3 = "text";
$content2 = " in Latvian";

$content4 = include_once("../include/footer.php");

I hope you can see what I am aiming at here. It will keep file organisation simple and allow additional languages to be added easily as some of the code could be inserted as 'include' files.

I a sure that once I get the answer for this step, I will hit more walls but  I am learning all the time :-)


Share this post

Link to post
Share on other sites


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.