From e7d9bd950cd60a7c2b52e69e4dc191150eeb63f7 Mon Sep 17 00:00:00 2001
From: "mathias.chouet" <mathias.chouet@irstea.fr>
Date: Thu, 13 Jun 2019 16:12:24 +0200
Subject: [PATCH] Pab : traduction

---
 src/app/calculators/pab/pab.en.json           |  8 +-
 src/app/calculators/pab/pab.fr.json           |  2 +
 .../pab-table/pab-table.component.html        |  5 +-
 .../pab-table/pab-table.component.ts          | 76 ++++++++++---------
 .../internationalisation.service.ts           | 10 ++-
 src/locale/messages.en.json                   | 23 ++++++
 src/locale/messages.fr.json                   | 23 ++++++
 7 files changed, 103 insertions(+), 44 deletions(-)

diff --git a/src/app/calculators/pab/pab.en.json b/src/app/calculators/pab/pab.en.json
index 54434a65a..56e4550ab 100644
--- a/src/app/calculators/pab/pab.en.json
+++ b/src/app/calculators/pab/pab.en.json
@@ -3,9 +3,9 @@
     "Q": "Flow",
     "Z1": "Upstream elevation",
     "Z2": "Downstream elevation",
-    "LB": "Longueur du bassin",
-    "BB": "Largeur du bassin",
-    "PB": "Profondeur moyenne du bassin",
+    "LB": "Basin length",
+    "BB": "Basin width",
+    "PB": "Basin mean depth",
     "W": "Gate opening",
     "ZRAM": "Bottom elevation",
     "ZRMB": "Mid-basin elevation",
@@ -15,6 +15,8 @@
     "bassin_container": "Basins",
     "select_modele_cloisons": "Cross walls model",
     "select_modele_cloison_aval": "Downstream wall model",
+    "UNIT_LB": "m",
+    "UNIT_BB": "m",
     "UNIT_DH": "m",
 	"UNIT_PV": "W/m³",
     "UNIT_Q": "m³/s",
diff --git a/src/app/calculators/pab/pab.fr.json b/src/app/calculators/pab/pab.fr.json
index f0b6ba086..bd691a552 100644
--- a/src/app/calculators/pab/pab.fr.json
+++ b/src/app/calculators/pab/pab.fr.json
@@ -15,6 +15,8 @@
     "bassin_container": "Bassins",
     "select_modele_cloisons": "Modèle de cloisons",
     "select_modele_cloison_aval": "Modèle de la cloison aval",
+    "UNIT_LB": "m",
+    "UNIT_BB": "m",
     "UNIT_DH": "m",
 	"UNIT_PV": "W/m³",
     "UNIT_Q": "m³/s",
diff --git a/src/app/components/pab-table/pab-table.component.html b/src/app/components/pab-table/pab-table.component.html
index 4ad104839..bdd4f919b 100644
--- a/src/app/components/pab-table/pab-table.component.html
+++ b/src/app/components/pab-table/pab-table.component.html
@@ -6,8 +6,6 @@
 
 <mat-card-content>
 
-    <!-- <button (click)="zpouet()">CLIKZYVOIR</button> -->
-
     <div id="pab-table-toolbar">
         <button type="button" id="edit-pab-table" mat-raised-button color="accent"
           [disabled]="! enableEditPabButton" (click)="showEditPab()">
@@ -76,7 +74,8 @@
                   [ngClass]="cell.class"
                   [class.editable-cell]="hasModel(cell)" [class.readonly-cell]="! hasModel(cell)"
                   [class.selectable-cell]="isSelectable(cell)" [class.selected-cell]="isSelected(cell) && ! isSelected(row)"
-                  [attr.rowspan]="rowSpan(cell)" [attr.colspan]="colSpan(cell)">
+                  [attr.rowspan]="rowSpan(cell)" [attr.colspan]="colSpan(cell)"
+                  [title]="cellTitle(cell)">
 
                     <input matInput *ngIf="isNumberInput(cell)" type="number" [(ngModel)]="cell.model.singleValue">
 
diff --git a/src/app/components/pab-table/pab-table.component.ts b/src/app/components/pab-table/pab-table.component.ts
index c70b83a2b..6ba74e562 100644
--- a/src/app/components/pab-table/pab-table.component.ts
+++ b/src/app/components/pab-table/pab-table.component.ts
@@ -116,6 +116,15 @@ export class PabTableComponent implements /* DoCheck, AfterViewInit, */ OnInit {
         }
     }
 
