From 2927d17bed217f056a9f5eeee9d573e1bbfd6a13 Mon Sep 17 00:00:00 2001
From: naji <naji@cines.fr>
Date: Wed, 9 Mar 2022 08:36:52 +0100
Subject: [PATCH] traduction

---
 .../file-tree-metadata.component.ts           |  1 +
 .../add-pua-control.component.ts              | 40 +++++++++++++++----
 .../projects/pastis/src/assets/i18n/en.json   | 11 ++++-
 .../projects/pastis/src/assets/i18n/fr.json   | 11 ++++-
 4 files changed, 54 insertions(+), 9 deletions(-)

diff --git a/ui/ui-frontend/projects/pastis/src/app/profile/edit-profile/file-tree-metadata/file-tree-metadata.component.ts b/ui/ui-frontend/projects/pastis/src/app/profile/edit-profile/file-tree-metadata/file-tree-metadata.component.ts
index 8615a9632..ed6fdfbaf 100644
--- a/ui/ui-frontend/projects/pastis/src/app/profile/edit-profile/file-tree-metadata/file-tree-metadata.component.ts
+++ b/ui/ui-frontend/projects/pastis/src/app/profile/edit-profile/file-tree-metadata/file-tree-metadata.component.ts
@@ -80,6 +80,7 @@ function constantToTranslate() {
   this.popupSousTitre = this.translated('.POPUP_SOUS_TITRE');
   this.popupValider = this.translated('.POPUP_VALIDER');
   this.popupAnnuler = this.translated('.POPUP_ANNULER');
+  this.popupControlOkLabel = this.translated('.POPUP_CONTROL_OK_BUTTON_LABEL');
 }
 
 @Component({
diff --git a/ui/ui-frontend/projects/pastis/src/app/user-actions/add-pua-control/add-pua-control.component.ts b/ui/ui-frontend/projects/pastis/src/app/user-actions/add-pua-control/add-pua-control.component.ts
index d9b7dd20e..ca81db210 100644
--- a/ui/ui-frontend/projects/pastis/src/app/user-actions/add-pua-control/add-pua-control.component.ts
+++ b/ui/ui-frontend/projects/pastis/src/app/user-actions/add-pua-control/add-pua-control.component.ts
@@ -36,11 +36,25 @@ The fact that you are presently reading this means that you have had
 knowledge of the CeCILL-C license and that you accept its terms.
 */
 import { Component, OnInit } from '@angular/core';
-import { SedaData } from '../../models/seda-data';
 import { MatDialogRef } from '@angular/material/dialog';
 import { PastisDialogConfirmComponent } from '../../shared/pastis-dialog/pastis-dialog-confirm/pastis-dialog-confirm.component';
 import { PastisDialogData } from '../../shared/pastis-dialog/classes/pastis-dialog-data';
 import { PopupService } from '../../core/services/popup.service';
+import { environment } from 'projects/pastis/src/environments/environment';
+import { LangChangeEvent, TranslateService } from '@ngx-translate/core';
+
+
+const ADD_PUA_CONTROL_TRANSLATE_PATH = 'USER_ACTION.ADD_PUA_CONTROL';
+
+function constantToTranslate() {
+  this.enumerationsLabel = this.translated('.ENUMERATIONS_LABEL');
+  this.expressionReguliereLabel = this.translated('.EXPRESSION_REGULIERE_LABEL');
+  this.lengthMinMaxLabel = this.translated('.LENGTH_MIN_MAX_LABEL');
+  this.valueMinMaxLabel = this.translated('.VALUE_MIN_MAX_LABEL');
+  this.enumerationsDefinition = this.translated('.ENUMERATIONS_DEFINITION');
+  this.expressionReguliereDefinition = this.translated('.EXPRESSION_REGULIERE_DEFINITION');
+}
+
 
 @Component({
   selector: 'pastis-user-action-add-metadata',
@@ -50,8 +64,6 @@ import { PopupService } from '../../core/services/popup.service';
 export class UserActionAddPuaControlComponent implements OnInit {
 
   btnIsDisabled: boolean;
-
-  sedaData: SedaData;
   enumerationsLabel: string = "Enumération";
   expressionReguliereLabel: string = "Expression régulière";
   lengthMinMaxLabel: string = "Longueur Min/Max";
@@ -63,10 +75,15 @@ export class UserActionAddPuaControlComponent implements OnInit {
   dialogData: PastisDialogData;
 
   atLeastOneIsSelected: boolean;
+  isStandalone: boolean = environment.standalone;
 
 
   constructor(public dialogRef: MatDialogRef<PastisDialogConfirmComponent>,
-    private popUpService: PopupService) {
+    private popUpService: PopupService, private translateService: TranslateService) {
+      if(!this.isStandalone){
+        constantToTranslate.call(this);
+        this.translatedOnChange();
+      }
       this.refreshAllowedChildren();
     }
 
@@ -117,9 +134,6 @@ export class UserActionAddPuaControlComponent implements OnInit {
     return '';
   }
 
-  ngOnDestroy(): void {
-  }
-
   isExclusive(element: string): boolean{
     return element === this.valueMinMaxLabel || element === this.enumerationsLabel;
   }
@@ -140,4 +154,16 @@ export class UserActionAddPuaControlComponent implements OnInit {
     }
   }
 
+  translatedOnChange(): void {
+    this.translateService.onLangChange
+      .subscribe((event: LangChangeEvent) => {
+        constantToTranslate.call(this);
+        console.log(event.lang);
+      });
+  }
+
+  translated(nameOfFieldToTranslate: string): string {
+    return this.translateService.instant(ADD_PUA_CONTROL_TRANSLATE_PATH + nameOfFieldToTranslate);
+  }
+
 }
diff --git a/ui/ui-frontend/projects/pastis/src/assets/i18n/en.json b/ui/ui-frontend/projects/pastis/src/assets/i18n/en.json
index 7d701f8c2..a10de77cc 100644
--- a/ui/ui-frontend/projects/pastis/src/assets/i18n/en.json
+++ b/ui/ui-frontend/projects/pastis/src/assets/i18n/en.json
@@ -182,7 +182,8 @@
           "NOM_ATTRIBUT": "Attribute name",
           "VALEUR_FIXE": "Fixed value",
           "COMMENTAIRE": "Comment"
-        }
+        },
+        "POPUP_CONTROL_OK_BUTTON_LABEL": "ADD CONTROLS"
       }
     },
     "LIST_PROFILE": {
@@ -214,6 +215,14 @@
       "METADATA_ADD": "The metadata to add",
       "BOUTON_AJOUTER": "Add",
       "MESSAGE_PLUS_METADONNEE": "There is no more metadata to add"
+    },
+    "ADD_PUA_CONTROL": {
+      "ENUMERATIONS_LABEL": "Enumeration",
+      "EXPRESSION_REGULIERE_LABEL": "Regular expression",
+      "LENGTH_MIN_MAX_LABEL": "Length Min/Max",
+      "VALUE_MIN_MAX_LABEL": "Value Min/Max",
+      "ENUMERATIONS_DEFINITION": "Report allowed values",
+      "EXPRESSION_REGULIERE_DEFINITION": "Define a regular expression for the metadata value"
     }
   },
   "COMMON": {
diff --git a/ui/ui-frontend/projects/pastis/src/assets/i18n/fr.json b/ui/ui-frontend/projects/pastis/src/assets/i18n/fr.json
index 03151e5ae..490100c5a 100644
--- a/ui/ui-frontend/projects/pastis/src/assets/i18n/fr.json
+++ b/ui/ui-frontend/projects/pastis/src/assets/i18n/fr.json
@@ -182,7 +182,8 @@
           "NOM_ATTRIBUT": "Nom de l'attribut",
           "VALEUR_FIXE": "Valeur fixe",
           "COMMENTAIRE": "Commentaire"
-        }
+        },
+        "POPUP_CONTROL_OK_BUTTON_LABEL": "AJOUTER LES CONTROLES"
       }
     },
     "LIST_PROFILE": {
@@ -214,6 +215,14 @@
       "METADATA_ADD": "Les métadonnées à ajouter",
       "BOUTON_AJOUTER": "Ajouter",
       "MESSAGE_PLUS_METADONNEE": "Il n'y a plus de métadonnées à ajouter"
+    },
+    "ADD_PUA_CONTROL": {
+      "ENUMERATIONS_LABEL": "Enumération",
+      "EXPRESSION_REGULIERE_LABEL": "Expression régulière",
+      "LENGTH_MIN_MAX_LABEL": "Longueur Min/Max",
+      "VALUE_MIN_MAX_LABEL": "Valeur Min/Max",
+      "ENUMERATIONS_DEFINITION": "Signaler les valeurs autorisées",
+      "EXPRESSION_REGULIERE_DEFINITION": "Définir une expression régulière pour la valeur de la métadonnée"
     }
   },
   "COMMON": {
-- 
GitLab