@esfaenza/localizations 11.2.9 → 11.2.10

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,13 +1,339 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@esfaenza/extensions')) :
3
- typeof define === 'function' && define.amd ? define('@esfaenza/localizations', ['exports', '@angular/core', '@esfaenza/extensions'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.esfaenza = global.esfaenza || {}, global.esfaenza.localizations = {}), global.ng.core, global.extensions));
5
- }(this, (function (exports, core, extensions) { 'use strict';
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('rxjs/operators'), require('rxjs'), require('@esfaenza/extensions')) :
3
+ typeof define === 'function' && define.amd ? define('@esfaenza/localizations', ['exports', '@angular/core', 'rxjs/operators', 'rxjs', '@esfaenza/extensions'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.esfaenza = global.esfaenza || {}, global.esfaenza.localizations = {}), global.ng.core, global.rxjs.operators, global.rxjs, global.extensions));
5
+ }(this, (function (exports, i0, operators, rxjs, extensions) { 'use strict';
6
6
 
7
- /**
8
- * Locale da utilizzare per le traduzioni
9
- */
10
- var LOC_LOCALE = new core.InjectionToken('LOC_LOCALE');
7
+ function _interopNamespace(e) {
8
+ if (e && e.__esModule) return e;
9
+ var n = Object.create(null);
10
+ if (e) {
11
+ Object.keys(e).forEach(function (k) {
12
+ if (k !== 'default') {
13
+ var d = Object.getOwnPropertyDescriptor(e, k);
14
+ Object.defineProperty(n, k, d.get ? d : {
15
+ enumerable: true,
16
+ get: function () {
17
+ return e[k];
18
+ }
19
+ });
20
+ }
21
+ });
22
+ }
23
+ n['default'] = e;
24
+ return Object.freeze(n);
25
+ }
26
+
27
+ var i0__namespace = /*#__PURE__*/_interopNamespace(i0);
28
+
29
+ /*! *****************************************************************************
30
+ Copyright (c) Microsoft Corporation.
31
+
32
+ Permission to use, copy, modify, and/or distribute this software for any
33
+ purpose with or without fee is hereby granted.
34
+
35
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
36
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
37
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
38
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
39
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
40
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
41
+ PERFORMANCE OF THIS SOFTWARE.
42
+ ***************************************************************************** */
43
+ /* global Reflect, Promise */
44
+ var extendStatics = function (d, b) {
45
+ extendStatics = Object.setPrototypeOf ||
46
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
47
+ function (d, b) { for (var p in b)
48
+ if (Object.prototype.hasOwnProperty.call(b, p))
49
+ d[p] = b[p]; };
50
+ return extendStatics(d, b);
51
+ };
52
+ function __extends(d, b) {
53
+ if (typeof b !== "function" && b !== null)
54
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
55
+ extendStatics(d, b);
56
+ function __() { this.constructor = d; }
57
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
58
+ }
59
+ var __assign = function () {
60
+ __assign = Object.assign || function __assign(t) {
61
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
62
+ s = arguments[i];
63
+ for (var p in s)
64
+ if (Object.prototype.hasOwnProperty.call(s, p))
65
+ t[p] = s[p];
66
+ }
67
+ return t;
68
+ };
69
+ return __assign.apply(this, arguments);
70
+ };
71
+ function __rest(s, e) {
72
+ var t = {};
73
+ for (var p in s)
74
+ if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
75
+ t[p] = s[p];
76
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
77
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
78
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
79
+ t[p[i]] = s[p[i]];
80
+ }
81
+ return t;
82
+ }
83
+ function __decorate(decorators, target, key, desc) {
84
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
85
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
86
+ r = Reflect.decorate(decorators, target, key, desc);
87
+ else
88
+ for (var i = decorators.length - 1; i >= 0; i--)
89
+ if (d = decorators[i])
90
+ r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
91
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
92
+ }
93
+ function __param(paramIndex, decorator) {
94
+ return function (target, key) { decorator(target, key, paramIndex); };
95
+ }
96
+ function __metadata(metadataKey, metadataValue) {
97
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
98
+ return Reflect.metadata(metadataKey, metadataValue);
99
+ }
100
+ function __awaiter(thisArg, _arguments, P, generator) {
101
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
102
+ return new (P || (P = Promise))(function (resolve, reject) {
103
+ function fulfilled(value) { try {
104
+ step(generator.next(value));
105
+ }
106
+ catch (e) {
107
+ reject(e);
108
+ } }
109
+ function rejected(value) { try {
110
+ step(generator["throw"](value));
111
+ }
112
+ catch (e) {
113
+ reject(e);
114
+ } }
115
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
116
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
117
+ });
118
+ }
119
+ function __generator(thisArg, body) {
120
+ var _ = { label: 0, sent: function () { if (t[0] & 1)
121
+ throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
122
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function () { return this; }), g;
123
+ function verb(n) { return function (v) { return step([n, v]); }; }
124
+ function step(op) {
125
+ if (f)
126
+ throw new TypeError("Generator is already executing.");
127
+ while (_)
128
+ try {
129
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done)
130
+ return t;
131
+ if (y = 0, t)
132
+ op = [op[0] & 2, t.value];
133
+ switch (op[0]) {
134
+ case 0:
135
+ case 1:
136
+ t = op;
137
+ break;
138
+ case 4:
139
+ _.label++;
140
+ return { value: op[1], done: false };
141
+ case 5:
142
+ _.label++;
143
+ y = op[1];
144
+ op = [0];
145
+ continue;
146
+ case 7:
147
+ op = _.ops.pop();
148
+ _.trys.pop();
149
+ continue;
150
+ default:
151
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
152
+ _ = 0;
153
+ continue;
154
+ }
155
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) {
156
+ _.label = op[1];
157
+ break;
158
+ }
159
+ if (op[0] === 6 && _.label < t[1]) {
160
+ _.label = t[1];
161
+ t = op;
162
+ break;
163
+ }
164
+ if (t && _.label < t[2]) {
165
+ _.label = t[2];
166
+ _.ops.push(op);
167
+ break;
168
+ }
169
+ if (t[2])
170
+ _.ops.pop();
171
+ _.trys.pop();
172
+ continue;
173
+ }
174
+ op = body.call(thisArg, _);
175
+ }
176
+ catch (e) {
177
+ op = [6, e];
178
+ y = 0;
179
+ }
180
+ finally {
181
+ f = t = 0;
182
+ }
183
+ if (op[0] & 5)
184
+ throw op[1];
185
+ return { value: op[0] ? op[1] : void 0, done: true };
186
+ }
187
+ }
188
+ var __createBinding = Object.create ? (function (o, m, k, k2) {
189
+ if (k2 === undefined)
190
+ k2 = k;
191
+ Object.defineProperty(o, k2, { enumerable: true, get: function () { return m[k]; } });
192
+ }) : (function (o, m, k, k2) {
193
+ if (k2 === undefined)
194
+ k2 = k;
195
+ o[k2] = m[k];
196
+ });
197
+ function __exportStar(m, o) {
198
+ for (var p in m)
199
+ if (p !== "default" && !Object.prototype.hasOwnProperty.call(o, p))
200
+ __createBinding(o, m, p);
201
+ }
202
+ function __values(o) {
203
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
204
+ if (m)
205
+ return m.call(o);
206
+ if (o && typeof o.length === "number")
207
+ return {
208
+ next: function () {
209
+ if (o && i >= o.length)
210
+ o = void 0;
211
+ return { value: o && o[i++], done: !o };
212
+ }
213
+ };
214
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
215
+ }
216
+ function __read(o, n) {
217
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
218
+ if (!m)
219
+ return o;
220
+ var i = m.call(o), r, ar = [], e;
221
+ try {
222
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done)
223
+ ar.push(r.value);
224
+ }
225
+ catch (error) {
226
+ e = { error: error };
227
+ }
228
+ finally {
229
+ try {
230
+ if (r && !r.done && (m = i["return"]))
231
+ m.call(i);
232
+ }
233
+ finally {
234
+ if (e)
235
+ throw e.error;
236
+ }
237
+ }
238
+ return ar;
239
+ }
240
+ /** @deprecated */
241
+ function __spread() {
242
+ for (var ar = [], i = 0; i < arguments.length; i++)
243
+ ar = ar.concat(__read(arguments[i]));
244
+ return ar;
245
+ }
246
+ /** @deprecated */
247
+ function __spreadArrays() {
248
+ for (var s = 0, i = 0, il = arguments.length; i < il; i++)
249
+ s += arguments[i].length;
250
+ for (var r = Array(s), k = 0, i = 0; i < il; i++)
251
+ for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
252
+ r[k] = a[j];
253
+ return r;
254
+ }
255
+ function __spreadArray(to, from) {
256
+ for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
257
+ to[j] = from[i];
258
+ return to;
259
+ }
260
+ function __await(v) {
261
+ return this instanceof __await ? (this.v = v, this) : new __await(v);
262
+ }
263
+ function __asyncGenerator(thisArg, _arguments, generator) {
264
+ if (!Symbol.asyncIterator)
265
+ throw new TypeError("Symbol.asyncIterator is not defined.");
266
+ var g = generator.apply(thisArg, _arguments || []), i, q = [];
267
+ return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
268
+ function verb(n) { if (g[n])
269
+ i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
270
+ function resume(n, v) { try {
271
+ step(g[n](v));
272
+ }
273
+ catch (e) {
274
+ settle(q[0][3], e);
275
+ } }
276
+ function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
277
+ function fulfill(value) { resume("next", value); }
278
+ function reject(value) { resume("throw", value); }
279
+ function settle(f, v) { if (f(v), q.shift(), q.length)
280
+ resume(q[0][0], q[0][1]); }
281
+ }
282
+ function __asyncDelegator(o) {
283
+ var i, p;
284
+ return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
285
+ function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; }
286
+ }
287
+ function __asyncValues(o) {
288
+ if (!Symbol.asyncIterator)
289
+ throw new TypeError("Symbol.asyncIterator is not defined.");
290
+ var m = o[Symbol.asyncIterator], i;
291
+ return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
292
+ function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
293
+ function settle(resolve, reject, d, v) { Promise.resolve(v).then(function (v) { resolve({ value: v, done: d }); }, reject); }
294
+ }
295
+ function __makeTemplateObject(cooked, raw) {
296
+ if (Object.defineProperty) {
297
+ Object.defineProperty(cooked, "raw", { value: raw });
298
+ }
299
+ else {
300
+ cooked.raw = raw;
301
+ }
302
+ return cooked;
303
+ }
304
+ ;
305
+ var __setModuleDefault = Object.create ? (function (o, v) {
306
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
307
+ }) : function (o, v) {
308
+ o["default"] = v;
309
+ };
310
+ function __importStar(mod) {
311
+ if (mod && mod.__esModule)
312
+ return mod;
313
+ var result = {};
314
+ if (mod != null)
315
+ for (var k in mod)
316
+ if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k))
317
+ __createBinding(result, mod, k);
318
+ __setModuleDefault(result, mod);
319
+ return result;
320
+ }
321
+ function __importDefault(mod) {
322
+ return (mod && mod.__esModule) ? mod : { default: mod };
323
+ }
324
+ function __classPrivateFieldGet(receiver, privateMap) {
325
+ if (!privateMap.has(receiver)) {
326
+ throw new TypeError("attempted to get private field on non-instance");
327
+ }
328
+ return privateMap.get(receiver);
329
+ }
330
+ function __classPrivateFieldSet(receiver, privateMap, value) {
331
+ if (!privateMap.has(receiver)) {
332
+ throw new TypeError("attempted to set private field on non-instance");
333
+ }
334
+ privateMap.set(receiver, value);
335
+ return value;
336
+ }
11
337
 
