Gitlab CSE Unil

Commit 2e14a32a authored by M. Chardon's avatar M. Chardon
Browse files

ajout cookie pour conservation choix langue

parent 314cafcf
......@@ -420,6 +420,10 @@
</script>
<script src="../js/main.js"></script>
<script>
var lang = initCookieLang();
initLang(lang);
</script>
</body>
</html>
......@@ -183,6 +183,10 @@
</script>
<script src="../js/main.js"></script>
<script>
var lang = initCookieLang();
initLang(lang);
</script>
</body>
</html>
initLang('en');
function initLang(lang = 'en') {
document.cookie = "lang=" + lang + "; path=/";
if (lang !== 'en') {
$("#help").load("block/help_" + lang + ".html");
} else {
$("#help").load("block/help.html");
}
$.i18n.debug = true;
$.i18n.debug = false;
var i18n = $.i18n();
var language = lang;
i18n.locale = language;
......
......@@ -239,6 +239,10 @@
</script>
<script src="../js/main.js"></script>
<script>
var lang = initCookieLang();
initLang(lang);
</script>
</body>
</html>
......@@ -236,6 +236,10 @@
</script>
<script src="../js/main.js"></script>
<script>
var lang = initCookieLang();
initLang(lang);
</script>
</body>
</html>
......@@ -236,6 +236,10 @@
</script>
<script src="../js/main.js"></script>
<script>
var lang = initCookieLang();
initLang(lang);
</script>
</body>
</html>
......@@ -92,5 +92,9 @@
<script src="js/vendor/modernizr-2.8.3-respond-1.4.2.min.js"></script>
<script src="js/languages.js"></script>
<script src="js/main.js"></script>
<script>
var lang = initCookieLang();
initFooter(lang);
</script>
</body>
</html>
function initLang(lang = 'en') {
$.i18n.debug = true;
document.cookie = "lang=" + lang + "; path=/";
$.i18n.debug = false;
var i18n = $.i18n();
var language = lang;
i18n.locale = language;
......
initFooter();
function initFooter(lang = 'en') {
//var lang = navigator.language || navigator.userLanguage;
if (lang !== 'en') {
$("#contacts").load("../block/contact_" + lang + ".html");
$("#credits").load("../block/credit_" + lang + ".html");
$(".footer").load("../block/footer_" + lang + ".html");
$("#contacts").load("block/contact_" + lang + ".html");
$("#credits").load("block/credit_" + lang + ".html");
$(".footer").load("block/footer_" + lang + ".html");
} else {
$("#contacts").load("../block/contact.html");
$("#credits").load("../block/credit.html");
$(".footer").load("../block/footer.html");
$("#contacts").load("block/contact.html");
$("#credits").load("block/credit.html");
$(".footer").load("block/footer.html");
}
initLang(lang);
}
function initCookieLang() {
var lang = "en";
var coockies = decodeURIComponent(document.cookie);
var coockiesSplit = coockies.split(";");
for (var i = 0; i < coockiesSplit.length; i++) {
var c = coockiesSplit[i];
while (c.charAt(0) === ' ') {
c = c.substring(1);
}
if (c.indexOf("lang") === 0) {
var langTmp = c.substring("lang".length + 1, c.length);
if (langTmp === "en" || langTmp === "fr") {
lang = langTmp;
}
}
}
return lang;
}
\ No newline at end of file
......@@ -630,7 +630,8 @@
<footer class="footer"></footer>
<script type="text/javascript">
initCommun();
var lang = initCookieLang();
initCommun(lang);
initAttack();
updateText();
</script>
......
......@@ -309,7 +309,8 @@
<footer class="footer"></footer>
<script type="text/javascript">
initCommun();
var lang = initCookieLang();
initCommun(lang);
init();
updateText();
</script>
......
function initLang(lang = 'en') {
$.i18n.debug = true;
document.cookie = "lang=" + lang + "; path=/";
$.i18n.debug = false;
var i18n = $.i18n();
var language = lang;
i18n.locale = language;
......@@ -41,4 +43,23 @@ function updateText() {
$(this).text($.i18n(cle));
}
});
}
function initCookieLang() {
var lang = "en";
var coockies = decodeURIComponent(document.cookie);
var coockiesSplit = coockies.split(";");
for (var i = 0; i < coockiesSplit.length; i++) {
var c = coockiesSplit[i];
while (c.charAt(0) === ' ') {
c = c.substring(1);
}
if (c.indexOf("lang") === 0) {
var langTmp = c.substring("lang".length + 1, c.length);
if (langTmp === "en" || langTmp === "fr") {
lang = langTmp;
}
}
}
return lang;
}
\ No newline at end of file
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