Hi,

I have managed to get the code below working with a few tweaks here and there. However, you can see that I have written a small function in the file name local.php to allow the user to select "English" or "German" in the link on the test.php page.

This works fine but it will only work on that particular webpage. As soon as I move away from that page the locale will return back to "en_US"(English). Is there a way I could implement lets say an option dropdown and save the locale across the whole site.

Just in case its relevant I have a MySQL DB available for use if thats appropriate.

local.php
PHP Code:
<?php

function english(){
    
$directory dirname(__FILE__).'/locale';
$domain 'messages';    
$locale ="en_UK.utf8";
setlocaleLC_MESSAGES$locale);
bindtextdomain($domain$directory);
textdomain($domain);
bind_textdomain_codeset($domain'UTF-8');

}

function 
german(){
    
$directory dirname(__FILE__).'/locale';
$domain 'messages';    
$locale ="de_DE.utf8";
setlocaleLC_MESSAGES$locale);
bindtextdomain($domain$directory);
textdomain($domain);
bind_textdomain_codeset($domain'UTF-8');

}

//Pagination and normal view switch 
if (isset($_GET['run'])) $linkchoice=$_GET['run'];
else 
$linkchoice='';

switch(
$linkchoice){

case 
'English' :
    
english();
    break;

case 
'German' :
    
german();
    break;

default :
    
english();
    break;

}

?>
test.php
PHP Code:
<?php include("local.php"); ?>
<html><head></head>
<body>
<?php echo "<p><a href='?run=English'>English</a> | <a href='?run=German'>German</a> </p>"?>
<br />
<?php echo gettext("Welcome to My PHP Application");
echo 
"<br />";
// Or use the alias _() for gettext()
echo _("Have a nice day"); ?>
</body>
</html>
Many thanks in advance!