Commit 96bb4568 authored by okhin's avatar okhin 🚴

Merge branch '75-probleme-de-traductions' into 'preprod'

Resolve "Problème de traductions"

Closes #75

See merge request !71
parents f07ad62a e9b7be15
Pipeline #2348 passed with stages
in 1 minute and 40 seconds
......@@ -19,11 +19,3 @@ DEBUG=0
; Langue par défaut
LANGUAGE='fr'
; Variables globales du site
;languages['DE']="support","de_DE","de"
;languages['IT']="sostegno","it_IT","it"
languages['ES']="apoyar","es_ES","es"
languages['FR']="soutien","fr_FR","fr"
languages['EN']="support","en_US","en"
......@@ -28,6 +28,8 @@ define("CTX_MODE", getenv('CTX_MODE'));
//define("CERTIFICATE","XXXXXXXXXXXXXXXXXXXXXXXXx");
//define("CTX_MODE","PRODUCTION");
define("LANGUAGES", "fr_FR,en_US");
define("PIPLOME_PATH", getenv('PIPLOME_PATH'));
define("PIPLOME_URL", getenv('PIPLOME_URL'));
......
......@@ -22,27 +22,45 @@ class Controller
}
define("ROOTURL", "https://".$HTTP_HOST.'/');
// Sélection de la langue par l'url
$main = explode('.', $HTTP_HOST)[0];
$lang = "fr_FR";
$lang_short = "fr";
foreach ($f3->get('languages') as $key => $language) {
if ($main==$language[0]) {
$lang = $language[1];
$lang_short = $language[2];
// Sélection de la langue par header
$lang = 'fr_FR';
$lang_short = 'fr';
if ($f3->exists('GET.lang')) {
// On force la langue passée dans l'URL GET
$accept_languages = [$f3->get('GET.lang')];
$f3->set('SESSION.lang', $f3->get('GET.lang'));
} else {
if ($f3->exists('SESSION.lang')) {
// On a déjà défini une langue précédemment
$accept_languages = [$f3->get('SESSION.lang')];
} else {
// On récupère la langue du navigateur
$accept_languages = $f3->exists('HEADERS.Accept-Language') ? explode(',', $f3->get('HEADERS.Accept-Language')) : [];
}
}
foreach (explode(',', LANGUAGES) as $language) {
foreach ($accept_languages as $accept_language) {
if (strpos($language, $accept_language)>=0) {
$lang = $language;
$lang_short = explode($language, '-')[0];
}
}
}
if (!bindtextdomain("messages", dirname(__FILE__)."/../locales")) {
if (!bindtextdomain("messages", "../locales/")) {
echo "<!-- bondtextdomain failed -->";
}
// Language ok, set the locale environment
putenv("LC_MESSAGES=".$lang);
putenv("LANG=".$lang);
putenv("LANGUAGE=".$lang);
// this locale MUST be selected in "dpkg-reconfigure locales"
if (!setlocale(LC_ALL, $lang)) {
echo "<!-- setlocale failed -->";
echo "<!-- setlocale $lang failed -->";
}
if (!textdomain("messages")) {
echo "<!-- textdomain failed -->";
}
......
......@@ -90,8 +90,8 @@
<div class="hidden-xs hidden-sm">
<nav id="up-bar" class="navbar navbar-default dark-blue">
<ul class="nav navbar-nav navbar-right blue">
<li><a href="?lang=fr">{{ _("[FR]")}}</a></li>
<li><a href="?lang=en">{{ _("[EN]")}}</a></li>
<li><a href="?lang=fr_FR">{{ _("[FR]")}}</a></li>
<li><a href="?lang=en_US">{{ _("[EN]")}}</a></li>
</ul>
<ul class="nav navbar-nav navbar-right">
<check if="{{ array_key_exists('user', @SESSION) }}">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment