I recently started implementing language options for my website. Here is how it basically works:
if(isset($_GET['lang']))
{
$langr= $_GET['lang'];
$_SESSION['lang'] = $langr;
setcookie('lang', $langr, time() + (3600 * 24 * 30));
}
elseif(isset($_SESSION['lang']))
{
$langr = $_SESSION['lang'];
}
elseif(isset($_COOKIE['lang']))
{
$langr = $_COOKIE['lang'];
}
else
{
$langr = 'en';
}
switch ($langr)
{
case 'en':
$lang_file = $_SERVER['DOCUMENT_ROOT']."/includes/lang/en.php";
break;
case 'fr':
setlocale (LC_ALL, 'fr_FR.utf8','fra');
$lang_file = $_SERVER['DOCUMENT_ROOT']."/includes/lang/fr.php";
break;
default:
$lang_file = $_SERVER['DOCUMENT_ROOT']."/includes/lang/en.php";
}
include_once $lang_file;
It loads the appropriate language file at the top of every page in my website. However, issues starting coming out when using jQuery's UI datepicker. I found a regional settings file for the datepicker online and have created a separate file for it :
///jquery.ui.datepicker-fr.js file
jQuery(function($){
$.datepicker.regional['fr'] = {
closeText: 'Fermer',
prevText: 'Précédent',
nextText: 'Suivant',
currentText: 'Aujourd\'hui',
monthNames: ['janvier', 'février', 'mars', 'avril', 'mai', 'juin',
'juillet', 'août', 'septembre', 'octobre', 'novembre', 'décembre'],
monthNamesShort: ['janv.', 'févr.', 'mars', 'avril', 'mai', 'juin',
'juil.', 'août', 'sept.', 'oct.', 'nov.', 'déc.'],
dayNames: ['dimanche', 'lundi', 'mardi', 'mercredi', 'jeudi', 'vendredi', 'samedi'],
dayNamesShort: ['dim.', 'lun.', 'mar.', 'mer.', 'jeu.', 'ven.', 'sam.'],
dayNamesMin: ['D','L','M','M','J','V','S'],
weekHeader: 'Sem.',
dateFormat: 'dd/mm/yy',
firstDay: 1,
isRTL: false,
showMonthAfterYear: false,
yearSuffix: ''};
$.datepicker.setDefaults($.datepicker.regional['fr']);
});
The issue is I need to dynamically load jquery.ui.datepicker-fr.js
whenever a language change is detected so that my datepicker switches to french. What I was thinking is creating a PHP function that I would put in my <head>
that would echo out my file, but the problem with that is that not all my web pages are PHP and I don't find this a very effective method. Any other ideas on how to do this?
Or [here is an artical on redirecting from the htaccess](http://stackoverflow.com/questions/3978726/how-to-do-htaccess-redirect-based-on-cookie-value). You can redirect the en file to go to the fr file based on the cookie and could also redirect based on get values! Good luck, let me know how you get on! – Charlie Walton Jun 10 '13 at 01:38