From c8d64c4231665719cd061c53adfd9d9e967d1a69 Mon Sep 17 00:00:00 2001
From: Boris Paing <boris.paing@laposte.net>
Date: Fri, 20 Dec 2019 11:09:15 +0100
Subject: [PATCH] Fix lang error appearing in some environment where some langs
are not installed
---
config.php | 49 ++++++++++++++++++++++++++++++++++++----
foot.php | 20 ++++++-----------
head.php | 10 +++++----
inc/lang.php | 58 ++++++++++++++++++------------------------------
index.php | 8 ++-----
lib/style.css | 17 ++++++++++----
tpl/features.php | 4 ++--
tpl/home.php | 4 ++--
tpl/tuto.php | 4 ++--
9 files changed, 101 insertions(+), 73 deletions(-)
diff --git a/config.php b/config.php
index fbd7a07..05cbf56 100644
--- a/config.php
+++ b/config.php
@@ -16,14 +16,55 @@ $legalNotice =
/* ====== i18n ====== */
+function checkAvailableLanguages ($langList) {
+
+ foreach ($langList as $k => $v) {
+
+ $loc = setlocale(LC_ALL, $langList[$k]['folder'], ($langList[$k]['folder'] . '.utf8'));
+
+ if ($loc === false) {
+
+ $langList[$k] = NULL;
+
+ } else {
+
+ $langList[$k]['localeCode'] = $loc;
+ }
+ }
+
+ return $langList;
+}
+
$availableLanguages =
[
- 'fr',
- 'en',
- 'es',
- 'va'
+ 'fr' => [
+ 'name' => 'français',
+ 'folder' => 'fr_FR'
+ ],
+ 'en' => [
+ 'name' => 'english',
+ 'folder' => 'fr_FR'
+ ],
+ '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');
diff --git a/foot.php b/foot.php
index 0fe69d9..fc2b88b 100644
--- a/foot.php
+++ b/foot.php
@@ -91,35 +91,32 @@ textdomain('menu');
textdomain('menu');
- foreach ($availableLanguages as $l)
+ foreach ($availableLanguages as $thisLangIsoCode => $thisLang)
{
echo '
<li>';
- if ($l == LANG) {
+ if ($isoCode == 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>';
@@ -128,9 +125,6 @@ textdomain('menu');
echo '
</li>';
}
-
- putenv('LC_ALL='. L10N_FOLDER);
- setlocale(LC_ALL, L10N_FOLDER . '.utf8');
?>
</ul>
</nav>
diff --git a/head.php b/head.php
index bda221c..4b5b2a3 100644
--- a/head.php
+++ b/head.php
@@ -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 .'/" />';
}
?>
diff --git a/inc/lang.php b/inc/lang.php
index b892d43..6102ef6 100644
--- a/inc/lang.php
+++ b/inc/lang.php
@@ -1,66 +1,52 @@
<?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;
- if (isset($_GET['lang'])) {
+ if (isset($_GET['lang'])) { /* From URL */
$lang = $_GET['lang'];
- } else {
+ } 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);
} else {
-
+
define('LANG', $lang);
}
- define('L10N_FOLDER', getGetTextFolder(LANG));
+ define('LOCALE_CODE', getLocaleCode(LANG));
+ define('LANG_FOLDER', getLangFolder(LANG));
}
function bindTextDomains ($textDomains)
diff --git a/index.php b/index.php
index e718d4f..37769f6 100644
--- a/index.php
+++ b/index.php
@@ -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='. LOCALE_CODE);
+setlocale(LC_ALL, LOCALE_CODE);
textdomain("menu");
diff --git a/lib/style.css b/lib/style.css
index 99c7b45..e947cc5 100644
--- a/lib/style.css
+++ b/lib/style.css
@@ -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);
}
}
diff --git a/tpl/features.php b/tpl/features.php
index d96559a..33f6574 100644
--- a/tpl/features.php
+++ b/tpl/features.php
@@ -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>';
diff --git a/tpl/home.php b/tpl/home.php
index 20669fc..21a0863 100644
--- a/tpl/home.php
+++ b/tpl/home.php
@@ -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)
{
diff --git a/tpl/tuto.php b/tpl/tuto.php
index 66b1277..8e7e582 100644
--- a/tpl/tuto.php
+++ b/tpl/tuto.php
@@ -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);
--
GitLab