From 8eadb03d5971f155daadcf0717006f5db5e45377 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Wed, 15 Aug 2018 08:55:15 +0200 Subject: [PATCH] Updated language picker. --- assets/js/common/langs.js | 4 ++++ assets/js/components/languagePicker.js | 20 ++++++++++---------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/assets/js/common/langs.js b/assets/js/common/langs.js index c790e3b9..1466a651 100644 --- a/assets/js/common/langs.js +++ b/assets/js/common/langs.js @@ -100,6 +100,10 @@ ComunicWeb.common.langs = { * @return {String} The string ready to show */ getTranslatedText: function(stringName, stringParams){ + + if(!this[this.__currentLang]) + return "Invalid language!"; + //Try to get string if(this[this.__currentLang][stringName]) var string = this[this.__currentLang][stringName]; diff --git a/assets/js/components/languagePicker.js b/assets/js/components/languagePicker.js index ffcb972c..d8971696 100644 --- a/assets/js/components/languagePicker.js +++ b/assets/js/components/languagePicker.js @@ -62,27 +62,27 @@ ComunicWeb.components.langPicker = { class: "modal-body", }); - //Display the list of languages - var langs = [ - ["fr", "Français"], - ["en", "English"] - ]; - + //Display the list of language var buttons = []; - langs.forEach(function(lang){ + for(language in ComunicWeb.common.langs.list){ + + if(typeof language !== "string") + continue; + + var info = ComunicWeb.common.langs.list[language]; const button = createElem2({ appendTo: modalBody, type: "div", class: "btn btn-default", - innerHTML: lang[1] + innerHTML: info.local_name + " (" + info.name + ")" }); - button.setAttribute("data-lang", lang[0]); + button.setAttribute("data-lang", language); buttons.push(button); add_space(modalBody); - }); + }; //Modal footer var modalFooter = createElem2({