43 lines
1.0 KiB
PHP
43 lines
1.0 KiB
PHP
|
<?php
|
||
|
$current_dir= basename (getcwd ());
|
||
|
|
||
|
/*
|
||
|
* Language registration
|
||
|
*/
|
||
|
|
||
|
$registered_languages= array();
|
||
|
|
||
|
function register_lang ( $code, $lang ) {
|
||
|
global $registered_languages;
|
||
|
$registered_languages[$code]= $lang;
|
||
|
}
|
||
|
|
||
|
if ($current_dir == "htdocs")
|
||
|
include ("languages.php");
|
||
|
else
|
||
|
include ("../languages.php");
|
||
|
|
||
|
/*
|
||
|
* Prefered language detection
|
||
|
*/
|
||
|
|
||
|
function prefered_language () {
|
||
|
global $registered_languages;
|
||
|
$locale= locale_accept_from_http ($_SERVER['HTTP_ACCEPT_LANGUAGE']);
|
||
|
return locale_lookup (array_keys ($registered_languages), $locale, true, 'fr');
|
||
|
}
|
||
|
|
||
|
/*
|
||
|
* Redirect to prefered language, if needed, when referer is none or ourself
|
||
|
*/
|
||
|
if (!isset ($_SERVER['HTTP_REFERER']) or strrpos ($_SERVER['HTTP_REFERER'], $_SERVER['SERVER_NAME']) === false) {
|
||
|
if ($current_dir == "htdocs")
|
||
|
$current_dir= $registered_languages['fr']['loc'];
|
||
|
$prefered_dir= $registered_languages[prefered_language ()]['loc'];
|
||
|
if (basename($current_dir) != basename ($prefered_dir)) {
|
||
|
header ("Location: " . $prefered_dir);
|
||
|
exit ();
|
||
|
}
|
||
|
}
|
||
|
?>
|