mirror of
				https://github.com/pierre42100/ComunicWeb
				synced 2025-11-04 04:04:20 +00:00 
			
		
		
		
	Update lang component.
This commit is contained in:
		@@ -76,16 +76,13 @@ var ComunicWeb = {
 | 
			
		||||
			 */
 | 
			
		||||
			getCurrentLanguage: function(){},
 | 
			
		||||
 | 
			
		||||
			/**
 | 
			
		||||
			 * Include and install specified language
 | 
			
		||||
			 */
 | 
			
		||||
			installLanguage: function(languageID){},
 | 
			
		||||
 | 
			
		||||
			/**
 | 
			
		||||
			 * Initializate languages
 | 
			
		||||
			 */
 | 
			
		||||
			initLanguages: function(){},
 | 
			
		||||
 | 
			
		||||
			//TODO : implement
 | 
			
		||||
 | 
			
		||||
			/**
 | 
			
		||||
			 *  Return a string in correct language
 | 
			
		||||
			 */
 | 
			
		||||
 
 | 
			
		||||
@@ -4,35 +4,59 @@
 | 
			
		||||
 * @author Pierre HUBERT
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
ComunicWeb.common.langs = {
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Local storage lang item name
 | 
			
		||||
     */
 | 
			
		||||
    _lang_storage_field_name: "comunic_v2_lang",
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Currently selected language
 | 
			
		||||
     */
 | 
			
		||||
    __currentLang: "en",
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Default langage (updated on init)
 | 
			
		||||
     */
 | 
			
		||||
    __defaultLang: "en",
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get current language
 | 
			
		||||
     *
 | 
			
		||||
     * @return {String} The id of the current language
 | 
			
		||||
     */
 | 
			
		||||
ComunicWeb.common.langs.getCurrentLanguage = function(){
 | 
			
		||||
    return "fr";
 | 
			
		||||
    //return ComunicWeb.__config.defaultLanguage;
 | 
			
		||||
};
 | 
			
		||||
    getCurrentLanguage: 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);
 | 
			
		||||
 | 
			
		||||
        //Else return default language
 | 
			
		||||
        return ComunicWeb.__config.defaultLanguage;
 | 
			
		||||
    },
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
 * Include and install specified language
 | 
			
		||||
     * Set language
 | 
			
		||||
     * 
 | 
			
		||||
 * @param {String} languageID The languageID to install
 | 
			
		||||
     * @param {String} lang The language to set
 | 
			
		||||
     */
 | 
			
		||||
ComunicWeb.common.langs.installLanguage = function(languageID){
 | 
			
		||||
    //Generate filename to include
 | 
			
		||||
    var fileToInclude = ComunicWeb.__config.languagesPath + languageID + ".inc.js";
 | 
			
		||||
    setLang: function(lang){
 | 
			
		||||
 | 
			
		||||
    //Include filename
 | 
			
		||||
    ComunicWeb.common.jsFiles.includeFile(fileToInclude);
 | 
			
		||||
};
 | 
			
		||||
        //Set new language in local storage
 | 
			
		||||
        localStorage.setItem(this._lang_storage_field_name, lang);
 | 
			
		||||
 | 
			
		||||
        //Save name
 | 
			
		||||
        this.__currentLang = lang;
 | 
			
		||||
    },
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Language initiator
 | 
			
		||||
     * 
 | 
			
		||||
 * @return Boolean False if it fails
 | 
			
		||||
     * @return {Boolean} False if it fails
 | 
			
		||||
     */
 | 
			
		||||
ComunicWeb.common.langs.initLanguages = function(){
 | 
			
		||||
    initLanguages: function(){
 | 
			
		||||
        
 | 
			
		||||
        //Debug message
 | 
			
		||||
        ComunicWeb.debug.logMessage("Get and install languages...");
 | 
			
		||||
 | 
			
		||||
@@ -40,16 +64,9 @@ ComunicWeb.common.langs.initLanguages = function(){
 | 
			
		||||
        this.__currentLang = this.getCurrentLanguage();
 | 
			
		||||
        this.__defaultLang = ComunicWeb.__config.defaultLanguage;
 | 
			
		||||
 | 
			
		||||
    //Install default language (made by default)
 | 
			
		||||
    //this.installLanguage(this.__defaultLang);
 | 
			
		||||
 | 
			
		||||
    //If selected language is different than default one, install it too
 | 
			
		||||
    if(this.__currentLang !== this.__defaultLang)
 | 
			
		||||
        this.installLanguage(this.__currentLang);
 | 
			
		||||
    
 | 
			
		||||
        //Everything is OK
 | 
			
		||||
        return 0;
 | 
			
		||||
}
 | 
			
		||||
    },
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Return a string in correct language
 | 
			
		||||
@@ -58,7 +75,7 @@ ComunicWeb.common.langs.initLanguages = function(){
 | 
			
		||||
     * @param {Array} stringParams The optionnal parametres to include with the string
 | 
			
		||||
     * @return {String} The string ready to show
 | 
			
		||||
     */
 | 
			
		||||
ComunicWeb.common.langs.getTranslatedText = function(stringName, stringParams){
 | 
			
		||||
    getTranslatedText: function(stringName, stringParams){
 | 
			
		||||
        //Try to get string
 | 
			
		||||
        if(this[this.__currentLang][stringName])
 | 
			
		||||
            var string = this[this.__currentLang][stringName];
 | 
			
		||||
@@ -75,4 +92,5 @@ ComunicWeb.common.langs.getTranslatedText = function(stringName, stringParams){
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return string;
 | 
			
		||||
    },
 | 
			
		||||
}
 | 
			
		||||
@@ -189,8 +189,9 @@ class Dev {
 | 
			
		||||
		"js/common/date.js",
 | 
			
		||||
		"js/common/system.js",
 | 
			
		||||
 | 
			
		||||
		//Default langage
 | 
			
		||||
		//Languages
 | 
			
		||||
		"js/langs/en.inc.js",
 | 
			
		||||
		"js/langs/fr.inc.js",
 | 
			
		||||
 | 
			
		||||
		//Components
 | 
			
		||||
			//Mail caching
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user