import config = require("./config"); export class Global { // #region Properties locale: string = ""; language: any; langLoaded: Boolean = false; // #endregion // #region Constructor constructor(locale: string, configuration: config.Config) { if (locale !== "" && locale !== undefined) { this.locale = locale.length > 0 ? locale : this.getConfig().locale; this.loadLocalization(this.locale, configuration); } } // #endregion // #region Methods loadLocalization(locale: string, configuration: config.Config) { this.locale = locale; var resFile = configuration.globalfileloc + locale + ".json"; var loadedLanguage: any; try { loadedLanguage = require(resFile); } catch (e) { loadedLanguage = undefined; } if (loadedLanguage === undefined) { this.language = require(configuration.globalfileloc + "en-us.json"); } else { this.language = loadedLanguage; } this.langLoaded = !(this.language === undefined); } getText(key: string) { try { return this.language[key] === undefined ? key : this.language[key]; } catch (e) { return key; } } getTextUpper(key: string) { return this.getText(key).toUpperCase(); } getMenuItem(item: string) { item = item.toLowerCase(); return this.language[`menu${item}`] === undefined ? "" : this.language[`menu${item}`]; } getMenuItemUpper(item: string) { return this.getMenuItem(item).toUpperCase(); } menuExists(item: string) { return this.getMenuItem(item) !== ""; } // #endregion // #region Helper Methods getConfig(): any { var conf = new config.Config(); return conf; } // #endregion }