12-04-2022

mise en place de $_SESSION pour la localisation
This commit is contained in:
2022-04-12 12:22:54 +02:00
parent 629d9fd711
commit 053598bf47
5 changed files with 43 additions and 68 deletions

View File

@@ -6,13 +6,10 @@
*/
function month($w) {
//setlocale(LC_TIME, 'fr_FR');
$m = date('m', strtotime($w)); // month
$y = date('Y', strtotime($w)); // year
//echo $w . "- month: " . $m . "- year: " . $y;
// or any other locales like pl_PL, cs_CZ, fr_FR, zh, zh_Hans, ...
$locale = 'fr_FR';
$locale = getenv('LC_ALL=');
$dateFormatter = new IntlDateFormatter(
$locale,
IntlDateFormatter::LONG, // date type
@@ -29,9 +26,7 @@ function month($w) {
array_unshift($months_locale,"");
unset($months_locale[0]);
//_pr($months_locale);
$my = ucfirst($months_locale[(int)$m]) . " " . $y;
//echo $my;
return $my;
}
@@ -392,11 +387,13 @@ function list_dir($dir) {
return $myLanguages;
}
function _locale_language_from_browser($languages) {
//function _locale_language_from_browser($languages) {
function _locale_language_from_browser() {
if (empty($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
return FALSE;
}
$languages = "";
// The Accept-Language header contains information about the language
// preferences configured in the user's browser / operating system.
// RFC 2616 (section 14.4) defines the Accept-Language header as follows:
@@ -414,6 +411,9 @@ function _locale_language_from_browser($languages) {
$langcode = strtolower($match[1]);
$qvalue = isset($match[2]) ? (double) $match[2] : 1;
$browser_langcodes[$langcode] = (int) ($qvalue * 1000);
_pr($match);
echo $langcode . '-' . $qvalue . '-' . $browser_langcodes[$langcode] . '<br>';
}
}
@@ -524,7 +524,6 @@ function locale_language_from_browser($languages) {
}
}
//if (!isset($lang)) $lang = 'fr_FR';
return $lang;
}
@@ -536,8 +535,6 @@ function localize($domain) {
$dir_locales = $root . '/Locale';
$liste_locale = list_dir($dir_locales);
//echo "liste_locale: <br>";
//_pr($liste_locale);
/*
Array
(
@@ -548,15 +545,28 @@ function localize($domain) {
)
*/
if ((!isset($_POST['lang'])) and (!isset($_GET['lang']))) $langue = locale_language_from_browser($liste_locale);
else $langue = $_REQUEST['lang'];
$langue .= ".utf-8";
//echo $langue;
//if ((!isset($_POST['lang'])) and (!isset($_GET['lang']))) $langue = locale_language_from_browser($liste_locale);
//else $langue = $_REQUEST['lang'];
if ((empty($_REQUEST['lang'])) and (empty($_SESSION['language']))){
$langue = locale_language_from_browser($liste_locale);
}
elseif (!empty($_REQUEST['lang'])) {
$langue = $_REQUEST['lang'];
$_SESSION['language'] = $_REQUEST['lang'];
}
else $langue = $_SESSION['language'];
$langue .= ".utf8";
/*
if (isset($_GET['lang'])) echo "_GET lang: " . $_GET['lang'] . "<br>";
else echo "_GET lang: NULL" . "<br>";
if (isset($_REQUEST['lang'])) echo "_REQUEST lang: " . $_REQUEST['lang'] . "<br>";
else echo "_REQUEST lang: NULL" . "<br>";
if (isset($_SESSION['language'])) echo "_SESSION language: " . $_SESSION['language'] . "<br>";
else echo "_SESSION language: NULL" . "<br>";
echo "langue: " . $langue . "<br>";
*/
//echo "<br>HTTP_ACCEPT_LANGUAGE: " . $_SERVER['HTTP_ACCEPT_LANGUAGE'];
//$domain = 'sentier';
$_SESSION["lang"]=$langue;
putenv('LC_ALL=' . $langue);
$loc = setlocale(LC_ALL, $langue);