Skip to content
Snippets Groups Projects
Commit ff4d2345 authored by mathias.chouet's avatar mathias.chouet
Browse files

Update #223 : remove unused fallback language loading mechanism

parent 670edfcb
No related branches found
No related tags found
2 merge requests!105Resolve "Améliorer le système de traduction",!82Resolve "Ajout de la fonctionnalité "Respect des critères""
......@@ -130,14 +130,6 @@ export class FormulaireService extends Observable {
&& langCache[this.intlService.currentLanguage][textKey] !== undefined
) {
return langCache[this.intlService.currentLanguage][textKey];
} else if ( // try calculator type specific translation, but for default language
langCache
&& langCache[this.appSetupService.fallbackLanguage]
&& langCache[this.appSetupService.fallbackLanguage][textKey] !== undefined
) {
return langCache[this.appSetupService.fallbackLanguage][textKey];
}
}
// fallback to global (not calculator type specific) translation system
......
......@@ -21,9 +21,6 @@ export class I18nService extends Observable implements Observer {
/** localized messages */
private _Messages: StringMap;
/** localized messages in fallback language (the one in the config file) */
private _fallbackMessages: StringMap;
/** to avoid loading language files multiple times */
private _languageCache = {};
......@@ -36,10 +33,6 @@ export class I18nService extends Observable implements Observer {
fr: "Français",
en: "English"
};
// load fallback language messages once for all
this.httpGetMessages(this.applicationSetupService.fallbackLanguage).then((res: any) => {
this._fallbackMessages = res;
});
// add language preferences observer
this.applicationSetupService.addObserver(this);
}
......@@ -97,20 +90,14 @@ export class I18nService extends Observable implements Observer {
}
/**
* Loads the localisation file dedicated to calculator type ct; tries the current
* language then the fallback language; uses cache if available
* Loads the localisation file dedicated to calculator type ct; uses cache if available
*/
public loadLocalisation(calc: CalculatorType): Promise<any> {
const lang = this.currentLanguage;
return this.loadLocalisationForLang(calc, lang).then((localisation) => {
return localisation as StringMap;
}).catch((e) => {
// try default lang (the one in the config file) ?
const fallbackLang = this.applicationSetupService.fallbackLanguage;
if (lang !== fallbackLang) {
console.error(`localisation for ${CalculatorType[calc]} not found, trying fallback language: ${fallbackLang}`);
return this.loadLocalisationForLang(calc, fallbackLang);
}
return "";
});
}
......@@ -120,12 +107,8 @@ export class I18nService extends Observable implements Observer {
*/
private loadLocalisationForLang(calc: CalculatorType, lang: string): Promise<any> {
const ct = String(calc);
// already in cache ?
if (Object.keys(this._languageCache).includes(ct) && Object.keys(this._languageCache[calc]).includes(lang)) {
return new Promise((resolve) => {
resolve(this._languageCache[ct][lang]);
});
} else {
// if not already in cache
if (! Object.keys(this._languageCache).includes(ct) || ! Object.keys(this._languageCache[calc]).includes(lang)) {
const f: string = FormulaireService.getConfigPathPrefix(calc) + lang + ".json";
return this.httpService.httpGetRequestPromise(f).then((localisation) => {
this._languageCache[ct] = this._languageCache[ct] || {};
......@@ -165,7 +148,6 @@ export class I18nService extends Observable implements Observer {
* In production mode, looks in different messages collections :
* 1. ${msg} if provided
* 2. messages for current language
* 3. messages for fallback language
*
* In dev mode, looks only in 1. if provided, else only in 2. which makes missing
* translations easier to detect
......@@ -183,12 +165,6 @@ export class I18nService extends Observable implements Observer {
if (this._Messages !== undefined && this._Messages["INFO_LIB_" + textKey.toUpperCase()] !== undefined) {
return decodeHtml(this._Messages["INFO_LIB_" + textKey.toUpperCase()]);
}
if (!isDevMode()) {
// try fallback language before giving up
if (this._fallbackMessages[textKey] !== undefined) {
return decodeHtml(this._fallbackMessages[textKey]);
}
}
return `*** message not found: ${textKey} ***`;
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment