@esfaenza/localizations 15.2.0 → 15.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,12 +1,10 @@
1
+ import { __awaiter } from 'tslib';
1
2
  import * as i0 from '@angular/core';
2
3
  import { InjectionToken, Injectable, Inject, Pipe, Optional, NgModule } from '@angular/core';
4
+ import { take, first } from 'rxjs/operators';
5
+ import { ReplaySubject, of } from 'rxjs';
3
6
  import * as i1 from '@esfaenza/extensions';
4
7
 
5
- /**
6
- * Locale da utilizzare per le traduzioni
7
- */
8
- const LOC_LOCALE = new InjectionToken('LOC_LOCALE');
9
-
10
8
  /**
11
9
  * Contenitore delle localizzazioni collegate ad un testo "base", una per ogni linguaggio supportato
12
10
  */
@@ -96,77 +94,13 @@ class SpecializedLocalization {
96
94
  }
97
95
  }
98
96
 
99
- /**
100
- * Classe singleton che contiene le traduzioni di base (per evitare di ripeterle in oggi classe di traduzione) e le funzioni base per
101
- * inserire e leggere traduzioni in/da una cache
102
- */
103
- class BaseLocalization {
104
- /**
105
- * Costruttore. Da qui utilizzando il metodo statico **BaseLocalization.set** si va a popolare la cache delle traduzioni **BaseTranslations**
106
- */
107
- constructor() {
108
- /**
109
- * Cache di tutte le localizzazioni di base
110
- */
111
- this.BaseTranslations = {};
112
- // Odio sprecare caratteri... soprattutto quando rischio che non vengano minificati
113
- let bt = this.BaseTranslations;
114
- let bl = BaseLocalization;
115
- bl.set(bt, "en->it", "Remove", ["Elimina"]);
116
- bl.set(bt, "en->it", "Paging", ["Paginazione"]);
117
- bl.set(bt, "en->it", "Yes", ["Si"]);
118
- bl.set(bt, "en->it", "No", ["No"]);
119
- bl.set(bt, "en->it", "YES", ["SI'"]);
120
- bl.set(bt, "en->it", "NO", ["NO"]);
121
- bl.set(bt, "en->it", "Found objects", ["Risultati trovati"]);
122
- bl.set(bt, "en->it", "Loading data...", ["Carico i dati..."]);
123
- bl.set(bt, "en->it", "Error during save operations", ["Errori durante il salvataggio"]);
124
- bl.set(bt, "en->it", "Error", ["Errore"]);
125
- bl.set(bt, "en->it", "Warning", ["Avviso"]);
126
- bl.set(bt, "en->it", "Information", ["Informazione"]);
127
- bl.set(bt, "en->it", "Save", ["Salva"]);
128
- bl.set(bt, "en->it", "Back", ["Indietro"]);
129
- bl.set(bt, "en->it", "From", ["Da"]);
130
- bl.set(bt, "en->it", "To", ["A"]);
131
- bl.set(bt, "en->it", "View Chart", ["Vedi Grafico"]);
132
- bl.set(bt, "en->it", "View Table", ["Vedi Tabella"]);
133
- bl.set(bt, "en->it", "Notes", ["Note"]);
134
- bl.set(bt, "en->it", "Edit Notes", ["Modifica Note"]);
135
- bl.set(bt, "en->it", "Cancel", ["Annulla"]);
136
- bl.set(bt, "en->it", "Confirm", ["Conferma"]);
137
- bl.set(bt, "en->it", "View", ["Visualizza"]);
138
- bl.set(bt, "en->it", "Close", ["Chiudi"]);
139
- bl.set(bt, "en->it", "Select", ["Seleziona"]);
140
- bl.set(bt, "en->it", "Meter Reading registered successfully", ["Lettura registrata correttamente"]);
141
- bl.set(bt, "en->it", "Validation errors during save operations", ["Errori di validazione durante il salvataggio"]);
142
- bl.set(bt, "en->it", "Can't register reading", ["Impossibile registrare la lettura"]);
143
- bl.set(bt, "en->it", "Electricity", ["Elettricita"]);
144
- bl.set(bt, "en->it", "Gas", ["Gas"]);
145
- bl.set(bt, "en->it", "Water", ["Acqua"]);
146
- bl.set(bt, "en->it", "Delete", ["Elimina"]);
147
- bl.set(bt, "en->it", "This operation cannot be reverted", ["Questa operazione non puo' essere annullata"]);
148
- bl.set(bt, "en->it", "Hide", ["Nascondi"]);
149
- // Helper validazione
150
- bl.set(bt, "en->it", "Required field", ["Campo richiesto"]);
151
- bl.set(bt, "en->it", "Wrong field format", ["Formato campo errato"]);
152
- bl.set(bt, "en->it", "Wrong field format or field missing", ["Formato campo errato o campo mancante"]);
153
- bl.set(bt, "en->it", "You don't have the required permissions to view this page. The navigation has been blocked", ["Non si hanno privilegi a sufficienza per accedere a questa pagina. La navigazione e' stata bloccata"]);
154
- // Informazioni sulle date
155
- bl.setToken(bt, "en->it", "getDateMonthPosition", "0", ["1"]);
156
- bl.setToken(bt, "en->it", "getDisplayDateMonthPosition", "1", ["1"]);
157
- bl.setToken(bt, "en->it", "getLocale", "en-US", ["it-IT"]);
158
- bl.setToken(bt, "en->it", "getSmallDateFormat", "MM/DD/YYYY", ["DD/MM/YYYY"]);
159
- bl.setToken(bt, "en->it", "getDefaultDateFormat", "MM/DD/YYYY", ["MM/DD/YYYY"]);
160
- bl.setToken(bt, "en->it", "getSmallDateDisplayFormat", "DD/MM/YYYY", ["DD/MM/YYYY"]);
161
- bl.setToken(bt, "en->it", "getFullDateFormat", "MM/DD/YYYY HH:mm:ss", ["DD/MM/YYYY HH:mm:ss"]);
162
- bl.setToken(bt, "en->it", "getFullDateDisplayFormat", "DD/MM/YYYY HH:mm:ss", ["DD/MM/YYYY HH:mm:ss"]);
163
- bl.setToken(bt, "en->it", "getFullDateFormatNoSeconds", "MM/DD/YYYY HH:mm", ["DD/MM/YYYY HH:mm"]);
164
- bl.setToken(bt, "en->it", "getFullDateDisplayFormatNoSeconds", "DD/MM/YYYY HH:mm", ["DD/MM/YYYY HH:mm"]);
97
+ class LocalizationPersistor {
98
+ constructor(LocCache = null) {
99
+ this.LocCache = LocCache;
165
100
  }
166
101
  /**
167
102
  * Imposta la localizzazione di un token all'interno della cache scelta
168
103
  *
169
- * @param {{ [id: string]: ItemLocalization }} locCache Cache all'interno della quale inserire l'informazione del token con le localizzazioni
170
104
  * @param {string} direction Direzione della traduzione, rappresenta la lingua base in cui aspettarsi il testo e le varie lingue in cui viene tradotta.
171
105
  * Ad esempio, "en->it" indica che il parametro **left** è valido per le localizzazioni in inglese, mentre nell'elemento 0 del parametro **right**
172
106
  * è presente l'unica traduzione in italiano, per definire più traduzioni sul lato destro della freccia bisogna concatenarle con la virgola, ad esempio "en->it,jp,ecc"
@@ -174,56 +108,54 @@ class BaseLocalization {
174
108
  * @param {string} left Valore del token per la lingua specificata nel lato immediatamente sinistro alla freccia del parametro **direction**
175
109
  * @param {string} right Array con i valori facenti riferimento all'N-esima lingua del lato destro del parametro **direction**
176
110
  */
177
- static setToken(locCache, direction, token, left, right) {
111
+ setToken(direction, token, left, right) {
178
112
  let parsingRegex = /([a-zA-Z]+)[\s]*->[\s]*([a-zA-Z,\s]+)+/g;
179
113
  var parsingRes = parsingRegex.exec(direction);
180
114
  let from = parsingRes[1];
181
115
  let to = parsingRes[2].replace(/\s/g, '').split(',');
182
116
  let localeFrom = LocaleDefinitions.getByAlias(from);
183
- BaseLocalization._set(locCache, token, localeFrom.id, left, true);
117
+ this._set(token, localeFrom.id, left, true);
184
118
  to.forEach((t, index) => {
185
119
  let localeTo = LocaleDefinitions.getByAlias(t);
186
- BaseLocalization._set(locCache, token, localeTo.id, right[index], true);
120
+ this._set(token, localeTo.id, right[index], true);
187
121
  });
188
122
  }
189
123
  /**
190
124
  * Imposta la localizzazione di una frase all'interno della cache scelta
191
125
  *
192
- * @param {{ [id: string]: ItemLocalization }} locCache Cache all'interno della quale inserire l'informazione della frase con le localizzazioni
193
126
  * @param {string} direction Direzione della traduzione, rappresenta la lingua base in cui aspettarsi il testo e le varie lingue in cui viene tradotta.
194
127
  * Ad esempio, "en->it" indica che il parametro **left** è valido per le localizzazioni in inglese, mentre nell'elemento 0 del parametro **right**
195
128
  * è presente l'unica traduzione in italiano, per definire più traduzioni sul lato destro della freccia bisogna concatenarle con la virgola, ad esempio "en->it,jp,ecc"
196
129
  * @param {string} left Valore della frase per la lingua specificata nel lato immediatamente sinistro alla freccia del parametro **direction**
197
130
  * @param {string} right Array con i valori facenti riferimento all'N-esima lingua del lato destro del parametro **direction**
198
131
  */
199
- static set(locCache, direction, left, right) {
132
+ set(direction, left, right) {
200
133
  let parsingRegex = /([a-zA-Z]+)[\s]*->[\s]*([a-zA-Z,\s]+)+/g;
201
134
  var parsingRes = parsingRegex.exec(direction);
202
135
  let from = parsingRes[1];
203
136
  let to = parsingRes[2].replace(/\s/g, '').split(',');
204
137
  let localeFrom = LocaleDefinitions.getByAlias(from);
205
- BaseLocalization._set(locCache, left, localeFrom.id, left);
138
+ this._set(left, localeFrom.id, left);
206
139
  to.forEach((t, index) => {
207
140
  let localeTo = LocaleDefinitions.getByAlias(t);
208
- BaseLocalization._set(locCache, left, localeTo.id, right[index]);
141
+ this._set(left, localeTo.id, right[index]);
209
142
  });
210
143
  }
211
144
  /**
212
145
  * Imposta all'interno della cache specificata un'unica traduzione partendo da un testo di base
213
146
  *
214
- * @param {{ [id: string]: ItemLocalization }} locCache Cache all'interno della quale inserire l'informazione del testo con le localizzazioni
215
147
  * @param {string} text Testo da tradurre
216
148
  * @param {string} culture Lingua per cui inserire la traduzione
217
149
  * @param {string} translation Traduzione del **text** nella lingua specificata da **culture**
218
150
  * @param {boolean} token Indica se il **text** è un token o è una frase normale
219
151
  */
220
- static _set(locCache, text, culture, translation, token) {
221
- let item = BaseLocalization.findByText(locCache, text, token);
152
+ _set(text, culture, translation, token) {
153
+ let item = this.get(text, token);
222
154
  if (!item) {
223
- locCache[text] = new ItemLocalization(token, text, [new SpecializedLocalization(culture, translation)]);
155
+ this.LocCache[text] = new ItemLocalization(token, text, [new SpecializedLocalization(culture, translation)]);
224
156
  return;
225
157
  }
226
- var trs = BaseLocalization.translationByCulture(item, culture);
158
+ var trs = this.translationByCulture(item, culture);
227
159
  if (trs) {
228
160
  console.warn("Localization already loaded for sentence '" + text + "' and culture " + culture);
229
161
  return;
@@ -233,15 +165,14 @@ class BaseLocalization {
233
165
  /**
234
166
  * Partendo da una cache di localizzazione, dato un testo che può essere o meno un token, cerca quell'elemento all'interno della cache
235
167
  *
236
- * @param {{ [id: string]: ItemLocalization }} locCache Cache all'interno del quale cercare il **text**
237
- * @param {string} text Testo da cercare nella **locCache**
168
+ * @param {string} text Testo da cercare nella **LocCache**
238
169
  * @param {boolean} allowtokens Indica se l'elemento cercato può essere un token o se dev'essere per forza una frase (per evitare rari
239
170
  * casi di collisione in cui magari un token è uguale a una frase tradotta)
240
171
  *
241
172
  * @returns {ItemLocalization} Informazioni di localizzazione per il **text** cercato
242
173
  */
243
- static findByText(locCache, text, allowtokens) {
244
- let possibleItem = locCache[text];
174
+ get(text, allowtokens) {
175
+ let possibleItem = this.LocCache[text];
245
176
  if (!possibleItem)
246
177
  return null;
247
178
  var item = allowtokens || !possibleItem.token ? possibleItem : null;
@@ -255,7 +186,7 @@ class BaseLocalization {
255
186
  *
256
187
  * @returns {SpecializedLocalization} Informazioni di localizzazione specifiche della lingua richiesta
257
188
  */
258
- static translationByCulture(item, culture) {
189
+ translationByCulture(item, culture) {
259
190
  for (let i = 0; i < item.translations.length; i++) {
260
191
  let trl = item.translations[i];
261
192
  if (trl.culture == culture)
@@ -263,12 +194,125 @@ class BaseLocalization {
263
194
  }
264
195
  return null;
265
196
  }
197
+ }
198
+
199
+ var BaseLocalizationTokens;
200
+ (function (BaseLocalizationTokens) {
201
+ BaseLocalizationTokens["getDateMonthPosition"] = "getDateMonthPosition";
202
+ BaseLocalizationTokens["getDisplayDateMonthPosition"] = "getDisplayDateMonthPosition";
203
+ BaseLocalizationTokens["getLocale"] = "getLocale";
204
+ BaseLocalizationTokens["getSmallDateFormat"] = "getSmallDateFormat";
205
+ BaseLocalizationTokens["getDefaultDateFormat"] = "getDefaultDateFormat";
206
+ BaseLocalizationTokens["getSmallDateDisplayFormat"] = "getSmallDateDisplayFormat";
207
+ BaseLocalizationTokens["getFullDateFormat"] = "getFullDateFormat";
208
+ BaseLocalizationTokens["getFullDateDisplayFormat"] = "getFullDateDisplayFormat";
209
+ BaseLocalizationTokens["getFullDateFormatNoSeconds"] = "getFullDateFormatNoSeconds";
210
+ BaseLocalizationTokens["getFullDateDisplayFormatNoSeconds"] = "getFullDateDisplayFormatNoSeconds";
211
+ })(BaseLocalizationTokens || (BaseLocalizationTokens = {}));
212
+
213
+ /**
214
+ * Locale da utilizzare per le traduzioni
215
+ */
216
+ const LOC_LOCALE = new InjectionToken('LOC_LOCALE');
217
+
218
+ /** Classe astratta che rappresenta lo stato di persistenza fra la libreria e uno storage */
219
+ class LocalePersistor {
220
+ constructor() {
221
+ /** Chiave su cui salvare il locale */
222
+ this.LOCALE = "LOCALE";
223
+ }
224
+ }
225
+
226
+ /**
227
+ * Classe singleton che contiene le traduzioni di base (per evitare di ripeterle in oggi classe di traduzione) e le funzioni base per
228
+ * inserire e leggere traduzioni in/da una cache
229
+ */
230
+ class BaseLocalization {
231
+ /**
232
+ * Costruttore. Da qui utilizzando il metodo statico **BaseLocalization.set** si va a popolare la cache delle traduzioni **BaseTranslations**
233
+ */
234
+ constructor(LocalePersistor, defaultLocale) {
235
+ this.LocalePersistor = LocalePersistor;
236
+ /**
237
+ * Cache di tutte le localizzazioni di base
238
+ */
239
+ this.LocCache = {};
240
+ /**
241
+ * Locale di riferimento per tutte le traduzioni
242
+ */
243
+ this.Locale = new ReplaySubject(1);
244
+ // Recupero il locale alla partenza del BaseLocalization in modo, spero di dare tempo all'applicazione di tirarlo su
245
+ this.LocalePersistor.recover().pipe(take(1)).subscribe((l) => __awaiter(this, void 0, void 0, function* () {
246
+ if (!l) {
247
+ l = defaultLocale;
248
+ this.LocalePersistor.persist(defaultLocale);
249
+ }
250
+ this.Locale.next(l);
251
+ }));
252
+ this.Persistor = new LocalizationPersistor(this.LocCache);
253
+ this.Persistor.set("en->it", "Remove", ["Elimina"]);
254
+ this.Persistor.set("en->it", "Paging", ["Paginazione"]);
255
+ this.Persistor.set("en->it", "Yes", ["Si"]);
256
+ this.Persistor.set("en->it", "No", ["No"]);
257
+ this.Persistor.set("en->it", "YES", ["SI'"]);
258
+ this.Persistor.set("en->it", "NO", ["NO"]);
259
+ this.Persistor.set("en->it", "Found objects", ["Risultati trovati"]);
260
+ this.Persistor.set("en->it", "Loading data...", ["Carico i dati..."]);
261
+ this.Persistor.set("en->it", "Error during save operations", ["Errori durante il salvataggio"]);
262
+ this.Persistor.set("en->it", "Error", ["Errore"]);
263
+ this.Persistor.set("en->it", "Warning", ["Avviso"]);
264
+ this.Persistor.set("en->it", "Information", ["Informazione"]);
265
+ this.Persistor.set("en->it", "Save", ["Salva"]);
266
+ this.Persistor.set("en->it", "Back", ["Indietro"]);
267
+ this.Persistor.set("en->it", "From", ["Da"]);
268
+ this.Persistor.set("en->it", "To", ["A"]);
269
+ this.Persistor.set("en->it", "View Chart", ["Vedi Grafico"]);
270
+ this.Persistor.set("en->it", "View Table", ["Vedi Tabella"]);
271
+ this.Persistor.set("en->it", "Notes", ["Note"]);
272
+ this.Persistor.set("en->it", "Edit Notes", ["Modifica Note"]);
273
+ this.Persistor.set("en->it", "Cancel", ["Annulla"]);
274
+ this.Persistor.set("en->it", "Confirm", ["Conferma"]);
275
+ this.Persistor.set("en->it", "View", ["Visualizza"]);
276
+ this.Persistor.set("en->it", "Close", ["Chiudi"]);
277
+ this.Persistor.set("en->it", "Select", ["Seleziona"]);
278
+ this.Persistor.set("en->it", "Meter Reading registered successfully", ["Lettura registrata correttamente"]);
279
+ this.Persistor.set("en->it", "Validation errors during save operations", ["Errori di validazione durante il salvataggio"]);
280
+ this.Persistor.set("en->it", "Can't register reading", ["Impossibile registrare la lettura"]);
281
+ this.Persistor.set("en->it", "Electricity", ["Elettricita"]);
282
+ this.Persistor.set("en->it", "Gas", ["Gas"]);
283
+ this.Persistor.set("en->it", "Water", ["Acqua"]);
284
+ this.Persistor.set("en->it", "Delete", ["Elimina"]);
285
+ this.Persistor.set("en->it", "This operation cannot be reverted", ["Questa operazione non puo' essere annullata"]);
286
+ this.Persistor.set("en->it", "Hide", ["Nascondi"]);
287
+ // Helper validazione
288
+ this.Persistor.set("en->it", "Required field", ["Campo richiesto"]);
289
+ this.Persistor.set("en->it", "Wrong field format", ["Formato campo errato"]);
290
+ this.Persistor.set("en->it", "Wrong field format or field missing", ["Formato campo errato o campo mancante"]);
291
+ this.Persistor.set("en->it", "You don't have the required permissions to view this page. The navigation has been blocked", ["Non si hanno privilegi a sufficienza per accedere a questa pagina. La navigazione e' stata bloccata"]);
292
+ // Informazioni sulle date
293
+ this.Persistor.setToken("en->it", BaseLocalizationTokens.getDateMonthPosition, "0", ["1"]);
294
+ this.Persistor.setToken("en->it", BaseLocalizationTokens.getDisplayDateMonthPosition, "1", ["1"]);
295
+ this.Persistor.setToken("en->it", BaseLocalizationTokens.getLocale, "en-US", ["it-IT"]);
296
+ this.Persistor.setToken("en->it", BaseLocalizationTokens.getSmallDateFormat, "MM/DD/YYYY", ["DD/MM/YYYY"]);
297
+ this.Persistor.setToken("en->it", BaseLocalizationTokens.getDefaultDateFormat, "MM/DD/YYYY", ["MM/DD/YYYY"]);
298
+ this.Persistor.setToken("en->it", BaseLocalizationTokens.getSmallDateDisplayFormat, "DD/MM/YYYY", ["DD/MM/YYYY"]);
299
+ this.Persistor.setToken("en->it", BaseLocalizationTokens.getFullDateFormat, "MM/DD/YYYY HH:mm:ss", ["DD/MM/YYYY HH:mm:ss"]);
300
+ this.Persistor.setToken("en->it", BaseLocalizationTokens.getFullDateDisplayFormat, "DD/MM/YYYY HH:mm:ss", ["DD/MM/YYYY HH:mm:ss"]);
301
+ this.Persistor.setToken("en->it", BaseLocalizationTokens.getFullDateFormatNoSeconds, "MM/DD/YYYY HH:mm", ["DD/MM/YYYY HH:mm"]);
302
+ this.Persistor.setToken("en->it", BaseLocalizationTokens.getFullDateDisplayFormatNoSeconds, "DD/MM/YYYY HH:mm", ["DD/MM/YYYY HH:mm"]);
303
+ }
266
304
  }
267
- BaseLocalization.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: BaseLocalization, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
268
- BaseLocalization.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: BaseLocalization });
305
+ BaseLocalization.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: BaseLocalization, deps: [{ token: LocalePersistor }, { token: LOC_LOCALE }], target: i0.ɵɵFactoryTarget.Injectable });
306
+ BaseLocalization.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: BaseLocalization, providedIn: 'root' });
269
307
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: BaseLocalization, decorators: [{
270
- type: Injectable
271
- }], ctorParameters: function () { return []; } });
308
+ type: Injectable,
309
+ args: [{ providedIn: 'root' }]
310
+ }], ctorParameters: function () {
311
+ return [{ type: LocalePersistor }, { type: undefined, decorators: [{
312
+ type: Inject,
313
+ args: [LOC_LOCALE]
314
+ }] }];
315
+ } });
272
316
 
273
317
  /**
274
318
  * Classe di localizzazione estendibile che permette di specificare le proprie localizzazioni e comunque rendere disponibili le localizzazioni globali
@@ -277,17 +321,22 @@ class LocalizationService {
277
321
  /**
278
322
  * Costruttore
279
323
  *
280
- * @param {string} baseLoc Locale da utilizzare nel momento che questo servizio richiede le traduzioni
324
+ * @param {string} Locale Locale da utilizzare nel momento che questo servizio richiede le traduzioni
281
325
  * @param {baseLocalization} baseLocalization Classe base di localizzazione già fornita a livello di root dalla libreria stessa.
282
326
  * È sufficiente iniettarla nell'eventuale costruttore che estende questa classe e passarla as-is
283
327
  */
284
- constructor(baseLoc, baseLocalization) {
285
- this.baseLoc = baseLoc;
286
- this.baseLocalization = baseLocalization;
328
+ constructor(injector) {
329
+ this.injector = injector;
287
330
  /**
288
331
  * Cache di tutte le localizzazioni disonibili all'interno di questa classe
289
332
  */
290
333
  this.TranslationCache = {};
334
+ this.LocalePersistor = this.injector.get(LocalePersistor);
335
+ this.baseLocalization = this.injector.get(BaseLocalization);
336
+ this.Persistor = new LocalizationPersistor(this.TranslationCache);
337
+ this.baseLocalization.Locale.subscribe(lr => {
338
+ this.Locale = lr;
339
+ });
291
340
  }
292
341
  /**
293
342
  * Imposta la localizzazione di un token all'interno della **TranslationCache**
@@ -300,7 +349,7 @@ class LocalizationService {
300
349
  * @param {string} right Array con i valori facenti riferimento all'N-esima lingua del lato destro del parametro **direction**
301
350
  */
302
351
  setToken(direction, token, left, right) {
303
- BaseLocalization.setToken(this.TranslationCache, direction, token, left, right);
352
+ this.Persistor.setToken(direction, token, left, right);
304
353
  }
305
354
  /**
306
355
  * Imposta la localizzazione di una frase all'interno della **TranslationCache**
@@ -312,7 +361,13 @@ class LocalizationService {
312
361
  * @param {string} right Array con i valori facenti riferimento all'N-esima lingua del lato destro del parametro **direction**
313
362
  */
314
363
  set(direction, left, right) {
315
- BaseLocalization.set(this.TranslationCache, direction, left, right);
364
+ // Controlla di non reinserire la stessa localizzazione presente nel BaseLocalization
365
+ // i controlli per il non reinserimento della stessa localizzazione all'interno della stessa istanza è fatto lato Persistor
366
+ if (this.baseLocalization.Persistor.get(left, false)) {
367
+ console.warn(`La localizzazione per ${left} è già presente fra le localizzazioni base, ignoro l'operazione`);
368
+ return;
369
+ }
370
+ this.Persistor.set(direction, left, right);
316
371
  }
317
372
  /**
318
373
  * Localizza un token
@@ -335,49 +390,42 @@ class LocalizationService {
335
390
  loc(text, allowtokens) {
336
391
  if (!text || text == "undefined")
337
392
  return "";
338
- // Questo può succedere solo se qualcuno crea questa service a manazza. In quel caso prendo la classe di default e basta
339
- if (this.baseLocalization == null)
340
- this.baseLocalization = new BaseLocalization();
341
393
  // Prendo la localizzazione o dalla cache attuale o dalla cache del servizio base
342
- var item = BaseLocalization.findByText(this.TranslationCache, text, allowtokens) || BaseLocalization.findByText(this.baseLocalization.BaseTranslations, text, allowtokens);
394
+ var item = this.Persistor.get(text, allowtokens) || this.baseLocalization.Persistor.get(text, allowtokens);
343
395
  if (!item) {
344
- console.error("Couldn't find localization for '" + text + "'");
396
+ console.error("Impossibile trovare la localizzazione per '" + text + "'");
397
+ return "";
398
+ }
399
+ if (!this.Locale) {
400
+ console.error("Il sistema di localizzazione non ha ancora caricato il Locale, assicurarsi di caricare l'APP solo al retrieve del locale'");
345
401
  return "";
346
402
  }
347
- var loc = BaseLocalization.translationByCulture(item, this.baseLoc);
403
+ var loc = this.Persistor.translationByCulture(item, this.Locale);
348
404
  if (!loc) {
349
- console.error("Couldn't find localization for '" + text + "', culture " + this.baseLoc);
405
+ console.error("Impossibile trovare la localizzazione per '" + text + "', culture " + this.Locale);
350
406
  return "";
351
407
  }
352
408
  return loc.translation;
353
409
  }
354
- /**
355
- * Localizzazione per Severity classiche (E per errore, W per warning e I per info)
356
- *
357
- * @param {string} text Severity da tradurre
358
- *
359
- * @returns {string} Severity tradotta
360
- */
361
- locSeverity(text) {
362
- if (text == "E")
363
- return this.loc("Error");
364
- if (text == "W")
365
- return this.loc("Warning");
366
- if (text == "I")
367
- return this.loc("Information");
368
- return "";
410
+ changeLocale(newLocale) {
411
+ return __awaiter(this, void 0, void 0, function* () {
412
+ let locale = yield this.LocalePersistor.recover().toPromise();
413
+ if (newLocale == locale) {
414
+ console.info("Il locale richiesto è lo stesso del locale attuale. Ignoro l'operazione");
415
+ return;
416
+ }
417
+ else {
418
+ yield this.LocalePersistor.persist(newLocale).toPromise();
419
+ location.reload();
420
+ }
421
+ });
369
422
  }
370
423
  }
371
- LocalizationService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: LocalizationService, deps: [{ token: LOC_LOCALE }, { token: BaseLocalization }], target: i0.ɵɵFactoryTarget.Injectable });
424
+ LocalizationService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: LocalizationService, deps: [{ token: i0.Injector }], target: i0.ɵɵFactoryTarget.Injectable });
372
425
  LocalizationService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: LocalizationService });
