@esfaenza/localizations 19.2.12 → 19.2.13
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.
- package/esm2020/esfaenza-localizations.mjs +5 -0
- package/esm2020/lib/core/localization.base.mjs +80 -0
- package/esm2020/lib/core/localization.persistor.mjs +103 -0
- package/esm2020/lib/locale-persistor/LocalStorageCachePersistor.mjs +25 -0
- package/esm2020/lib/locale-persistor/LocalePersistor.mjs +8 -0
- package/esm2020/lib/localizations.module.mjs +38 -0
- package/esm2020/lib/localizations.service.mjs +148 -0
- package/esm2020/lib/models/BaseLocalizationTokens.mjs +14 -0
- package/esm2020/lib/models/ItemLocalization.mjs +18 -0
- package/esm2020/lib/models/LocaleDefinitions.mjs +26 -0
- package/esm2020/lib/models/LocaleObject.mjs +20 -0
- package/esm2020/lib/models/LocalizationMissingPolicy.mjs +12 -0
- package/esm2020/lib/models/LocalizationModuleConfig.mjs +6 -0
- package/esm2020/lib/models/SpecializedLocalization.mjs +16 -0
- package/esm2020/lib/pipes/localize.pipe.mjs +42 -0
- package/esm2020/lib/tokens.mjs +8 -0
- package/esm2020/public-api.mjs +12 -0
- package/fesm2015/esfaenza-localizations.mjs +543 -0
- package/fesm2015/esfaenza-localizations.mjs.map +1 -0
- package/{fesm2022 → fesm2020}/esfaenza-localizations.mjs +502 -498
- package/fesm2020/esfaenza-localizations.mjs.map +1 -0
- package/index.d.ts +5 -5
- package/lib/core/localization.base.d.ts +32 -32
- package/lib/core/localization.persistor.d.ts +57 -57
- package/lib/locale-persistor/LocalStorageCachePersistor.d.ts +11 -11
- package/lib/locale-persistor/LocalePersistor.d.ts +18 -18
- package/lib/localizations.module.d.ts +10 -10
- package/lib/localizations.service.d.ts +74 -74
- package/lib/models/BaseLocalizationTokens.d.ts +12 -12
- package/lib/models/ItemLocalization.d.ts +17 -17
- package/lib/models/LocaleDefinitions.d.ts +20 -20
- package/lib/models/LocaleObject.d.ts +18 -18
- package/lib/models/LocalizationMissingPolicy.d.ts +10 -9
- package/lib/models/LocalizationModuleConfig.d.ts +19 -19
- package/lib/models/SpecializedLocalization.d.ts +14 -14
- package/lib/pipes/localize.pipe.d.ts +28 -28
- package/lib/tokens.d.ts +8 -8
- package/package.json +11 -3
- package/public-api.d.ts +8 -8
- package/fesm2022/esfaenza-localizations.mjs.map +0 -1
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Classe di configurazione per il modulo di localizzazione
|
|
3
|
+
*/
|
|
4
|
+
export class LocalizationModuleConfig {
|
|
5
|
+
}
|
|
6
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiTG9jYWxpemF0aW9uTW9kdWxlQ29uZmlnLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vLi4vcHJvamVjdHMvbG9jYWxpemF0aW9ucy9zcmMvbGliL21vZGVscy9Mb2NhbGl6YXRpb25Nb2R1bGVDb25maWcudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBSUE7O0dBRUc7QUFDSCxNQUFNLE9BQU8sd0JBQXdCO0NBZ0JwQyIsInNvdXJjZXNDb250ZW50IjpbImltcG9ydCB7IFR5cGUgfSBmcm9tIFwiQGFuZ3VsYXIvY29yZVwiO1xyXG5pbXBvcnQgeyBMb2NhbGVQZXJzaXN0b3IgfSBmcm9tIFwiLi4vbG9jYWxlLXBlcnNpc3Rvci9Mb2NhbGVQZXJzaXN0b3JcIjtcclxuaW1wb3J0IHsgTG9jYWxpemF0aW9uTWlzc2luZ1BvbGljeSB9IGZyb20gXCIuL0xvY2FsaXphdGlvbk1pc3NpbmdQb2xpY3lcIjtcclxuXHJcbi8qKlxyXG4gKiBDbGFzc2UgZGkgY29uZmlndXJhemlvbmUgcGVyIGlsIG1vZHVsbyBkaSBsb2NhbGl6emF6aW9uZVxyXG4gKi9cclxuZXhwb3J0IGNsYXNzIExvY2FsaXph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|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Classe che rappresenta la localizzazione di un test base per una certa lingua
|
|
3
|
+
*/
|
|
4
|
+
export class SpecializedLocalization {
|
|
5
|
+
/**
|
|
6
|
+
* Costruttore
|
|
7
|
+
*
|
|
8
|
+
* @param {string} culture Culture della traduzione
|
|
9
|
+
* @param {string} translation Traduzione nella lingua specificata dalla **culture**
|
|
10
|
+
*/
|
|
11
|
+
constructor(culture, translation) {
|
|
12
|
+
this.culture = culture;
|
|
13
|
+
this.translation = translation;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiU3BlY2lhbGl6ZWRMb2NhbGl6YXRpb24uanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi8uLi9wcm9qZWN0cy9sb2NhbGl6YXRpb25zL3NyYy9saWIvbW9kZWxzL1NwZWNpYWxpemVkTG9jYWxpemF0aW9uLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBOztHQUVHO0FBQ0gsTUFBTSxPQUFPLHVCQUF1QjtJQUVsQzs7Ozs7T0FLRztJQUNILFlBQW1CLE9BQWUsRUFBUyxXQUFtQjtRQUEzQyxZQUFPLEdBQVAsT0FBTyxDQUFRO1FBQVMsZ0JBQVcsR0FBWCxXQUFXLENBQVE7SUFBSSxDQUFDO0NBQ3BFIiwic291cmNlc0NvbnRlbnQiOlsiLyoqXHJcbiAqIENsYXNzZSBjaGUgcmFwcHJlc2VudGEgbGEgbG9jYWxpenphemlvbmUgZGkgdW4gdGVzdCBiYXNlIHBlciB1bmEgY2VydGEgbGluZ3VhXHJcbiAqL1xyXG5leHBvcnQgY2xhc3MgU3BlY2lhbGl6ZWRMb2NhbGl6YXRpb24ge1xyXG5cclxuICAvKipcclxuICAgKiBDb3N0cnV0dG9yZVxyXG4gICAqIFxyXG4gICAqIEBwYXJhbSB7c3RyaW5nfSBjdWx0dXJlIEN1bHR1cmUgZGVsbGEgdHJhZHV6aW9uZVxyXG4gICAqIEBwYXJhbSB7c3RyaW5nfSB0cmFuc2xhdGlvbiBUcmFkdXppb25lIG5lbGxhIGxpbmd1YSBzcGVjaWZpY2F0YSBkYWxsYSAqKmN1bHR1cmUqKlxyXG4gICAqL1xyXG4gIGNvbnN0cnVjdG9yKHB1YmxpYyBjdWx0dXJlOiBzdHJpbmcsIHB1YmxpYyB0cmFuc2xhdGlvbjogc3RyaW5nKSB7IH1cclxufVxyXG4iXX0=
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// Angular
|
|
2
|
+
import { Pipe } from "@angular/core";
|
|
3
|
+
import * as i0 from "@angular/core";
|
|
4
|
+
import * as i1 from "../localizations.service";
|
|
5
|
+
/**
|
|
6
|
+
* Pipe di localizzazione per tradurre direttamente da template
|
|
7
|
+
*/
|
|
8
|
+
export class LocalizePipe {
|
|
9
|
+
/**
|
|
10
|
+
* Costruttore
|
|
11
|
+
*
|
|
12
|
+
* @param {LocalizationService} translationContainer Container delle traduzioni disponibili nel contesto in cui viene usata la pipe.
|
|
13
|
+
*
|
|
14
|
+
* Viene iniettata dal provider dichiarato nel singolo componente che utilizza la traduzione e, se non esiste, viene iniettato dal default
|
|
15
|
+
*/
|
|
16
|
+
constructor(translationContainer) {
|
|
17
|
+
this.translationContainer = translationContainer;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Trasformazione della stringa in input ad una stringa tradotta
|
|
21
|
+
*
|
|
22
|
+
* @param {string} value Testo da tradurre
|
|
23
|
+
* @param {LocalizationService} locContainerOverride Override al contenitore della traduzione iniettato dal costruttore, qualora serva
|
|
24
|
+
*
|
|
25
|
+
* @returns {string} Frase tradotta
|
|
26
|
+
*/
|
|
27
|
+
transform(value, locContainerOverride) {
|
|
28
|
+
if (value == null || value === "")
|
|
29
|
+
return "";
|
|
30
|
+
return (locContainerOverride || this.translationContainer).loc(value);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
LocalizePipe.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: LocalizePipe, deps: [{ token: i1.LocalizationService }], target: i0.ɵɵFactoryTarget.Pipe });
|
|
34
|
+
LocalizePipe.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "15.2.9", ngImport: i0, type: LocalizePipe, name: "localize" });
|
|
35
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: LocalizePipe, decorators: [{
|
|
36
|
+
type: Pipe,
|
|
37
|
+
args: [{
|
|
38
|
+
name: "localize", pure: true,
|
|
39
|
+
standalone: false
|
|
40
|
+
}]
|
|
41
|
+
}], ctorParameters: function () { return [{ type: i1.LocalizationService }]; } });
|
|
42
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibG9jYWxpemUucGlwZS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uLy4uL3Byb2plY3RzL2xvY2FsaXphdGlvbnMvc3JjL2xpYi9waXBlcy9sb2NhbGl6ZS5waXBlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLFVBQVU7QUFDVixPQUFPLEVBQUUsSUFBSSxFQUFpQixNQUFNLGVBQWUsQ0FBQzs7O0FBR3BEOztHQUVHO0FBS0gsTUFBTSxPQUFPLFlBQVk7SUFFckI7Ozs7OztPQU1HO0lBQ0gsWUFBb0Isb0JBQXlDO1FBQXpDLHlCQUFvQixHQUFwQixvQkFBb0IsQ0FBcUI7SUFBSSxDQUFDO0lBRWxFOzs7Ozs7O09BT0c7SUFDSCxTQUFTLENBQUMsS0FBYSxFQUFFLG9CQUEwQztRQUMvRCxJQUFJLEtBQUssSUFBSSxJQUFJLElBQUksS0FBSyxLQUFLLEVBQUU7WUFB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n0iXX0=
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { InjectionToken } from '@angular/core';
|
|
2
|
+
/** Locale da utilizzare per le traduzioni */
|
|
3
|
+
export const LOC_LOCALE = new InjectionToken('LOC_LOCALE');
|
|
4
|
+
/** Policy da utilizzare per traduzioni mancanti */
|
|
5
|
+
export const LOC_MISSING_POLICY = new InjectionToken('LOC_MISSING_POLICY');
|
|
6
|
+
/** Modalità di Debug */
|
|
7
|
+
export const LOC_DEBUG_MODE = new InjectionToken('LOC_DEBUG_MODE');
|
|
8
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidG9rZW5zLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vcHJvamVjdHMvbG9jYWxpemF0aW9ucy9zcmMvbGliL3Rva2Vucy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEVBQUUsY0FBYyxFQUFFLE1BQU0sZUFBZSxDQUFDO0FBRy9DLDZDQUE2QztBQUM3QyxNQUFNLENBQUMsTUFBTSxVQUFVLEdBQTJCLElBQUksY0FBYyxDQUFTLFlBQVksQ0FBQyxDQUFDO0FBRTNGLG1EQUFtRDtBQUNuRCxNQUFNLENBQUMsTUFBTSxrQkFBa0IsR0FBOEMsSUFBSSxjQUFjLENBQTRCLG9CQUFvQixDQUFDLENBQUM7QUFFakosd0JBQXdCO0FBQ3hCLE1BQU0sQ0FBQyxNQUFNLGNBQWMsR0FBNEIsSUFBSSxjQUFjLENBQVUsZ0JBQWdCLENBQUMsQ0FBQyIsInNvdXJjZXNDb250ZW50IjpbImltcG9ydCB7IEluamVjdGlvblRva2VuIH0gZnJvbSAnQGFuZ3VsYXIvY29yZSc7XHJcbmltcG9ydCB7IExvY2FsaXphdGlvbk1pc3NpbmdQb2xpY3kgfSBmcm9tIFwiLi9tb2RlbHMvTG9jYWxpemF0aW9uTWlzc2luZ1BvbGljeVwiXHJcblxyXG4vKiogTG9jYWxlIGRhIHV0aWxpenphcmUgcGVyIGxlIHRyYWR1emlvbmkgKi9cclxuZXhwb3J0IGNvbnN0IExPQ19MT0NBTEU6IEluamVjdGlvblRva2VuPHN0cmluZz4gPSBuZXcgSW5qZWN0aW9uVG9rZW48c3RyaW5nPignTE9DX0xPQ0FMRScpO1xyXG5cclxuLyoqIFBvbGljeSBkYSB1dGlsaXp6YXJlIHBlciB0cmFkdXppb25pIG1hbmNhbnRpICovXHJcbmV4cG9ydCBjb25zdCBMT0NfTUlTU0lOR19QT0xJQ1k6IEluamVjdGlvblRva2VuPExvY2FsaXphdGlvbk1pc3NpbmdQb2xpY3k+ID0gbmV3IEluamVjdGlvblRva2VuPExvY2FsaXphdGlvbk1pc3NpbmdQb2xpY3k+KCdMT0NfTUlTU0lOR19QT0xJQ1knKTtcclxuXHJcbi8qKiBNb2RhbGl0w6AgZGkgRGVidWcgKi9cclxuZXhwb3J0IGNvbnN0IExPQ19ERUJVR19NT0RFOiBJbmplY3Rpb25Ub2tlbjxib29sZWFuPiA9IG5ldyBJbmplY3Rpb25Ub2tlbjxib29sZWFuPignTE9DX0RFQlVHX01PREUnKTsiXX0=
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Public API Surface of localizations
|
|
3
|
+
*/
|
|
4
|
+
export * from './lib/core/localization.base';
|
|
5
|
+
export * from './lib/localizations.module';
|
|
6
|
+
export * from './lib/localizations.service';
|
|
7
|
+
export * from './lib/pipes/localize.pipe';
|
|
8
|
+
export * from './lib/tokens';
|
|
9
|
+
export * from './lib/models/LocalizationModuleConfig';
|
|
10
|
+
export * from './lib/models/BaseLocalizationTokens';
|
|
11
|
+
export * from './lib/models/LocalizationMissingPolicy';
|
|
12
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicHVibGljLWFwaS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3Byb2plY3RzL2xvY2FsaXphdGlvbnMvc3JjL3B1YmxpYy1hcGkudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUE7O0dBRUc7QUFFSCxjQUFjLDhCQUE4QixDQUFDO0FBQzdDLGNBQWMsNEJBQTRCLENBQUM7QUFDM0MsY0FBYyw2QkFBNkIsQ0FBQztBQUM1QyxjQUFjLDJCQUEyQixDQUFDO0FBQzFDLGNBQWMsY0FBYyxDQUFDO0FBQzdCLGNBQWMsdUNBQXVDLENBQUM7QUFDdEQsY0FBYyxxQ0FBcUMsQ0FBQztBQUNwRCxjQUFjLHdDQUF3QyxDQUFDIiwic291cmNlc0NvbnRlbnQiOlsiLypcclxuICogUHVibGljIEFQSSBTdXJmYWNlIG9mIGxvY2FsaXphdGlvbnNcclxuICovXHJcblxyXG5leHBvcnQgKiBmcm9tICcuL2xpYi9jb3JlL2xvY2FsaXphdGlvbi5iYXNlJztcclxuZXhwb3J0ICogZnJvbSAnLi9saWIvbG9jYWxpemF0aW9ucy5tb2R1bGUnO1xyXG5leHBvcnQgKiBmcm9tICcuL2xpYi9sb2NhbGl6YXRpb25zLnNlcnZpY2UnO1xyXG5leHBvcnQgKiBmcm9tICcuL2xpYi9waXBlcy9sb2NhbGl6ZS5waXBlJztcclxuZXhwb3J0ICogZnJvbSAnLi9saWIvdG9rZW5zJztcclxuZXhwb3J0ICogZnJvbSAnLi9saWIvbW9kZWxzL0xvY2FsaXphdGlvbk1vZHVsZUNvbmZpZyc7XHJcbmV4cG9ydCAqIGZyb20gJy4vbGliL21vZGVscy9CYXNlTG9jYWxpemF0aW9uVG9rZW5zJztcclxuZXhwb3J0ICogZnJvbSAnLi9saWIvbW9kZWxzL0xvY2FsaXphdGlvbk1pc3NpbmdQb2xpY3knOyJdfQ==
|
|
@@ -0,0 +1,543 @@
|
|
|
1
|
+
import { __awaiter } from 'tslib';
|
|
2
|
+
import * as i0 from '@angular/core';
|
|
3
|
+
import { InjectionToken, Injectable, Inject, Injector, Pipe, NgModule } from '@angular/core';
|
|
4
|
+
import { take, first } from 'rxjs/operators';
|
|
5
|
+
import { ReplaySubject, of } from 'rxjs';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Contenitore delle localizzazioni collegate ad un testo "base", una per ogni linguaggio supportato
|
|
9
|
+
*/
|
|
10
|
+
class ItemLocalization {
|
|
11
|
+
/**
|
|
12
|
+
* Costruttore
|
|
13
|
+
*
|
|
14
|
+
* @param {boolean} token Indica se è un token o se è un testo
|
|
15
|
+
* @param {string} baseText Testo base che verrà richiesto quando verrà cercata la localizzazione
|
|
16
|
+
* @param {SpecializedLocalization[]} translations Lista di traduzioni in base al testo base
|
|
17
|
+
*/
|
|
18
|
+
constructor(token, baseText, translations) {
|
|
19
|
+
this.token = token;
|
|
20
|
+
this.baseText = baseText;
|
|
21
|
+
this.translations = translations;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Classe che rappresenta un locale (Es. 'Italiano') con i propri alias (Es. 'it' oppure 'it-IT')
|
|
27
|
+
*/
|
|
28
|
+
class LocaleObject {
|
|
29
|
+
/**
|
|
30
|
+
* Costruttore
|
|
31
|
+
*
|
|
32
|
+
* @param {string} id Codice locale
|
|
33
|
+
* @param {string} description Descrizione locale
|
|
34
|
+
* @param {string[]} aliases Alias con cui quel locale è conosciuto
|
|
35
|
+
* @param {string} smallVersion Versione standard "small" del locale. Es. "it-IT" -> "it"
|
|
36
|
+
*/
|
|
37
|
+
constructor(id, description, aliases, smallVersion) {
|
|
38
|
+
this.id = id;
|
|
39
|
+
this.description = description;
|
|
40
|
+
this.aliases = aliases;
|
|
41
|
+
this.smallVersion = smallVersion;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** Classe che gestisce le definizioni dei locali disponibili */
|
|
46
|
+
class LocaleDefinitions {
|
|
47
|
+
/** @ignore Costruttore */
|
|
48
|
+
constructor() { }
|
|
49
|
+
/**
|
|
50
|
+
* In base a un alias restituisce il locale rappresentato
|
|
51
|
+
*
|
|
52
|
+
* @param {string} alias Alias in base al quale raccogliere il Locale
|
|
53
|
+
*
|
|
54
|
+
* @returns {LocaleObject} Locale richiesto dall'alias
|
|
55
|
+
*/
|
|
56
|
+
static getByAlias(alias) {
|
|
57
|
+
if (!this.LocaleCache[alias])
|
|
58
|
+
this.LocaleCache[alias] = this.AvailableLocales.find(t => !!t.aliases.find(a => a == alias));
|
|
59
|
+
return this.LocaleCache[alias];
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
/** Cache per ottimizzare la chiamata **getByAlias** */
|
|
63
|
+
LocaleDefinitions.LocaleCache = {};
|
|
64
|
+
/** Lista dei locali disponibili, definiti anche con i vari alias */
|
|
65
|
+
LocaleDefinitions.AvailableLocales = [
|
|
66
|
+
new LocaleObject('it-IT', 'Italiano', ['it', 'it-IT'], "it"),
|
|
67
|
+
new LocaleObject('en-US', 'English', ['en', 'en-US'], "en")
|
|
68
|
+
];
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Classe che rappresenta la localizzazione di un test base per una certa lingua
|
|
72
|
+
*/
|
|
73
|
+
class SpecializedLocalization {
|
|
74
|
+
/**
|
|
75
|
+
* Costruttore
|
|
76
|
+
*
|
|
77
|
+
* @param {string} culture Culture della traduzione
|
|
78
|
+
* @param {string} translation Traduzione nella lingua specificata dalla **culture**
|
|
79
|
+
*/
|
|
80
|
+
constructor(culture, translation) {
|
|
81
|
+
this.culture = culture;
|
|
82
|
+
this.translation = translation;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
class LocalizationPersistor {
|
|
87
|
+
constructor(LocCache = null) {
|
|
88
|
+
this.LocCache = LocCache;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Imposta la localizzazione di un token all'interno della cache scelta
|
|
92
|
+
*
|
|
93
|
+
* @param {string} direction Direzione della traduzione, rappresenta la lingua base in cui aspettarsi il testo e le varie lingue in cui viene tradotta.
|
|
94
|
+
* Ad esempio, "en->it" indica che il parametro **left** è valido per le localizzazioni in inglese, mentre nell'elemento 0 del parametro **right**
|
|
95
|
+
* è 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"
|
|
96
|
+
* @param {string} token Nome del token
|
|
97
|
+
* @param {string} left Valore del token per la lingua specificata nel lato immediatamente sinistro alla freccia del parametro **direction**
|
|
98
|
+
* @param {string} right Array con i valori facenti riferimento all'N-esima lingua del lato destro del parametro **direction**
|
|
99
|
+
*/
|
|
100
|
+
setToken(direction, token, left, right) {
|
|
101
|
+
let parsingRegex = /([a-zA-Z]+)[\s]*->[\s]*([a-zA-Z,\s]+)+/g;
|
|
102
|
+
var parsingRes = parsingRegex.exec(direction);
|
|
103
|
+
let from = parsingRes[1];
|
|
104
|
+
let to = parsingRes[2].replace(/\s/g, '').split(',');
|
|
105
|
+
let localeFrom = LocaleDefinitions.getByAlias(from);
|
|
106
|
+
this._set(token, localeFrom.id, left, true);
|
|
107
|
+
to.forEach((t, index) => {
|
|
108
|
+
let localeTo = LocaleDefinitions.getByAlias(t);
|
|
109
|
+
this._set(token, localeTo.id, right[index], true);
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Imposta la localizzazione di una frase all'interno della cache scelta
|
|
114
|
+
*
|
|
115
|
+
* @param {string} direction Direzione della traduzione, rappresenta la lingua base in cui aspettarsi il testo e le varie lingue in cui viene tradotta.
|
|
116
|
+
* Ad esempio, "en->it" indica che il parametro **left** è valido per le localizzazioni in inglese, mentre nell'elemento 0 del parametro **right**
|
|
117
|
+
* è 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"
|
|
118
|
+
* @param {string} left Valore della frase per la lingua specificata nel lato immediatamente sinistro alla freccia del parametro **direction**
|
|
119
|
+
* @param {string} right Array con i valori facenti riferimento all'N-esima lingua del lato destro del parametro **direction**
|
|
120
|
+
*/
|
|
121
|
+
set(direction, left, right) {
|
|
122
|
+
let parsingRegex = /([a-zA-Z]+)[\s]*->[\s]*([a-zA-Z,\s]+)+/g;
|
|
123
|
+
var parsingRes = parsingRegex.exec(direction);
|
|
124
|
+
let from = parsingRes[1];
|
|
125
|
+
let to = parsingRes[2].replace(/\s/g, '').split(',');
|
|
126
|
+
let localeFrom = LocaleDefinitions.getByAlias(from);
|
|
127
|
+
this._set(left, localeFrom.id, left);
|
|
128
|
+
to.forEach((t, index) => {
|
|
129
|
+
let localeTo = LocaleDefinitions.getByAlias(t);
|
|
130
|
+
this._set(left, localeTo.id, right[index]);
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Imposta all'interno della cache specificata un'unica traduzione partendo da un testo di base
|
|
135
|
+
*
|
|
136
|
+
* @param {string} text Testo da tradurre
|
|
137
|
+
* @param {string} culture Lingua per cui inserire la traduzione
|
|
138
|
+
* @param {string} translation Traduzione del **text** nella lingua specificata da **culture**
|
|
139
|
+
* @param {boolean} token Indica se il **text** è un token o è una frase normale
|
|
140
|
+
*/
|
|
141
|
+
_set(text, culture, translation, token) {
|
|
142
|
+
let item = this.get(text, token);
|
|
143
|
+
if (!item) {
|
|
144
|
+
this.LocCache[text] = new ItemLocalization(token, text, [new SpecializedLocalization(culture, translation)]);
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
var trs = this.translationByCulture(item, culture);
|
|
148
|
+
if (trs) {
|
|
149
|
+
//console.warn("Localization already loaded for sentence '" + text + "' and culture " + culture);
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
item.translations.push(new SpecializedLocalization(culture, translation));
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Partendo da una cache di localizzazione, dato un testo che può essere o meno un token, cerca quell'elemento all'interno della cache
|
|
156
|
+
*
|
|
157
|
+
* @param {string} text Testo da cercare nella **LocCache**
|
|
158
|
+
* @param {boolean} allowtokens Indica se l'elemento cercato può essere un token o se dev'essere per forza una frase (per evitare rari
|
|
159
|
+
* casi di collisione in cui magari un token è uguale a una frase tradotta)
|
|
160
|
+
*
|
|
161
|
+
* @returns {ItemLocalization} Informazioni di localizzazione per il **text** cercato
|
|
162
|
+
*/
|
|
163
|
+
get(text, allowtokens) {
|
|
164
|
+
let possibleItem = this.LocCache[text];
|
|
165
|
+
var item = possibleItem && (allowtokens || !possibleItem.token) ? possibleItem : null;
|
|
166
|
+
return item;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Date le informazioni di localizzazione per un testo cerca e restituisce la traduzione per una lingua specifica
|
|
170
|
+
*
|
|
171
|
+
* @param {ItemLocalization} Informazioni di localizzazione
|
|
172
|
+
* @param {string} culture Lingua della traduzione richiesta
|
|
173
|
+
*
|
|
174
|
+
* @returns {SpecializedLocalization} Informazioni di localizzazione specifiche della lingua richiesta
|
|
175
|
+
*/
|
|
176
|
+
translationByCulture(item, culture) {
|
|
177
|
+
for (let i = 0; i < item.translations.length; i++) {
|
|
178
|
+
let trl = item.translations[i];
|
|
179
|
+
if (trl.culture == culture)
|
|
180
|
+
return trl;
|
|
181
|
+
}
|
|
182
|
+
return null;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
var BaseLocalizationTokens;
|
|
187
|
+
(function (BaseLocalizationTokens) {
|
|
188
|
+
BaseLocalizationTokens["getDateMonthPosition"] = "getDateMonthPosition";
|
|
189
|
+
BaseLocalizationTokens["getDisplayDateMonthPosition"] = "getDisplayDateMonthPosition";
|
|
190
|
+
BaseLocalizationTokens["getLocale"] = "getLocale";
|
|
191
|
+
BaseLocalizationTokens["getSmallDateFormat"] = "getSmallDateFormat";
|
|
192
|
+
BaseLocalizationTokens["getDefaultDateFormat"] = "getDefaultDateFormat";
|
|
193
|
+
BaseLocalizationTokens["getSmallDateDisplayFormat"] = "getSmallDateDisplayFormat";
|
|
194
|
+
BaseLocalizationTokens["getFullDateFormat"] = "getFullDateFormat";
|
|
195
|
+
BaseLocalizationTokens["getFullDateDisplayFormat"] = "getFullDateDisplayFormat";
|
|
196
|
+
BaseLocalizationTokens["getFullDateFormatNoSeconds"] = "getFullDateFormatNoSeconds";
|
|
197
|
+
BaseLocalizationTokens["getFullDateDisplayFormatNoSeconds"] = "getFullDateDisplayFormatNoSeconds";
|
|
198
|
+
})(BaseLocalizationTokens || (BaseLocalizationTokens = {}));
|
|
199
|
+
|
|
200
|
+
/** Locale da utilizzare per le traduzioni */
|
|
201
|
+
const LOC_LOCALE = new InjectionToken('LOC_LOCALE');
|
|
202
|
+
/** Policy da utilizzare per traduzioni mancanti */
|
|
203
|
+
const LOC_MISSING_POLICY = new InjectionToken('LOC_MISSING_POLICY');
|
|
204
|
+
/** Modalità di Debug */
|
|
205
|
+
const LOC_DEBUG_MODE = new InjectionToken('LOC_DEBUG_MODE');
|
|
206
|
+
|
|
207
|
+
/** Classe astratta che rappresenta lo stato di persistenza fra la libreria e uno storage */
|
|
208
|
+
class LocalePersistor {
|
|
209
|
+
constructor() {
|
|
210
|
+
/** Chiave su cui salvare il locale */
|
|
211
|
+
this.LOCALE = "LOCALE";
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Classe singleton che contiene le traduzioni di base (per evitare di ripeterle in oggi classe di traduzione) e le funzioni base per
|
|
217
|
+
* inserire e leggere traduzioni in/da una cache
|
|
218
|
+
*/
|
|
219
|
+
class BaseLocalization {
|
|
220
|
+
/**
|
|
221
|
+
* Costruttore. Da qui utilizzando il metodo statico **BaseLocalization.set** si va a popolare la cache delle traduzioni **BaseTranslations**
|
|
222
|
+
*/
|
|
223
|
+
constructor(LocalePersistor, defaultLocale) {
|
|
224
|
+
this.LocalePersistor = LocalePersistor;
|
|
225
|
+
/**
|
|
226
|
+
* Cache di tutte le localizzazioni di base
|
|
227
|
+
*/
|
|
228
|
+
this.LocCache = {};
|
|
229
|
+
/**
|
|
230
|
+
* Locale di riferimento per tutte le traduzioni
|
|
231
|
+
*/
|
|
232
|
+
this.Locale = new ReplaySubject(1);
|
|
233
|
+
// Recupero il locale alla partenza del BaseLocalization in modo, spero di dare tempo all'applicazione di tirarlo su
|
|
234
|
+
this.LocalePersistor.recover().pipe(take(1)).subscribe((l) => __awaiter(this, void 0, void 0, function* () {
|
|
235
|
+
if (!l) {
|
|
236
|
+
l = defaultLocale;
|
|
237
|
+
this.LocalePersistor.persist(defaultLocale);
|
|
238
|
+
}
|
|
239
|
+
this.Locale.next(l);
|
|
240
|
+
}));
|
|
241
|
+
this.Persistor = new LocalizationPersistor(this.LocCache);
|
|
242
|
+
this.Persistor.set("it->en", "Sì", ["Yes"]);
|
|
243
|
+
this.Persistor.set("it->en", "No", ["No"]);
|
|
244
|
+
this.Persistor.set("it->en", "Errore", ["Error"]);
|
|
245
|
+
this.Persistor.set("it->en", "Avviso", ["Warning"]);
|
|
246
|
+
this.Persistor.set("it->en", "Informazione", ["Information"]);
|
|
247
|
+
this.Persistor.set("it->en", "Salva", ["Save"]);
|
|
248
|
+
this.Persistor.set("it->en", "Indietro", ["Back"]);
|
|
249
|
+
this.Persistor.set("it->en", "Da", ["From"]);
|
|
250
|
+
this.Persistor.set("it->en", "A", ["To"]);
|
|
251
|
+
this.Persistor.set("it->en", "Note", ["Notes"]);
|
|
252
|
+
this.Persistor.set("it->en", "Modifica Note", ["Edit Notes"]);
|
|
253
|
+
this.Persistor.set("it->en", "Annulla", ["Cancel"]);
|
|
254
|
+
this.Persistor.set("it->en", "Conferma", ["Confirm"]);
|
|
255
|
+
this.Persistor.set("it->en", "Visualizza", ["View"]);
|
|
256
|
+
this.Persistor.set("it->en", "Elimina", ["Delete"]);
|
|
257
|
+
this.Persistor.set("it->en", "Chiudi", ["Close"]);
|
|
258
|
+
this.Persistor.set("it->en", "Seleziona", ["Select"]);
|
|
259
|
+
this.Persistor.set("it->en", "Elettricità", ["Electricity"]);
|
|
260
|
+
this.Persistor.set("it->en", "Gas", ["Gas"]);
|
|
261
|
+
this.Persistor.set("it->en", "Acqua", ["Water"]);
|
|
262
|
+
this.Persistor.set("it->en", "Questa operazione non può essere annullata", ["This operation cannot be reverted"]);
|
|
263
|
+
this.Persistor.set("it->en", "Nascondi", ["Hide"]);
|
|
264
|
+
// Informazioni sulle date
|
|
265
|
+
this.Persistor.setToken("en->it", BaseLocalizationTokens.getDateMonthPosition, "0", ["1"]);
|
|
266
|
+
this.Persistor.setToken("en->it", BaseLocalizationTokens.getDisplayDateMonthPosition, "1", ["1"]);
|
|
267
|
+
this.Persistor.setToken("en->it", BaseLocalizationTokens.getLocale, "en-US", ["it-IT"]);
|
|
268
|
+
this.Persistor.setToken("en->it", BaseLocalizationTokens.getSmallDateFormat, "MM/DD/YYYY", ["DD/MM/YYYY"]);
|
|
269
|
+
this.Persistor.setToken("en->it", BaseLocalizationTokens.getDefaultDateFormat, "MM/DD/YYYY", ["MM/DD/YYYY"]);
|
|
270
|
+
this.Persistor.setToken("en->it", BaseLocalizationTokens.getSmallDateDisplayFormat, "DD/MM/YYYY", ["DD/MM/YYYY"]);
|
|
271
|
+
this.Persistor.setToken("en->it", BaseLocalizationTokens.getFullDateFormat, "MM/DD/YYYY HH:mm:ss", ["DD/MM/YYYY HH:mm:ss"]);
|
|
272
|
+
this.Persistor.setToken("en->it", BaseLocalizationTokens.getFullDateDisplayFormat, "DD/MM/YYYY HH:mm:ss", ["DD/MM/YYYY HH:mm:ss"]);
|
|
273
|
+
this.Persistor.setToken("en->it", BaseLocalizationTokens.getFullDateFormatNoSeconds, "MM/DD/YYYY HH:mm", ["DD/MM/YYYY HH:mm"]);
|
|
274
|
+
this.Persistor.setToken("en->it", BaseLocalizationTokens.getFullDateDisplayFormatNoSeconds, "DD/MM/YYYY HH:mm", ["DD/MM/YYYY HH:mm"]);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
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 });
|
|
278
|
+
BaseLocalization.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: BaseLocalization, providedIn: 'root' });
|
|
279
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: BaseLocalization, decorators: [{
|
|
280
|
+
type: Injectable,
|
|
281
|
+
args: [{ providedIn: 'root' }]
|
|
282
|
+
}], ctorParameters: function () {
|
|
283
|
+
return [{ type: LocalePersistor }, { type: undefined, decorators: [{
|
|
284
|
+
type: Inject,
|
|
285
|
+
args: [LOC_LOCALE]
|
|
286
|
+
}] }];
|
|
287
|
+
} });
|
|
288
|
+
|
|
289
|
+
/**
|
|
290
|
+
* Enum che rappresenta le policy di comportamento qualore il sistema di localizzazione non trovi la localizzazione cercata,
|
|
291
|
+
* usare **ThrowException** solo se ci si sente infallibili o si vuole debuggare in maniera approfondita l'applicazione
|
|
292
|
+
*/
|
|
293
|
+
var LocalizationMissingPolicy;
|
|
294
|
+
(function (LocalizationMissingPolicy) {
|
|
295
|
+
LocalizationMissingPolicy[LocalizationMissingPolicy["PrintEmpty"] = 0] = "PrintEmpty";
|
|
296
|
+
LocalizationMissingPolicy[LocalizationMissingPolicy["PrintSource"] = 1] = "PrintSource";
|
|
297
|
+
LocalizationMissingPolicy[LocalizationMissingPolicy["PrintSourceWithoutWarnings"] = 2] = "PrintSourceWithoutWarnings";
|
|
298
|
+
LocalizationMissingPolicy[LocalizationMissingPolicy["ThrowException"] = 3] = "ThrowException";
|
|
299
|
+
})(LocalizationMissingPolicy || (LocalizationMissingPolicy = {}));
|
|
300
|
+
|
|
301
|
+
/**
|
|
302
|
+
* Classe di localizzazione estendibile che permette di specificare le proprie localizzazioni e comunque rendere disponibili le localizzazioni globali
|
|
303
|
+
*/
|
|
304
|
+
class LocalizationService {
|
|
305
|
+
/**
|
|
306
|
+
* Costruttore
|
|
307
|
+
*
|
|
308
|
+
* @param {string} Locale Locale da utilizzare nel momento che questo servizio richiede le traduzioni
|
|
309
|
+
* @param {baseLocalization} baseLocalization Classe base di localizzazione già fornita a livello di root dalla libreria stessa.
|
|
310
|
+
* È sufficiente iniettarla nell'eventuale costruttore che estende questa classe e passarla as-is
|
|
311
|
+
*/
|
|
312
|
+
constructor(injector) {
|
|
313
|
+
this.injector = injector;
|
|
314
|
+
/**
|
|
315
|
+
* Cache di tutte le localizzazioni disonibili all'interno di questa classe
|
|
316
|
+
*/
|
|
317
|
+
this.TranslationCache = {};
|
|
318
|
+
this.LocalePersistor = this.injector.get(LocalePersistor);
|
|
319
|
+
this.baseLocalization = this.injector.get(BaseLocalization);
|
|
320
|
+
this.onMissing = this.injector.get(LOC_MISSING_POLICY);
|
|
321
|
+
this.Persistor = new LocalizationPersistor(this.TranslationCache);
|
|
322
|
+
this.baseLocalization.Locale.subscribe(lr => {
|
|
323
|
+
this.Locale = lr;
|
|
324
|
+
this.SmallLocale = LocaleDefinitions.getByAlias(lr).smallVersion;
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
/**
|
|
328
|
+
* Genera un nuovo servizio di localizzazione data una classe in modo che le localizzazioni non siano più solo da provide-are a livello di componente, ma possano
|
|
329
|
+
* anche essere create al volo dal componente/servizio/qualsiasicosa che le deve utilizzare
|
|
330
|
+
*
|
|
331
|
+
* @param {Type<LocalizationService>} lcst Classe da usare per crare il nuovo servizio di localizzazione
|
|
332
|
+
*/
|
|
333
|
+
generateFromType(lcst) {
|
|
334
|
+
const injector = Injector.create({
|
|
335
|
+
providers: [
|
|
336
|
+
{ provide: LOC_MISSING_POLICY, useValue: this.onMissing },
|
|
337
|
+
{ provide: BaseLocalization, useValue: this.baseLocalization },
|
|
338
|
+
{ provide: LocalePersistor, useValue: this.LocalePersistor },
|
|
339
|
+
{ provide: LocalizationService, useClass: lcst }
|
|
340
|
+
]
|
|
341
|
+
});
|
|
342
|
+
return injector.get(LocalizationService);
|
|
343
|
+
}
|
|
344
|
+
/**
|
|
345
|
+
* Imposta la localizzazione di un token all'interno della **TranslationCache**
|
|
346
|
+
*
|
|
347
|
+
* @param {string} direction Direzione della traduzione, rappresenta la lingua base in cui aspettarsi il testo e le varie lingue in cui viene tradotta.
|
|
348
|
+
* Ad esempio, "en->it" indica che il parametro **left** è valido per le localizzazioni in inglese, mentre nell'elemento 0 del parametro **right**
|
|
349
|
+
* è 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"
|
|
350
|
+
* @param {string} token Nome del token
|
|
351
|
+
* @param {string} left Valore del token per la lingua specificata nel lato immediatamente sinistro alla freccia del parametro **direction**
|
|
352
|
+
* @param {string} right Array con i valori facenti riferimento all'N-esima lingua del lato destro del parametro **direction**
|
|
353
|
+
*/
|
|
354
|
+
setToken(direction, token, left, right) {
|
|
355
|
+
this.Persistor.setToken(direction, token, left, right);
|
|
356
|
+
}
|
|
357
|
+
/**
|
|
358
|
+
* Imposta la localizzazione di una frase all'interno della **TranslationCache**
|
|
359
|
+
*
|
|
360
|
+
* @param {string} direction Direzione della traduzione, rappresenta la lingua base in cui aspettarsi il testo e le varie lingue in cui viene tradotta.
|
|
361
|
+
* Ad esempio, "en->it" indica che il parametro **left** è valido per le localizzazioni in inglese, mentre nell'elemento 0 del parametro **right**
|
|
362
|
+
* è 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"
|
|
363
|
+
* @param {string} left Valore della frase per la lingua specificata nel lato immediatamente sinistro alla freccia del parametro **direction**
|
|
364
|
+
* @param {string} right Array con i valori facenti riferimento all'N-esima lingua del lato destro del parametro **direction**
|
|
365
|
+
*/
|
|
366
|
+
set(direction, left, right) {
|
|
367
|
+
// Controlla di non reinserire la stessa localizzazione presente nel BaseLocalization
|
|
368
|
+
// i controlli per il non reinserimento della stessa localizzazione all'interno della stessa istanza è fatto lato Persistor
|
|
369
|
+
if (this.baseLocalization.Persistor.get(left, false)) {
|
|
370
|
+
if (this.onMissing != LocalizationMissingPolicy.PrintSourceWithoutWarnings)
|
|
371
|
+
console.warn(`La localizzazione per ${left} è già presente fra le localizzazioni base, ignoro l'operazione`);
|
|
372
|
+
return;
|
|
373
|
+
}
|
|
374
|
+
this.Persistor.set(direction, left, right);
|
|
375
|
+
}
|
|
376
|
+
/**
|
|
377
|
+
* Localizza un token
|
|
378
|
+
*
|
|
379
|
+
* @param {string} text Il token da localizzare
|
|
380
|
+
*
|
|
381
|
+
* @returns {string} Token localizzato
|
|
382
|
+
*/
|
|
383
|
+
token(text) {
|
|
384
|
+
return this.loc(text, true);
|
|
385
|
+
}
|
|
386
|
+
/**
|
|
387
|
+
* Localizza una frase
|
|
388
|
+
*
|
|
389
|
+
* @param {string} text Frase da localizzare
|
|
390
|
+
* @param {boolean} allowtokens Indica se la frase **text** potrebbe essere un token o no
|
|
391
|
+
*
|
|
392
|
+
* @returns {string} Frase localizzata
|
|
393
|
+
*/
|
|
394
|
+
loc(text, allowtokens) {
|
|
395
|
+
if (!this.Locale)
|
|
396
|
+
throw "Il sistema di localizzazione non ha ancora caricato il Locale, assicurarsi di caricare l'APP solo al retrieve del locale'";
|
|
397
|
+
if (!text || text == "undefined")
|
|
398
|
+
return "";
|
|
399
|
+
// Prendo la localizzazione o dalla cache attuale o dalla cache del servizio base
|
|
400
|
+
var item = this.Persistor.get(text, allowtokens) || this.baseLocalization.Persistor.get(text, allowtokens);
|
|
401
|
+
if (!item) {
|
|
402
|
+
let message = `Impossibile trovare la localizzazione per '${text}'`;
|
|
403
|
+
switch (this.onMissing) {
|
|
404
|
+
case LocalizationMissingPolicy.PrintEmpty:
|
|
405
|
+
console.error(message);
|
|
406
|
+
return "";
|
|
407
|
+
case LocalizationMissingPolicy.PrintSource:
|
|
408
|
+
console.warn(message);
|
|
409
|
+
return text;
|
|
410
|
+
case LocalizationMissingPolicy.PrintSourceWithoutWarnings:
|
|
411
|
+
return text;
|
|
412
|
+
case LocalizationMissingPolicy.ThrowException:
|
|
413
|
+
throw message;
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
var loc = this.Persistor.translationByCulture(item, this.Locale);
|
|
417
|
+
if (!loc) {
|
|
418
|
+
console.error("Impossibile trovare la localizzazione per '" + text + "', culture " + this.Locale);
|
|
419
|
+
return "";
|
|
420
|
+
}
|
|
421
|
+
return loc.translation;
|
|
422
|
+
}
|
|
423
|
+
changeLocale(newLocale) {
|
|
424
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
425
|
+
let locale = yield this.LocalePersistor.recover().toPromise();
|
|
426
|
+
if (newLocale == locale) {
|
|
427
|
+
console.info("Il locale richiesto è lo stesso del locale attuale. Ignoro l'operazione");
|
|
428
|
+
return;
|
|
429
|
+
}
|
|
430
|
+
else {
|
|
431
|
+
yield this.LocalePersistor.persist(newLocale).toPromise();
|
|
432
|
+
location.reload();
|
|
433
|
+
}
|
|
434
|
+
});
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
LocalizationService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: LocalizationService, deps: [{ token: i0.Injector }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
438
|
+
LocalizationService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: LocalizationService });
|
|
439
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: LocalizationService, decorators: [{
|
|
440
|
+
type: Injectable
|
|
441
|
+
}], ctorParameters: function () { return [{ type: i0.Injector }]; } });
|
|
442
|
+
|
|
443
|
+
// Angular
|
|
444
|
+
/**
|
|
445
|
+
* Pipe di localizzazione per tradurre direttamente da template
|
|
446
|
+
*/
|
|
447
|
+
class LocalizePipe {
|
|
448
|
+
/**
|
|
449
|
+
* Costruttore
|
|
450
|
+
*
|
|
451
|
+
* @param {LocalizationService} translationContainer Container delle traduzioni disponibili nel contesto in cui viene usata la pipe.
|
|
452
|
+
*
|
|
453
|
+
* Viene iniettata dal provider dichiarato nel singolo componente che utilizza la traduzione e, se non esiste, viene iniettato dal default
|
|
454
|
+
*/
|
|
455
|
+
constructor(translationContainer) {
|
|
456
|
+
this.translationContainer = translationContainer;
|
|
457
|
+
}
|
|
458
|
+
/**
|
|
459
|
+
* Trasformazione della stringa in input ad una stringa tradotta
|
|
460
|
+
*
|
|
461
|
+
* @param {string} value Testo da tradurre
|
|
462
|
+
* @param {LocalizationService} locContainerOverride Override al contenitore della traduzione iniettato dal costruttore, qualora serva
|
|
463
|
+
*
|
|
464
|
+
* @returns {string} Frase tradotta
|
|
465
|
+
*/
|
|
466
|
+
transform(value, locContainerOverride) {
|
|
467
|
+
if (value == null || value === "")
|
|
468
|
+
return "";
|
|
469
|
+
return (locContainerOverride || this.translationContainer).loc(value);
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
LocalizePipe.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: LocalizePipe, deps: [{ token: LocalizationService }], target: i0.ɵɵFactoryTarget.Pipe });
|
|
473
|
+
LocalizePipe.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "15.2.9", ngImport: i0, type: LocalizePipe, name: "localize" });
|
|
474
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: LocalizePipe, decorators: [{
|
|
475
|
+
type: Pipe,
|
|
476
|
+
args: [{
|
|
477
|
+
name: "localize", pure: true,
|
|
478
|
+
standalone: false
|
|
479
|
+
}]
|
|
480
|
+
}], ctorParameters: function () { return [{ type: LocalizationService }]; } });
|
|
481
|
+
|
|
482
|
+
// Angular
|
|
483
|
+
class LocalStorageLocalePersistor extends LocalePersistor {
|
|
484
|
+
/** @ignore Vedi classe base */
|
|
485
|
+
persist(locale) {
|
|
486
|
+
localStorage.setItem(this.LOCALE, locale);
|
|
487
|
+
return of(true).pipe(first());
|
|
488
|
+
}
|
|
489
|
+
/** @ignore Vedi classe base */
|
|
490
|
+
recover() {
|
|
491
|
+
var ret = localStorage.getItem(this.LOCALE);
|
|
492
|
+
return of(ret).pipe(first());
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
LocalStorageLocalePersistor.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: LocalStorageLocalePersistor, deps: null, target: i0.ɵɵFactoryTarget.Injectable });
|
|
496
|
+
LocalStorageLocalePersistor.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: LocalStorageLocalePersistor });
|
|
497
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: LocalStorageLocalePersistor, decorators: [{
|
|
498
|
+
type: Injectable
|
|
499
|
+
}] });
|
|
500
|
+
|
|
501
|
+
// Angular
|
|
502
|
+
class LocalizationModule {
|
|
503
|
+
static forRoot(config) {
|
|
504
|
+
return {
|
|
505
|
+
ngModule: LocalizationModule,
|
|
506
|
+
providers: [
|
|
507
|
+
LocalizationService,
|
|
508
|
+
BaseLocalization,
|
|
509
|
+
{ provide: LOC_LOCALE, useValue: (config === null || config === void 0 ? void 0 : config.defaultLocale) || 'it-IT' },
|
|
510
|
+
{ provide: LOC_MISSING_POLICY, useValue: (config === null || config === void 0 ? void 0 : config.localizationMissingPolicy) || LocalizationMissingPolicy.PrintEmpty },
|
|
511
|
+
{ provide: LocalePersistor, useClass: (config === null || config === void 0 ? void 0 : config.localePersistor) || LocalStorageLocalePersistor },
|
|
512
|
+
{ provide: LOC_DEBUG_MODE, useValue: (config === null || config === void 0 ? void 0 : config.debugMode) || false },
|
|
513
|
+
]
|
|
514
|
+
};
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
LocalizationModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: LocalizationModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
|
518
|
+
LocalizationModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.2.9", ngImport: i0, type: LocalizationModule, declarations: [LocalizePipe], exports: [LocalizePipe] });
|
|
519
|
+
LocalizationModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: LocalizationModule });
|
|
520
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: LocalizationModule, decorators: [{
|
|
521
|
+
type: NgModule,
|
|
522
|
+
args: [{
|
|
523
|
+
declarations: [LocalizePipe],
|
|
524
|
+
exports: [LocalizePipe]
|
|
525
|
+
}]
|
|
526
|
+
}] });
|
|
527
|
+
|
|
528
|
+
/**
|
|
529
|
+
* Classe di configurazione per il modulo di localizzazione
|
|
530
|
+
*/
|
|
531
|
+
class LocalizationModuleConfig {
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
/*
|
|
535
|
+
* Public API Surface of localizations
|
|
536
|
+
*/
|
|
537
|
+
|
|
538
|
+
/**
|
|
539
|
+
* Generated bundle index. Do not edit.
|
|
540
|
+
*/
|
|
541
|
+
|
|
542
|
+
export { BaseLocalization, BaseLocalizationTokens, LOC_DEBUG_MODE, LOC_LOCALE, LOC_MISSING_POLICY, LocalizationMissingPolicy, LocalizationModule, LocalizationModuleConfig, LocalizationService, LocalizePipe };
|
|
543
|
+
//# sourceMappingURL=esfaenza-localizations.mjs.map
|