I've made a website with a full background image. The user selects at the first screen whether he/she wants to view the site in English or in German. The site then reloads as index.php for English (English is default) or indexG.php for German.
After the language is selected, I've implemented ajax in order to not reload the background on each click of a link.
The first page determines in which language the menu is to be shown:
<?php if ($currentPage == 'index.php')
{
include ('includes/navE.inc.php');
}
else if ($currentPage == 'indexG.php')
{
include ('includes/navG.inc.php');
}
?>
Each menu item calls a function. Here is an example from the English menu:
<li><a href="#" class="nav" id="navitem2" onclick="showMiddle(2);">menu item</a></li>
and the function showMiddle(str):
function showMiddle(str)
{
$.ajax({
type: 'GET',
url: 'getlist.php',
data: 'q=' + str,
success: function(msg){
//alert("data retrieved: " + msg);
$('#middle').css({opacity:0}).html(msg).delay(550).fadeTo(1500,1);
}
});
}
Now, getlist.php consists of another menu (titles of videos), and a div that serves as a container for a selected video.
I would like for getlist.php to be able to tell if English or German was selected, and then show the appropriate title from the database.
I'm not sure if I should do this with a variable in getlist.php or by passing a parameter to getlist.php. Anything I've tried to do in order to get the URL only returns "getlist.php" (which makes sense) instead of index.php or indexG.php.
The language thing I do it this way.. I never say
indexG.php or
something.php?language=en or
where language = 'english' or
or ./articles/english/ or whatever
I only at the top of index.php do that
$lang='what ever it is' then you always use this $lang variable which is seen everywhere since declared on the top. It goes
something.php?language=$lang or where language = $language or or ./articles/$language/ etc etc
and I never store a single word in scripts it all goes to classes stored in separate files:
this classes only contain texts, example:
<?PHP
class txtcomcateg
{
/****************************PAGE TITLES************************************/
public static $comcateg_formtitle="Φόρμα διαχείρισης κατηγοριών..";
public static $comcateg_name="Όνομα κατηγορίας..";
then i just use it calling the analogous static class:
$login_tpl->set('uname',txtStandard::$uname);
for me it is a trivial thing I never bother much with it, when ever I want to change a text I know where it is and do not have to search inside any code. I just give meningful names to the static class members so I know what text it contains in. The language can be stored in a cookie or session so you don't have to load it in url.
I ended up duplicating function showMiddle()
and called the copy showMiddle_G()
. Menu items in the English menu call the first function and pass data: 'q=' + str + '&language=english',
. Menu items from the German menu call the showMiddle_G()
and pass data: 'q=' + str + '&language=deutsch',
. I'm sure there's a simpler/better way to do this.