373
426
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: LocalizationService, decorators: [{
374
427
  type: Injectable
375
- }], ctorParameters: function () {
376
- return [{ type: undefined, decorators: [{
377
- type: Inject,
378
- args: [LOC_LOCALE]
379
- }] }, { type: BaseLocalization }];
380
- } });
428
+ }], ctorParameters: function () { return [{ type: i0.Injector }]; } });
381
429
 
382
430
  // Angular
383
431
  /**
@@ -457,6 +505,25 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImpor
457
505
  args: [{ name: "localize", pure: true }]
458
506
  }], ctorParameters: function () { return [{ type: LocalizationService }]; } });
459
507
 
508
+ // Angular
509
+ class LocalStorageLocalePersistor extends LocalePersistor {
510
+ /** @ignore Vedi classe base */
511
+ persist(locale) {
512
+ localStorage.setItem(this.LOCALE, locale);
513
+ return of(true).pipe(first());
514
+ }
515
+ /** @ignore Vedi classe base */
516
+ recover() {
517
+ var ret = localStorage.getItem(this.LOCALE);
518
+ return of(ret).pipe(first());
519
+ }
520
+ }
521
+ LocalStorageLocalePersistor.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: LocalStorageLocalePersistor, deps: null, target: i0.ɵɵFactoryTarget.Injectable });
522
+ LocalStorageLocalePersistor.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: LocalStorageLocalePersistor });
523
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: LocalStorageLocalePersistor, decorators: [{
524
+ type: Injectable
525
+ }] });
526
+
460
527
  class LocalizationModule {
461
528
  static forRoot(config) {
462
529
  return {
@@ -464,7 +531,8 @@ class LocalizationModule {
464
531
  providers: [
465
532
  LocalizationService,
466
533
  BaseLocalization,
467
- { provide: LOC_LOCALE, useValue: (config === null || config === void 0 ? void 0 : config.locale) || 'it-IT' }
534
+ { provide: LOC_LOCALE, useValue: (config === null || config === void 0 ? void 0 : config.defaultLocale) || 'it-IT' },
535
+ { provide: LocalePersistor, useClass: (config === null || config === void 0 ? void 0 : config.localePersistor) || LocalStorageLocalePersistor },
468
536
  ]
469
537
  };
470
538
  }
@@ -488,5 +556,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImpor
488
556
  * Generated bundle index. Do not edit.
489
557
  */
490
558
 
491
- export { LOC_LOCALE, LocDatePipe, LocalizationModule, LocalizationModuleConfig, LocalizationService, LocalizePipe };
559
+ export { BaseLocalization, BaseLocalizationTokens, LOC_LOCALE, LocDatePipe, LocalizationModule, LocalizationModuleConfig, LocalizationService, LocalizePipe };
492
560
  //# sourceMappingURL=esfaenza-localizations.mjs.map