From a924fbbe2691add7ab2cfa5b2613313ee1446a4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Grand?= <francois.grand@inrae.fr> Date: Wed, 31 May 2023 13:53:01 +0200 Subject: [PATCH] refactor: convert (some of the) enums used in translations refs #621 --- .../services/internationalisation.service.ts | 17 ++++++++++- src/locale/messages.en.json | 30 +++++++++---------- src/locale/messages.fr.json | 30 +++++++++---------- 3 files changed, 46 insertions(+), 31 deletions(-) diff --git a/src/app/services/internationalisation.service.ts b/src/app/services/internationalisation.service.ts index deee494fe..95895d47d 100644 --- a/src/app/services/internationalisation.service.ts +++ b/src/app/services/internationalisation.service.ts @@ -1,6 +1,6 @@ import { Injectable, isDevMode } from "@angular/core"; -import { Message, MessageCode, Observable, Observer, Nub, CalculatorType, PreBarrage, PbCloison, PbBassin } from "jalhyd"; +import { Message, MessageCode, Observable, Observer, Nub, CalculatorType, PreBarrage, PbCloison, PbBassin, enumValueFromString } from "jalhyd"; import { StringMap } from "../stringmap"; import { ApplicationSetupService } from "./app-setup.service"; @@ -165,6 +165,21 @@ export class I18nService extends Observable implements Observer { if (! this._Messages) { return `*** messages not loaded: ${this._currentLanguage} ***`; } + + // key is an enum ? + if (textKey.indexOf("INFO_ENUM_") !== -1) { + // key ends with a number ? + const re = /^((INFO_ENUM)_(.+)_)([0-9]+)$/; + const res = textKey.match(re); + if (res !== null) { + // convert end number to enum symbolic value + const enumClass = res[3]; + const value = res[4]; + const val = enumValueFromString(enumClass, value); + textKey = res[1] + val; + } + } + if (this._Messages[textKey] !== undefined) { return this.translateMessage(this._Messages[textKey], vars); } else { diff --git a/src/locale/messages.en.json b/src/locale/messages.en.json index de71e8bbb..98aaefe3e 100755 --- a/src/locale/messages.en.json +++ b/src/locale/messages.en.json @@ -156,9 +156,9 @@ "INFO_DIALOG_SAVE_SESSION_TITLE": "Save calculator modules", "INFO_EMPTY_SESSION_DIALOGUE_TEXT": "Warning ! All open calculators will be lost. Continue ?", "INFO_EMPTY_SESSION_DIALOGUE_TITRE": "New session", - "INFO_ENUM_MACRORUGOFLOWTYPE_0": "Emergent", - "INFO_ENUM_MACRORUGOFLOWTYPE_1": "Quasi-emergent", - "INFO_ENUM_MACRORUGOFLOWTYPE_2": "Submerged", + "INFO_ENUM_MACRORUGOFLOWTYPE_EMERGENT": "Emergent", + "INFO_ENUM_MACRORUGOFLOWTYPE_QUASI_EMERGENT": "Quasi-emergent", + "INFO_ENUM_MACRORUGOFLOWTYPE_SUBMERGED": "Submerged", "INFO_ENUM_OUVRAGE_Q_MODE_0": "Weir", "INFO_ENUM_OUVRAGE_Q_MODE_1": "Orifice", "INFO_ENUM_OUVRAGE_Q_MODE_2": "Zero flow", @@ -166,8 +166,8 @@ "INFO_ENUM_OUVRAGE_Q_REGIME_1": "Partially submerged", "INFO_ENUM_OUVRAGE_Q_REGIME_2": "Submerged", "INFO_ENUM_OUVRAGE_Q_REGIME_3": "Zero flow", - "INFO_ENUM_PARFLOWREGIME_0": "Free", - "INFO_ENUM_PARFLOWREGIME_1": "Submerged", + "INFO_ENUM_PARFLOWREGIME_FREE": "Free", + "INFO_ENUM_PARFLOWREGIME_SUBMERGED": "Submerged", "INFO_ENUM_SPECIES_1": "Salmon, trout [50-100] (1)", "INFO_ENUM_SPECIES_2": "Mule (2)", "INFO_ENUM_SPECIES_3a": "Great shad (3a)", @@ -188,16 +188,16 @@ "INFO_ENUM_SPECIES_10": "Sunbleak, bitterling, stickleback, minnow (10)", "INFO_ENUM_SPECIES_11a": "European eel [yellow] (11a)", "INFO_ENUM_SPECIES_11b": "European Eel [glass eel] (11b)", - "INFO_ENUM_STRUCTUREFLOWMODE_0": "Weir", - "INFO_ENUM_STRUCTUREFLOWMODE_1": "Orifice", - "INFO_ENUM_STRUCTUREFLOWMODE_2": "Zero flow", - "INFO_ENUM_STRUCTUREFLOWREGIME_0": "Free flow", - "INFO_ENUM_STRUCTUREFLOWREGIME_1": "Partially submerged", - "INFO_ENUM_STRUCTUREFLOWREGIME_2": "Submerged", - "INFO_ENUM_STRUCTUREFLOWREGIME_3": "Zero flow", - "INFO_ENUM_STRUCTUREJETTYPE_0": "diving", - "INFO_ENUM_STRUCTUREJETTYPE_1": "surface", - "INFO_ENUM_STRUCTUREJETTYPE_2": "not applicable", + "INFO_ENUM_STRUCTUREFLOWMODE_WEIR": "Weir", + "INFO_ENUM_STRUCTUREFLOWMODE_ORIFICE": "Orifice", + "INFO_ENUM_STRUCTUREFLOWMODE_NULL": "Zero flow", + "INFO_ENUM_STRUCTUREFLOWREGIME_FREE": "Free flow", + "INFO_ENUM_STRUCTUREFLOWREGIME_PARTIAL": "Partially submerged", + "INFO_ENUM_STRUCTUREFLOWREGIME_SUBMERGED": "Submerged", + "INFO_ENUM_STRUCTUREFLOWREGIME_NULL": "Zero flow", + "INFO_ENUM_STRUCTUREJETTYPE_PLONGEANT": "diving", + "INFO_ENUM_STRUCTUREJETTYPE_SURFACE": "surface", + "INFO_ENUM_STRUCTUREJETTYPE_SO": "not applicable", "INFO_CHART_BUTTON_TITLE_RESET_ZOOM": "Restore default zoom", "INFO_CHART_BUTTON_TITLE_EXPORT_IMAGE": "Save picture", "INFO_CHART_BUTTON_TITLE_ENTER_FS": "Display fullscreen", diff --git a/src/locale/messages.fr.json b/src/locale/messages.fr.json index fa3145215..07fee9502 100755 --- a/src/locale/messages.fr.json +++ b/src/locale/messages.fr.json @@ -156,9 +156,9 @@ "INFO_DIALOG_SAVE_SESSION_TITLE": "Enregistrer les modules de calcul", "INFO_EMPTY_SESSION_DIALOGUE_TEXT": "Attention ! Tous les modules de calcul ouverts seront perdus.", "INFO_EMPTY_SESSION_DIALOGUE_TITRE": "Démarrer une nouvelle session", - "INFO_ENUM_MACRORUGOFLOWTYPE_0": "Émergent", - "INFO_ENUM_MACRORUGOFLOWTYPE_1": "Quasi-émergent", - "INFO_ENUM_MACRORUGOFLOWTYPE_2": "Immergé", + "INFO_ENUM_MACRORUGOFLOWTYPE_EMERGENT": "Émergent", + "INFO_ENUM_MACRORUGOFLOWTYPE_QUASI_EMERGENT": "Quasi-émergent", + "INFO_ENUM_MACRORUGOFLOWTYPE_SUBMERGED": "Immergé", "INFO_ENUM_OUVRAGE_Q_MODE_0": "Surface libre", "INFO_ENUM_OUVRAGE_Q_MODE_1": "En charge", "INFO_ENUM_OUVRAGE_Q_MODE_2": "Débit nul", @@ -166,8 +166,8 @@ "INFO_ENUM_OUVRAGE_Q_REGIME_1": "Partiellement noyé", "INFO_ENUM_OUVRAGE_Q_REGIME_2": "Noyé", "INFO_ENUM_OUVRAGE_Q_REGIME_3": "Débit nul", - "INFO_ENUM_PARFLOWREGIME_0": "Dénoyé", - "INFO_ENUM_PARFLOWREGIME_1": "Noyé", + "INFO_ENUM_PARFLOWREGIME_FREE": "Dénoyé", + "INFO_ENUM_PARFLOWREGIME_SUBMERGED": "Noyé", "INFO_ENUM_SPECIES_1": "Saumon, truite [50-100] (1)", "INFO_ENUM_SPECIES_2": "Mulets (2)", "INFO_ENUM_SPECIES_3a": "Grande Alose (3a)", @@ -188,16 +188,16 @@ "INFO_ENUM_SPECIES_10": "Able, bouvière, épinoche(tte), vairons (10)", "INFO_ENUM_SPECIES_11a": "Anguille européenne [jaune] (11a)", "INFO_ENUM_SPECIES_11b": "Anguille européenne [civelle] (11b)", - "INFO_ENUM_STRUCTUREFLOWMODE_0": "Surface libre", - "INFO_ENUM_STRUCTUREFLOWMODE_1": "En charge", - "INFO_ENUM_STRUCTUREFLOWMODE_2": "Débit nul", - "INFO_ENUM_STRUCTUREFLOWREGIME_0": "Dénoyé", - "INFO_ENUM_STRUCTUREFLOWREGIME_1": "Partiellement noyé", - "INFO_ENUM_STRUCTUREFLOWREGIME_2": "Noyé", - "INFO_ENUM_STRUCTUREFLOWREGIME_3": "Débit nul", - "INFO_ENUM_STRUCTUREJETTYPE_0": "plongeant", - "INFO_ENUM_STRUCTUREJETTYPE_1": "de surface", - "INFO_ENUM_STRUCTUREJETTYPE_2": "sans objet", + "INFO_ENUM_STRUCTUREFLOWMODE_WEIR": "Surface libre", + "INFO_ENUM_STRUCTUREFLOWMODE_ORIFICE": "En charge", + "INFO_ENUM_STRUCTUREFLOWMODE_NULL": "Débit nul", + "INFO_ENUM_STRUCTUREFLOWREGIME_FREE": "Dénoyé", + "INFO_ENUM_STRUCTUREFLOWREGIME_PARTIAL": "Partiellement noyé", + "INFO_ENUM_STRUCTUREFLOWREGIME_SUBMERGED": "Noyé", + "INFO_ENUM_STRUCTUREFLOWREGIME_NULL": "Débit nul", + "INFO_ENUM_STRUCTUREJETTYPE_PLONGEANT": "plongeant", + "INFO_ENUM_STRUCTUREJETTYPE_SURFACE": "de surface", + "INFO_ENUM_STRUCTUREJETTYPE_SO": "sans objet", "INFO_CHART_BUTTON_TITLE_RESET_ZOOM": "Réinitialiser le zoom", "INFO_CHART_BUTTON_TITLE_EXPORT_IMAGE": "Enregistrer l'image", "INFO_CHART_BUTTON_TITLE_ENTER_FS": "Afficher en plein écran", -- GitLab