Automatically detect appropriated language

This commit is contained in:
Pierre HUBERT 2018-08-15 07:52:05 +02:00
parent e214573e4e
commit 40593e00ed
2 changed files with 10 additions and 3 deletions

View File

@ -74,7 +74,7 @@ var ComunicWeb = {
/**
* Return current language
*/
getCurrentLanguage: function(){},
current: function(){},
/**
* Initializate languages

View File

@ -26,12 +26,19 @@ ComunicWeb.common.langs = {
*
* @return {String} The id of the current language
*/
getCurrentLanguage: function(){
current: function(){
//Check if a language has been set in local storage
if(localStorage.getItem(this._lang_storage_field_name) != null)
return localStorage.getItem(this._lang_storage_field_name);
//Get user language
var language = navigator.language || navigator.userLanguage;
if(language){
return language.split("-")[0];
}
//Else return default language
return ComunicWeb.__config.defaultLanguage;
},
@ -61,7 +68,7 @@ ComunicWeb.common.langs = {
ComunicWeb.debug.logMessage("Get and install languages...");
//Get languages to install
this.__currentLang = this.getCurrentLanguage();
this.__currentLang = this.current();
this.__defaultLang = ComunicWeb.__config.defaultLanguage;
//Everything is OK