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 0925d424692886a28c8d6984a30babb217e88d3c..48b269ce9d3a3c227641d7bea716cdfd072dda33 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 209f357b5f0f1f96c650f9cd9e5f8a98d2fc28e7..53fff99656de4a8e04de9b02562dac6bf7d28a7a 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 c03b8c5104c450533f6f5b8d3528d9d640da719f..72cec056145ed3fd1bb79984b56419704c422dfd 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 a0878d77cd7c087ba09c5e2ffebb10a2c0e3a576..eac0383b50c593067b59644388c270f838ff9de5 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 27500a7d68dd672a5752ef35eb824c0a19b1340e..f010427d9b99184f4cb50a6616c3fb84cfa07578 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 d0fa6e61fb32081e1e15b56619e2a936c6bf40ba..69c3b8f87818a462c62e51496a1492691a69e19f 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