Skip to content
Snippets Groups Projects
Commit f7f553c7 authored by Mathias Chouet's avatar Mathias Chouet Committed by mathias.chouet
Browse files

Fix #394 − PAR error messages : use complete variables translation instead of symbols

parent 1f8422eb
No related branches found
No related tags found
1 merge request!99Devel - PAR
......@@ -5,7 +5,8 @@ import { Message, MessageCode, Observable, Observer, Nub } from "jalhyd";
import { StringMap } from "../stringmap";
import { ApplicationSetupService } from "./app-setup.service";
import { HttpService } from "./http.service";
import { fv } from "../util";
import { fv, decodeHtml } from "../util";
import { ServiceFactory } from "./service-factory";
@Injectable()
export class I18nService extends Observable implements Observer {
......@@ -146,16 +147,50 @@ export class I18nService extends Observable implements Observer {
if (r.extraVar.hasOwnProperty(k)) {
const v: any = r.extraVar[k];
let s: string;
if (typeof v === "number") {
s = fv(v);
// detect variable names to translate
if (k === "variables" && Array.isArray(v)) {
// array of variable names
s = v.map((e) => {
return this.localizeText("INFO_LIB_" + e.toUpperCase());
}).join(", ");
} else if (k.substring(0, 4) === "var_") {
// single variable name
s = this.localizeText("INFO_LIB_" + v.toUpperCase());
} else {
s = v;
if (typeof v === "number") {
s = fv(v);
} else {
s = v;
}
}
m = this.replaceAll(m, "%" + k + "%", s);
}
}
return m;
// replace "ENUM_X_Y" by translated enum value;
// example for lang "fr" : "ENUM_SPECIES_6" => "INFO_ENUM_SPECIES_6" => "Ombre commun"
// (partly redundant with MSG_* but shorter to write)
m = m.replace(/(ENUM_[^ ,;\.]+)/g, (match, p1) => {
return this.localizeText("INFO_" + p1);
});
// replace "FORM_ID_X" by form name in current session, if any
m = m.replace(/FORM_ID_(\w{6})/g, (match, p1) => {
const form = ServiceFactory.instance.formulaireService.getFormulaireFromNubId(p1); // cannot inject FormulaireService => cyclic dependency :/
let formName = "**UNKNOWN_FORM**";
if (form !== undefined) {
formName = form.calculatorName;
}
return formName;
});
// replace MSG_* with the translation of * ; allows
// to inject any text translation in a message
m = m.replace(/MSG_([^ ,;\.]+)/g, (match, p1) => {
return this.localizeText(p1);
});
return decodeHtml(m);
}
private replaceAll(str: string, find: string, replace: string) {
......
{
"ERROR_AT_LEAST_ONE_OF_THOSE_MUST_BE_DEFINED": "At least one of the following values should be specified : %symbols%",
"ERROR_AT_LEAST_ONE_OF_THOSE_MUST_BE_DEFINED": "At least one of the following values should be specified : %variables%",
"ERROR_CLOISON_AVAL_UN_OUVRAGE_REGULE": "Only one regulated device is allowed on the downstream wall",
"WARNING_DEVER_ZR_SUP_Z1": "Elevation of the river bed can't be higher than water elevation: Impossible to calculate the kinetic energy",
"WARNING_DOWNSTREAM_ELEVATION_POSSIBLE_SUBMERSION": "Downstream elevation is higher than weir elevation (possible submersion)",
......@@ -34,7 +34,7 @@
"ERROR_PAB_Z1_LOWER_THAN_Z2": "Upstream water elevation should be higher than downstream water elevation",
"ERROR_PAB_Z1_LOWER_THAN_UPSTREAM_WALL": "Upstream water elevation is too low for water to flow through the first wall",
"ERROR_PAR_NB_INCONSISTENT": "Number of baffles should be %stdNb%",
"ERROR_PAR_ZR_ZD_MISMATCH": "Values of %ZR% and %ZD% mismatch : either %ZR% should be %expectedZR%, or %ZD% should be %expectedZD%",
"ERROR_PAR_ZR_ZD_MISMATCH": "Values of %var_ZR% and %var_ZD% mismatch : either %var_ZR% should be %expectedZR%, or %var_ZD% should be %expectedZD%",
"ERROR_PARAM_MUST_BE_A_NUMBER": "Please type a numeric value",
"ERROR_PARAM_MUST_BE_AT_LEAST": "Value must be >= %s",
"ERROR_PARAM_MUST_BE_POSITIVE": "Please type a positive numeric value",
......@@ -318,6 +318,10 @@
"INFO_LIB_ZCO": "Orifice center elevation",
"INFO_LIB_ZDV": "Crest weir elevation or gate base",
"INFO_LIB_ZF2": "Downstream bottom elevation",
"INFO_LIB_ZD1": "Upstream spilling elevation",
"INFO_LIB_ZD2": "Downstream spilling elevation",
"INFO_LIB_ZR1": "Upstream apron elevation",
"INFO_LIB_ZR2": "Downstream apron elevation",
"INFO_LIB_ZRAM": "Upstream apron elevation",
"INFO_LIB_ZRMB": "Downstream basin bottom elevation",
"INFO_LIB_ZT": "Triangle top elevation",
......@@ -550,8 +554,8 @@
"WARNING_VARIATED_LENGTH_LIMITED_BY_LINKED_RESULT": "Number of results is limited by linked result %symbol%",
"WARNING_PAR_P_WAS_IGNORED": "Given spacing value was ignored",
"ERROR_PAR_P_DEVIATES_MORE_THAN_10_5_PCT": "Given spacing value is more than 10% lower or more than 5% greater than standard value %stdP%",
"ERROR_PAR_QSTAR_OUT_OF_RANGE": "qStar value %val% is outside of validity interval [ %min%, %max% ] given by abacuses",
"ERROR_PAR_HA_OUT_OF_RANGE": "ha value %val% is outside of validity interval [ %min%, %max% ] given by abacuses",
"ERROR_PAR_QSTAR_OUT_OF_RANGE": "Flow value %val% is outside of validity interval [ %min%, %max% ] given by abacuses",
"ERROR_PAR_HA_OUT_OF_RANGE": "Upstream head value %val% is outside of validity interval [ %min%, %max% ] given by abacuses",
"WARNING_PAR_L": "A witdh greater than %max% is discouraged",
"ERROR_PAR_L": "Width is outside validity interval [ %min%, %max% ]",
"WARNING_ERROR_PAR_L": "Width is outside validity interval [ %min%, %max% ]",
......
{
"ERROR_AT_LEAST_ONE_OF_THOSE_MUST_BE_DEFINED": "Au moins une des valeurs suivantes doit être renseignée : %symbols%",
"ERROR_AT_LEAST_ONE_OF_THOSE_MUST_BE_DEFINED": "Au moins une des valeurs suivantes doit être renseignée : %variables%",
"ERROR_CLOISON_AVAL_UN_OUVRAGE_REGULE": "Un seul ouvrage régulé est autorisé sur la cloison aval",
"WARNING_DEVER_ZR_SUP_Z1": "La cote du lit du cours d'eau ne peut pas être supérieure à la cote de l'eau : Impossible de calculer l'énergie cinétique",
"WARNING_DOWNSTREAM_ELEVATION_POSSIBLE_SUBMERSION": "La cote de l'eau aval est plus élevée que la cote du seuil (ennoiement possible)",
......@@ -34,7 +34,7 @@
"ERROR_PAB_Z1_LOWER_THAN_Z2": "La cote de l'eau amont doit être supérieure à la cote de l'eau aval",
"ERROR_PAB_Z1_LOWER_THAN_UPSTREAM_WALL": "La cote de l'eau amont est trop basse pour que l'eau s'écoule à travers la première cloison",
"ERROR_PAR_NB_INCONSISTENT": "Le nombre de ralentisseurs devrait être %stdNb%",
"ERROR_PAR_ZR_ZD_MISMATCH": "Les valeurs de %ZR% et %ZD% ne correspondent pas : soit %ZR% devrait valoir %expectedZR%, soit %ZD% devrait valoir %expectedZD%",
"ERROR_PAR_ZR_ZD_MISMATCH": "Les valeurs de %var_ZR% et %var_ZD% ne correspondent pas : soit %var_ZR% devrait valoir %expectedZR%, soit %var_ZD% devrait valoir %expectedZD%",
"ERROR_PARAM_MUST_BE_A_NUMBER": "Veuillez entrer une valeur numérique",
"ERROR_PARAM_MUST_BE_AT_LEAST": "La valeur doit être >= %s",
"ERROR_PARAM_MUST_BE_POSITIVE": "Veuillez entrer une valeur numérique positive",
......@@ -319,6 +319,10 @@
"INFO_LIB_ZCO": "Cote du centre de l'orifice",
"INFO_LIB_ZDV": "Cote de la crête du déversoir ou du radier de la vanne",
"INFO_LIB_ZF2": "Cote de fond aval",
"INFO_LIB_ZD1": "Cote de déversement à l'amont",
"INFO_LIB_ZD2": "Cote de déversement à l'aval",
"INFO_LIB_ZR1": "Cote de radier à l'amont",
"INFO_LIB_ZR2": "Cote de radier à l'aval",
"INFO_LIB_ZRAM": "Cote du radier amont",
"INFO_LIB_ZRMB": "Cote de radier mi-bassin",
"INFO_LIB_ZT": "Cote haute du triangle",
......@@ -551,8 +555,8 @@
"WARNING_VARIATED_LENGTH_LIMITED_BY_LINKED_RESULT": "Le nombre de résultats est limité par le résultat lié %symbol%",
"WARNING_PAR_P_WAS_IGNORED": "La valeur d'espacement fournie a été ignorée",
"ERROR_PAR_P_DEVIATES_MORE_THAN_10_5_PCT": "La valeur d'espacement fournie est plus de 10% plus petite ou plus de 5% plus grande que la valeur standard %stdP%",
"ERROR_PAR_QSTAR_OUT_OF_RANGE": "La valeur %val% de qStar sort de l'intervalle de validité [ %min%, %max% ] donné par les abaques",
"ERROR_PAR_HA_OUT_OF_RANGE": "La valeur %val% de ha sort de l'intervalle de validité [ %min%, %max% ] donné par les abaques",
"ERROR_PAR_QSTAR_OUT_OF_RANGE": "La valeur %val% du débit sort de l'intervalle de validité [ %min%, %max% ] donné par les abaques",
"ERROR_PAR_HA_OUT_OF_RANGE": "La valeur %val% de la charge amont sort de l'intervalle de validité [ %min%, %max% ] donné par les abaques",
"WARNING_PAR_L": "Une largeur supérieure à %max% est déconseillée",
"ERROR_PAR_L": "La largeur est en dehors de l'intervalle de validité [ %min%, %max% ]",
"WARNING_ERROR_PAR_L": "La largeur est en dehors de l'intervalle de validité [ %min%, %max% ]",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment