Skip to content
Snippets Groups Projects
Commit 18f5141f authored by toto's avatar toto
Browse files

feat: localise service worker messages

refs #445
parent 9ac7b759
No related branches found
No related tags found
2 merge requests!225Release v4.17.0,!183Resolve "Install Cassiopee as a PWA"
Pipeline #140003 passed
......@@ -160,12 +160,12 @@ export class I18nService extends Observable implements Observer {
*
* @param textKey id du texte (ex: "ERROR_PARAM_NULL")
*/
public localizeText(textKey: string) {
public localizeText(textKey: string, vars: {} = {}) {
if (! this._Messages) {
return `*** messages not loaded: ${this._currentLanguage} ***`;
}
if (this._Messages[textKey] !== undefined) {
return decodeHtml(this._Messages[textKey]);
return this.translateMessage(this._Messages[textKey], vars);
} else {
// try general message
if (this._Messages !== undefined && this._Messages["INFO_LIB_" + textKey.toUpperCase()] !== undefined) {
......@@ -176,17 +176,16 @@ export class I18nService extends Observable implements Observer {
}
/**
* Traduit un Message (classe Message de JaLHyd, pour les logs de calcul par exemple)
* @param r Message
* @param nDigits nombre de chiffres à utiliser pour l'arrondi dans le cas de données numériques
* Translate a text optionally subtituting variables denoted by %XXX%
* @param m message to translate
* @param vars variable map
* @returns translated message with variables value
*/
public localizeMessage(r: Message, nDigits: number = 3): string {
let text: string;
let m: string = this.getMessageFromCode(r.code);
// replace %X% by formatted value of extraVar.X
for (const k in r.extraVar) {
if (r.extraVar.hasOwnProperty(k)) {
const v: any = r.extraVar[k];
private translateMessage(m: string, vars: {}) {
// replace %X% by formatted value of vars.X
for (const k in vars) {
if (vars.hasOwnProperty(k)) {
const v: any = vars[k];
let s: string;
// detect variable names to translate
if (k === "variables" && Array.isArray(v)) {
......@@ -248,7 +247,18 @@ export class I18nService extends Observable implements Observer {
return this.localizeText(p1);
});
text = decodeHtml(m);
return decodeHtml(m);
}
/**
* Traduit un Message (classe Message de JaLHyd, pour les logs de calcul par exemple)
* @param r Message
* @param nDigits nombre de chiffres à utiliser pour l'arrondi dans le cas de données numériques
*/
public localizeMessage(r: Message, nDigits: number = 3): string {
let m: string = this.getMessageFromCode(r.code);
let text: string = this.translateMessage(m, r.extraVar);
// prefix message if needed
if (r.parent && r.parent.parent && r.parent.parent.sourceNub) {
......
import { Injectable } from "@angular/core";
import { SwUpdate } from '@angular/service-worker';
import { I18nService } from "./internationalisation.service";
import { NotificationsService } from "./notifications.service";
@Injectable()
export class ServiceWorkerUpdateService {
constructor(
private swUpdate: SwUpdate,
private notificationService: NotificationsService
private notificationService: NotificationsService,
private i18nService: I18nService
) {
swUpdate.versionUpdates.subscribe(evt => {
switch (evt.type) {
case 'VERSION_DETECTED':
let ver = evt.version.appData["version"];
console.log(`new version detected ${ver}`);
notificationService.notify(`Downloading new version: ${ver}`, 10000);
let msg = i18nService.localizeText("INFO_SERVICE_WORKER_VERSION_DETECTED", { "ver": ver });
notificationService.notify(msg, 10000);
break;
case 'VERSION_READY':
const currVer = evt.currentVersion.appData["version"];
const newVer = evt.latestVersion.appData["version"];
console.log(`new version ready ${newVer}, current = ${currVer}`);
notificationService.notify(`New version ready for use: ${newVer}, replacing ${currVer}`, 10000);
// const currVer = evt.currentVersion.appData["version"];
msg = i18nService.localizeText("INFO_SERVICE_WORKER_VERSION_READY", { "ver": newVer });
notificationService.notify(msg, 10000);
break;
case 'VERSION_INSTALLATION_FAILED':
ver = evt.version.appData["version"];
console.log(`version install failed ${ver} : ${evt.error}`);
notificationService.notify(`Failed to install version '${ver}': ${evt.error}`, 10000);
msg = i18nService.localizeText("ERROR_SERVICE_WORKER_INSTALL_FAILED", { "ver": ver });
notificationService.notify(msg, 10000);
break;
}
});
......
......@@ -670,6 +670,9 @@
"INFO_ESPECE_TITRE": "Fish species characteristics",
"INFO_ESPECE_DESCRIPTION": "ichtyocompatible",
"INFO_ESPECE_TITRE_COURT": "Species",
"INFO_SERVICE_WORKER_VERSION_DETECTED": "Downloading Cassiopée version %ver%...",
"INFO_SERVICE_WORKER_VERSION_READY": "Cassiopée version %ver% is ready to be used, please restart.",
"ERROR_SERVICE_WORKER_INSTALL_FAILED": "Cassiopée version %ver% installation failed.",
"ERROR_JET_SUBMERGED_NO_SOLUTION": "There is no solution",
"WARNING_DEVER_ZDV_INF_ZR": "Apron elevation of structure #%number% is below river bed elevation",
"WARNING_JET_START_SUBMERGED": "Water elevation is greater than jet start elevation",
......
......@@ -671,6 +671,9 @@
"INFO_ESPECE_TITRE": "Caractéristiques d'une espèce",
"INFO_ESPECE_DESCRIPTION": "ichtyocompatible",
"INFO_ESPECE_TITRE_COURT": "Espèce",
"INFO_SERVICE_WORKER_VERSION_DETECTED": "Téléchargement de la version %ver% de Cassiopée en cours...",
"INFO_SERVICE_WORKER_VERSION_READY": "La version %ver% de Cassiopée est prête à être utilisée, veuillez redémarrer.",
"ERROR_SERVICE_WORKER_INSTALL_FAILED": "Erreur d'installation de Cassiopée version %ver%.",
"ERROR_JET_SUBMERGED_NO_SOLUTION": "Il n'y a pas de solution",
"WARNING_DEVER_ZDV_INF_ZR": "La cote de radier de l'ouvrage n°%number% est sous la cote de fond du lit",
"WARNING_JET_START_SUBMERGED": "La cote de l'eau est supérieure à la cote de départ du jet",
......
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