It's quite a painstaking tast to be honest.
Have a database table called languages, with just an ID and a name (English etc)
Have another table called 'Translations' or something like that, and have the columns ID (pk), SectionID, Language, and Text.
for every block of text (including menu text, titles, paragraphs, form labels, etc), there will be a different SectionID.
You can then have a row for every different language (using their IDs) with each block of text. So say you have 5 languages and 200 text blocks, there'll be 1000 rows.
Then, have a few functions like so:
PHP Code:
function GetText($ID, $Language = 1){ //1 = english, 2 = french etc - by their IDs
$Query = MySQL_Query("SELECT Text FROM Translations WHERE Language = {$Language} AND ID = {$ID}");
if(MySQL_Num_Rows($Query) < 1 && $Language == 1) return false;
if(MySQL_Num_Rows($Query) < 1) return GetText($ID, 1); //returns english if there is no translation
return MySQL_Result($Query, 0);
}
function LanguageExists($ID){
$Query = MySQL_Query("SELECT ID FROM Languages WHERE ID = {$ID}");
return (MySQL_Num_Rows($Query) == 1);
}
And when you need an element of text, just put (for example on the menu):
PHP Code:
<li><a href="/SomePage/"><?php echo GetText(1, $_SESSION['Language']); ?>
At the top of the file, you'll want to make sure they have a language, so for example:
PHP Code:
<?php
Session_Start();
if(array_key_exists('Language', $_GET)){
$_SESSION['Language'] = (int)$_GET['Language'];
}
if(!array_key_exists('Language', $_SESSION) || !LanguageExists($_SESSION['Language']){
$_SESSION['Language'] = 1;
}
And to change the language, simply have a link putting '?Language=x', where x is the ID of the language.
A slight variation could use the actual names of the languages and/or the english text not the block ID, but that's upto you.
Bookmarks