+    /** "title" tooltip to display in a cell */
+    public cellTitle(cell: any) {
+        if (cell !== undefined && cell.title !== undefined) {
+            return cell.title;
+        } else {
+            return "";
+        }
+    }
+
     public rowSpan(cell: any) {
         if (cell !== undefined && cell.rowspan) {
             return cell.rowspan;
@@ -250,7 +259,6 @@ export class PabTableComponent implements /* DoCheck, AfterViewInit, */ OnInit {
             // clean list
             this.selectedItems = this.selectedItems.filter(e => e !== undefined);
 
-            // @TODO useful ?
             $event.preventDefault();
             $event.stopPropagation();
             return false;
@@ -276,24 +284,6 @@ export class PabTableComponent implements /* DoCheck, AfterViewInit, */ OnInit {
         return Array(20).fill(0).map((value, index) => index + 1);
     }
 
-    // DEBUG
-    private dumpParams(n: Nub) {
-        console.log(`---- PARAMETERS FOR NUB "${n.uid}" (${n.constructor.name}) ----`);
-        for (const p of n.parameterIterator) {
-            if (p.visible) {
-                console.log(`> ${p.symbol} : ${p.singleValue}, ${p.currentValue}, ${p.v}`);
-            }
-        }
-    }
-
-    public zpouet() {
-        console.log("!!!------------ zpoueeeeeeeeet ------------!!!");
-        for (const c of this.model.children) {
-            this.dumpParams(c);
-        }
-        this.dumpParams(this.model.downWall);
-    }
-
     // at this time @Input data is supposed to be already populated
     public ngOnInit() {
         this.model = this.pabTable.pab;
@@ -312,14 +302,14 @@ export class PabTableComponent implements /* DoCheck, AfterViewInit, */ OnInit {
         let bs: any[] = this.model.children;
         bs = bs.concat(this.model.downWall);
         this.headers.push({
-            title: "Bassin",
+            title: this.i18nService.localizeText("INFO_PAB_BASSIN"),
             colspan: 6,
             selectable: bs
         });
         // 1 header for each device of the wall having the most devices (including downwall)
         for (let i = 0; i < maxNbDevices; i++) {
             this.headers.push({
-                title: "Cloison : ouvrage n°" + (i + 1),
+                title: sprintf(this.i18nService.localizeText("INFO_PAB_CLOISON_OUVRAGE_N"), (i + 1)),
                 colspan: 3,
                 selectable: this.model.children.map(c => c.getChildren()[i]).concat(this.model.downWall.getChildren()[i]),
                 selectableColumn: i
@@ -330,44 +320,44 @@ export class PabTableComponent implements /* DoCheck, AfterViewInit, */ OnInit {
         this.cols = [];
         // 6 cols for basin
         this.cols.push({
-            title: "N° de bassin",
+            title: this.i18nService.localizeText("INFO_PAB_NUM_BASSIN"),
             selectable: bs
         });
         this.cols.push({
-            title: "Longueur",
+            title: this.formService.expandVariableNameAndUnit(CalculatorType.Pab, "LB"),
             selectable: bs
         });
         this.cols.push({
-            title: "Largeur",
+            title: this.formService.expandVariableNameAndUnit(CalculatorType.Pab, "BB"),
             selectable: bs
         });
         this.cols.push({
-            title: "Débit d'attrait",
+            title: this.formService.expandVariableNameAndUnit(CalculatorType.Pab, "QA"),
             selectable: bs
         });
         this.cols.push({
-            title: "Cote radier mi-bassin",
+            title: this.formService.expandVariableNameAndUnit(CalculatorType.Pab, "ZRMB"),
             selectable: bs
         });
         this.cols.push({
-            title: "Cote radier amont paroi",
+            title: this.formService.expandVariableNameAndUnit(CalculatorType.Pab, "ZRAM"),
             selectable: bs
         });
         // no col for wall type (defined by rowspan-2 header above)
         // 3 cols for each device of the wall having the most devices (including downwall)
         for (let i = 0; i < maxNbDevices; i++) {
             this.cols.push({
-                title: "Type",
+                title: this.i18nService.localizeText("INFO_PAB_HEADER_TYPE"),
                 selectable: this.model.children.map(c => c.getChildren()[i]).concat(this.model.downWall.getChildren()[i]),
                 selectableColumn: i
             });
             this.cols.push({
-                title: "Paramètres",
+                title: this.i18nService.localizeText("INFO_PAB_HEADER_PARAMETERS"),
                 selectable: this.model.children.map(c => c.getChildren()[i]).concat(this.model.downWall.getChildren()[i]),
                 selectableColumn: i
             });
             this.cols.push({
-                title: "Valeurs",
+                title: this.i18nService.localizeText("INFO_PAB_HEADER_VALUES"),
                 selectable: this.model.children.map(c => c.getChildren()[i]).concat(this.model.downWall.getChildren()[i]),
                 selectableColumn: i
             });
@@ -381,7 +371,7 @@ export class PabTableComponent implements /* DoCheck, AfterViewInit, */ OnInit {
             // admissible LoiDebit
             const loisCloisons = cloison.getLoisAdmissiblesArray().map(l => { // @TODO move up ? (same for all cloisons)
                 return {
-                    label: LoiDebit[l],
+                    label: this.i18nService.localizeLoiDebit(l),
                     value: l
                 };
             });
@@ -411,6 +401,7 @@ export class PabTableComponent implements /* DoCheck, AfterViewInit, */ OnInit {
                 // device param cells : 3 cells for each device
                 for (const ouvrage of cloison.structures) {
                     const nvParam = ouvrage.getNthVisibleParam(i);
+                    const nvParamTitle = nvParam ? this.formService.expandVariableNameAndUnit(CalculatorType.Pab, nvParam.symbol) : "";
                     // cell 1 : device type
                     if (i === 0) { // 1st row
                         deviceParamRow.cells.push({
@@ -431,6 +422,7 @@ export class PabTableComponent implements /* DoCheck, AfterViewInit, */ OnInit {
                     if (nvParam) {
                         deviceParamRow.cells.push({
                             value: nvParam.symbol,
+                            title: nvParamTitle,
                             selectable: ouvrage
                         });
                     } else {
@@ -442,6 +434,7 @@ export class PabTableComponent implements /* DoCheck, AfterViewInit, */ OnInit {
                     if (nvParam) {
                         deviceParamRow.cells.push({
                             model: nvParam,
+                            title: nvParamTitle,
                             selectable: ouvrage
                         });
                     } else {
@@ -471,19 +464,24 @@ export class PabTableComponent implements /* DoCheck, AfterViewInit, */ OnInit {
                 cells: [
                     // no cell for basin number (defined by rowspan-n cell above)
                     {
-                        model: cloison.prms.LB
+                        model: cloison.prms.LB,
+                        title: this.formService.expandVariableNameAndUnit(CalculatorType.Pab, "LB")
                     },
                     {
-                        model: cloison.prms.BB
+                        model: cloison.prms.BB,
+                        title: this.formService.expandVariableNameAndUnit(CalculatorType.Pab, "BB")
                     },
                     {
-                        model: cloison.prms.QA
+                        model: cloison.prms.QA,
+                        title: this.formService.expandVariableNameAndUnit(CalculatorType.Pab, "QA")
                     },
                     {
-                        model: cloison.prms.ZRMB
+                        model: cloison.prms.ZRMB,
+                        title: this.formService.expandVariableNameAndUnit(CalculatorType.Pab, "ZRMB")
                     },
                     {
-                        model: cloison.prms.ZRAM
+                        model: cloison.prms.ZRAM,
+                        title: this.formService.expandVariableNameAndUnit(CalculatorType.Pab, "ZRAM")
                     }
                 ]
             };
@@ -502,7 +500,7 @@ export class PabTableComponent implements /* DoCheck, AfterViewInit, */ OnInit {
         // admissible LoiDebit
         const loisAval = this.model.downWall.getLoisAdmissiblesArray().map(l => {
             return {
-                label: LoiDebit[l],
+                label: this.i18nService.localizeLoiDebit(l),
                 value: l
             };
         });
@@ -531,6 +529,7 @@ export class PabTableComponent implements /* DoCheck, AfterViewInit, */ OnInit {
             // downwall device param cells : 3 cells for each device
             for (const ouvrage of this.model.downWall.structures) {
                 const nvParam = ouvrage.getNthVisibleParam(i);
+                const nvParamTitle = nvParam ? this.formService.expandVariableNameAndUnit(CalculatorType.Pab, nvParam.symbol) : "";
                 // cell 1 : device type
                 if (i === 0) { // 1st row
                     deviceParamRowDW.cells.push({
@@ -550,6 +549,7 @@ export class PabTableComponent implements /* DoCheck, AfterViewInit, */ OnInit {
                 if (nvParam) {
                     deviceParamRowDW.cells.push({
                         value: nvParam.symbol,
+                        title: nvParamTitle,
                         selectable: ouvrage
                     });
                 } else {
@@ -561,6 +561,7 @@ export class PabTableComponent implements /* DoCheck, AfterViewInit, */ OnInit {
                 if (nvParam) {
                     deviceParamRowDW.cells.push({
                         model: nvParam,
+                        title: nvParamTitle,
                         selectable: ouvrage
                     });
                 } else {
@@ -853,6 +854,7 @@ export class PabTableComponent implements /* DoCheck, AfterViewInit, */ OnInit {
         } else {
             this.notifService.notify(sprintf(this.i18nService.localizeText("INFO_WALL_REMOVED"), pos));
         }
+        this.selectedItems = [];
         this.refresh();
     }
 
diff --git a/src/app/services/internationalisation/internationalisation.service.ts b/src/app/services/internationalisation/internationalisation.service.ts
index bd560fae2..f95bcc9ba 100644
--- a/src/app/services/internationalisation/internationalisation.service.ts
+++ b/src/app/services/internationalisation/internationalisation.service.ts
@@ -1,6 +1,6 @@
 import { Injectable, isDevMode } from "@angular/core";
 
-import { Message, MessageCode, Observable, Observer, CalculatorType } from "jalhyd";
+import { Message, MessageCode, Observable, Observer, CalculatorType, LoiDebit } from "jalhyd";
 
 import { StringMap } from "../../stringmap";
 import { ApplicationSetupService } from "../app-setup/app-setup.service";
@@ -173,6 +173,14 @@ export class I18nService extends Observable implements Observer {
         return m;
     }
 
+    /**
+     * Finds the localized title for a LoiDebit item
+     * @TODO add StructureType context ? (ex: cem88d / cem88v)
+     */
+    public localizeLoiDebit(l: LoiDebit) {
+        return this.localizeText("INFO_LOIDEBIT_" + LoiDebit[l]);
+    }
+
     private replaceAll(str: string, find: string, replace: string) {
         return str.replace(new RegExp(find, "g"), replace);
     }
diff --git a/src/locale/messages.en.json b/src/locale/messages.en.json
index ee5a7fd05..04826c092 100644
--- a/src/locale/messages.en.json
+++ b/src/locale/messages.en.json
@@ -184,6 +184,23 @@
     "INFO_LINKED_VALUE_RESULT": "%s (%s)",
     "INFO_LINKED_VALUE_SECTION_RESULT": "%s (%s, section)",
     "INFO_LINKED_VALUE_SECTION": "%s (%s, section)",
+    "INFO_LOIDEBIT_KIVI": "Kindsvater-Carter and Villemonte",
+    "INFO_LOIDEBIT_CloisonsKIVI": "Kindsvater-Carter and Villemonte",
+    "INFO_LOIDEBIT_WeirSubmergedLarinier": "Submerged slot (Larinier 1992)",
+    "INFO_LOIDEBIT_CloisonsWeirSubmergedLarinier": "Submerged slot (Larinier 1992)",
+    "INFO_LOIDEBIT_OrificeSubmerged": "Submerged orifice",
+    "INFO_LOIDEBIT_TriangularWeirFree": "Free flow triangular weir",
+    "INFO_LOIDEBIT_CloisonsTriangularWeirFree": "Free flow triangular weir",
+    "INFO_LOIDEBIT_TriangularTruncWeirFree": "Free flow truncated triangular weir",
+    "INFO_LOIDEBIT_CloisonsTriangularTruncWeirFree": "Free flow truncated triangular weir",
+    "INFO_LOIDEBIT_GateCem88d": "Weir/Orifice Cemagref 88",
+    "INFO_LOIDEBIT_GateCem88v": "Weir/Undershot gate Cemagref 88",
+    "INFO_LOIDEBIT_WeirCem88d": "Weir/Orifice Cemagref 88",
+    "INFO_LOIDEBIT_WeirCem88v": "Weir/Undershot gate Cemagref 88",
+    "INFO_LOIDEBIT_Cunge80": "Cunge 80",
+    "INFO_LOIDEBIT_RectangularOrificeFree": "Free flow gate",
+    "INFO_LOIDEBIT_RectangularOrificeSubmerged": "Submerged gate",
+    "INFO_LOIDEBIT_WeirFree": "Free flow weir",
     "INFO_MACRORUGO_TITRE_COURT": "Rock-ramp",
     "INFO_MACRORUGO_TITRE": "Rock-ramp fishpasses",
     "INFO_MENU_EMPTY_SESSION_TITLE": "New session",
@@ -209,6 +226,12 @@
     "INFO_OPTION_VALIDATE": "Validate",
     "INFO_OPTION_YES": "Yes",
     "INFO_OUVRAGE": "Structure",
+    "INFO_PAB_BASSIN": "Basin",
+    "INFO_PAB_NUM_BASSIN": "Basin #",
+    "INFO_PAB_HEADER_TYPE": "Type",
+    "INFO_PAB_HEADER_PARAMETERS": "Parameters",
+    "INFO_PAB_HEADER_VALUES": "Values",
+    "INFO_PAB_CLOISON_OUVRAGE_N": "Wall : device #%s",
     "INFO_PAB_TITRE_COURT": "Fish ladder",
     "INFO_PAB_TITRE": "Fish ladder",
     "INFO_PAB_TABLE": "Fish ladder geometry",
diff --git a/src/locale/messages.fr.json b/src/locale/messages.fr.json
index 095711c8c..98784bb6b 100644
--- a/src/locale/messages.fr.json
+++ b/src/locale/messages.fr.json
@@ -184,6 +184,23 @@
     "INFO_LINKED_VALUE_RESULT": "%s (%s)",
     "INFO_LINKED_VALUE_SECTION_RESULT": "%s (%s, section)",
     "INFO_LINKED_VALUE_SECTION": "%s (%s, section)",
+    "INFO_LOIDEBIT_KIVI": "Kindsvater-Carter et Villemonte",
+    "INFO_LOIDEBIT_CloisonsKIVI": "Kindsvater-Carter et Villemonte",
+    "INFO_LOIDEBIT_WeirSubmergedLarinier": "Fente noyée (Larinier 1992)",
+    "INFO_LOIDEBIT_CloisonsWeirSubmergedLarinier": "Fente noyée (Larinier 1992)",
+    "INFO_LOIDEBIT_OrificeSubmerged": "Orifice noyé",
+    "INFO_LOIDEBIT_TriangularWeirFree": "Déversoir triangulaire dénoyé",
+    "INFO_LOIDEBIT_CloisonsTriangularWeirFree": "Déversoir triangulaire dénoyé",
+    "INFO_LOIDEBIT_TriangularTruncWeirFree": "Déversoir triangulaire tronqué dénoyé",
+    "INFO_LOIDEBIT_CloisonsTriangularTruncWeirFree": "Déversoir triangulaire tronqué dénoyé",
+    "INFO_LOIDEBIT_GateCem88d": "Déversoir/Orifice Cemagref 88",
+    "INFO_LOIDEBIT_GateCem88v": "Déversoir/Vanne de fond Cemagref 88",
+    "INFO_LOIDEBIT_WeirCem88d": "Déversoir/Orifice Cemagref 88",
+    "INFO_LOIDEBIT_WeirCem88v": "Déversoir/Vanne de fond Cemagref 88",
+    "INFO_LOIDEBIT_Cunge80": "Cunge 80",
+    "INFO_LOIDEBIT_RectangularOrificeFree": "Vanne dénoyé",
+    "INFO_LOIDEBIT_RectangularOrificeSubmerged": "Vanne noyé",
+    "INFO_LOIDEBIT_WeirFree": "Seuil dénoyé",
     "INFO_MACRORUGO_TITRE_COURT": "Macro-rugo.",
     "INFO_MACRORUGO_TITRE": "Passe à macro-rugosités",
     "INFO_MENU_EMPTY_SESSION_TITLE": "Nouvelle session",
@@ -209,6 +226,12 @@
     "INFO_OPTION_VALIDATE": "Valider",
     "INFO_OPTION_YES": "Oui",
     "INFO_OUVRAGE": "Ouvrage",
+    "INFO_PAB_BASSIN": "Bassin",
+    "INFO_PAB_NUM_BASSIN": "N° de bassin",
+    "INFO_PAB_HEADER_TYPE": "Type",
+    "INFO_PAB_HEADER_PARAMETERS": "Paramètres",
+    "INFO_PAB_HEADER_VALUES": "Valeurs",
+    "INFO_PAB_CLOISON_OUVRAGE_N": "Cloison : ouvrage n° %s",
     "INFO_PAB_TITRE_COURT": "PAB",
     "INFO_PAB_TITRE": "Passe à bassins",
     "INFO_PAB_TABLE": "Géométrie de la passe",
-- 
GitLab