12
338
  /**
13
339
  * Contenitore delle localizzazioni collegate ad un testo "base", una per ogni linguaggio supportato
@@ -106,77 +432,14 @@
106
432
  return SpecializedLocalization;
107
433
  }());
108
434
 
109
- /**
110
- * Classe singleton che contiene le traduzioni di base (per evitare di ripeterle in oggi classe di traduzione) e le funzioni base per
111
- * inserire e leggere traduzioni in/da una cache
112
- */
113
- var BaseLocalization = /** @class */ (function () {
114
- /**
115
- * Costruttore. Da qui utilizzando il metodo statico **BaseLocalization.set** si va a popolare la cache delle traduzioni **BaseTranslations**
116
- */
117
- function BaseLocalization() {
118
- /**
119
- * Cache di tutte le localizzazioni di base
120
- */
121
- this.BaseTranslations = {};
122
- // Odio sprecare caratteri... soprattutto quando rischio che non vengano minificati
123
- var bt = this.BaseTranslations;
124
- var bl = BaseLocalization;
125
- bl.set(bt, "en->it", "Remove", ["Elimina"]);
126
- bl.set(bt, "en->it", "Paging", ["Paginazione"]);
127
- bl.set(bt, "en->it", "Yes", ["Si"]);
128
- bl.set(bt, "en->it", "No", ["No"]);
129
- bl.set(bt, "en->it", "YES", ["SI'"]);
130
- bl.set(bt, "en->it", "NO", ["NO"]);
131
- bl.set(bt, "en->it", "Found objects", ["Risultati trovati"]);
132
- bl.set(bt, "en->it", "Loading data...", ["Carico i dati..."]);
133
- bl.set(bt, "en->it", "Error during save operations", ["Errori durante il salvataggio"]);
134
- bl.set(bt, "en->it", "Error", ["Errore"]);
135
- bl.set(bt, "en->it", "Warning", ["Avviso"]);
136
- bl.set(bt, "en->it", "Information", ["Informazione"]);
137
- bl.set(bt, "en->it", "Save", ["Salva"]);
138
- bl.set(bt, "en->it", "Back", ["Indietro"]);
139
- bl.set(bt, "en->it", "From", ["Da"]);
140
- bl.set(bt, "en->it", "To", ["A"]);
141
- bl.set(bt, "en->it", "View Chart", ["Vedi Grafico"]);
142
- bl.set(bt, "en->it", "View Table", ["Vedi Tabella"]);
143
- bl.set(bt, "en->it", "Notes", ["Note"]);
144
- bl.set(bt, "en->it", "Edit Notes", ["Modifica Note"]);
145
- bl.set(bt, "en->it", "Cancel", ["Annulla"]);
146
- bl.set(bt, "en->it", "Confirm", ["Conferma"]);
147
- bl.set(bt, "en->it", "View", ["Visualizza"]);
148
- bl.set(bt, "en->it", "Close", ["Chiudi"]);
149
- bl.set(bt, "en->it", "Select", ["Seleziona"]);
150
- bl.set(bt, "en->it", "Meter Reading registered successfully", ["Lettura registrata correttamente"]);
151
- bl.set(bt, "en->it", "Validation errors during save operations", ["Errori di validazione durante il salvataggio"]);
152
- bl.set(bt, "en->it", "Can't register reading", ["Impossibile registrare la lettura"]);
153
- bl.set(bt, "en->it", "Electricity", ["Elettricita"]);
154
- bl.set(bt, "en->it", "Gas", ["Gas"]);
155
- bl.set(bt, "en->it", "Water", ["Acqua"]);
156
- bl.set(bt, "en->it", "Delete", ["Elimina"]);
157
- bl.set(bt, "en->it", "This operation cannot be reverted", ["Questa operazione non puo' essere annullata"]);
158
- bl.set(bt, "en->it", "Hide", ["Nascondi"]);
159
- // Helper validazione
160
- bl.set(bt, "en->it", "Required field", ["Campo richiesto"]);
161
- bl.set(bt, "en->it", "Wrong field format", ["Formato campo errato"]);
162
- bl.set(bt, "en->it", "Wrong field format or field missing", ["Formato campo errato o campo mancante"]);
163
- 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"]);
164
- // Informazioni sulle date
165
- bl.setToken(bt, "en->it", "getDateMonthPosition", "0", ["1"]);
166
- bl.setToken(bt, "en->it", "getDisplayDateMonthPosition", "1", ["1"]);
167
- bl.setToken(bt, "en->it", "getLocale", "en-US", ["it-IT"]);
168
- bl.setToken(bt, "en->it", "getSmallDateFormat", "MM/DD/YYYY", ["DD/MM/YYYY"]);
169
- bl.setToken(bt, "en->it", "getDefaultDateFormat", "MM/DD/YYYY", ["MM/DD/YYYY"]);
170
- bl.setToken(bt, "en->it", "getSmallDateDisplayFormat", "DD/MM/YYYY", ["DD/MM/YYYY"]);
171
- bl.setToken(bt, "en->it", "getFullDateFormat", "MM/DD/YYYY HH:mm:ss", ["DD/MM/YYYY HH:mm:ss"]);
172
- bl.setToken(bt, "en->it", "getFullDateDisplayFormat", "DD/MM/YYYY HH:mm:ss", ["DD/MM/YYYY HH:mm:ss"]);
173
- bl.setToken(bt, "en->it", "getFullDateFormatNoSeconds", "MM/DD/YYYY HH:mm", ["DD/MM/YYYY HH:mm"]);
174
- bl.setToken(bt, "en->it", "getFullDateDisplayFormatNoSeconds", "DD/MM/YYYY HH:mm", ["DD/MM/YYYY HH:mm"]);
435
+ var LocalizationPersistor = /** @class */ (function () {
436
+ function LocalizationPersistor(LocCache) {
437
+ if (LocCache === void 0) { LocCache = null; }
438
+ this.LocCache = LocCache;
175
439
  }
176
440
  /**
177
441
  * Imposta la localizzazione di un token all'interno della cache scelta
178
442
  *
179
- * @param {{ [id: string]: ItemLocalization }} locCache Cache all'interno della quale inserire l'informazione del token con le localizzazioni
180
443
  * @param {string} direction Direzione della traduzione, rappresenta la lingua base in cui aspettarsi il testo e le varie lingue in cui viene tradotta.
181
444
  * Ad esempio, "en->it" indica che il parametro **left** è valido per le localizzazioni in inglese, mentre nell'elemento 0 del parametro **right**
182
445
  * è 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"
@@ -184,56 +447,56 @@
184
447
  * @param {string} left Valore del token per la lingua specificata nel lato immediatamente sinistro alla freccia del parametro **direction**
185
448
  * @param {string} right Array con i valori facenti riferimento all'N-esima lingua del lato destro del parametro **direction**
186
449
  */
187
- BaseLocalization.setToken = function (locCache, direction, token, left, right) {
450
+ LocalizationPersistor.prototype.setToken = function (direction, token, left, right) {
451
+ var _this = this;
188
452
  var parsingRegex = /([a-zA-Z]+)[\s]*->[\s]*([a-zA-Z,\s]+)+/g;
189
453
  var parsingRes = parsingRegex.exec(direction);
190
454
  var from = parsingRes[1];
191
455
  var to = parsingRes[2].replace(/\s/g, '').split(',');
192
456
  var localeFrom = LocaleDefinitions.getByAlias(from);
193
- BaseLocalization._set(locCache, token, localeFrom.id, left, true);
457
+ this._set(token, localeFrom.id, left, true);
194
458
  to.forEach(function (t, index) {
195
459
  var localeTo = LocaleDefinitions.getByAlias(t);
196
- BaseLocalization._set(locCache, token, localeTo.id, right[index], true);
460
+ _this._set(token, localeTo.id, right[index], true);
197
461
  });
198
462
  };
199
463
  /**
200
464
  * Imposta la localizzazione di una frase all'interno della cache scelta
201
465
  *
202
- * @param {{ [id: string]: ItemLocalization }} locCache Cache all'interno della quale inserire l'informazione della frase con le localizzazioni
203
466
  * @param {string} direction Direzione della traduzione, rappresenta la lingua base in cui aspettarsi il testo e le varie lingue in cui viene tradotta.
204
467
  * Ad esempio, "en->it" indica che il parametro **left** è valido per le localizzazioni in inglese, mentre nell'elemento 0 del parametro **right**
205
468
  * è 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"
206
469
  * @param {string} left Valore della frase per la lingua specificata nel lato immediatamente sinistro alla freccia del parametro **direction**
207
470
  * @param {string} right Array con i valori facenti riferimento all'N-esima lingua del lato destro del parametro **direction**
208
471
  */
209
- BaseLocalization.set = function (locCache, direction, left, right) {
472
+ LocalizationPersistor.prototype.set = function (direction, left, right) {
473
+ var _this = this;
210
474
  var parsingRegex = /([a-zA-Z]+)[\s]*->[\s]*([a-zA-Z,\s]+)+/g;
211
475
  var parsingRes = parsingRegex.exec(direction);
212
476
  var from = parsingRes[1];
213
477
  var to = parsingRes[2].replace(/\s/g, '').split(',');
214
478
  var localeFrom = LocaleDefinitions.getByAlias(from);
215
- BaseLocalization._set(locCache, left, localeFrom.id, left);
479
+ this._set(left, localeFrom.id, left);
216
480
  to.forEach(function (t, index) {
217
481
  var localeTo = LocaleDefinitions.getByAlias(t);
218
- BaseLocalization._set(locCache, left, localeTo.id, right[index]);
482
+ _this._set(left, localeTo.id, right[index]);
219
483
  });
220
484
  };
221
485
  /**
222
486
  * Imposta all'interno della cache specificata un'unica traduzione partendo da un testo di base
223
487
  *
224
- * @param {{ [id: string]: ItemLocalization }} locCache Cache all'interno della quale inserire l'informazione del testo con le localizzazioni
225
488
  * @param {string} text Testo da tradurre
226
489
  * @param {string} culture Lingua per cui inserire la traduzione
227
490
  * @param {string} translation Traduzione del **text** nella lingua specificata da **culture**
228
491
  * @param {boolean} token Indica se il **text** è un token o è una frase normale
229
492
  */
230
- BaseLocalization._set = function (locCache, text, culture, translation, token) {
231
- var item = BaseLocalization.findByText(locCache, text, token);
493
+ LocalizationPersistor.prototype._set = function (text, culture, translation, token) {
494
+ var item = this.get(text, token);
232
495
  if (!item) {
233
- locCache[text] = new ItemLocalization(token, text, [new SpecializedLocalization(culture, translation)]);
496
+ this.LocCache[text] = new ItemLocalization(token, text, [new SpecializedLocalization(culture, translation)]);
234
497
  return;
235
498
  }
236
- var trs = BaseLocalization.translationByCulture(item, culture);
499
+ var trs = this.translationByCulture(item, culture);
237
500
  if (trs) {
238
501
  console.warn("Localization already loaded for sentence '" + text + "' and culture " + culture);
239
502
  return;
@@ -243,15 +506,14 @@
243
506
  /**
244
507
  * Partendo da una cache di localizzazione, dato un testo che può essere o meno un token, cerca quell'elemento all'interno della cache
245
508
  *
246
- * @param {{ [id: string]: ItemLocalization }} locCache Cache all'interno del quale cercare il **text**
247
- * @param {string} text Testo da cercare nella **locCache**
509
+ * @param {string} text Testo da cercare nella **LocCache**
248
510
  * @param {boolean} allowtokens Indica se l'elemento cercato può essere un token o se dev'essere per forza una frase (per evitare rari
249
511
  * casi di collisione in cui magari un token è uguale a una frase tradotta)
250
512
  *
251
513
  * @returns {ItemLocalization} Informazioni di localizzazione per il **text** cercato
252
514
  */
253
- BaseLocalization.findByText = function (locCache, text, allowtokens) {
254
- var possibleItem = locCache[text];
515
+ LocalizationPersistor.prototype.get = function (text, allowtokens) {
516
+ var possibleItem = this.LocCache[text];
255
517
  if (!possibleItem)
256
518
  return null;
257
519
  var item = allowtokens || !possibleItem.token ? possibleItem : null;
@@ -265,7 +527,7 @@
265
527
  *
266
528
  * @returns {SpecializedLocalization} Informazioni di localizzazione specifiche della lingua richiesta
267
529
  */
268
- BaseLocalization.translationByCulture = function (item, culture) {
530
+ LocalizationPersistor.prototype.translationByCulture = function (item, culture) {
269
531
  for (var i = 0; i < item.translations.length; i++) {
270
532
  var trl = item.translations[i];
271
533
  if (trl.culture == culture)
@@ -273,12 +535,129 @@
273
535
  }
274
536
  return null;
275
537
  };
538
+ return LocalizationPersistor;
539
+ }());
540
+
541
+ exports.BaseLocalizationTokens = void 0;
542
+ (function (BaseLocalizationTokens) {
543
+ BaseLocalizationTokens["getDateMonthPosition"] = "getDateMonthPosition";
544
+ BaseLocalizationTokens["getDisplayDateMonthPosition"] = "getDisplayDateMonthPosition";
545
+ BaseLocalizationTokens["getLocale"] = "getLocale";
546
+ BaseLocalizationTokens["getSmallDateFormat"] = "getSmallDateFormat";
547
+ BaseLocalizationTokens["getDefaultDateFormat"] = "getDefaultDateFormat";
548
+ BaseLocalizationTokens["getSmallDateDisplayFormat"] = "getSmallDateDisplayFormat";
549
+ BaseLocalizationTokens["getFullDateFormat"] = "getFullDateFormat";
550
+ BaseLocalizationTokens["getFullDateDisplayFormat"] = "getFullDateDisplayFormat";
551
+ BaseLocalizationTokens["getFullDateFormatNoSeconds"] = "getFullDateFormatNoSeconds";
552
+ BaseLocalizationTokens["getFullDateDisplayFormatNoSeconds"] = "getFullDateDisplayFormatNoSeconds";
553
+ })(exports.BaseLocalizationTokens || (exports.BaseLocalizationTokens = {}));
554
+
555
+ /** Classe astratta che rappresenta lo stato di persistenza fra la libreria e uno storage */
556
+ var LocalePersistor = /** @class */ (function () {
557
+ function LocalePersistor() {
558
+ /** Chiave su cui salvare il locale */
559
+ this.LOCALE = "LOCALE";
560
+ }
561
+ return LocalePersistor;
562
+ }());
563
+
564
+ /**
565
+ * Locale da utilizzare per le traduzioni
566
+ */
567
+ var LOC_LOCALE = new i0.InjectionToken('LOC_LOCALE');
568
+
569
+ /**
570
+ * Classe singleton che contiene le traduzioni di base (per evitare di ripeterle in oggi classe di traduzione) e le funzioni base per
571
+ * inserire e leggere traduzioni in/da una cache
572
+ */
573
+ var BaseLocalization = /** @class */ (function () {
574
+ /**
575
+ * Costruttore. Da qui utilizzando il metodo statico **BaseLocalization.set** si va a popolare la cache delle traduzioni **BaseTranslations**
576
+ */
577
+ function BaseLocalization(LocalePersistor, defaultLocale) {
578
+ var _this = this;
579
+ this.LocalePersistor = LocalePersistor;
580
+ /**
581
+ * Cache di tutte le localizzazioni di base
582
+ */
583
+ this.LocCache = {};
584
+ /**
585
+ * Locale di riferimento per tutte le traduzioni
586
+ */
587
+ this.Locale = new rxjs.ReplaySubject(1);
588
+ // Recupero il locale alla partenza del BaseLocalization in modo, spero di dare tempo all'applicazione di tirarlo su
589
+ this.LocalePersistor.recover().pipe(operators.take(1)).subscribe(function (l) { return __awaiter(_this, void 0, void 0, function () {
590
+ return __generator(this, function (_a) {
591
+ if (!l) {
592
+ l = defaultLocale;
593
+ this.LocalePersistor.persist(defaultLocale);
594
+ }
595
+ this.Locale.next(l);
596
+ return [2 /*return*/];
597
+ });
598
+ }); });
599
+ this.Persistor = new LocalizationPersistor(this.LocCache);
600
+ this.Persistor.set("en->it", "Remove", ["Elimina"]);
601
+ this.Persistor.set("en->it", "Paging", ["Paginazione"]);
602
+ this.Persistor.set("en->it", "Yes", ["Si"]);
603
+ this.Persistor.set("en->it", "No", ["No"]);
604
+ this.Persistor.set("en->it", "YES", ["SI'"]);
605
+ this.Persistor.set("en->it", "NO", ["NO"]);
606
+ this.Persistor.set("en->it", "Found objects", ["Risultati trovati"]);
607
+ this.Persistor.set("en->it", "Loading data...", ["Carico i dati..."]);
608
+ this.Persistor.set("en->it", "Error during save operations", ["Errori durante il salvataggio"]);
609
+ this.Persistor.set("en->it", "Error", ["Errore"]);
610
+ this.Persistor.set("en->it", "Warning", ["Avviso"]);
611
+ this.Persistor.set("en->it", "Information", ["Informazione"]);
612
+ this.Persistor.set("en->it", "Save", ["Salva"]);
613
+ this.Persistor.set("en->it", "Back", ["Indietro"]);
614
+ this.Persistor.set("en->it", "From", ["Da"]);
615
+ this.Persistor.set("en->it", "To", ["A"]);
616
+ this.Persistor.set("en->it", "View Chart", ["Vedi Grafico"]);
617
+ this.Persistor.set("en->it", "View Table", ["Vedi Tabella"]);
618
+ this.Persistor.set("en->it", "Notes", ["Note"]);
619
+ this.Persistor.set("en->it", "Edit Notes", ["Modifica Note"]);
620
+ this.Persistor.set("en->it", "Cancel", ["Annulla"]);
621
+ this.Persistor.set("en->it", "Confirm", ["Conferma"]);
622
+ this.Persistor.set("en->it", "View", ["Visualizza"]);
623
+ this.Persistor.set("en->it", "Close", ["Chiudi"]);
624
+ this.Persistor.set("en->it", "Select", ["Seleziona"]);
625
+ this.Persistor.set("en->it", "Meter Reading registered successfully", ["Lettura registrata correttamente"]);
626
+ this.Persistor.set("en->it", "Validation errors during save operations", ["Errori di validazione durante il salvataggio"]);
627
+ this.Persistor.set("en->it", "Can't register reading", ["Impossibile registrare la lettura"]);
628
+ this.Persistor.set("en->it", "Electricity", ["Elettricita"]);
629
+ this.Persistor.set("en->it", "Gas", ["Gas"]);
630
+ this.Persistor.set("en->it", "Water", ["Acqua"]);
631
+ this.Persistor.set("en->it", "Delete", ["Elimina"]);
632
+ this.Persistor.set("en->it", "This operation cannot be reverted", ["Questa operazione non puo' essere annullata"]);
633
+ this.Persistor.set("en->it", "Hide", ["Nascondi"]);
634
+ // Helper validazione
635
+ this.Persistor.set("en->it", "Required field", ["Campo richiesto"]);
636
+ this.Persistor.set("en->it", "Wrong field format", ["Formato campo errato"]);
637
+ this.Persistor.set("en->it", "Wrong field format or field missing", ["Formato campo errato o campo mancante"]);
638
+ 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"]);
639
+ // Informazioni sulle date
640
+ this.Persistor.setToken("en->it", exports.BaseLocalizationTokens.getDateMonthPosition, "0", ["1"]);
641
+ this.Persistor.setToken("en->it", exports.BaseLocalizationTokens.getDisplayDateMonthPosition, "1", ["1"]);
642
+ this.Persistor.setToken("en->it", exports.BaseLocalizationTokens.getLocale, "en-US", ["it-IT"]);
643
+ this.Persistor.setToken("en->it", exports.BaseLocalizationTokens.getSmallDateFormat, "MM/DD/YYYY", ["DD/MM/YYYY"]);
644
+ this.Persistor.setToken("en->it", exports.BaseLocalizationTokens.getDefaultDateFormat, "MM/DD/YYYY", ["MM/DD/YYYY"]);
645
+ this.Persistor.setToken("en->it", exports.BaseLocalizationTokens.getSmallDateDisplayFormat, "DD/MM/YYYY", ["DD/MM/YYYY"]);
646
+ this.Persistor.setToken("en->it", exports.BaseLocalizationTokens.getFullDateFormat, "MM/DD/YYYY HH:mm:ss", ["DD/MM/YYYY HH:mm:ss"]);
647
+ this.Persistor.setToken("en->it", exports.BaseLocalizationTokens.getFullDateDisplayFormat, "DD/MM/YYYY HH:mm:ss", ["DD/MM/YYYY HH:mm:ss"]);
648
+ this.Persistor.setToken("en->it", exports.BaseLocalizationTokens.getFullDateFormatNoSeconds, "MM/DD/YYYY HH:mm", ["DD/MM/YYYY HH:mm"]);
649
+ this.Persistor.setToken("en->it", exports.BaseLocalizationTokens.getFullDateDisplayFormatNoSeconds, "DD/MM/YYYY HH:mm", ["DD/MM/YYYY HH:mm"]);
650
+ }
276
651
  return BaseLocalization;
277
652
  }());
653
+ BaseLocalization.ɵprov = i0__namespace.ɵɵdefineInjectable({ factory: function BaseLocalization_Factory() { return new BaseLocalization(i0__namespace.ɵɵinject(LocalePersistor), i0__namespace.ɵɵinject(LOC_LOCALE)); }, token: BaseLocalization, providedIn: "root" });
278
654
  BaseLocalization.decorators = [
279
- { type: core.Injectable }
655
+ { type: i0.Injectable, args: [{ providedIn: 'root' },] }
280
656
  ];
281
- BaseLocalization.ctorParameters = function () { return []; };
657
+ BaseLocalization.ctorParameters = function () { return [
658
+ { type: LocalePersistor },
659
+ { type: String, decorators: [{ type: i0.Inject, args: [LOC_LOCALE,] }] }
660
+ ]; };
282
661
 
283
662
  /**
284
663
  * Classe di localizzazione estendibile che permette di specificare le proprie localizzazioni e comunque rendere disponibili le localizzazioni globali
@@ -287,17 +666,23 @@
287
666
  /**
288
667
  * Costruttore
289
668
  *
290
- * @param {string} baseLoc Locale da utilizzare nel momento che questo servizio richiede le traduzioni
669
+ * @param {string} Locale Locale da utilizzare nel momento che questo servizio richiede le traduzioni
291
670
  * @param {baseLocalization} baseLocalization Classe base di localizzazione già fornita a livello di root dalla libreria stessa.
292
671
  * È sufficiente iniettarla nell'eventuale costruttore che estende questa classe e passarla as-is
293
672
  */
294
- function LocalizationService(baseLoc, baseLocalization) {
295
- this.baseLoc = baseLoc;
296
- this.baseLocalization = baseLocalization;
673
+ function LocalizationService(injector) {
674
+ var _this = this;
675
+ this.injector = injector;
297
676
  /**
298
677
  * Cache di tutte le localizzazioni disonibili all'interno di questa classe
299
678
  */
300
679
  this.TranslationCache = {};
680
+ this.LocalePersistor = this.injector.get(LocalePersistor);
681
+ this.baseLocalization = this.injector.get(BaseLocalization);
682
+ this.Persistor = new LocalizationPersistor(this.TranslationCache);
683
+ this.baseLocalization.Locale.subscribe(function (lr) {
684
+ _this.Locale = lr;
685
+ });
301
686
  }
302
687
  /**
303
688
  * Imposta la localizzazione di un token all'interno della **TranslationCache**
@@ -310,7 +695,7 @@
310
695
  * @param {string} right Array con i valori facenti riferimento all'N-esima lingua del lato destro del parametro **direction**
311
696
  */
312
697
  LocalizationService.prototype.setToken = function (direction, token, left, right) {
313
- BaseLocalization.setToken(this.TranslationCache, direction, token, left, right);
698
+ this.Persistor.setToken(direction, token, left, right);
314
699
  };
315
700
  /**
316
701
  * Imposta la localizzazione di una frase all'interno della **TranslationCache**
@@ -322,7 +707,13 @@
322
707
  * @param {string} right Array con i valori facenti riferimento all'N-esima lingua del lato destro del parametro **direction**
323
708
  */
324
709
  LocalizationService.prototype.set = function (direction, left, right) {
325
- BaseLocalization.set(this.TranslationCache, direction, left, right);
710
+ // Controlla di non reinserire la stessa localizzazione presente nel BaseLocalization
711
+ // i controlli per il non reinserimento della stessa localizzazione all'interno della stessa istanza è fatto lato Persistor
712
+ if (this.baseLocalization.Persistor.get(left, false)) {
713
+ console.warn("La localizzazione per " + left + " \u00E8 gi\u00E0 presente fra le localizzazioni base, ignoro l'operazione");
714
+ return;
715
+ }
716
+ this.Persistor.set(direction, left, right);
326
717
  };
327
718
  /**
328
719
  * Localizza un token
@@ -345,46 +736,51 @@
345
736
  LocalizationService.prototype.loc = function (text, allowtokens) {
346
737
  if (!text || text == "undefined")
347
738
  return "";
348
- // Questo può succedere solo se qualcuno crea questa service a manazza. In quel caso prendo la classe di default e basta
349
- if (this.baseLocalization == null)
350
- this.baseLocalization = new BaseLocalization();
351
739
  // Prendo la localizzazione o dalla cache attuale o dalla cache del servizio base
352
- var item = BaseLocalization.findByText(this.TranslationCache, text, allowtokens) || BaseLocalization.findByText(this.baseLocalization.BaseTranslations, text, allowtokens);
740
+ var item = this.Persistor.get(text, allowtokens) || this.baseLocalization.Persistor.get(text, allowtokens);
353
741
  if (!item) {
354
- console.error("Couldn't find localization for '" + text + "'");
742
+ console.error("Impossibile trovare la localizzazione per '" + text + "'");
355
743
  return "";
356
744
  }
357
- var loc = BaseLocalization.translationByCulture(item, this.baseLoc);
745
+ if (!this.Locale) {
746
+ console.error("Il sistema di localizzazione non ha ancora caricato il Locale, assicurarsi di caricare l'APP solo al retrieve del locale'");
747
+ return "";
748
+ }
749
+ var loc = this.Persistor.translationByCulture(item, this.Locale);
358
750
  if (!loc) {
359
- console.error("Couldn't find localization for '" + text + "', culture " + this.baseLoc);
751
+ console.error("Impossibile trovare la localizzazione per '" + text + "', culture " + this.Locale);
360
752
  return "";
361
753
  }
362
754
  return loc.translation;
363
755
  };
364
- /**
365
- * Localizzazione per Severity classiche (E per errore, W per warning e I per info)
366
- *
367
- * @param {string} text Severity da tradurre
368
- *
369
- * @returns {string} Severity tradotta
370
- */
371
- LocalizationService.prototype.locSeverity = function (text) {
372
- if (text == "E")
373
- return this.loc("Error");
374
- if (text == "W")
375
- return this.loc("Warning");
376
- if (text == "I")
377
- return this.loc("Information");
378
- return "";
756
+ LocalizationService.prototype.changeLocale = function (newLocale) {
757
+ return __awaiter(this, void 0, void 0, function () {
758
+ var locale;
759
+ return __generator(this, function (_a) {
760
+ switch (_a.label) {
761
+ case 0: return [4 /*yield*/, this.LocalePersistor.recover().toPromise()];
762
+ case 1:
763
+ locale = _a.sent();
764
+ if (!(newLocale == locale)) return [3 /*break*/, 2];
765
+ console.info("Il locale richiesto è lo stesso del locale attuale. Ignoro l'operazione");
766
+ return [2 /*return*/];
767
+ case 2: return [4 /*yield*/, this.LocalePersistor.persist(newLocale).toPromise()];
768
+ case 3:
769
+ _a.sent();
770
+ location.reload();
771
+ _a.label = 4;
772
+ case 4: return [2 /*return*/];
773
+ }
774
+ });
775
+ });
379
776
  };
380
777
  return LocalizationService;
381
778
  }());
382
779
  LocalizationService.decorators = [
383
- { type: core.Injectable }
780
+ { type: i0.Injectable }
384
781
  ];
385
782
  LocalizationService.ctorParameters = function () { return [
386
- { type: String, decorators: [{ type: core.Inject, args: [LOC_LOCALE,] }] },
387
- { type: BaseLocalization }
783
+ { type: i0.Injector }
388
784
  ]; };
389
785
 
390
786
  // Angular
@@ -421,10 +817,10 @@
421
817
  return LocDatePipe;
422
818
  }());
423
819
  LocDatePipe.decorators = [
424
- { type: core.Pipe, args: [{ name: "loc_date", pure: true },] }
820
+ { type: i0.Pipe, args: [{ name: "loc_date", pure: true },] }
425
821
  ];
426
822
  LocDatePipe.ctorParameters = function () { return [
427
- { type: extensions.DateService, decorators: [{ type: core.Optional }] }
823
+ { type: extensions.DateService, decorators: [{ type: i0.Optional }] }
428
824
  ]; };
429
825
 
430
826
  // Angular
@@ -458,12 +854,33 @@
458
854
  return LocalizePipe;
459
855
  }());
460
856
  LocalizePipe.decorators = [
461
- { type: core.Pipe, args: [{ name: "localize", pure: true },] }
857
+ { type: i0.Pipe, args: [{ name: "localize", pure: true },] }
462
858
  ];
463
859
  LocalizePipe.ctorParameters = function () { return [
464
860
  { type: LocalizationService }
465
861
  ]; };
466
862
 
863
+ var LocalStorageLocalePersistor = /** @class */ (function (_super) {
864
+ __extends(LocalStorageLocalePersistor, _super);
865
+ function LocalStorageLocalePersistor() {
866
+ return _super !== null && _super.apply(this, arguments) || this;
867
+ }
868
+ /** @ignore Vedi classe base */
869
+ LocalStorageLocalePersistor.prototype.persist = function (locale) {
870
+ localStorage.setItem(this.LOCALE, locale);
871
+ return rxjs.of(true).pipe(operators.first());
872
+ };
873
+ /** @ignore Vedi classe base */
874
+ LocalStorageLocalePersistor.prototype.recover = function () {
875
+ var ret = localStorage.getItem(this.LOCALE);
876
+ return rxjs.of(ret).pipe(operators.first());
877
+ };
878
+ return LocalStorageLocalePersistor;
879
+ }(LocalePersistor));
880
+ LocalStorageLocalePersistor.decorators = [
881
+ { type: i0.Injectable }
882
+ ];
883
+
467
884
  var LocalizationModule = /** @class */ (function () {
468
885
  function LocalizationModule() {
469
886
  }
@@ -473,14 +890,15 @@
473
890
  providers: [
474
891
  LocalizationService,
475
892
  BaseLocalization,
476
- { provide: LOC_LOCALE, useValue: (config === null || config === void 0 ? void 0 : config.locale) || 'it-IT' }
893
+ { provide: LOC_LOCALE, useValue: (config === null || config === void 0 ? void 0 : config.defaultLocale) || 'it-IT' },
894
+ { provide: LocalePersistor, useClass: (config === null || config === void 0 ? void 0 : config.localePersistor) || LocalStorageLocalePersistor },
477
895
  ]
478
896
  };
479
897
  };
480
898
  return LocalizationModule;
481
899
  }());
482
900
  LocalizationModule.decorators = [
483
- { type: core.NgModule, args: [{
901
+ { type: i0.NgModule, args: [{
484
902
  declarations: [LocalizePipe, LocDatePipe],
485
903
  exports: [LocalizePipe, LocDatePipe]
486
904
  },] }
@@ -494,13 +912,15 @@
494
912
  * Generated bundle index. Do not edit.
495
913
  */
496
914
 
915
+ exports.BaseLocalization = BaseLocalization;
497
916
  exports.LOC_LOCALE = LOC_LOCALE;
498
917
  exports.LocDatePipe = LocDatePipe;
499
918
  exports.LocalizationModule = LocalizationModule;
500
919
  exports.LocalizationModuleConfig = LocalizationModuleConfig;
501
920
  exports.LocalizationService = LocalizationService;
502
921
  exports.LocalizePipe = LocalizePipe;
503
- exports.ɵa = BaseLocalization;
922
+ exports.ɵa = LocalePersistor;
923
+ exports.ɵb = LocalStorageLocalePersistor;
504
924
 
505
925
  Object.defineProperty(exports, '__esModule', { value: true });
506
926