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);

View File

@@ -26,9 +26,10 @@
<link rel="stylesheet" type="text/css" href="css/sls.css" />
<?php include 'functions.php';
$domain = 'sentier';
localize($domain);
<?php include 'functions.php';
session_start();
$domain = 'sentier';
localize($domain);
?>
<?php
@@ -48,7 +49,7 @@ $wp = (($_SERVER['SERVER_NAME'] == "sur-le-sentier.fr") ? "blog" : "wordpress");
</head>
<body>
<?php //echo "Session language: " . $_SESSION['language']; ?>
<script>
$("#exemple, body").vegas({
@@ -135,9 +136,9 @@ $("#exemple, body").vegas({
<div class="myForm">
<form name="langSelect" action="" method="get" >
<form name="langSelect" action="index.php" method="get" >
<select name="lang" id="lang" class="mySelect">
<option>Language</option>
<option value="">Language</option>
<option value="de_DE">German</option>
<option value="en_US">English</option>
<option value="es_ES">Spanish</option>
@@ -149,7 +150,7 @@ $("#exemple, body").vegas({
</div>
<div class="vegas-info">
<?php echo gettext('Powered by'); ?> <a href="https://wordpress.org">WordPress</a> - <a href="https://www.zenphoto.org">Zenphoto</a> - <a href="https://vegas.jaysalvat.com">Vegas Background Slideshow 2</a>. <a href="">License des photos</a>. (c) 2013-<?php echo date('Y'); ?> sur-le-sentier.fr
<a href="close.php">close</a>a><?php echo gettext('Powered by'); ?> <a href="https://wordpress.org">WordPress</a> - <a href="https://www.zenphoto.org">Zenphoto</a> - <a href="https://vegas.jaysalvat.com">Vegas Background Slideshow 2</a>. <a href="">License des photos</a>. (c) 2013-<?php echo date('Y'); ?> sur-le-sentier.fr
</div>
</body>

View File

@@ -5,7 +5,7 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title><?php gettext('Insert photos in Sqlite base'; ?></title>
<title><?php gettext('Insert photos in Sqlite base'); ?></title>
<link rel="stylesheet" href="css/sls.css" />
<link rel='stylesheet' href='css/lc_lightbox.min.css' />
@@ -13,35 +13,11 @@
<link rel='stylesheet' href='css/minimal.css' />
<?php include 'functions.php';
session_start();
$domain = 'sentier';
localize($domain);
?>
<?php
/*
//if ($_SERVER['SERVER_NAME'] == 'airbook.local')
$root = $_SERVER['DOCUMENT_ROOT'];
//$root = dirname($_SERVER['SCRIPT_FILENAME']); // /Users/bruno/Sites/sls
include($root.'/lib2/localize.php');
$dir_locales = $root . '/Locale';
$liste_locale = list_dir($dir_locales);
if ((!isset($_POST['lang'])) and (!isset($_GET['lang']))) $langue = locale_language_from_browser($myLanguages);
else $langue = $_REQUEST['lang'];
$domain = 'sentier';
putenv('LC_ALL=' . $langue);
$loc = setlocale(LC_ALL, $langue);
bindtextdomain($domain, $root . '/Locale/');
bind_textdomain_codeset($domain, 'UTF-8');
textdomain($domain);
$nation = array('fr_FR' => gettext('French'), 'en_US' => gettext('English') , 'de_DE' => gettext('German'), 'es_ES' => gettext('Spanish') );
include 'functions.php';
*/
?>
<script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>
</head>
@@ -111,8 +87,7 @@ foreach($dir as $file){
if ($x == false) { //false
if ($exif = @exif_read_data($file, 0, true )) {
//_pr($exif);
//if (($file == 'photos/img/12_2007.jpg') || ($file == 'photos/img/11_2007.jpg') || ($file == 'photos/img/10_2020.jpg')) {
if (($file == 'photos/img/4_2008.jpg') || ($file == 'photos/img/10_2020.jpg')) {
_pr($exif);
}
@@ -292,8 +267,6 @@ foreach($dir as $file){
$ep = '';
}
///echo "File: " . basename($file) . " - Objectif: " . $obj . " - Model: " . $mod . " - Metering: " . $mm . " - Flash: " . $fla. " - Focal: " . $fl. " - Exposure: " . " - Balance: " . $wb. " - Program: " . $ep . "<br>";
$wi = isset($exif['COMPUTED']['Width']) ? $exif['COMPUTED']['Width'] : '';
$he = isset($exif['COMPUTED']['Height']) ? $exif['COMPUTED']['Height'] : '';
$ht = isset($exif['COMPUTED']['html']) ? $exif['COMPUTED']['html'] : '';
@@ -329,9 +302,6 @@ foreach($dir as $file){
);
}
//$qq = getimagesize($file, $info);
//_pr($qq);
if ($iptc = @getimagesize($file, $info)) {
//_pr($iptc);
if (isset($info["APP13"])) {
@@ -368,7 +338,6 @@ foreach($dir as $file){
$i++;
}
//_pr($photos);
$z = count($photos);
if ($z == 0) {
echo '<h3>' . gettext('No new image files to add') . '...</h3>';
@@ -423,8 +392,6 @@ try {
$stmt->bindParam(':wb', $wb);
$stmt->bindParam(':program', $ep);
//echo count($photos);
//_pr($photos);
if (isset($photos)) {
foreach ($photos as $item) {

View File

@@ -23,6 +23,7 @@
</style>
<?php include 'functions.php';
session_start();
$domain = 'sentier';
localize($domain);
?>

View File

@@ -12,7 +12,8 @@
<link rel='stylesheet' href='css/open_close_fx.css' />
<link rel='stylesheet' href='css/minimal.css' />
<?php include 'functions.php';
<?php include 'functions.php';
session_start();
$domain = 'sentier';
localize($domain);
?>
@@ -45,8 +46,6 @@ try {
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
$rowcount = count($result);
//_pr($result);
$conn4 = null;
}
catch(PDOException $e) {
@@ -134,9 +133,6 @@ try {
// data-lcl-author="' . htmlspecialchars($lb['exif']) . '"
//
_pr($lb);
//echo $lb['exif'];
echo '<div class="item">';
echo '<a href ="' . $lb['big'] . '" title="' . htmlspecialchars($lb['title']) . '" data-lcl-txt="' . htmlspecialchars($lb['title']) .'" data-lcl-author="' . htmlspecialchars($meta) . '">';
echo '<img src="' . $lb['thumb'] . '" alt="' . htmlspecialchars($lb['title']) . '" />';