From 3105e07ebcecc451a38555202bfb27f04162d183 Mon Sep 17 00:00:00 2001 From: "francois.grand" <francois.grand@irstea.fr> Date: Wed, 2 May 2018 15:31:59 +0200 Subject: [PATCH] =?UTF-8?q?=20#80=20InternationalisationService=20:=20ajou?= =?UTF-8?q?t=20de=20la=20m=C3=A9thode=20formatResult()=20pour=20traduire?= =?UTF-8?q?=20d'=C3=A9ventuels=20r=C3=A9sultats=20sous=20forme=20de=20code?= =?UTF-8?q?=20-=20InternationalisationService=20:=20m=C3=A9thode=20transla?= =?UTF-8?q?te()=20renomm=C3=A9e=20en=20translateLabel()=20-=20error=5Fmess?= =?UTF-8?q?ages.*.json=20:=20ajout=20des=20codes=20INFO=5FLIB=5FENUM=5FRES?= =?UTF-8?q?=5F*?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../horizontal-result-element.component.ts | 2 +- .../vertical-result-element.component.ts | 4 +- src/app/results/var-results.ts | 2 +- .../internationalisation.service.ts | 59 +++++++++++++++++-- src/locale/error_messages.en.json | 9 ++- src/locale/error_messages.fr.json | 9 ++- 6 files changed, 74 insertions(+), 11 deletions(-) diff --git a/src/app/components/result-element/horizontal-result-element.component.ts b/src/app/components/result-element/horizontal-result-element.component.ts index 0925d4246..48b269ce9 100644 --- a/src/app/components/result-element/horizontal-result-element.component.ts +++ b/src/app/components/result-element/horizontal-result-element.component.ts @@ -37,7 +37,7 @@ export class HorizontalResultElementComponent extends ResultElementBaseComponent for (const h of this._headerKeys) { let v = this._resultElement.extraResults[h]; if (typeof (v) === "number") - v = v.toFixed(this.appSetupService.displayDigits); + v = this.intlService.formatResult(h, v); this.vcRef.createEmbeddedView(this.tdTemplate, { extraResultValue: v }); } } diff --git a/src/app/components/result-element/vertical-result-element.component.ts b/src/app/components/result-element/vertical-result-element.component.ts index 209f357b5..53fff9965 100644 --- a/src/app/components/result-element/vertical-result-element.component.ts +++ b/src/app/components/result-element/vertical-result-element.component.ts @@ -48,15 +48,13 @@ export class VerticalResultElementComponent extends ResultElementBaseComponent { this.vcRef.clear(); if (this._resultElement) { - const nDigits = this.appSetupService.displayDigits; - let i = 0; for (const k in this._resultElement.extraResults) { const er: number = this._resultElement.extraResults[k]; const lblClass = (i % 2) == 0 ? "label1" : "label2"; const valueClass = (i % 2) == 0 ? "value1" : "value2"; this.vcRef.createEmbeddedView(this.trTemplate, { - extraRes: { "label": this.intlService.translate(k), "value": er.toFixed(nDigits) }, + extraRes: { "label": this.intlService.translateLabel(k), "value": this.intlService.formatResult(k, er) }, classes: { "label_class": lblClass, "value_class": valueClass } }); i++; diff --git a/src/app/results/var-results.ts b/src/app/results/var-results.ts index c03b8c510..72cec0561 100644 --- a/src/app/results/var-results.ts +++ b/src/app/results/var-results.ts @@ -136,6 +136,6 @@ export class VarResults extends CalculatedParamResults { const intlService = ServiceFactory.instance.internationalisationService; for (const k of this._extraResultKeys) - this._extraResultHeaders.push(intlService.translate(k)); + this._extraResultHeaders.push(intlService.translateLabel(k)); } } diff --git a/src/app/services/internationalisation/internationalisation.service.ts b/src/app/services/internationalisation/internationalisation.service.ts index a0878d77c..eac0383b5 100644 --- a/src/app/services/internationalisation/internationalisation.service.ts +++ b/src/app/services/internationalisation/internationalisation.service.ts @@ -5,6 +5,7 @@ import { Message, MessageCode, Observable } from "jalhyd"; import { HttpService } from "../http/http.service"; import { StringMap } from "../../stringmap"; +import { ServiceFactory } from '../service-factory'; /* language tag : fr-FR @@ -167,7 +168,18 @@ export class InternationalisationService extends Observable { return this._Messages[code]; } - public translate(o: any) { + /** + * analyse un libellé du type ouvrage[n].XX + */ + private parseLabel(lbl: string) { + const re = /([A-Z,a-z]+)\[(\d+)\]\.(.+)/; + return re.exec(lbl); + } + + /** + * traduit un libellé qui peut être un code + */ + public translateLabel(o: any) { let res; if (typeof o === "string") { switch (o) { @@ -180,9 +192,7 @@ export class InternationalisationService extends Observable { break; default: - // const re = new RegExp("([A-Z,a-z]+)\[(\\d+\)]\\.(.+)"); - const re = /([A-Z,a-z]+)\[(\d+)\]\.(.+)/; - const match = re.exec(o); + const match = this.parseLabel(o); if (match) if (match[1] === "ouvrage") res = this.localizeText("INFO_OUVRAGE") + " n°" + (+match[2] + 1); @@ -206,4 +216,45 @@ export class InternationalisationService extends Observable { } return res; } + + /** + * met en forme ou traduit un résultat en fonction du libellé qui l'accompagne + */ + 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`); + } + + } + } + + const appSetupService = ServiceFactory.instance.applicationSetupService; + const nDigits = appSetupService.displayDigits; + return value.toFixed(nDigits); + } } diff --git a/src/locale/error_messages.en.json b/src/locale/error_messages.en.json index 27500a7d6..f010427d9 100644 --- a/src/locale/error_messages.en.json +++ b/src/locale/error_messages.en.json @@ -85,5 +85,12 @@ "INFO_OUVRAGEPARAL_TITRE": "Parallel structures", "INFO_OUVRAGE": "Structure", "INFO_TYPE_ECOULEMENT": "Mode", - "INFO_REGIME": "Regime" + "INFO_REGIME": "Regime", + "INFO_LIB_ENUM_RES_STRUCTURE_MODE_0": "Weir", + "INFO_LIB_ENUM_RES_STRUCTURE_MODE_1": "Orifice", + "INFO_LIB_ENUM_RES_STRUCTURE_MODE_2": "Zero flow", + "INFO_LIB_ENUM_RES_STRUCTURE_REGIME_0": "Free flow", + "INFO_LIB_ENUM_RES_STRUCTURE_REGIME_1": "Partially submerged", + "INFO_LIB_ENUM_RES_STRUCTURE_REGIME_2": "Submerged", + "INFO_LIB_ENUM_RES_STRUCTURE_REGIME_3": "Zero flow" } \ No newline at end of file diff --git a/src/locale/error_messages.fr.json b/src/locale/error_messages.fr.json index d0fa6e61f..69c3b8f87 100644 --- a/src/locale/error_messages.fr.json +++ b/src/locale/error_messages.fr.json @@ -93,5 +93,12 @@ "INFO_TYPE_ECOULEMENT": "Type d'écoulement", "INFO_REGIME": "Régime", "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" + "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" } \ No newline at end of file -- GitLab