From 3556b203613074c068182d3e894dad3750d77673 Mon Sep 17 00:00:00 2001 From: David Dorchies <david.dorchies@irstea.fr> Date: Mon, 2 Jul 2018 23:37:29 +0200 Subject: [PATCH] =?UTF-8?q?#43=20Ajout=20des=20libell=C3=A9s=20des=20extra?= =?UTF-8?q?Results=20+=20Simplification=20de=20la=20gestion=20des=20libell?= =?UTF-8?q?=C3=A9s=20des=20extraresults=20et=20des=20ENUM=20dans=20les=20e?= =?UTF-8?q?xtraresults?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../internationalisation.service.ts | 90 +++++-------------- src/locale/error_messages.fr.json | 33 ++++--- 2 files changed, 41 insertions(+), 82 deletions(-) diff --git a/src/app/services/internationalisation/internationalisation.service.ts b/src/app/services/internationalisation/internationalisation.service.ts index dfe76a54d..00397c931 100644 --- a/src/app/services/internationalisation/internationalisation.service.ts +++ b/src/app/services/internationalisation/internationalisation.service.ts @@ -180,87 +180,37 @@ export class InternationalisationService extends Observable { } /** - * traduit un libellé qui peut être un code + * Traduit un libellé qui peut être un code */ - public translateLabel(o: any) { - let res; - if (typeof o === "string") { - switch (o) { - case "flu": - res = this.localizeText("INFO_REMOUSRESULTS_LIGNEFLUVIALE"); - break; - - case "tor": - res = this.localizeText("INFO_REMOUSRESULTS_LIGNETORRENTIELLE"); - break; - - default: - const match = this.parseLabel(o); - if (match) { - if (match[1] === "ouvrage") - res = this.localizeText("INFO_OUVRAGE") + " n°" + (+match[2] + 1); - - const p = match[3]; - switch (p) { - case "Q": - res += " : " + this.localizeText("INFO_GRANDEUR_" + p); - break; - - case "Q_Mode": - res += " : " + this.localizeText("INFO_TYPE_ECOULEMENT"); - break; - - case "Q_Regime": - res += " : " + this.localizeText("INFO_REGIME"); - break; - } - } - else - res = o; - break; - } + public translateLabel(s: string) { + const key = "INFO_EXTRARES_LIB_"; + const match = this.parseLabel(s); + if (match) { + // Code du type "Ouvrage[n].XXX" + // Les libellés correspondants sont INFO OUVRAGE et INFO_EXTRARES_LIB_OUVRAGE_XXX + return this.localizeText(`INFO_${match[1].toUpperCase()}`) + " n°" + (+match[2] + 1) + ": " + + this.localizeText(`${key}${match[1].toUpperCase()}_${match[3].toUpperCase()}`); + } else { + // Autres codes INFO_EXTRARES_LIB_XXX + return this.localizeText(`${key}${s.toUpperCase()}`); } - return res; - } + } /** * met en forme ou traduit un résultat en fonction du libellé qui l'accompagne + * @todo Il manque un formalisme clair permettant de différencier les valeurs numériques des ENUM */ public formatResult(label: string, value: number): string { const match = this.parseLabel(label); - if (match) - switch (match[1]) { - case "ouvrage": - switch (match[3]) { - case "Q_Mode": - switch (value) { - case 0: - case 1: - case 2: - const key = `INFO_LIB_ENUM_RES_STRUCTURE_MODE_${value}`; - return this.localizeText(key); - - default: - throw new Error(`InternationalisationService.formatResult : valeur ${value} incorrecte pour STRUCTURE_MODE`); - } - - case "Q_Regime": - switch (value) { - case 0: - case 1: - case 2: - const key = `INFO_LIB_ENUM_RES_STRUCTURE_REGIME_${value}`; - return this.localizeText(key); - - default: - throw new Error(`InternationalisationService.formatResult : valeur ${value} incorrecte pour STRUCTURE_REGIME`); - } - - } + if (match) { + if (match[3] !== "Q") { // Le débit est une valeur numérique, tous les autres sont des ENUM ??? + // Label du type ouvrage[n].XXX => message INFO_EXTRARES_ENUM_OUVRAGE_XXX_value + return this.localizeText(`INFO_EXTRARES_ENUM_${match[1].toUpperCase()}_${match[3].toUpperCase()}_${value}`); } - + } const appSetupService = ServiceFactory.instance.applicationSetupService; const nDigits = appSetupService.displayDigits; return value.toFixed(nDigits); } + } diff --git a/src/locale/error_messages.fr.json b/src/locale/error_messages.fr.json index 5f0a08b5d..270d66e42 100644 --- a/src/locale/error_messages.fr.json +++ b/src/locale/error_messages.fr.json @@ -69,8 +69,6 @@ "INFO_GRANDEUR_TAU0": "La force tractrice (Pa)", "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", "INFO_REMOUSRESULTS_ABSCISSE": "Abscisse (m)", "INFO_REMOUSRESULTS_TIRANT": "Tirant d'eau (m)", "INFO_REMOUSRESULTS_FOND": "Fond", @@ -91,15 +89,26 @@ "INFO_PARALLELSTRUCTURE_TITRE": "Ouvrages en parallèle", "INFO_DEVER_TITRE": "Outil dever", "INFO_OUVRAGE": "Ouvrage", - "INFO_TYPE_ECOULEMENT": "Type d'écoulement", - "INFO_REGIME": "Régime", + + "INFO_EXTRARES_LIB_FLU": "Ligne d'eau fluviale", + "INFO_EXTRARES_LIB_TOR": "Ligne d'eau torrentielle", + "INFO_EXTRARES_LIB_OUVRAGE_Q": "Débit (m³/s)", + "INFO_EXTRARES_LIB_OUVRAGE_Q_MODE": "Type d'écoulement", + "INFO_EXTRARES_LIB_OUVRAGE_Q_REGIME": "Régime", + "INFO_EXTRARES_LIB_V": "V: Vitesse (m/s)", + "INFO_EXTRARES_LIB_EC": "EC: Énergie cinétique (m)", + "INFO_EXTRARES_LIB_CV": "Cv: Coefficient de vitesse d'approche", + "INFO_EXTRARES_LIB_CVQT": "CV.QT: Débit corrigé (m³/s)", + + "INFO_EXTRARES_ENUM_OUVRAGE_Q_MODE_0": "Surface libre", + "INFO_EXTRARES_ENUM_OUVRAGE_Q_MODE_1": "En charge", + "INFO_EXTRARES_ENUM_OUVRAGE_Q_MODE_2": "Débit nul", + "INFO_EXTRARES_ENUM_OUVRAGE_Q_REGIME_0": "Dénoyé", + "INFO_EXTRARES_ENUM_OUVRAGE_Q_REGIME_1": "Partiellement noyé", + "INFO_EXTRARES_ENUM_OUVRAGE_Q_REGIME_2": "Noyé", + "INFO_EXTRARES_ENUM_OUVRAGE_Q_REGIME_3": "Débit nul", + "WARNING_STRUCTUREKIVI_PELLE_TROP_FAIBLE": "La pelle du seuil doit mesurer au moins 0,1 m. Le coefficient béta est forcé à 0", - "WARNING_STRUCTUREKIVI_HP_TROP_ELEVE": "h/p ne doit pas être supérieur à 2,5. h/p est forcé à 2,5", - "INFO_LIB_ENUM_RES_STRUCTURE_MODE_0": "Surface libre", - "INFO_LIB_ENUM_RES_STRUCTURE_MODE_1": "En charge", - "INFO_LIB_ENUM_RES_STRUCTURE_MODE_2": "Débit nul", - "INFO_LIB_ENUM_RES_STRUCTURE_REGIME_0": "Dénoyé", - "INFO_LIB_ENUM_RES_STRUCTURE_REGIME_1": "Partiellement noyé", - "INFO_LIB_ENUM_RES_STRUCTURE_REGIME_2": "Noyé", - "INFO_LIB_ENUM_RES_STRUCTURE_REGIME_3": "Débit nul" + "WARNING_STRUCTUREKIVI_HP_TROP_ELEVE": "h/p ne doit pas être supérieur à 2,5. h/p est forcé à 2,5" + } \ No newline at end of file -- GitLab