From cab5fc5f053b1ba0f1cbef88f6967fad9cbfdca4 Mon Sep 17 00:00:00 2001 From: David Dorchies <david.dorchies@irstea.fr> Date: Thu, 28 Jun 2018 17:33:37 +0200 Subject: [PATCH] Simplification traitement du titre des calculettes --- .../services/formulaire/formulaire.service.ts | 32 ++----------------- .../internationalisation.service.ts | 10 ++++-- src/locale/error_messages.fr.json | 16 +++++----- 3 files changed, 18 insertions(+), 40 deletions(-) diff --git a/src/app/services/formulaire/formulaire.service.ts b/src/app/services/formulaire/formulaire.service.ts index 5984c3f9d..fa035f2d5 100644 --- a/src/app/services/formulaire/formulaire.service.ts +++ b/src/app/services/formulaire/formulaire.service.ts @@ -108,34 +108,8 @@ export class FormulaireService extends Observable { } public getLocalisedTitleFromCalculatorType(type: CalculatorType) { - switch (type) { - case CalculatorType.ConduiteDistributrice: - return this._intlService.localizeText("INFO_CONDDISTRI_TITRE"); - - case CalculatorType.LechaptCalmon: - return this._intlService.localizeText("INFO_LECHAPT_TITRE"); - - case CalculatorType.RegimeUniforme: - return this._intlService.localizeText("INFO_REGUNI_TITRE"); - - case CalculatorType.SectionParametree: - return this._intlService.localizeText("INFO_SECTPARAM_TITRE"); - - case CalculatorType.CourbeRemous: - return this._intlService.localizeText("INFO_REMOUS_TITRE") - - case CalculatorType.PabDimensions: - return this._intlService.localizeText("INFO_PABDIM_TITRE") - - case CalculatorType.PabPuissance: - return this._intlService.localizeText("INFO_PABPUISS_TITRE") - - case CalculatorType.ParallelStructure: - return this._intlService.localizeText("INFO_OUVRAGEPARAL_TITRE") - - default: - return "Invalid calculator type " + type; - } + const sCalculator: string = CalculatorType[type].toUpperCase(); + return this._intlService.localizeText(`INFO_${sCalculator}_TITRE`); } private loadConfig(form: FormulaireDefinition, ct: CalculatorType): Promise<Response> { @@ -199,7 +173,7 @@ export class FormulaireService extends Observable { /** * crée un formulaire d'un type donné * @param ct type de formulaire - * @param jsonState + * @param jsonState */ public createFormulaire(ct: CalculatorType, jsonState?: {}): Promise<FormulaireDefinition> { const f: FormulaireDefinition = this.newFormulaire(ct, jsonState); diff --git a/src/app/services/internationalisation/internationalisation.service.ts b/src/app/services/internationalisation/internationalisation.service.ts index d5e3486b8..dfe76a54d 100644 --- a/src/app/services/internationalisation/internationalisation.service.ts +++ b/src/app/services/internationalisation/internationalisation.service.ts @@ -71,7 +71,7 @@ export class InternationalisationService extends Observable { private getLanguageFromCode(lc: LanguageCode) { for (let l of this._languages) { - if (l.code == lc) + if (l.code === lc) return l; } throw new Message(MessageCode.ERROR_LANG_UNSUPPORTED); @@ -88,7 +88,7 @@ export class InternationalisationService extends Observable { } public setLocale(lng: string | LanguageCode) { - if (this._currLang != undefined) + if (this._currLang !== undefined) var oldLang: LanguageCode = this._currLang.code; if (typeof lng === "string") { @@ -162,8 +162,12 @@ export class InternationalisationService extends Observable { * @param code id du texte */ public localizeText(code: string) { - if (this._Messages == undefined) + if (this._Messages === undefined) { return "<messages not loaded>"; + } + if (this._Messages[code] === undefined) { + return `<message not exists: ${code}>`; + } return this._Messages[code]; } diff --git a/src/locale/error_messages.fr.json b/src/locale/error_messages.fr.json index 69c3b8f87..4959edd72 100644 --- a/src/locale/error_messages.fr.json +++ b/src/locale/error_messages.fr.json @@ -45,10 +45,10 @@ "INFO_CALCULATOR_PARAMFIXES": "Paramètres fixés", "INFO_CALCULATOR_VALEURS": "Valeurs", "INFO_CALCULATOR_CALCULER": "Calculer", - "INFO_CONDDISTRI_TITRE": "Conduite distributrice", - "INFO_LECHAPT_TITRE": "Lechapt-Calmon", - "INFO_REGUNI_TITRE": "Régime uniforme", - "INFO_SECTPARAM_TITRE": "Section paramétrée", + "INFO_CONDUITEDISTRIBUTRICE_TITRE": "Conduite distributrice", + "INFO_LECHAPTCALMON_TITRE": "Lechapt-Calmon", + "INFO_REGIMEUNIFORME_TITRE": "Régime uniforme", + "INFO_SECTIONPARAMETREE_TITRE": "Section paramétrée", "INFO_GRANDEUR_Q": "Débit (m³/s)", "INFO_GRANDEUR_HS": "La charge spécifique (m)", "INFO_GRANDEUR_HSC": "La charge critique (m)", @@ -67,7 +67,7 @@ "INFO_GRANDEUR_I-J": "Variation linéaire de l'énergie spécifique (m/m)", "INFO_GRANDEUR_IMP": "Impulsion (N)", "INFO_GRANDEUR_TAU0": "La force tractrice (Pa)", - "INFO_REMOUS_TITRE": "Courbes de remous", + "INFO_COURBEREMOUS_TITRE": "Courbes de remous", "INFO_REMOUSRESULTS_TITREJOURNAL": "Journal de calcul", "INFO_REMOUSRESULTS_LIGNEFLUVIALE": "Ligne d'eau fluviale", "INFO_REMOUSRESULTS_LIGNETORRENTIELLE": "Ligne d'eau torrentielle", @@ -86,9 +86,9 @@ "INFO_CLOSE_DIALOGUE_TEXT": "Attention ! Les paramètres et résultats de la calculette seront perdus. Vraiment fermer ?", "INFO_OPTION_YES": "Oui", "INFO_OPTION_NO": "Non", - "INFO_PABDIM_TITRE": "Passe à bassin : dimensions", - "INFO_PABPUISS_TITRE": "Passe à bassin : puissance dissipée", - "INFO_OUVRAGEPARAL_TITRE": "Ouvrages en parallèle", + "INFO_PABDIMENSIONS_TITRE": "Passe à bassin : dimensions", + "INFO_PABPUISSANCE_TITRE": "Passe à bassin : puissance dissipée", + "INFO_PARALLELSTRUCTURE_TITRE": "Ouvrages en parallèle", "INFO_OUVRAGE": "Ouvrage", "INFO_TYPE_ECOULEMENT": "Type d'écoulement", "INFO_REGIME": "Régime", -- GitLab