Skip to content
Snippets Groups Projects
Commit a76146c8 authored by staff's avatar staff
Browse files

Fix lang switching

parent d93d6757
Branches
Tags
No related merge requests found
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /www/cesium-website/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .*\.php - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/(.*)$ index.php?lang=$1&page=/$2 [L]
# Redirections pour gérer l'ancienne structure de liens sans perdre en SEO
# (ex : /telechargement au lieu de /fr/telechargement)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)$ fr/$1 [R=301]
</IfModule>
......@@ -14,16 +14,69 @@ $legalNotice =
// Trouver une façon de définir $rootURL sans faire ça :
if ($_SERVER['SERVER_NAME'] == 'localhost') {
$rootURL = '/www/cesium-website';
} else {
$rootURL = '';
}
/* ====== i18n ====== */
function checkAvailableLanguages ($langList) {
foreach ($langList as $isoCode => $l) {
$loc = setlocale(LC_ALL, $l['folder'], ($l['folder'] . '.utf8'));
if ($loc === false) {
unset($langList[$isoCode]);
} else {
$langList[$isoCode]['localeCode'] = $loc;
}
}
return $langList;
}
$availableLanguages =
[
'fr',
'en',
'es',
'va'
'fr' => [
'name' => 'français',
'folder' => 'fr_FR'
],
'en' => [
'name' => 'english',
'folder' => 'en_GB'
],
'es' => [
'name' => 'español',
'folder' => 'es_ES'
],
'va' => [
'name' => 'valyrio',
'folder' => 'en_US'
],
/*
'it' => [
'name' => 'italiano',
'folder' => 'it_IT'
],
*/
];
$availableLanguages = checkAvailableLanguages($availableLanguages);
//echo '<pre>'; print_r($availableLanguages); echo '</pre>';
define('DEFAULT_LANG', 'fr');
include('inc/lang.php');
......@@ -44,18 +97,6 @@ bindTextDomains($textDomains);
// Trouver une façon de définir $rootURL sans faire ça :
if ($_SERVER['SERVER_NAME'] == 'localhost') {
$rootURL = '/www/cesium-website';
} else {
$rootURL = '/cesium/cesium.app';
}
include('inc/functions.php');
include('inc/display.php');
......
......@@ -91,35 +91,36 @@ textdomain('menu');
textdomain('menu');
foreach ($availableLanguages as $l)
foreach ($availableLanguages as $thisLangIsoCode => $thisLang)
{
/* To have links translated */
putenv('LC_ALL='. $thisLang['localeCode']);
setlocale(LC_ALL, $thisLang['localeCode']);
echo '
<li>';
if ($l == LANG) {
if ($thisLangIsoCode == LANG) {
echo '
<strong>
<span>
' . $l . '
' . $thisLangIsoCode . '
</span>
<span>
' . getLangName($l) . '
' . $thisLang['name'] . '
</span>
</strong>';
} else {
putenv('LC_ALL='. getGetTextFolder($l));
setlocale(LC_ALL, getGetTextFolder($l) . '.utf8');
echo '
<a href="'. $rootURL .'/'. $l . _($pagePermalink) .'">
<a href="'. $rootURL .'/'. $thisLangIsoCode . _($pagePermalink) .'">
<span>
' . $l . '
' . $thisLangIsoCode . '
</span>
<span>
' . getLangName($l) . '
' . $thisLang['name'] . '
</span>
</a>';
......@@ -129,8 +130,8 @@ textdomain('menu');
</li>';
}
putenv('LC_ALL='. L10N_FOLDER);
setlocale(LC_ALL, L10N_FOLDER . '.utf8');
putenv('LC_ALL='. LANG_FOLDER);
setlocale(LC_ALL, LOCALE_CODE);
?>
</ul>
</nav>
......
......@@ -27,20 +27,22 @@ $bodyIds = !isset($bodyIds) ? '' : $bodyIds;
<meta property="og:description" content="<?php echo $pageDescription; ?>" />
<meta property="og:url" content="http://cesium.app/" />
<meta property="og:site_name" content="Cesium Ğ1" />
<meta property="og:image" content="<?php echo $rootURL . '/i18n/' . L10N_FOLDER . '/contents' . _('/accueil') . _('/Cesium-G1-maquette.png'); ?>" />
<meta property="og:image" content="<?php echo $rootURL . '/i18n/' . LANG_FOLDER . '/contents' . _('/accueil') . _('/Cesium-G1-maquette.png'); ?>" />
<meta property="og:type" content="website" />
<meta name="twitter:description" content="<?php echo $pageDescription; ?>" />
<meta name="twitter:title" content="<?php echo $pageTitle; ?>" />
<meta name="twitter:image" content="<?php echo $rootURL . '/i18n/' . L10N_FOLDER . '/contents' . _('/accueil') . _('/Cesium-G1-maquette.png'); ?>" />
<meta name="twitter:image" content="<?php echo $rootURL . '/i18n/' . LANG_FOLDER . '/contents' . _('/accueil') . _('/Cesium-G1-maquette.png'); ?>" />
<meta name="twitter:card" content="summary_large_image" />
<script type="text/javascript" src="<?php echo $rootURL; ?>/lib/lazyImg.min.js"></script>
<?php
foreach ($availableLanguages as $l)
foreach ($availableLanguages as $isoCode => $v)
{
echo '<link rel="alternate" hreflang="'. $l .'" href="'. $rootURL .'/'. $l .'/" />';
echo '<link rel="alternate" hreflang="'. $isoCode .'" href="'. $rootURL .'/'. $isoCode .'/" />';
}
?>
......
......@@ -30,7 +30,8 @@ function getUserIpAddress ()
} else if (array_key_exists('HTTP_X_FORWARDED_FOR', $_SERVER)) {
return array_pop(explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']));
$a = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
return array_pop($a);
} else {
......
<?php
function getLangName ($code)
function getLangName ($isoCode)
{
switch ($code)
{
case 'fr' :
return 'français';
case 'en' :
return 'english' ;
case 'es' :
return 'español';
case 'va' :
return 'valyrio';
case 'it' :
return 'italiano';
default :
return ''; // Supposedly cannot happen
}
global $availableLanguages;
return $availableLanguages[$isoCode]['name'];
}
function getGetTextFolder ($code)
function getLocaleCode ($isoCode)
{
switch ($code)
{
case 'fr' :
return 'fr_FR';
case 'en' :
return 'en_GB';
case 'es' :
return 'es_ES';
case 'va' :
return 'en_US';
case 'it' :
return 'it_IT';
global $availableLanguages;
return $availableLanguages[$isoCode]['localeCode'];
}
function getLangFolder ($isoCode)
{
global $availableLanguages;
return $availableLanguages[$isoCode]['folder'];
}
function defineLang ()
{
global $availableLanguages;
global $rootURL;
if (isset($_GET['lang'])) {
if (isset($_GET['lang'])) { /* From URL */
$lang = $_GET['lang'];
} else {
if (!in_array($lang, array_keys($availableLanguages))) {
header('Location: '. $rootURL . '/'. DEFAULT_LANG . '/');
}
} else { /* From browser (if visiting root page /) */
$lang = preg_replace('/^([^,-]+).*$/', '$1', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
}
if (!in_array($lang, $availableLanguages)) {
if (!in_array($lang, array_keys($availableLanguages))) {
define('LANG', DEFAULT_LANG);
......@@ -60,7 +52,8 @@ function defineLang ()
}
define('L10N_FOLDER', getGetTextFolder(LANG));
define('LOCALE_CODE', getLocaleCode(LANG));
define('LANG_FOLDER', getLangFolder(LANG));
}
function bindTextDomains ($textDomains)
......
......@@ -3,12 +3,8 @@ include('config.php');
defineLang();
putenv('LC_ALL='. L10N_FOLDER);
if (false === setlocale(LC_ALL, L10N_FOLDER . '.utf8')) {
exit (sprintf('La langue "%s" n\'est pas installée sur ce système.', L10N_FOLDER));
}
putenv('LC_ALL='. LANG_FOLDER);
setlocale(LC_ALL, LOCALE_CODE);
textdomain("menu");
......
......@@ -315,6 +315,7 @@ body header:first-child > h2
order: 2;
flex-grow: 1;
text-align: left;
font-size: 2.25rem;
}
body header:first-child > :first-child a,
......@@ -322,7 +323,7 @@ body header:first-child > :first-child a:hover
{
color: white;
text-decoration: none;
padding-left: 0.5em;
padding-left: 0.25em;
}
......@@ -683,6 +684,11 @@ body#home #showcase h2#USP
text-align: center;
}
body#home #showcase :not(figure) {
z-index: 666;
}
body#home #showcase h2#USP + p
{
margin-top: 0rem;
......@@ -775,7 +781,7 @@ body#home #showcase h2#USP + p
body#home #showcase div
{
flex-direction: column;
height: calc(100vh - 120px - 1rem);
height: calc(90vh - 120px - 1rem);
box-sizing: border-box;
}
......@@ -797,7 +803,9 @@ body#home #showcase h2#USP + p
body#home #showcase figure img
{
align-self: center;
width: 112.5%;
height: calc(90vh - 120px);
width: auto;
transform: translateY(1rem) translateX(-2vw);
}
}
......@@ -811,7 +819,8 @@ body#home #showcase h2#USP + p
body#home #showcase figure img
{
align-self: center;
width: 125%;
height: calc(90vh - 120px);
width: auto;
transform: translateY(1rem) translateX(-2vw);
}
}
......
......@@ -23,7 +23,7 @@ textdomain('features');
$reader = new Reader('vendor/GeoLite2-Country/GeoLite2-Country.mmdb');
$record = $reader->country(getUserIpAddress());
$path = './i18n/' . L10N_FOLDER . '/contents' . _('/fonctionnalites');
$path = './i18n/' . LANG_FOLDER . '/contents' . _('/fonctionnalites');
$mapFileName = _('/carte-des-utilisateurs') . _('/pays') . sprintf('/%s.png', $record->country->isoCode);
if (!file_exists($path . $mapFileName)) {
......@@ -134,7 +134,7 @@ textdomain('features');
{
echo '
<figure>
<img src="'. $rootURL .'/i18n/' . L10N_FOLDER . '/contents' . _('/fonctionnalites') . $f['img'] .'" />
<img src="'. $rootURL .'/i18n/' . LANG_FOLDER . '/contents' . _('/fonctionnalites') . $f['img'] .'" />
<figcaption>
<h2>'. $f['name'] .'</h2>';
......
......@@ -13,7 +13,7 @@ textdomain('home');
<section id="showcase">
<div>
<figure id="home-app-screenshot">
<img src="<?php echo $rootURL . '/i18n/' . L10N_FOLDER . '/contents' . _('/accueil') . _('/Cesium-G1-maquette.png'); ?>"
<img src="<?php echo $rootURL . '/i18n/' . LANG_FOLDER . '/contents' . _('/accueil') . _('/Cesium-G1-maquette.png'); ?>"
alt="capture d'écran de Cesium" />
</figure>
......@@ -143,7 +143,7 @@ textdomain('home');
<?php
$reviewsPath = './i18n/' . L10N_FOLDER . '/contents' . _('/accueil') . _('/avis') . '/';
$reviewsPath = './i18n/' . LANG_FOLDER . '/contents' . _('/accueil') . _('/avis') . '/';
if (file_exists($reviewsPath) AND ($reviewsFiles = scandir($reviewsPath)) AND count($reviewsFiles)-2 > 0)
{
......
......@@ -10,7 +10,7 @@ if (empty($subpage))
$tutoContentsPath = './i18n/' . L10N_FOLDER . '/contents/tuto';
$tutoContentsPath = './i18n/' . LANG_FOLDER . '/contents/tuto';
if (file_exists($tutoContentsPath . $subpage) and !is_dir($tutoContentsPath . $subpage) )
......@@ -75,7 +75,7 @@ if (file_exists($tutoContentsPath . $subpage) and !is_dir($tutoContentsPath . $s
{
/* === Menu === */
$menu = './i18n/' . L10N_FOLDER . '/contents/tuto/menu.html';
$menu = './i18n/' . LANG_FOLDER . '/contents/tuto/menu.html';
if (file_exists($menu))
{
$toc = file_get_contents($menu, FILE_USE_INCLUDE_PATH);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment