@o3r/localization 15.3.0-prerelease.13 → 15.3.0-prerelease.17

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,1190 +1,1247 @@
1
- import { immutablePrimitive, deepFill, otterComponentInfoPropertyName, sendOtterMessage, filterMessageContent } from '@o3r/core';
2
- import * as i0 from '@angular/core';
3
- import { InjectionToken, inject, Injectable, NgModule, ElementRef, ChangeDetectorRef, Input, Directive, Pipe, RendererFactory2, Optional, LOCALE_ID, Injector, ApplicationRef, DestroyRef } from '@angular/core';
4
- import { TranslateCompiler, TranslateService, TranslateDirective, TranslatePipe, TranslateModule, TranslateLoader } from '@ngx-translate/core';
5
- import { IntlMessageFormat } from 'intl-messageformat';
6
- import { BehaviorSubject, combineLatest, firstValueFrom, of, from, lastValueFrom, fromEvent } from 'rxjs';
7
- import * as i1 from '@ngrx/store';
8
- import { createAction, props, on, createReducer, StoreModule, createFeatureSelector, createSelector, Store, select } from '@ngrx/store';
9
- import { LoggerService } from '@o3r/logger';
10
- import { startWith, switchMap, map, distinctUntilChanged, shareReplay, catchError } from 'rxjs/operators';
11
- import { Directionality, BidiModule } from '@angular/cdk/bidi';
12
- import { CurrencyPipe, DatePipe, DecimalPipe, CommonModule } from '@angular/common';
13
- import { DynamicContentService } from '@o3r/dynamic-content';
14
- import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
15
-
16
- /**
17
- * Decorator to pass localization url
18
- * @param _url
19
- */
20
- // eslint-disable-next-line @typescript-eslint/naming-convention -- decorator should start with a capital letter
1
+ import { deepFill, filterMessageContent, immutablePrimitive, otterComponentInfoPropertyName, sendOtterMessage } from "@o3r/core";
2
+ import * as i0 from "@angular/core";
3
+ import { ApplicationRef, ChangeDetectorRef, DestroyRef, Directive, ElementRef, Injectable, InjectionToken, Injector, Input, LOCALE_ID, NgModule, Optional, Pipe, RendererFactory2, inject } from "@angular/core";
4
+ import { TranslateCompiler, TranslateDirective, TranslateLoader, TranslateModule, TranslatePipe, TranslateService } from "@ngx-translate/core";
5
+ import { IntlMessageFormat } from "intl-messageformat";
6
+ import { BehaviorSubject, combineLatest, firstValueFrom, from, fromEvent, lastValueFrom, of } from "rxjs";
7
+ import * as i1 from "@ngrx/store";
8
+ import { Store, StoreModule, createAction, createFeatureSelector, createReducer, createSelector, on, props, select } from "@ngrx/store";
9
+ import { LoggerService } from "@o3r/logger";
10
+ import { catchError, distinctUntilChanged, map, shareReplay, startWith, switchMap } from "rxjs/operators";
11
+ import { BidiModule, Directionality } from "@angular/cdk/bidi";
12
+ import { CommonModule, CurrencyPipe, DatePipe, DecimalPipe } from "@angular/common";
13
+ import { DynamicContentService } from "@o3r/dynamic-content";
14
+ import { takeUntilDestroyed } from "@angular/core/rxjs-interop";
21
15
  function Localization(_url) {
22
- return (target, key) => {
23
- const privateField = _url || `_${key}`;
24
- const privateValue = target[key];
25
- if (delete target[key]) {
26
- Object.defineProperty(target, key, {
27
- get: function () {
28
- return this[privateField];
29
- },
30
- set: function (value) {
31
- const currentField = this[privateField] || privateValue;
32
- this[privateField] = typeof currentField === 'undefined' ? immutablePrimitive(value) : deepFill(currentField, value);
33
- if (this[otterComponentInfoPropertyName]) {
34
- this[otterComponentInfoPropertyName].translations = this[privateField];
35
- }
36
- },
37
- enumerable: true,
38
- configurable: true
39
- });
40
- }
41
- };
16
+ return (target, key) => {
17
+ const privateField = _url || `_${key}`;
18
+ const privateValue = target[key];
19
+ if (delete target[key]) Object.defineProperty(target, key, {
20
+ get: function() {
21
+ return this[privateField];
22
+ },
23
+ set: function(value) {
24
+ const currentField = this[privateField] || privateValue;
25
+ this[privateField] = typeof currentField === "undefined" ? immutablePrimitive(value) : deepFill(currentField, value);
26
+ if (this[otterComponentInfoPropertyName]) this[otterComponentInfoPropertyName].translations = this[privateField];
27
+ },
28
+ enumerable: true,
29
+ configurable: true
30
+ });
31
+ };
42
32
  }
43
-
44
- /**
45
- * Default configuration for LocalizationModule
46
- */
47
33
  const DEFAULT_LOCALIZATION_CONFIGURATION = {
48
- supportedLocales: [],
49
- endPointUrl: '',
50
- useDynamicContent: false,
51
- rtlLanguages: ['ar', 'he'],
52
- fallbackLanguage: 'en',
53
- bundlesOutputPath: '',
54
- debugMode: false,
55
- enableTranslationDeactivation: false,
56
- mergeWithLocalTranslations: false
34
+ supportedLocales: [],
35
+ endPointUrl: "",
36
+ useDynamicContent: false,
37
+ rtlLanguages: ["ar", "he"],
38
+ fallbackLanguage: "en",
39
+ bundlesOutputPath: "",
40
+ debugMode: false,
41
+ enableTranslationDeactivation: false,
42
+ mergeWithLocalTranslations: false
57
43
  };
58
-
59
- /**
60
- * Message format configuration default value
61
- */
62
44
  const lazyMessageDefaultConfig = {
63
- enableCache: true,
64
- ignoreTag: true
45
+ enableCache: true,
46
+ ignoreTag: true
65
47
  };
66
- /** Message Format configuration Token */
67
- const MESSAGE_FORMAT_CONFIG = new InjectionToken('Message Format configuration');
68
- /**
69
- * This compiler expects ICU syntax and compiles the expressions with messageformat.js
70
- * Compare to ngx-translate-messageformat-compiler package, the compilation of the translation is done only on demand
71
- */
72
- class TranslateMessageFormatLazyCompiler extends TranslateCompiler {
73
- constructor() {
74
- const config = inject(MESSAGE_FORMAT_CONFIG, { optional: true });
75
- super();
76
- /** Cache of compiled translations */
77
- this.cache = {};
78
- this.config = config ? { ...lazyMessageDefaultConfig, ...config } : lazyMessageDefaultConfig;
79
- }
80
- /**
81
- * Clear the cache of the compiled translations
82
- */
83
- clearCache() {
84
- this.cache = {};
85
- }
86
- /** @inheritDoc */
87
- compile(value, lang) {
88
- return (params) => new IntlMessageFormat(value, lang, undefined, this.config).format(params);
89
- }
90
- /** @inheritDoc */
91
- compileTranslations(translations, lang) {
92
- const compilingStrategy = this.config.enableCache
93
- ? (acc, key) => {
94
- acc[key] = (params) => {
95
- const cached = this.cache[`${lang}_${key}`];
96
- if (cached) {
97
- return cached.format(params);
98
- }
99
- const newCachedItem = new IntlMessageFormat(translations[key], lang, undefined, this.config);
100
- this.cache[`${lang}_${key}`] = newCachedItem;
101
- return newCachedItem.format(params);
102
- };
103
- return acc;
104
- }
105
- : (acc, key) => {
106
- acc[key] = (params) => new IntlMessageFormat(translations[key], lang, undefined, this.config).format(params);
107
- return acc;
108
- };
109
- return Object.keys(translations).reduce((acc, key) => compilingStrategy(acc, key), {});
110
- }
111
- /** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: TranslateMessageFormatLazyCompiler, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
112
- /** @nocollapse */ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: TranslateMessageFormatLazyCompiler }); }
113
- }
114
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: TranslateMessageFormatLazyCompiler, decorators: [{
115
- type: Injectable
116
- }], ctorParameters: () => [] });
117
-
118
- /** Actions */
119
- const ACTION_SET = '[LocalizationOverride] set';
120
- /**
121
- * Clear all overrides and fill the store with the payload
122
- */
123
- const setLocalizationOverride = createAction(ACTION_SET, props());
124
-
125
- /**
126
- * LocalizationOverride Store initial value
127
- */
48
+ const MESSAGE_FORMAT_CONFIG = new InjectionToken("Message Format configuration");
49
+ var TranslateMessageFormatLazyCompiler = class TranslateMessageFormatLazyCompiler extends TranslateCompiler {
50
+ constructor() {
51
+ const config = inject(MESSAGE_FORMAT_CONFIG, { optional: true });
52
+ super();
53
+ this.cache = {};
54
+ this.config = config ? {
55
+ ...lazyMessageDefaultConfig,
56
+ ...config
57
+ } : lazyMessageDefaultConfig;
58
+ }
59
+ clearCache() {
60
+ this.cache = {};
61
+ }
62
+ compile(value, lang) {
63
+ return (params) => new IntlMessageFormat(value, lang, void 0, this.config).format(params);
64
+ }
65
+ compileTranslations(translations, lang) {
66
+ const compilingStrategy = this.config.enableCache ? (acc, key) => {
67
+ acc[key] = (params) => {
68
+ const cached = this.cache[`${lang}_${key}`];
69
+ if (cached) return cached.format(params);
70
+ const newCachedItem = new IntlMessageFormat(translations[key], lang, void 0, this.config);
71
+ this.cache[`${lang}_${key}`] = newCachedItem;
72
+ return newCachedItem.format(params);
73
+ };
74
+ return acc;
75
+ } : (acc, key) => {
76
+ acc[key] = (params) => new IntlMessageFormat(translations[key], lang, void 0, this.config).format(params);
77
+ return acc;
78
+ };
79
+ return Object.keys(translations).reduce((acc, key) => compilingStrategy(acc, key), {});
80
+ }
81
+ static {
82
+ this.ɵfac = i0.ɵɵngDeclareFactory({
83
+ minVersion: "12.0.0",
84
+ version: "22.2.3",
85
+ ngImport: i0,
86
+ type: TranslateMessageFormatLazyCompiler,
87
+ deps: [],
88
+ target: i0.ɵɵFactoryTarget.Injectable
89
+ });
90
+ }
91
+ static {
92
+ this.ɵprov = i0.ɵɵngDeclareInjectable({
93
+ minVersion: "12.0.0",
94
+ version: "22.2.3",
95
+ ngImport: i0,
96
+ type: TranslateMessageFormatLazyCompiler
97
+ });
98
+ }
99
+ };
100
+ i0.ɵɵngDeclareClassMetadata({
101
+ minVersion: "12.0.0",
102
+ version: "22.2.3",
103
+ ngImport: i0,
104
+ type: TranslateMessageFormatLazyCompiler,
105
+ decorators: [{ type: Injectable }],
106
+ ctorParameters: () => []
107
+ });
108
+ const setLocalizationOverride = createAction("[LocalizationOverride] set", props());
128
109
  const localizationOverrideInitialState = { localizationOverrides: {} };
129
- /**
130
- * List of basic actions for LocalizationOverride Store
131
- */
132
- const localizationOverrideReducerFeatures = [
133
- on(setLocalizationOverride, (_state, payload) => ({ ...payload.state }))
134
- ];
135
- /**
136
- * LocalizationOverride Store reducer
137
- */
110
+ const localizationOverrideReducerFeatures = [on(setLocalizationOverride, (_state, payload) => ({ ...payload.state }))];
138
111
  const localizationOverrideReducer = createReducer(localizationOverrideInitialState, ...localizationOverrideReducerFeatures);
139
-
140
- /**
141
- * Name of the LocalizationOverride Store
142
- */
143
- const LOCALIZATION_OVERRIDE_STORE_NAME = 'localizationOverride';
144
-
145
- /** Token of the LocalizationOverride reducer */
146
- const LOCALIZATION_OVERRIDE_REDUCER_TOKEN = new InjectionToken('Feature LocalizationOverride Reducer');
147
- /** Provide default reducer for LocalizationOverride store */
112
+ const LOCALIZATION_OVERRIDE_STORE_NAME = "localizationOverride";
113
+ const LOCALIZATION_OVERRIDE_REDUCER_TOKEN = new InjectionToken("Feature LocalizationOverride Reducer");
148
114
  function getDefaultLocalizationOverrideReducer() {
149
- return localizationOverrideReducer;
150
- }
151
- class LocalizationOverrideStoreModule {
152
- static forRoot(reducerFactory) {
153
- return {
154
- ngModule: LocalizationOverrideStoreModule,
155
- providers: [
156
- { provide: LOCALIZATION_OVERRIDE_REDUCER_TOKEN, useFactory: reducerFactory }
157
- ]
158
- };
159
- }
160
- /** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: LocalizationOverrideStoreModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
161
- /** @nocollapse */ static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "22.2.0", ngImport: i0, type: LocalizationOverrideStoreModule, imports: [i1.StoreFeatureModule] }); }
162
- /** @nocollapse */ static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: LocalizationOverrideStoreModule, providers: [
163
- { provide: LOCALIZATION_OVERRIDE_REDUCER_TOKEN, useFactory: getDefaultLocalizationOverrideReducer }
164
- ], imports: [StoreModule.forFeature(LOCALIZATION_OVERRIDE_STORE_NAME, LOCALIZATION_OVERRIDE_REDUCER_TOKEN)] }); }
115
+ return localizationOverrideReducer;
165
116
  }
166
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: LocalizationOverrideStoreModule, decorators: [{
167
- type: NgModule,
168
- args: [{
169
- imports: [
170
- StoreModule.forFeature(LOCALIZATION_OVERRIDE_STORE_NAME, LOCALIZATION_OVERRIDE_REDUCER_TOKEN)
171
- ],
172
- providers: [
173
- { provide: LOCALIZATION_OVERRIDE_REDUCER_TOKEN, useFactory: getDefaultLocalizationOverrideReducer }
174
- ]
175
- }]
176
- }] });
177
-
178
- /** Select LocalizationOverride State */
117
+ var LocalizationOverrideStoreModule = class LocalizationOverrideStoreModule {
118
+ static forRoot(reducerFactory) {
119
+ return {
120
+ ngModule: LocalizationOverrideStoreModule,
121
+ providers: [{
122
+ provide: LOCALIZATION_OVERRIDE_REDUCER_TOKEN,
123
+ useFactory: reducerFactory
124
+ }]
125
+ };
126
+ }
127
+ static {
128
+ this.ɵfac = i0.ɵɵngDeclareFactory({
129
+ minVersion: "12.0.0",
130
+ version: "22.2.3",
131
+ ngImport: i0,
132
+ type: LocalizationOverrideStoreModule,
133
+ deps: [],
134
+ target: i0.ɵɵFactoryTarget.NgModule
135
+ });
136
+ }
137
+ static {
138
+ this.ɵmod = i0.ɵɵngDeclareNgModule({
139
+ minVersion: "14.0.0",
140
+ version: "22.2.3",
141
+ ngImport: i0,
142
+ type: LocalizationOverrideStoreModule,
143
+ imports: [i1.StoreFeatureModule]
144
+ });
145
+ }
146
+ static {
147
+ this.ɵinj = i0.ɵɵngDeclareInjector({
148
+ minVersion: "12.0.0",
149
+ version: "22.2.3",
150
+ ngImport: i0,
151
+ type: LocalizationOverrideStoreModule,
152
+ providers: [{
153
+ provide: LOCALIZATION_OVERRIDE_REDUCER_TOKEN,
154
+ useFactory: getDefaultLocalizationOverrideReducer
155
+ }],
156
+ imports: [StoreModule.forFeature(LOCALIZATION_OVERRIDE_STORE_NAME, LOCALIZATION_OVERRIDE_REDUCER_TOKEN)]
157
+ });
158
+ }
159
+ };
160
+ i0.ɵɵngDeclareClassMetadata({
161
+ minVersion: "12.0.0",
162
+ version: "22.2.3",
163
+ ngImport: i0,
164
+ type: LocalizationOverrideStoreModule,
165
+ decorators: [{
166
+ type: NgModule,
167
+ args: [{
168
+ imports: [StoreModule.forFeature(LOCALIZATION_OVERRIDE_STORE_NAME, LOCALIZATION_OVERRIDE_REDUCER_TOKEN)],
169
+ providers: [{
170
+ provide: LOCALIZATION_OVERRIDE_REDUCER_TOKEN,
171
+ useFactory: getDefaultLocalizationOverrideReducer
172
+ }]
173
+ }]
174
+ }]
175
+ });
179
176
  const selectLocalizationOverrideState = createFeatureSelector(LOCALIZATION_OVERRIDE_STORE_NAME);
180
- /** Select all localization override map */
181
177
  const selectLocalizationOverride = createSelector(selectLocalizationOverrideState, (state) => state?.localizationOverrides || {});
182
-
183
178
  const localizationOverrideStorageDeserializer = (rawObject) => {
184
- if (!rawObject) {
185
- return localizationOverrideInitialState;
186
- }
187
- return rawObject;
179
+ if (!rawObject) return localizationOverrideInitialState;
180
+ return rawObject;
188
181
  };
189
- const localizationOverrideStorageSync = {
190
- deserialize: localizationOverrideStorageDeserializer
182
+ const localizationOverrideStorageSync = { deserialize: localizationOverrideStorageDeserializer };
183
+ const LOCALIZATION_CONFIGURATION_TOKEN = new InjectionToken("Localization Configuration injection token");
184
+ var LocalizationService = class LocalizationService {
185
+ constructor() {
186
+ this.translateService = inject(TranslateService);
187
+ this.logger = inject(LoggerService);
188
+ this.configuration = inject(LOCALIZATION_CONFIGURATION_TOKEN);
189
+ this.store = inject(Store, { optional: true });
190
+ this.localeSplitIdentifier = "-";
191
+ this._showKeys$ = new BehaviorSubject(false);
192
+ this.showKeys$ = this._showKeys$.asObservable();
193
+ this.configure();
194
+ if (this.store) this.keyMapping$ = this.store.pipe(select(selectLocalizationOverride));
195
+ }
196
+ checkFallbackLocalesMap(language) {
197
+ if (language && !this.configuration.supportedLocales.includes(language)) {
198
+ const closestSupportedLanguageCode = this.getFirstClosestSupportedLanguageCode(language);
199
+ const fallbackForLanguage = this.getFallbackMapLangCode(language);
200
+ const fallbackStrategyDebug = fallbackForLanguage && " associated fallback language " || closestSupportedLanguageCode && " closest supported language " || this.configuration.fallbackLanguage && " configured default language ";
201
+ const fallbackLang = fallbackForLanguage || closestSupportedLanguageCode || this.configuration.fallbackLanguage || language;
202
+ if (language !== fallbackLang) this.logger.debug(`Non supported languages ${language} will fallback to ${fallbackStrategyDebug} ${fallbackLang}`);
203
+ return fallbackLang;
204
+ } else if (!language) this.logger.debug("Language is not defined");
205
+ return language;
206
+ }
207
+ getFallbackMapLangCode(language) {
208
+ const fallbackLocalesMap = this.configuration.fallbackLocalesMap;
209
+ const [locale] = language.split(this.localeSplitIdentifier);
210
+ return fallbackLocalesMap && (fallbackLocalesMap[language] || fallbackLocalesMap[locale]);
211
+ }
212
+ getFirstClosestSupportedLanguageCode(language) {
213
+ const [locale] = language.split(this.localeSplitIdentifier);
214
+ const firstClosestRegx = new RegExp(`^${locale}${this.localeSplitIdentifier}?`, "i");
215
+ return this.configuration.supportedLocales.find((supportedLang) => firstClosestRegx.test(supportedLang));
216
+ }
217
+ getTranslationStream(translationKey, interpolateParams) {
218
+ const translation$ = this.translateService.onTranslationChange.pipe(startWith(void 0), switchMap(() => this.translateService.stream(translationKey, interpolateParams)), map((value) => this.configuration.debugMode ? `${translationKey} - ${value}` : value), distinctUntilChanged());
219
+ if (!this.configuration.enableTranslationDeactivation) return translation$;
220
+ return combineLatest([translation$, this.showKeys$]).pipe(map(([value, showKeys]) => showKeys ? translationKey : value));
221
+ }
222
+ async configure() {
223
+ const language = this.checkFallbackLocalesMap(this.configuration.language || this.configuration.fallbackLanguage);
224
+ this.translateService.addLangs(this.configuration.supportedLocales);
225
+ this.translateService.setDefaultLang(language);
226
+ await firstValueFrom(this.useLanguage(language));
227
+ }
228
+ isTranslationDeactivationEnabled() {
229
+ return this.configuration.enableTranslationDeactivation;
230
+ }
231
+ getLanguages() {
232
+ return this.translateService.getLangs();
233
+ }
234
+ useLanguage(language) {
235
+ language = this.checkFallbackLocalesMap(language);
236
+ return this.translateService.use(language);
237
+ }
238
+ getCurrentLanguage() {
239
+ return this.translateService.currentLang;
240
+ }
241
+ getTranslateService() {
242
+ return this.translateService;
243
+ }
244
+ toggleShowKeys(value) {
245
+ if (!this.configuration.enableTranslationDeactivation) throw new Error("Translation deactivation is not enabled. Please set the LocalizationConfiguration property \"enableTranslationDeactivation\" accordingly.");
246
+ const newValue = value === void 0 ? !this.showKeys : value;
247
+ this._showKeys$.next(newValue);
248
+ }
249
+ get showKeys() {
250
+ return this._showKeys$.value;
251
+ }
252
+ getKey(requestedKey) {
253
+ return this.keyMapping$ ? this.keyMapping$.pipe(map((keyMapping) => keyMapping?.[requestedKey] || requestedKey), distinctUntilChanged()) : of(requestedKey);
254
+ }
255
+ translate(key, interpolateParams) {
256
+ return this.getKey(key).pipe(switchMap((translationKey) => this.getTranslationStream(translationKey, interpolateParams)), shareReplay({
257
+ refCount: true,
258
+ bufferSize: 1
259
+ }));
260
+ }
261
+ static {
262
+ this.ɵfac = i0.ɵɵngDeclareFactory({
263
+ minVersion: "12.0.0",
264
+ version: "22.2.3",
265
+ ngImport: i0,
266
+ type: LocalizationService,
267
+ deps: [],
268
+ target: i0.ɵɵFactoryTarget.Injectable
269
+ });
270
+ }
271
+ static {
272
+ this.ɵprov = i0.ɵɵngDeclareInjectable({
273
+ minVersion: "12.0.0",
274
+ version: "22.2.3",
275
+ ngImport: i0,
276
+ type: LocalizationService
277
+ });
278
+ }
191
279
  };
192
-
193
- /** Localization Configuration Token */
194
- const LOCALIZATION_CONFIGURATION_TOKEN = new InjectionToken('Localization Configuration injection token');
195
-
196
- /**
197
- * Service which is wrapping the configuration logic of TranslateService from ngx-translate
198
- * Any application willing to use localization just needs to inject LocalizationService
199
- * in the root component and call its configure() method.
200
- */
201
- class LocalizationService {
202
- constructor() {
203
- this.translateService = inject(TranslateService);
204
- this.logger = inject(LoggerService);
205
- this.configuration = inject(LOCALIZATION_CONFIGURATION_TOKEN);
206
- this.store = inject(Store, { optional: true });
207
- this.localeSplitIdentifier = '-';
208
- /**
209
- * Internal subject that we use to track changes between keys only and translation mode
210
- */
211
- this._showKeys$ = new BehaviorSubject(false);
212
- /**
213
- * _showKeys$ exposed as an Observable
214
- */
215
- this.showKeys$ = this._showKeys$.asObservable();
216
- void this.configure();
217
- if (this.store) {
218
- this.keyMapping$ = this.store.pipe(select(selectLocalizationOverride));
219
- }
220
- }
221
- /**
222
- * This will handle the fallback language hierarchy to find out fallback language.
223
- * supportedLocales language has highest priority, next priority goes to fallbackLocalesMap and default would be
224
- * fallbackLanguage.
225
- * @param language Selected language.
226
- * @returns selected language if supported, fallback language otherwise.
227
- */
228
- checkFallbackLocalesMap(language) {
229
- if (language && !this.configuration.supportedLocales.includes(language)) {
230
- const closestSupportedLanguageCode = this.getFirstClosestSupportedLanguageCode(language);
231
- const fallbackForLanguage = this.getFallbackMapLangCode(language);
232
- const fallbackStrategyDebug = (fallbackForLanguage && ' associated fallback language ')
233
- || (closestSupportedLanguageCode && ' closest supported language ')
234
- || (this.configuration.fallbackLanguage && ' configured default language ');
235
- const fallbackLang = fallbackForLanguage || closestSupportedLanguageCode || this.configuration.fallbackLanguage || language;
236
- if (language !== fallbackLang) {
237
- this.logger.debug(`Non supported languages ${language} will fallback to ${fallbackStrategyDebug} ${fallbackLang}`);
238
- }
239
- return fallbackLang;
240
- }
241
- else if (!language) {
242
- this.logger.debug('Language is not defined');
243
- }
244
- return language;
245
- }
246
- /**
247
- * This function checks if fallback language can be provided from fallbackLocalesMap.
248
- * supportedLocales: ['en-GB', 'en-US', 'fr-FR'], fallbackLocalesMap: {'en-CA': 'en-US', 'de': 'fr-FR'}
249
- * translate to en-CA -> fallback to en-US, translate to de-DE -> fallback to fr-FR
250
- * translate to en-NZ -> fallback to en-GB
251
- * @param language Selected language.
252
- * @returns Fallback language if available, undefined otherwise.
253
- */
254
- getFallbackMapLangCode(language) {
255
- const fallbackLocalesMap = this.configuration.fallbackLocalesMap;
256
- const [locale] = language.split(this.localeSplitIdentifier);
257
- return fallbackLocalesMap && (fallbackLocalesMap[language] || fallbackLocalesMap[locale]);
258
- }
259
- /**
260
- * This function checks if closest supported language available incase of selected language is not
261
- * supported language.
262
- * supportedLocales: ['en-GB', 'en-US', 'fr-FR']
263
- * translate to en-CA -> fallback to en-GB
264
- * @param language Selected language.
265
- * @returns Closest supported language if available, undefined otherwise.
266
- */
267
- getFirstClosestSupportedLanguageCode(language) {
268
- const [locale] = language.split(this.localeSplitIdentifier);
269
- const firstClosestRegx = new RegExp(`^${locale}${this.localeSplitIdentifier}?`, 'i');
270
- return this.configuration.supportedLocales.find((supportedLang) => firstClosestRegx.test(supportedLang));
271
- }
272
- /**
273
- * Returns a stream of translated values of a key which updates whenever the language changes.
274
- * @param translationKey Key to translate
275
- * @param interpolateParams Object to use in translation binding
276
- * @returns A stream of the translated key
277
- */
278
- getTranslationStream(translationKey, interpolateParams) {
279
- const translation$ = this.translateService.onTranslationChange.pipe(startWith(undefined), switchMap(() => this.translateService.stream(translationKey, interpolateParams)), map((value) => this.configuration.debugMode ? `${translationKey} - ${value}` : value), distinctUntilChanged());
280
- if (!this.configuration.enableTranslationDeactivation) {
281
- return translation$;
282
- }
283
- return combineLatest([
284
- translation$,
285
- this.showKeys$
286
- ]).pipe(map(([value, showKeys]) => showKeys ? translationKey : value));
287
- }
288
- /**
289
- * Configures TranslateService and registers locales. This method is called from the application level.
290
- */
291
- async configure() {
292
- const language = this.checkFallbackLocalesMap(this.configuration.language || this.configuration.fallbackLanguage);
293
- this.translateService.addLangs(this.configuration.supportedLocales);
294
- this.translateService.setDefaultLang(language);
295
- await firstValueFrom(this.useLanguage(language));
296
- }
297
- /**
298
- * Is the translation deactivation enabled
299
- */
300
- isTranslationDeactivationEnabled() {
301
- return this.configuration.enableTranslationDeactivation;
302
- }
303
- /**
304
- * Wrapper to call the ngx-translate service TranslateService method getLangs().
305
- */
306
- getLanguages() {
307
- return this.translateService.getLangs();
308
- }
309
- /**
310
- * Wrapper to call the ngx-translate service TranslateService method use(language).
311
- * @param language
312
- */
313
- useLanguage(language) {
314
- language = this.checkFallbackLocalesMap(language);
315
- return this.translateService.use(language);
316
- }
317
- /**
318
- * Wrapper to get the ngx-translate service TranslateService currentLang.
319
- */
320
- getCurrentLanguage() {
321
- return this.translateService.currentLang;
322
- }
323
- /**
324
- * Get the instance of the ngx-translate TranslateService used by LocalizationService.
325
- */
326
- getTranslateService() {
327
- return this.translateService;
328
- }
329
- /**
330
- * Toggle the ShowKeys mode between active and inactive.
331
- * @param value if specified, set the ShowKeys mode to value. If not specified, toggle the ShowKeys mode.
332
- */
333
- toggleShowKeys(value) {
334
- if (!this.configuration.enableTranslationDeactivation) {
335
- throw new Error('Translation deactivation is not enabled. Please set the LocalizationConfiguration property "enableTranslationDeactivation" accordingly.');
336
- }
337
- const newValue = value === undefined ? !this.showKeys : value;
338
- this._showKeys$.next(newValue);
339
- }
340
- /**
341
- * Return the current value of debug show/hide translation keys.
342
- */
343
- get showKeys() {
344
- return this._showKeys$.value;
345
- }
346
- /**
347
- * Get an observable of translation key after global mapping
348
- * @param requestedKey Original translation key
349
- */
350
- getKey(requestedKey) {
351
- return this.keyMapping$
352
- ? this.keyMapping$.pipe(map((keyMapping) => keyMapping?.[requestedKey] || requestedKey), distinctUntilChanged())
353
- : of(requestedKey);
354
- }
355
- /**
356
- * Returns a stream of translated values of a key which updates whenever the language changes.
357
- * @param key Key to translate
358
- * @param interpolateParams Object to use in translation binding
359
- * @returns A stream of the translated key
360
- */
361
- translate(key, interpolateParams) {
362
- return this.getKey(key).pipe(switchMap((translationKey) => this.getTranslationStream(translationKey, interpolateParams)), shareReplay({ refCount: true, bufferSize: 1 }));
363
- }
364
- /** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: LocalizationService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
365
- /** @nocollapse */ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: LocalizationService }); }
366
- }
367
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: LocalizationService, decorators: [{
368
- type: Injectable
369
- }], ctorParameters: () => [] });
370
-
371
- /**
372
- * TranslateDirective class adding debug functionality
373
- */
374
- class LocalizationTranslateDirective extends TranslateDirective {
375
- /** @inheritdoc */
376
- set translate(key) {
377
- if (key && key !== this.key) {
378
- if (this.onKeyChange) {
379
- this.onKeyChange.unsubscribe();
380
- }
381
- this.onKeyChange = this.localizationService.getKey(key).subscribe((newKey) => {
382
- this.key = newKey;
383
- this.checkNodes();
384
- });
385
- }
386
- }
387
- constructor() {
388
- const translateService = inject(TranslateService);
389
- const element = inject(ElementRef);
390
- const ref = inject(ChangeDetectorRef);
391
- super(translateService, element, ref);
392
- this.localizationService = inject(LocalizationService);
393
- this.localizationConfig = inject(LOCALIZATION_CONFIGURATION_TOKEN);
394
- /**
395
- * Should we display keys instead of translations
396
- */
397
- this.showKeys = false;
398
- const localizationService = this.localizationService;
399
- const localizationConfig = this.localizationConfig;
400
- if (localizationConfig.enableTranslationDeactivation) {
401
- this.onShowKeysChange = localizationService.showKeys$.subscribe((showKeys) => {
402
- this.showKeys = showKeys;
403
- this.checkNodes(true);
404
- });
405
- }
406
- }
407
- /**
408
- * Overriding parent's setContent to plug debugging feature
409
- * @param node
410
- * @param content
411
- */
412
- setContent(node, content) {
413
- const key = node.originalContent;
414
- const newContent = this.showKeys ? key : (this.localizationConfig.debugMode && key ? `${key} - ${content}` : content);
415
- if (typeof node.textContent !== 'undefined' && node.textContent !== null) {
416
- node.textContent = newContent;
417
- }
418
- else {
419
- node.data = newContent;
420
- }
421
- }
422
- ngOnDestroy() {
423
- super.ngOnDestroy();
424
- if (this.onShowKeysChange) {
425
- this.onShowKeysChange.unsubscribe();
426
- }
427
- if (this.onKeyChange) {
428
- this.onKeyChange?.unsubscribe();
429
- }
430
- }
431
- /** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: LocalizationTranslateDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
432
- /** @nocollapse */ static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "22.2.0", type: LocalizationTranslateDirective, isStandalone: false, selector: "[translate],[ngx-translate]", inputs: { translate: "translate" }, usesInheritance: true, ngImport: i0 }); }
433
- }
434
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: LocalizationTranslateDirective, decorators: [{
435
- type: Directive,
436
- args: [{
437
- selector: '[translate],[ngx-translate]',
438
- standalone: false
439
- }]
440
- }], ctorParameters: () => [], propDecorators: { translate: [{
441
- type: Input
442
- }] } });
443
-
444
- /**
445
- * TranslatePipe class adding debug functionality
446
- */
447
- class O3rLocalizationTranslatePipe extends TranslatePipe {
448
- constructor() {
449
- super(inject(TranslateService), inject(ChangeDetectorRef));
450
- /** Localization service instance */
451
- this.localizationService = inject(LocalizationService);
452
- /** Change detector service instance */
453
- this.changeDetector = inject(ChangeDetectorRef);
454
- /** Localization config token */
455
- this.localizationConfig = inject(LOCALIZATION_CONFIGURATION_TOKEN);
456
- /**
457
- * Should we display keys instead of translations
458
- */
459
- this.showKeys = false;
460
- if (this.localizationConfig.enableTranslationDeactivation) {
461
- this.onShowKeysChange = this.localizationService.showKeys$.subscribe((showKeys) => {
462
- this.showKeys = showKeys;
463
- this.changeDetector.markForCheck();
464
- });
465
- }
466
- }
467
- /**
468
- * Calls original transform method and eventually outputs the key if debugMode (in LocalizationConfiguration) is enabled
469
- * @inheritdoc
470
- */
471
- transform(query, ...args) {
472
- if (this.showKeys) {
473
- return query;
474
- }
475
- if (query !== this.lastQueryKey) {
476
- this.lastQueryKey = query;
477
- if (this.onKeyChange) {
478
- this.onKeyChange.unsubscribe();
479
- }
480
- this.onKeyChange = this.localizationService.getKey(query).subscribe((key) => {
481
- this.lastResolvedKey = key;
482
- this.changeDetector.markForCheck();
483
- });
484
- }
485
- if (this.lastResolvedKey) {
486
- const value = super.transform(this.lastResolvedKey, ...args);
487
- if (this.localizationConfig.debugMode) {
488
- return `${this.lastResolvedKey} - ${value}`;
489
- }
490
- return value;
491
- }
492
- return this.value;
493
- }
494
- ngOnDestroy() {
495
- super.ngOnDestroy();
496
- if (this.onShowKeysChange) {
497
- this.onShowKeysChange.unsubscribe();
498
- }
499
- if (this.onKeyChange) {
500
- this.onKeyChange.unsubscribe();
501
- }
502
- }
503
- /** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: O3rLocalizationTranslatePipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe }); }
504
- /** @nocollapse */ static { this.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "22.2.0", ngImport: i0, type: O3rLocalizationTranslatePipe, isStandalone: false, name: "o3rTranslate", pure: false }); }
505
- }
506
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: O3rLocalizationTranslatePipe, decorators: [{
507
- type: Pipe,
508
- args: [{
509
- name: 'o3rTranslate',
510
- pure: false,
511
- standalone: false
512
- }]
513
- }], ctorParameters: () => [] });
514
-
515
- /**
516
- * Native angular CurrencyPipe taking the current lang into consideration
517
- */
518
- class LocalizedCurrencyPipe extends CurrencyPipe {
519
- constructor() {
520
- super(inject(LocalizationService).getCurrentLanguage());
521
- this.localizationService = inject(LocalizationService);
522
- this.changeDetectorRef = inject(ChangeDetectorRef);
523
- this.onLangChange = this.localizationService.getTranslateService().onLangChange.subscribe(() => this.changeDetectorRef.markForCheck());
524
- }
525
- transform(value, currencyCode, display, digitsInfo, locale) {
526
- return super.transform(value, currencyCode, display, digitsInfo, locale || this.localizationService.getCurrentLanguage());
527
- }
528
- ngOnDestroy() {
529
- this.onLangChange.unsubscribe();
530
- }
531
- /** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: LocalizedCurrencyPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe }); }
532
- /** @nocollapse */ static { this.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "22.2.0", ngImport: i0, type: LocalizedCurrencyPipe, isStandalone: false, name: "currency", pure: false }); }
533
- }
534
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: LocalizedCurrencyPipe, decorators: [{
535
- type: Pipe,
536
- args: [{
537
- name: 'currency',
538
- pure: false,
539
- standalone: false
540
- }]
541
- }], ctorParameters: () => [] });
542
-
543
- /**
544
- * Native angular DatePipe taking the current lang into consideration
545
- */
546
- class LocalizedDatePipe extends DatePipe {
547
- constructor() {
548
- super(inject(LocalizationService).getCurrentLanguage());
549
- this.localizationService = inject(LocalizationService);
550
- this.changeDetectorRef = inject(ChangeDetectorRef);
551
- this.onLangChange = this.localizationService.getTranslateService().onLangChange.subscribe(() => this.changeDetectorRef.markForCheck());
552
- }
553
- transform(value, format = 'mediumDate', timezone, locale) {
554
- return this.localizationService.showKeys ? format : super.transform(value, format, timezone, locale || this.localizationService.getCurrentLanguage());
555
- }
556
- ngOnDestroy() {
557
- this.onLangChange.unsubscribe();
558
- }
559
- /** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: LocalizedDatePipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe }); }
560
- /** @nocollapse */ static { this.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "22.2.0", ngImport: i0, type: LocalizedDatePipe, isStandalone: false, name: "date", pure: false }); }
561
- }
562
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: LocalizedDatePipe, decorators: [{
563
- type: Pipe,
564
- args: [{
565
- name: 'date',
566
- pure: false,
567
- standalone: false
568
- }]
569
- }], ctorParameters: () => [] });
570
-
571
- /**
572
- * Native angular DecimalPipe taking the current lang into consideration
573
- */
574
- class LocalizedDecimalPipe extends DecimalPipe {
575
- constructor() {
576
- super(inject(LocalizationService).getCurrentLanguage());
577
- this.localizationService = inject(LocalizationService);
578
- this.changeDetectorRef = inject(ChangeDetectorRef);
579
- this.onLangChange = this.localizationService.getTranslateService().onLangChange.subscribe(() => this.changeDetectorRef.markForCheck());
580
- }
581
- transform(value, digitsInfo, locale) {
582
- return super.transform(value, digitsInfo, locale || this.localizationService.getCurrentLanguage());
583
- }
584
- ngOnDestroy() {
585
- this.onLangChange.unsubscribe();
586
- }
587
- /** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: LocalizedDecimalPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe }); }
588
- /** @nocollapse */ static { this.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "22.2.0", ngImport: i0, type: LocalizedDecimalPipe, isStandalone: false, name: "decimal", pure: false }); }
589
- }
590
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: LocalizedDecimalPipe, decorators: [{
591
- type: Pipe,
592
- args: [{
593
- name: 'decimal',
594
- pure: false,
595
- standalone: false
596
- }]
597
- }], ctorParameters: () => [] });
598
-
599
- /**
600
- * Service for handling the text direction based on the LocalizationConfiguration
601
- */
602
- class TextDirectionService {
603
- constructor() {
604
- this.translateService = inject(TranslateService);
605
- this.configuration = inject(LOCALIZATION_CONFIGURATION_TOKEN);
606
- this.rendererFactory = inject(RendererFactory2);
607
- this.directionality = inject(Directionality);
608
- this.renderer = this.rendererFactory.createRenderer(null, null);
609
- }
610
- /**
611
- * Updates the dir attribute on body HTML tag.
612
- * @returns a subscription that updates the dir attribute
613
- */
614
- onLangChangeSubscription() {
615
- if (this.subscription && !this.subscription.closed) {
616
- return this.subscription;
617
- }
618
- this.subscription = this.translateService.onLangChange.subscribe((event) => {
619
- const direction = this.configuration.rtlLanguages.includes(event.lang.split('-')[0]) ? 'rtl' : 'ltr';
620
- this.renderer.setAttribute(document.body, 'dir', direction);
621
- this.directionality.change.emit(direction);
622
- });
623
- return this.subscription;
624
- }
625
- /** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: TextDirectionService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
626
- /** @nocollapse */ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: TextDirectionService }); }
627
- }
628
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: TextDirectionService, decorators: [{
629
- type: Injectable
630
- }], ctorParameters: () => [] });
631
-
632
- /**
633
- * @deprecated The value of Directionality is no longer readonly and can be updated, this class will be removed in v16
634
- */
635
- class TextDirectionality extends Directionality {
636
- get value() {
637
- return this._value;
638
- }
639
- set value(value) {
640
- this._value = value;
641
- }
642
- constructor() {
643
- super();
644
- /**
645
- * The current 'ltr' or 'rtl' value.
646
- * @override
647
- */
648
- this._value = 'ltr';
649
- this.change
650
- .pipe(startWith(this._value))
651
- .subscribe((value) => this._value = value);
652
- }
653
- ngOnDestroy() {
654
- this.change.complete();
655
- }
656
- /** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: TextDirectionality, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
657
- /** @nocollapse */ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: TextDirectionality }); }
658
- }
659
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: TextDirectionality, decorators: [{
660
- type: Injectable
661
- }], ctorParameters: () => [] });
662
-
663
- /**
664
- * creates LocalizationConfiguration, which is used if the application
665
- * @param configuration Localization configuration
666
- */
280
+ i0.ɵɵngDeclareClassMetadata({
281
+ minVersion: "12.0.0",
282
+ version: "22.2.3",
283
+ ngImport: i0,
284
+ type: LocalizationService,
285
+ decorators: [{ type: Injectable }],
286
+ ctorParameters: () => []
287
+ });
288
+ var LocalizationTranslateDirective = class LocalizationTranslateDirective extends TranslateDirective {
289
+ set translate(key) {
290
+ if (key && key !== this.key) {
291
+ if (this.onKeyChange) this.onKeyChange.unsubscribe();
292
+ this.onKeyChange = this.localizationService.getKey(key).subscribe((newKey) => {
293
+ this.key = newKey;
294
+ this.checkNodes();
295
+ });
296
+ }
297
+ }
298
+ constructor() {
299
+ const translateService = inject(TranslateService);
300
+ const element = inject(ElementRef);
301
+ const ref = inject(ChangeDetectorRef);
302
+ super(translateService, element, ref);
303
+ this.localizationService = inject(LocalizationService);
304
+ this.localizationConfig = inject(LOCALIZATION_CONFIGURATION_TOKEN);
305
+ this.showKeys = false;
306
+ const localizationService = this.localizationService;
307
+ if (this.localizationConfig.enableTranslationDeactivation) this.onShowKeysChange = localizationService.showKeys$.subscribe((showKeys) => {
308
+ this.showKeys = showKeys;
309
+ this.checkNodes(true);
310
+ });
311
+ }
312
+ setContent(node, content) {
313
+ const key = node.originalContent;
314
+ const newContent = this.showKeys ? key : this.localizationConfig.debugMode && key ? `${key} - ${content}` : content;
315
+ if (typeof node.textContent !== "undefined" && node.textContent !== null) node.textContent = newContent;
316
+ else node.data = newContent;
317
+ }
318
+ ngOnDestroy() {
319
+ super.ngOnDestroy();
320
+ if (this.onShowKeysChange) this.onShowKeysChange.unsubscribe();
321
+ if (this.onKeyChange) this.onKeyChange?.unsubscribe();
322
+ }
323
+ static {
324
+ this.ɵfac = i0.ɵɵngDeclareFactory({
325
+ minVersion: "12.0.0",
326
+ version: "22.2.3",
327
+ ngImport: i0,
328
+ type: LocalizationTranslateDirective,
329
+ deps: [],
330
+ target: i0.ɵɵFactoryTarget.Directive
331
+ });
332
+ }
333
+ static {
334
+ this.ɵdir = i0.ɵɵngDeclareDirective({
335
+ minVersion: "14.0.0",
336
+ version: "22.2.3",
337
+ type: LocalizationTranslateDirective,
338
+ isStandalone: false,
339
+ selector: "[translate],[ngx-translate]",
340
+ inputs: { translate: "translate" },
341
+ usesInheritance: true,
342
+ ngImport: i0
343
+ });
344
+ }
345
+ };
346
+ i0.ɵɵngDeclareClassMetadata({
347
+ minVersion: "12.0.0",
348
+ version: "22.2.3",
349
+ ngImport: i0,
350
+ type: LocalizationTranslateDirective,
351
+ decorators: [{
352
+ type: Directive,
353
+ args: [{
354
+ selector: "[translate],[ngx-translate]",
355
+ standalone: false
356
+ }]
357
+ }],
358
+ ctorParameters: () => [],
359
+ propDecorators: { translate: [{ type: Input }] }
360
+ });
361
+ var O3rLocalizationTranslatePipe = class O3rLocalizationTranslatePipe extends TranslatePipe {
362
+ constructor() {
363
+ super(inject(TranslateService), inject(ChangeDetectorRef));
364
+ this.localizationService = inject(LocalizationService);
365
+ this.changeDetector = inject(ChangeDetectorRef);
366
+ this.localizationConfig = inject(LOCALIZATION_CONFIGURATION_TOKEN);
367
+ this.showKeys = false;
368
+ if (this.localizationConfig.enableTranslationDeactivation) this.onShowKeysChange = this.localizationService.showKeys$.subscribe((showKeys) => {
369
+ this.showKeys = showKeys;
370
+ this.changeDetector.markForCheck();
371
+ });
372
+ }
373
+ transform(query, ...args) {
374
+ if (this.showKeys) return query;
375
+ if (query !== this.lastQueryKey) {
376
+ this.lastQueryKey = query;
377
+ if (this.onKeyChange) this.onKeyChange.unsubscribe();
378
+ this.onKeyChange = this.localizationService.getKey(query).subscribe((key) => {
379
+ this.lastResolvedKey = key;
380
+ this.changeDetector.markForCheck();
381
+ });
382
+ }
383
+ if (this.lastResolvedKey) {
384
+ const value = super.transform(this.lastResolvedKey, ...args);
385
+ if (this.localizationConfig.debugMode) return `${this.lastResolvedKey} - ${value}`;
386
+ return value;
387
+ }
388
+ return this.value;
389
+ }
390
+ ngOnDestroy() {
391
+ super.ngOnDestroy();
392
+ if (this.onShowKeysChange) this.onShowKeysChange.unsubscribe();
393
+ if (this.onKeyChange) this.onKeyChange.unsubscribe();
394
+ }
395
+ static {
396
+ this.ɵfac = i0.ɵɵngDeclareFactory({
397
+ minVersion: "12.0.0",
398
+ version: "22.2.3",
399
+ ngImport: i0,
400
+ type: O3rLocalizationTranslatePipe,
401
+ deps: [],
402
+ target: i0.ɵɵFactoryTarget.Pipe
403
+ });
404
+ }
405
+ static {
406
+ this.ɵpipe = i0.ɵɵngDeclarePipe({
407
+ minVersion: "14.0.0",
408
+ version: "22.2.3",
409
+ ngImport: i0,
410
+ type: O3rLocalizationTranslatePipe,
411
+ isStandalone: false,
412
+ name: "o3rTranslate",
413
+ pure: false
414
+ });
415
+ }
416
+ };
417
+ i0.ɵɵngDeclareClassMetadata({
418
+ minVersion: "12.0.0",
419
+ version: "22.2.3",
420
+ ngImport: i0,
421
+ type: O3rLocalizationTranslatePipe,
422
+ decorators: [{
423
+ type: Pipe,
424
+ args: [{
425
+ name: "o3rTranslate",
426
+ pure: false,
427
+ standalone: false
428
+ }]
429
+ }],
430
+ ctorParameters: () => []
431
+ });
432
+ var LocalizedCurrencyPipe = class LocalizedCurrencyPipe extends CurrencyPipe {
433
+ constructor() {
434
+ super(inject(LocalizationService).getCurrentLanguage());
435
+ this.localizationService = inject(LocalizationService);
436
+ this.changeDetectorRef = inject(ChangeDetectorRef);
437
+ this.onLangChange = this.localizationService.getTranslateService().onLangChange.subscribe(() => this.changeDetectorRef.markForCheck());
438
+ }
439
+ transform(value, currencyCode, display, digitsInfo, locale) {
440
+ return super.transform(value, currencyCode, display, digitsInfo, locale || this.localizationService.getCurrentLanguage());
441
+ }
442
+ ngOnDestroy() {
443
+ this.onLangChange.unsubscribe();
444
+ }
445
+ static {
446
+ this.ɵfac = i0.ɵɵngDeclareFactory({
447
+ minVersion: "12.0.0",
448
+ version: "22.2.3",
449
+ ngImport: i0,
450
+ type: LocalizedCurrencyPipe,
451
+ deps: [],
452
+ target: i0.ɵɵFactoryTarget.Pipe
453
+ });
454
+ }
455
+ static {
456
+ this.ɵpipe = i0.ɵɵngDeclarePipe({
457
+ minVersion: "14.0.0",
458
+ version: "22.2.3",
459
+ ngImport: i0,
460
+ type: LocalizedCurrencyPipe,
461
+ isStandalone: false,
462
+ name: "currency",
463
+ pure: false
464
+ });
465
+ }
466
+ };
467
+ i0.ɵɵngDeclareClassMetadata({
468
+ minVersion: "12.0.0",
469
+ version: "22.2.3",
470
+ ngImport: i0,
471
+ type: LocalizedCurrencyPipe,
472
+ decorators: [{
473
+ type: Pipe,
474
+ args: [{
475
+ name: "currency",
476
+ pure: false,
477
+ standalone: false
478
+ }]
479
+ }],
480
+ ctorParameters: () => []
481
+ });
482
+ var LocalizedDatePipe = class LocalizedDatePipe extends DatePipe {
483
+ constructor() {
484
+ super(inject(LocalizationService).getCurrentLanguage());
485
+ this.localizationService = inject(LocalizationService);
486
+ this.changeDetectorRef = inject(ChangeDetectorRef);
487
+ this.onLangChange = this.localizationService.getTranslateService().onLangChange.subscribe(() => this.changeDetectorRef.markForCheck());
488
+ }
489
+ transform(value, format = "mediumDate", timezone, locale) {
490
+ return this.localizationService.showKeys ? format : super.transform(value, format, timezone, locale || this.localizationService.getCurrentLanguage());
491
+ }
492
+ ngOnDestroy() {
493
+ this.onLangChange.unsubscribe();
494
+ }
495
+ static {
496
+ this.ɵfac = i0.ɵɵngDeclareFactory({
497
+ minVersion: "12.0.0",
498
+ version: "22.2.3",
499
+ ngImport: i0,
500
+ type: LocalizedDatePipe,
501
+ deps: [],
502
+ target: i0.ɵɵFactoryTarget.Pipe
503
+ });
504
+ }
505
+ static {
506
+ this.ɵpipe = i0.ɵɵngDeclarePipe({
507
+ minVersion: "14.0.0",
508
+ version: "22.2.3",
509
+ ngImport: i0,
510
+ type: LocalizedDatePipe,
511
+ isStandalone: false,
512
+ name: "date",
513
+ pure: false
514
+ });
515
+ }
516
+ };
517
+ i0.ɵɵngDeclareClassMetadata({
518
+ minVersion: "12.0.0",
519
+ version: "22.2.3",
520
+ ngImport: i0,
521
+ type: LocalizedDatePipe,
522
+ decorators: [{
523
+ type: Pipe,
524
+ args: [{
525
+ name: "date",
526
+ pure: false,
527
+ standalone: false
528
+ }]
529
+ }],
530
+ ctorParameters: () => []
531
+ });
532
+ var LocalizedDecimalPipe = class LocalizedDecimalPipe extends DecimalPipe {
533
+ constructor() {
534
+ super(inject(LocalizationService).getCurrentLanguage());
535
+ this.localizationService = inject(LocalizationService);
536
+ this.changeDetectorRef = inject(ChangeDetectorRef);
537
+ this.onLangChange = this.localizationService.getTranslateService().onLangChange.subscribe(() => this.changeDetectorRef.markForCheck());
538
+ }
539
+ transform(value, digitsInfo, locale) {
540
+ return super.transform(value, digitsInfo, locale || this.localizationService.getCurrentLanguage());
541
+ }
542
+ ngOnDestroy() {
543
+ this.onLangChange.unsubscribe();
544
+ }
545
+ static {
546
+ this.ɵfac = i0.ɵɵngDeclareFactory({
547
+ minVersion: "12.0.0",
548
+ version: "22.2.3",
549
+ ngImport: i0,
550
+ type: LocalizedDecimalPipe,
551
+ deps: [],
552
+ target: i0.ɵɵFactoryTarget.Pipe
553
+ });
554
+ }
555
+ static {
556
+ this.ɵpipe = i0.ɵɵngDeclarePipe({
557
+ minVersion: "14.0.0",
558
+ version: "22.2.3",
559
+ ngImport: i0,
560
+ type: LocalizedDecimalPipe,
561
+ isStandalone: false,
562
+ name: "decimal",
563
+ pure: false
564
+ });
565
+ }
566
+ };
567
+ i0.ɵɵngDeclareClassMetadata({
568
+ minVersion: "12.0.0",
569
+ version: "22.2.3",
570
+ ngImport: i0,
571
+ type: LocalizedDecimalPipe,
572
+ decorators: [{
573
+ type: Pipe,
574
+ args: [{
575
+ name: "decimal",
576
+ pure: false,
577
+ standalone: false
578
+ }]
579
+ }],
580
+ ctorParameters: () => []
581
+ });
582
+ var TextDirectionService = class TextDirectionService {
583
+ constructor() {
584
+ this.translateService = inject(TranslateService);
585
+ this.configuration = inject(LOCALIZATION_CONFIGURATION_TOKEN);
586
+ this.rendererFactory = inject(RendererFactory2);
587
+ this.directionality = inject(Directionality);
588
+ this.renderer = this.rendererFactory.createRenderer(null, null);
589
+ }
590
+ onLangChangeSubscription() {
591
+ if (this.subscription && !this.subscription.closed) return this.subscription;
592
+ this.subscription = this.translateService.onLangChange.subscribe((event) => {
593
+ const direction = this.configuration.rtlLanguages.includes(event.lang.split("-")[0]) ? "rtl" : "ltr";
594
+ this.renderer.setAttribute(document.body, "dir", direction);
595
+ this.directionality.change.emit(direction);
596
+ });
597
+ return this.subscription;
598
+ }
599
+ static {
600
+ this.ɵfac = i0.ɵɵngDeclareFactory({
601
+ minVersion: "12.0.0",
602
+ version: "22.2.3",
603
+ ngImport: i0,
604
+ type: TextDirectionService,
605
+ deps: [],
606
+ target: i0.ɵɵFactoryTarget.Injectable
607
+ });
608
+ }
609
+ static {
610
+ this.ɵprov = i0.ɵɵngDeclareInjectable({
611
+ minVersion: "12.0.0",
612
+ version: "22.2.3",
613
+ ngImport: i0,
614
+ type: TextDirectionService
615
+ });
616
+ }
617
+ };
618
+ i0.ɵɵngDeclareClassMetadata({
619
+ minVersion: "12.0.0",
620
+ version: "22.2.3",
621
+ ngImport: i0,
622
+ type: TextDirectionService,
623
+ decorators: [{ type: Injectable }],
624
+ ctorParameters: () => []
625
+ });
626
+ var TextDirectionality = class TextDirectionality extends Directionality {
627
+ get value() {
628
+ return this._value;
629
+ }
630
+ set value(value) {
631
+ this._value = value;
632
+ }
633
+ constructor() {
634
+ super();
635
+ this._value = "ltr";
636
+ this.change.pipe(startWith(this._value)).subscribe((value) => this._value = value);
637
+ }
638
+ ngOnDestroy() {
639
+ this.change.complete();
640
+ }
641
+ static {
642
+ this.ɵfac = i0.ɵɵngDeclareFactory({
643
+ minVersion: "12.0.0",
644
+ version: "22.2.3",
645
+ ngImport: i0,
646
+ type: TextDirectionality,
647
+ deps: [],
648
+ target: i0.ɵɵFactoryTarget.Injectable
649
+ });
650
+ }
651
+ static {
652
+ this.ɵprov = i0.ɵɵngDeclareInjectable({
653
+ minVersion: "12.0.0",
654
+ version: "22.2.3",
655
+ ngImport: i0,
656
+ type: TextDirectionality
657
+ });
658
+ }
659
+ };
660
+ i0.ɵɵngDeclareClassMetadata({
661
+ minVersion: "12.0.0",
662
+ version: "22.2.3",
663
+ ngImport: i0,
664
+ type: TextDirectionality,
665
+ decorators: [{ type: Injectable }],
666
+ ctorParameters: () => []
667
+ });
667
668
  function createLocalizationConfiguration(configuration) {
668
- return {
669
- ...DEFAULT_LOCALIZATION_CONFIGURATION,
670
- ...configuration
671
- };
669
+ return {
670
+ ...DEFAULT_LOCALIZATION_CONFIGURATION,
671
+ ...configuration
672
+ };
672
673
  }
673
- /**
674
- * Factory to inject the LOCALE_ID token with the current language into Angular context
675
- * @param localizationService Localization service
676
- */
677
674
  function localeIdNgBridge(localizationService) {
678
- return localizationService.getCurrentLanguage();
675
+ return localizationService.getCurrentLanguage();
679
676
  }
680
- /** Custom Localization Configuration Token to override default localization configuration */
681
- const CUSTOM_LOCALIZATION_CONFIGURATION_TOKEN = new InjectionToken('Partial Localization configuration');
682
- class LocalizationModule {
683
- /**
684
- * forRoot method should be called only once from the application index.ts
685
- * It will do several things:
686
- * - provide the configuration for the whole application
687
- * - register all locales specified in the LocalizationConfiguration
688
- * - configure TranslateService
689
- * - inject LOCALE_ID token
690
- * @param configuration LocalizationConfiguration
691
- */
692
- static forRoot(configuration) {
693
- return {
694
- ngModule: LocalizationModule,
695
- providers: [
696
- LocalizationService,
697
- ...(configuration
698
- ? [{
699
- provide: CUSTOM_LOCALIZATION_CONFIGURATION_TOKEN,
700
- useFactory: configuration
701
- }]
702
- : [])
703
- ]
704
- };
705
- }
706
- /** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: LocalizationModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
707
- /** @nocollapse */ static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "22.2.0", ngImport: i0, type: LocalizationModule, declarations: [O3rLocalizationTranslatePipe, LocalizationTranslateDirective, LocalizedDatePipe, LocalizedDecimalPipe, LocalizedCurrencyPipe], imports: [TranslateModule, BidiModule, CommonModule], exports: [TranslateModule, O3rLocalizationTranslatePipe, LocalizationTranslateDirective, LocalizedDatePipe, LocalizedDecimalPipe, LocalizedCurrencyPipe] }); }
708
- /** @nocollapse */ static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: LocalizationModule, providers: [
709
- { provide: LOCALIZATION_CONFIGURATION_TOKEN, useFactory: createLocalizationConfiguration, deps: [[new Optional(), CUSTOM_LOCALIZATION_CONFIGURATION_TOKEN]] },
710
- { provide: LOCALE_ID, useFactory: localeIdNgBridge, deps: [LocalizationService] },
711
- { provide: Directionality, useClass: TextDirectionality },
712
- { provide: DatePipe, useClass: LocalizedDatePipe },
713
- { provide: DecimalPipe, useClass: LocalizedDecimalPipe },
714
- { provide: CurrencyPipe, useClass: LocalizedCurrencyPipe },
715
- TextDirectionService
716
- ], imports: [TranslateModule, BidiModule, CommonModule, TranslateModule] }); }
717
- }
718
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: LocalizationModule, decorators: [{
719
- type: NgModule,
720
- args: [{
721
- declarations: [O3rLocalizationTranslatePipe, LocalizationTranslateDirective, LocalizedDatePipe, LocalizedDecimalPipe, LocalizedCurrencyPipe],
722
- imports: [TranslateModule, BidiModule, CommonModule],
723
- exports: [TranslateModule, O3rLocalizationTranslatePipe, LocalizationTranslateDirective, LocalizedDatePipe, LocalizedDecimalPipe, LocalizedCurrencyPipe],
724
- providers: [
725
- { provide: LOCALIZATION_CONFIGURATION_TOKEN, useFactory: createLocalizationConfiguration, deps: [[new Optional(), CUSTOM_LOCALIZATION_CONFIGURATION_TOKEN]] },
726
- { provide: LOCALE_ID, useFactory: localeIdNgBridge, deps: [LocalizationService] },
727
- { provide: Directionality, useClass: TextDirectionality },
728
- { provide: DatePipe, useClass: LocalizedDatePipe },
729
- { provide: DecimalPipe, useClass: LocalizedDecimalPipe },
730
- { provide: CurrencyPipe, useClass: LocalizedCurrencyPipe },
731
- TextDirectionService
732
- ]
733
- }]
734
- }] });
735
-
736
- const JSON_EXT = '.json';
737
- /**
738
- * This class is responsible for loading translation bundles from remote or local endpoints depending on the LocalizationConfiguration.
739
- * Fallback mechanism ensures that if a bundle in some language cannot be fetched remotely
740
- * we try to fetch the same language bundle locally (bundles stored inside the application)
741
- * and finally load the fallback language bundle (if all previous fetches failed)
742
- */
743
- class TranslationsLoader {
744
- constructor() {
745
- this.localizationConfiguration = inject(LOCALIZATION_CONFIGURATION_TOKEN);
746
- this.logger = inject(LoggerService, { optional: true });
747
- this.dynamicContentService = inject(DynamicContentService, { optional: true });
748
- }
749
- /**
750
- * Download a language bundle file
751
- * @param url Url to the bundle file
752
- */
753
- downloadLanguageBundle$(url) {
754
- const queryParams = this.localizationConfiguration.queryParams;
755
- let queryString = '';
756
- if (queryParams) {
757
- queryString = '?' + Object.keys(queryParams).map((key) => encodeURIComponent(key) + '=' + encodeURIComponent(queryParams[key])).join('&');
758
- }
759
- return from(fetch(url + queryString, this.localizationConfiguration.fetchOptions)).pipe(switchMap((response) => from(response.json())));
760
- }
761
- /**
762
- * @inheritdoc
763
- */
764
- getTranslation(lang) {
765
- const fallback = this.localizationConfiguration.fallbackLanguage;
766
- let localizationPath$ = of(this.localizationConfiguration.endPointUrl);
767
- if (this.localizationConfiguration.useDynamicContent) {
768
- if (!this.dynamicContentService) {
769
- throw new Error('Dynamic Content is not available. Please verify you have provided the DynamicContent in your application');
770
- }
771
- localizationPath$ = this.dynamicContentService.getContentPathStream(this.localizationConfiguration.endPointUrl);
772
- }
773
- return localizationPath$.pipe(switchMap((localizationPath) => {
774
- if (localizationPath) {
775
- const localizationBundle$ = this.downloadLanguageBundle$(localizationPath + lang + JSON_EXT);
776
- if (this.localizationConfiguration.mergeWithLocalTranslations) {
777
- return combineLatest([
778
- localizationBundle$.pipe(catchError(() => of({}))),
779
- this.getTranslationFromLocal(lang, fallback).pipe(map((translations) => {
780
- Object.keys(translations).forEach((key) => translations[key] = `[local] ${translations[key]}`);
781
- return translations;
782
- }))
783
- ]).pipe(map(([dynamicTranslations, localTranslations]) => ({ ...localTranslations, ...dynamicTranslations })));
784
- }
785
- /*
786
- * if endPointUrl is specified by the configuration then:
787
- * 1. try to load lang from endPointUrl
788
- * 2. if 1 fails then try to load from the app (local file)
789
- */
790
- return localizationBundle$.pipe(catchError(() => {
791
- this.logger?.warn(`Failed to load the localization resource from ${localizationPath + lang + JSON_EXT}, trying from the application resources`);
792
- return this.getTranslationFromLocal(lang, fallback);
793
- }));
794
- }
795
- /*
796
- * else if endPointUrl NOT specified by then configuration then:
797
- * 1. try to load from the app (local file)
798
- */
799
- this.logger?.warn('No localization endpoint specified, localization fetch from application resources');
800
- return this.getTranslationFromLocal(lang, fallback);
801
- }));
802
- }
803
- /**
804
- *
805
- *Fetches localization bundles from published folder (internal to application)
806
- *
807
- *1. try to load lang from local
808
- *2. if 1 fails try to load fallback lang but only if it's different from lang in 1
809
- * @param lang - language of the bundle
810
- * @param fallbackLanguage - fallback language in case bundle in language not found
811
- */
812
- getTranslationFromLocal(lang, fallbackLanguage) {
813
- const pathPrefix = this.localizationConfiguration.bundlesOutputPath;
814
- return this.downloadLanguageBundle$(pathPrefix + lang + JSON_EXT).pipe(catchError(() => {
815
- if (lang === fallbackLanguage) {
816
- this.logger?.warn(`Failed to load ${lang} from ${pathPrefix + lang + JSON_EXT}.`);
817
- return of({});
818
- }
819
- else {
820
- this.logger?.warn(`Failed to load ${lang} from ${pathPrefix + lang + JSON_EXT}. Application will fallback to ${fallbackLanguage}`);
821
- return this.downloadLanguageBundle$(pathPrefix + fallbackLanguage + JSON_EXT).pipe(catchError(() => of({})));
822
- }
823
- }));
824
- }
825
- /** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: TranslationsLoader, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
826
- /** @nocollapse */ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: TranslationsLoader }); }
827
- }
828
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: TranslationsLoader, decorators: [{
829
- type: Injectable
830
- }] });
831
-
832
- /**
833
- * Creates a loader of translations bundles based on the configuration
834
- * (endPointUrl and language determine which bundle we load and where do we fetch it from)
835
- * @param localizationConfiguration
836
- * @param logger service to handle the log of warning and errors
837
- * @param dynamicContentService (optional)
838
- */
677
+ const CUSTOM_LOCALIZATION_CONFIGURATION_TOKEN = new InjectionToken("Partial Localization configuration");
678
+ var LocalizationModule = class LocalizationModule {
679
+ static forRoot(configuration) {
680
+ return {
681
+ ngModule: LocalizationModule,
682
+ providers: [LocalizationService, ...configuration ? [{
683
+ provide: CUSTOM_LOCALIZATION_CONFIGURATION_TOKEN,
684
+ useFactory: configuration
685
+ }] : []]
686
+ };
687
+ }
688
+ static {
689
+ this.ɵfac = i0.ɵɵngDeclareFactory({
690
+ minVersion: "12.0.0",
691
+ version: "22.2.3",
692
+ ngImport: i0,
693
+ type: LocalizationModule,
694
+ deps: [],
695
+ target: i0.ɵɵFactoryTarget.NgModule
696
+ });
697
+ }
698
+ static {
699
+ this.ɵmod = i0.ɵɵngDeclareNgModule({
700
+ minVersion: "14.0.0",
701
+ version: "22.2.3",
702
+ ngImport: i0,
703
+ type: LocalizationModule,
704
+ declarations: [
705
+ O3rLocalizationTranslatePipe,
706
+ LocalizationTranslateDirective,
707
+ LocalizedDatePipe,
708
+ LocalizedDecimalPipe,
709
+ LocalizedCurrencyPipe
710
+ ],
711
+ imports: [
712
+ TranslateModule,
713
+ BidiModule,
714
+ CommonModule
715
+ ],
716
+ exports: [
717
+ TranslateModule,
718
+ O3rLocalizationTranslatePipe,
719
+ LocalizationTranslateDirective,
720
+ LocalizedDatePipe,
721
+ LocalizedDecimalPipe,
722
+ LocalizedCurrencyPipe
723
+ ]
724
+ });
725
+ }
726
+ static {
727
+ this.ɵinj = i0.ɵɵngDeclareInjector({
728
+ minVersion: "12.0.0",
729
+ version: "22.2.3",
730
+ ngImport: i0,
731
+ type: LocalizationModule,
732
+ providers: [
733
+ {
734
+ provide: LOCALIZATION_CONFIGURATION_TOKEN,
735
+ useFactory: createLocalizationConfiguration,
736
+ deps: [[new Optional(), CUSTOM_LOCALIZATION_CONFIGURATION_TOKEN]]
737
+ },
738
+ {
739
+ provide: LOCALE_ID,
740
+ useFactory: localeIdNgBridge,
741
+ deps: [LocalizationService]
742
+ },
743
+ {
744
+ provide: Directionality,
745
+ useClass: TextDirectionality
746
+ },
747
+ {
748
+ provide: DatePipe,
749
+ useClass: LocalizedDatePipe
750
+ },
751
+ {
752
+ provide: DecimalPipe,
753
+ useClass: LocalizedDecimalPipe
754
+ },
755
+ {
756
+ provide: CurrencyPipe,
757
+ useClass: LocalizedCurrencyPipe
758
+ },
759
+ TextDirectionService
760
+ ],
761
+ imports: [
762
+ TranslateModule,
763
+ BidiModule,
764
+ CommonModule,
765
+ TranslateModule
766
+ ]
767
+ });
768
+ }
769
+ };
770
+ i0.ɵɵngDeclareClassMetadata({
771
+ minVersion: "12.0.0",
772
+ version: "22.2.3",
773
+ ngImport: i0,
774
+ type: LocalizationModule,
775
+ decorators: [{
776
+ type: NgModule,
777
+ args: [{
778
+ declarations: [
779
+ O3rLocalizationTranslatePipe,
780
+ LocalizationTranslateDirective,
781
+ LocalizedDatePipe,
782
+ LocalizedDecimalPipe,
783
+ LocalizedCurrencyPipe
784
+ ],
785
+ imports: [
786
+ TranslateModule,
787
+ BidiModule,
788
+ CommonModule
789
+ ],
790
+ exports: [
791
+ TranslateModule,
792
+ O3rLocalizationTranslatePipe,
793
+ LocalizationTranslateDirective,
794
+ LocalizedDatePipe,
795
+ LocalizedDecimalPipe,
796
+ LocalizedCurrencyPipe
797
+ ],
798
+ providers: [
799
+ {
800
+ provide: LOCALIZATION_CONFIGURATION_TOKEN,
801
+ useFactory: createLocalizationConfiguration,
802
+ deps: [[new Optional(), CUSTOM_LOCALIZATION_CONFIGURATION_TOKEN]]
803
+ },
804
+ {
805
+ provide: LOCALE_ID,
806
+ useFactory: localeIdNgBridge,
807
+ deps: [LocalizationService]
808
+ },
809
+ {
810
+ provide: Directionality,
811
+ useClass: TextDirectionality
812
+ },
813
+ {
814
+ provide: DatePipe,
815
+ useClass: LocalizedDatePipe
816
+ },
817
+ {
818
+ provide: DecimalPipe,
819
+ useClass: LocalizedDecimalPipe
820
+ },
821
+ {
822
+ provide: CurrencyPipe,
823
+ useClass: LocalizedCurrencyPipe
824
+ },
825
+ TextDirectionService
826
+ ]
827
+ }]
828
+ }]
829
+ });
830
+ const JSON_EXT = ".json";
831
+ var TranslationsLoader = class TranslationsLoader {
832
+ constructor() {
833
+ this.localizationConfiguration = inject(LOCALIZATION_CONFIGURATION_TOKEN);
834
+ this.logger = inject(LoggerService, { optional: true });
835
+ this.dynamicContentService = inject(DynamicContentService, { optional: true });
836
+ }
837
+ downloadLanguageBundle$(url) {
838
+ const queryParams = this.localizationConfiguration.queryParams;
839
+ let queryString = "";
840
+ if (queryParams) queryString = "?" + Object.keys(queryParams).map((key) => encodeURIComponent(key) + "=" + encodeURIComponent(queryParams[key])).join("&");
841
+ return from(fetch(url + queryString, this.localizationConfiguration.fetchOptions)).pipe(switchMap((response) => from(response.json())));
842
+ }
843
+ getTranslation(lang) {
844
+ const fallback = this.localizationConfiguration.fallbackLanguage;
845
+ let localizationPath$ = of(this.localizationConfiguration.endPointUrl);
846
+ if (this.localizationConfiguration.useDynamicContent) {
847
+ if (!this.dynamicContentService) throw new Error("Dynamic Content is not available. Please verify you have provided the DynamicContent in your application");
848
+ localizationPath$ = this.dynamicContentService.getContentPathStream(this.localizationConfiguration.endPointUrl);
849
+ }
850
+ return localizationPath$.pipe(switchMap((localizationPath) => {
851
+ if (localizationPath) {
852
+ const localizationBundle$ = this.downloadLanguageBundle$(localizationPath + lang + JSON_EXT);
853
+ if (this.localizationConfiguration.mergeWithLocalTranslations) return combineLatest([localizationBundle$.pipe(catchError(() => of({}))), this.getTranslationFromLocal(lang, fallback).pipe(map((translations) => {
854
+ Object.keys(translations).forEach((key) => translations[key] = `[local] ${translations[key]}`);
855
+ return translations;
856
+ }))]).pipe(map(([dynamicTranslations, localTranslations]) => ({
857
+ ...localTranslations,
858
+ ...dynamicTranslations
859
+ })));
860
+ return localizationBundle$.pipe(catchError(() => {
861
+ this.logger?.warn(`Failed to load the localization resource from ${localizationPath + lang + JSON_EXT}, trying from the application resources`);
862
+ return this.getTranslationFromLocal(lang, fallback);
863
+ }));
864
+ }
865
+ this.logger?.warn("No localization endpoint specified, localization fetch from application resources");
866
+ return this.getTranslationFromLocal(lang, fallback);
867
+ }));
868
+ }
869
+ getTranslationFromLocal(lang, fallbackLanguage) {
870
+ const pathPrefix = this.localizationConfiguration.bundlesOutputPath;
871
+ return this.downloadLanguageBundle$(pathPrefix + lang + JSON_EXT).pipe(catchError(() => {
872
+ if (lang === fallbackLanguage) {
873
+ this.logger?.warn(`Failed to load ${lang} from ${pathPrefix + lang + JSON_EXT}.`);
874
+ return of({});
875
+ } else {
876
+ this.logger?.warn(`Failed to load ${lang} from ${pathPrefix + lang + JSON_EXT}. Application will fallback to ${fallbackLanguage}`);
877
+ return this.downloadLanguageBundle$(pathPrefix + fallbackLanguage + JSON_EXT).pipe(catchError(() => of({})));
878
+ }
879
+ }));
880
+ }
881
+ static {
882
+ this.ɵfac = i0.ɵɵngDeclareFactory({
883
+ minVersion: "12.0.0",
884
+ version: "22.2.3",
885
+ ngImport: i0,
886
+ type: TranslationsLoader,
887
+ deps: [],
888
+ target: i0.ɵɵFactoryTarget.Injectable
889
+ });
890
+ }
891
+ static {
892
+ this.ɵprov = i0.ɵɵngDeclareInjectable({
893
+ minVersion: "12.0.0",
894
+ version: "22.2.3",
895
+ ngImport: i0,
896
+ type: TranslationsLoader
897
+ });
898
+ }
899
+ };
900
+ i0.ɵɵngDeclareClassMetadata({
901
+ minVersion: "12.0.0",
902
+ version: "22.2.3",
903
+ ngImport: i0,
904
+ type: TranslationsLoader,
905
+ decorators: [{ type: Injectable }]
906
+ });
839
907
  function createTranslateLoader(localizationConfiguration, logger, dynamicContentService) {
840
- const injector = Injector.create({
841
- providers: [
842
- { provide: LOCALIZATION_CONFIGURATION_TOKEN, useValue: localizationConfiguration },
843
- { provide: LoggerService, useValue: logger },
844
- { provide: DynamicContentService, useValue: dynamicContentService },
845
- {
846
- provide: TranslationsLoader,
847
- deps: [[LoggerService, new Optional()], [DynamicContentService, new Optional()], LOCALIZATION_CONFIGURATION_TOKEN]
848
- }
849
- ]
850
- });
851
- return injector.get(TranslationsLoader);
908
+ return Injector.create({ providers: [
909
+ {
910
+ provide: LOCALIZATION_CONFIGURATION_TOKEN,
911
+ useValue: localizationConfiguration
912
+ },
913
+ {
914
+ provide: LoggerService,
915
+ useValue: logger
916
+ },
917
+ {
918
+ provide: DynamicContentService,
919
+ useValue: dynamicContentService
920
+ },
921
+ {
922
+ provide: TranslationsLoader,
923
+ deps: [
924
+ [LoggerService, new Optional()],
925
+ [DynamicContentService, new Optional()],
926
+ LOCALIZATION_CONFIGURATION_TOKEN
927
+ ]
928
+ }
929
+ ] }).get(TranslationsLoader);
852
930
  }
853
- /**
854
- * TranslateLoader provider, using framework's TranslationsLoader class
855
- */
856
931
  const translateLoaderProvider = {
857
- provide: TranslateLoader,
858
- useFactory: createTranslateLoader,
859
- deps: [LOCALIZATION_CONFIGURATION_TOKEN, [new Optional(), LoggerService], [new Optional(), DynamicContentService]]
932
+ provide: TranslateLoader,
933
+ useFactory: createTranslateLoader,
934
+ deps: [
935
+ LOCALIZATION_CONFIGURATION_TOKEN,
936
+ [new Optional(), LoggerService],
937
+ [new Optional(), DynamicContentService]
938
+ ]
860
939
  };
861
-
862
- class OtterLocalizationDevtools {
863
- constructor() {
864
- this.localizationService = inject(LocalizationService);
865
- this.translateCompiler = inject(TranslateCompiler);
866
- this.appRef = inject(ApplicationRef);
867
- }
868
- /**
869
- * Is the translation deactivation enabled
870
- */
871
- isTranslationDeactivationEnabled() {
872
- return this.localizationService.isTranslationDeactivationEnabled();
873
- }
874
- /**
875
- * Show localization keys
876
- * @param value value enforced by the DevTools extension
877
- */
878
- showLocalizationKeys(value) {
879
- this.localizationService.toggleShowKeys(value);
880
- this.appRef.tick();
881
- }
882
- /**
883
- * Returns the current language
884
- */
885
- getCurrentLanguage() {
886
- return this.localizationService.getCurrentLanguage();
887
- }
888
- /**
889
- * Setup a listener on language change
890
- * @param fn called when the language is changed in the app
891
- */
892
- onLanguageChange(fn) {
893
- return this.localizationService
894
- .getTranslateService()
895
- .onLangChange
896
- .subscribe(({ lang }) => {
897
- fn(lang);
898
- });
899
- }
900
- /**
901
- * Switch the current language to the specified value
902
- * @param language new language to switch to
903
- */
904
- async switchLanguage(language) {
905
- if (!language) {
906
- return;
907
- }
908
- await lastValueFrom(this.localizationService.useLanguage(language));
909
- this.appRef.tick();
910
- }
911
- /**
912
- * Updates the specified localization key/values for the current language.
913
- *
914
- * Recommendation: To be used with a small number of keys to update to avoid performance issues.
915
- * @param keyValues key/values to update
916
- * @param language if not provided, the current language value
917
- */
918
- updateLocalizationKeys(keyValues, language) {
919
- const lang = language || this.getCurrentLanguage();
920
- const translateService = this.localizationService.getTranslateService();
921
- Object.entries(keyValues).forEach(([key, value]) => {
922
- translateService.set(key, value, lang);
923
- });
924
- this.appRef.tick();
925
- }
926
- /**
927
- * Reload a language from the language file
928
- * @see https://github.com/ngx-translate/core/blob/master/packages/core/lib/translate.service.ts#L490
929
- * @param language language to reload
930
- */
931
- async reloadLocalizationKeys(language) {
932
- const lang = language || this.getCurrentLanguage();
933
- if (this.translateCompiler.clearCache) {
934
- this.translateCompiler.clearCache();
935
- }
936
- const initialLocs = await lastValueFrom(this.localizationService
937
- .getTranslateService()
938
- .reloadLang(lang));
939
- this.localizationService.getTranslateService().setTranslation(language || this.getCurrentLanguage(), initialLocs);
940
- this.appRef.tick();
941
- }
942
- /** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: OtterLocalizationDevtools, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
943
- /** @nocollapse */ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: OtterLocalizationDevtools }); }
944
- }
945
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: OtterLocalizationDevtools, decorators: [{
946
- type: Injectable
947
- }] });
948
-
940
+ var OtterLocalizationDevtools = class OtterLocalizationDevtools {
941
+ constructor() {
942
+ this.localizationService = inject(LocalizationService);
943
+ this.translateCompiler = inject(TranslateCompiler);
944
+ this.appRef = inject(ApplicationRef);
945
+ }
946
+ isTranslationDeactivationEnabled() {
947
+ return this.localizationService.isTranslationDeactivationEnabled();
948
+ }
949
+ showLocalizationKeys(value) {
950
+ this.localizationService.toggleShowKeys(value);
951
+ this.appRef.tick();
952
+ }
953
+ getCurrentLanguage() {
954
+ return this.localizationService.getCurrentLanguage();
955
+ }
956
+ onLanguageChange(fn) {
957
+ return this.localizationService.getTranslateService().onLangChange.subscribe(({ lang }) => {
958
+ fn(lang);
959
+ });
960
+ }
961
+ async switchLanguage(language) {
962
+ if (!language) return;
963
+ await lastValueFrom(this.localizationService.useLanguage(language));
964
+ this.appRef.tick();
965
+ }
966
+ updateLocalizationKeys(keyValues, language) {
967
+ const lang = language || this.getCurrentLanguage();
968
+ const translateService = this.localizationService.getTranslateService();
969
+ Object.entries(keyValues).forEach(([key, value]) => {
970
+ translateService.set(key, value, lang);
971
+ });
972
+ this.appRef.tick();
973
+ }
974
+ async reloadLocalizationKeys(language) {
975
+ const lang = language || this.getCurrentLanguage();
976
+ if (this.translateCompiler.clearCache) this.translateCompiler.clearCache();
977
+ const initialLocs = await lastValueFrom(this.localizationService.getTranslateService().reloadLang(lang));
978
+ this.localizationService.getTranslateService().setTranslation(language || this.getCurrentLanguage(), initialLocs);
979
+ this.appRef.tick();
980
+ }
981
+ static {
982
+ this.ɵfac = i0.ɵɵngDeclareFactory({
983
+ minVersion: "12.0.0",
984
+ version: "22.2.3",
985
+ ngImport: i0,
986
+ type: OtterLocalizationDevtools,
987
+ deps: [],
988
+ target: i0.ɵɵFactoryTarget.Injectable
989
+ });
990
+ }
991
+ static {
992
+ this.ɵprov = i0.ɵɵngDeclareInjectable({
993
+ minVersion: "12.0.0",
994
+ version: "22.2.3",
995
+ ngImport: i0,
996
+ type: OtterLocalizationDevtools
997
+ });
998
+ }
999
+ };
1000
+ i0.ɵɵngDeclareClassMetadata({
1001
+ minVersion: "12.0.0",
1002
+ version: "22.2.3",
1003
+ ngImport: i0,
1004
+ type: OtterLocalizationDevtools,
1005
+ decorators: [{ type: Injectable }]
1006
+ });
949
1007
  const OTTER_LOCALIZATION_DEVTOOLS_DEFAULT_OPTIONS = {
950
- isActivatedOnBootstrap: false,
951
- isActivatedOnBootstrapWhenCMSContext: true,
952
- metadataFilePath: './metadata/localisation.metadata.json'
1008
+ isActivatedOnBootstrap: false,
1009
+ isActivatedOnBootstrapWhenCMSContext: true,
1010
+ metadataFilePath: "./metadata/localisation.metadata.json"
953
1011
  };
954
- const OTTER_LOCALIZATION_DEVTOOLS_OPTIONS = new InjectionToken('Otter Localization Devtools options');
955
-
956
- /* eslint-disable no-console -- This is the purpose of this service */
957
- class LocalizationDevtoolsConsoleService {
958
- /** Name of the Window property to access to the devtools */
959
- static { this.windowModuleName = 'localization'; }
960
- constructor() {
961
- this.localizationDevtools = inject(OtterLocalizationDevtools);
962
- this.options = inject(OTTER_LOCALIZATION_DEVTOOLS_OPTIONS, { optional: true }) ?? OTTER_LOCALIZATION_DEVTOOLS_DEFAULT_OPTIONS;
963
- if (this.options.isActivatedOnBootstrap
964
- || (this.options.isActivatedOnBootstrapWhenCMSContext
965
- && document.body.dataset.cmscontext === 'true')) {
966
- this.activate();
967
- }
968
- }
969
- /** @inheritDoc */
970
- activate() {
971
- const windowWithDevtools = window;
972
- windowWithDevtools._OTTER_DEVTOOLS_ ||= {};
973
- windowWithDevtools._OTTER_DEVTOOLS_[LocalizationDevtoolsConsoleService.windowModuleName] = this;
974
- console.info(`Otter localization Devtools is now accessible via the _OTTER_DEVTOOLS_.${LocalizationDevtoolsConsoleService.windowModuleName} variable`);
975
- }
976
- /**
977
- * @inheritdoc
978
- */
979
- isTranslationDeactivationEnabled() {
980
- return this.localizationDevtools.isTranslationDeactivationEnabled();
981
- }
982
- /**
983
- * @inheritdoc
984
- */
985
- showLocalizationKeys(value) {
986
- this.localizationDevtools.showLocalizationKeys(value);
987
- }
988
- /**
989
- * @inheritdoc
990
- */
991
- getCurrentLanguage() {
992
- const currentLanguage = this.localizationDevtools.getCurrentLanguage();
993
- return currentLanguage;
994
- }
995
- /**
996
- * @inheritdoc
997
- */
998
- async switchLanguage(language) {
999
- const previous = this.localizationDevtools.getCurrentLanguage();
1000
- await this.localizationDevtools.switchLanguage(language);
1001
- const current = this.localizationDevtools.getCurrentLanguage();
1002
- return {
1003
- requested: language,
1004
- previous,
1005
- current
1006
- };
1007
- }
1008
- /**
1009
- * @inheritdoc
1010
- */
1011
- onLanguageChange(fn) {
1012
- return this.localizationDevtools.onLanguageChange(fn);
1013
- }
1014
- /**
1015
- * @inheritdoc
1016
- */
1017
- updateLocalizationKeys(keyValues, language) {
1018
- return this.localizationDevtools.updateLocalizationKeys(keyValues, language);
1019
- }
1020
- /**
1021
- * @inheritdoc
1022
- */
1023
- reloadLocalizationKeys(language) {
1024
- return this.localizationDevtools.reloadLocalizationKeys(language);
1025
- }
1026
- /** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: LocalizationDevtoolsConsoleService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
1027
- /** @nocollapse */ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: LocalizationDevtoolsConsoleService }); }
1028
- }
1029
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: LocalizationDevtoolsConsoleService, decorators: [{
1030
- type: Injectable
1031
- }], ctorParameters: () => [] });
1032
-
1012
+ const OTTER_LOCALIZATION_DEVTOOLS_OPTIONS = new InjectionToken("Otter Localization Devtools options");
1013
+ var LocalizationDevtoolsConsoleService = class LocalizationDevtoolsConsoleService {
1014
+ static {
1015
+ this.windowModuleName = "localization";
1016
+ }
1017
+ constructor() {
1018
+ this.localizationDevtools = inject(OtterLocalizationDevtools);
1019
+ this.options = inject(OTTER_LOCALIZATION_DEVTOOLS_OPTIONS, { optional: true }) ?? OTTER_LOCALIZATION_DEVTOOLS_DEFAULT_OPTIONS;
1020
+ if (this.options.isActivatedOnBootstrap || this.options.isActivatedOnBootstrapWhenCMSContext && document.body.dataset.cmscontext === "true") this.activate();
1021
+ }
1022
+ activate() {
1023
+ const windowWithDevtools = window;
1024
+ windowWithDevtools._OTTER_DEVTOOLS_ ||= {};
1025
+ windowWithDevtools._OTTER_DEVTOOLS_[LocalizationDevtoolsConsoleService.windowModuleName] = this;
1026
+ console.info(`Otter localization Devtools is now accessible via the _OTTER_DEVTOOLS_.${LocalizationDevtoolsConsoleService.windowModuleName} variable`);
1027
+ }
1028
+ isTranslationDeactivationEnabled() {
1029
+ return this.localizationDevtools.isTranslationDeactivationEnabled();
1030
+ }
1031
+ showLocalizationKeys(value) {
1032
+ this.localizationDevtools.showLocalizationKeys(value);
1033
+ }
1034
+ getCurrentLanguage() {
1035
+ return this.localizationDevtools.getCurrentLanguage();
1036
+ }
1037
+ async switchLanguage(language) {
1038
+ const previous = this.localizationDevtools.getCurrentLanguage();
1039
+ await this.localizationDevtools.switchLanguage(language);
1040
+ return {
1041
+ requested: language,
1042
+ previous,
1043
+ current: this.localizationDevtools.getCurrentLanguage()
1044
+ };
1045
+ }
1046
+ onLanguageChange(fn) {
1047
+ return this.localizationDevtools.onLanguageChange(fn);
1048
+ }
1049
+ updateLocalizationKeys(keyValues, language) {
1050
+ return this.localizationDevtools.updateLocalizationKeys(keyValues, language);
1051
+ }
1052
+ reloadLocalizationKeys(language) {
1053
+ return this.localizationDevtools.reloadLocalizationKeys(language);
1054
+ }
1055
+ static {
1056
+ this.ɵfac = i0.ɵɵngDeclareFactory({
1057
+ minVersion: "12.0.0",
1058
+ version: "22.2.3",
1059
+ ngImport: i0,
1060
+ type: LocalizationDevtoolsConsoleService,
1061
+ deps: [],
1062
+ target: i0.ɵɵFactoryTarget.Injectable
1063
+ });
1064
+ }
1065
+ static {
1066
+ this.ɵprov = i0.ɵɵngDeclareInjectable({
1067
+ minVersion: "12.0.0",
1068
+ version: "22.2.3",
1069
+ ngImport: i0,
1070
+ type: LocalizationDevtoolsConsoleService
1071
+ });
1072
+ }
1073
+ };
1074
+ i0.ɵɵngDeclareClassMetadata({
1075
+ minVersion: "12.0.0",
1076
+ version: "22.2.3",
1077
+ ngImport: i0,
1078
+ type: LocalizationDevtoolsConsoleService,
1079
+ decorators: [{ type: Injectable }],
1080
+ ctorParameters: () => []
1081
+ });
1033
1082
  const isLocalizationMessage = (message) => {
1034
- return message && (message.dataType === 'displayLocalizationKeys'
1035
- || message.dataType === 'languages'
1036
- || message.dataType === 'switchLanguage'
1037
- || message.dataType === 'localizations'
1038
- || message.dataType === 'updateLocalization'
1039
- || message.dataType === 'requestMessages'
1040
- || message.dataType === 'connect'
1041
- || message.dataType === 'reloadLocalizationKeys'
1042
- || message.dataType === 'isTranslationDeactivationEnabled'
1043
- || message.dataType === 'getTranslationValuesContentMessage');
1083
+ return message && (message.dataType === "displayLocalizationKeys" || message.dataType === "languages" || message.dataType === "switchLanguage" || message.dataType === "localizations" || message.dataType === "updateLocalization" || message.dataType === "requestMessages" || message.dataType === "connect" || message.dataType === "reloadLocalizationKeys" || message.dataType === "isTranslationDeactivationEnabled" || message.dataType === "getTranslationValuesContentMessage");
1044
1084
  };
1045
- class LocalizationDevtoolsMessageService {
1046
- constructor() {
1047
- this.logger = inject(LoggerService);
1048
- this.localizationDevTools = inject(OtterLocalizationDevtools);
1049
- this.localizationService = inject(LocalizationService);
1050
- this.options = inject(OTTER_LOCALIZATION_DEVTOOLS_OPTIONS, { optional: true }) ?? OTTER_LOCALIZATION_DEVTOOLS_DEFAULT_OPTIONS;
1051
- this.sendMessage = (sendOtterMessage);
1052
- this.destroyRef = inject(DestroyRef);
1053
- this.options = {
1054
- ...OTTER_LOCALIZATION_DEVTOOLS_DEFAULT_OPTIONS,
1055
- ...this.options
1056
- };
1057
- if (this.options.isActivatedOnBootstrap) {
1058
- this.activate();
1059
- }
1060
- }
1061
- async sendLocalizationsMetadata() {
1062
- const metadata = await (await fetch(this.options.metadataFilePath)).json();
1063
- this.sendMessage('localizations', {
1064
- localizations: metadata
1065
- });
1066
- }
1067
- /**
1068
- * Function to trigger a re-send a requested messages to the Otter Chrome DevTools extension
1069
- * @param only restricted list of messages to re-send
1070
- */
1071
- async handleReEmitRequest(only) {
1072
- if (!only || only.includes('localizations')) {
1073
- void this.sendLocalizationsMetadata();
1074
- }
1075
- if (!only || only.includes('switchLanguage')) {
1076
- this.sendMessage('switchLanguage', { language: this.localizationDevTools.getCurrentLanguage() });
1077
- }
1078
- if (!only || only.includes('languages')) {
1079
- this.sendMessage('languages', { languages: this.localizationService.getLanguages() });
1080
- }
1081
- if (!only || only.includes('getTranslationValuesContentMessage')) {
1082
- this.sendMessage('getTranslationValuesContentMessage', {
1083
- translations: await firstValueFrom(this.localizationService.getTranslateService().getTranslation(this.localizationService.getCurrentLanguage()))
1084
- });
1085
- }
1086
- if (!only || only.includes('isTranslationDeactivationEnabled')) {
1087
- this.sendMessage('isTranslationDeactivationEnabled', { enabled: this.localizationService.isTranslationDeactivationEnabled() });
1088
- }
1089
- }
1090
- /**
1091
- * Function to handle the incoming messages from Otter Chrome DevTools extension
1092
- * @param message Message coming from the Otter Chrome DevTools extension
1093
- */
1094
- handleEvents(message) {
1095
- this.logger.debug('Message handling by the localization service', message);
1096
- switch (message.dataType) {
1097
- case 'connect': {
1098
- this.connectPlugin();
1099
- break;
1100
- }
1101
- case 'displayLocalizationKeys': {
1102
- this.localizationDevTools.showLocalizationKeys(message.toggle);
1103
- break;
1104
- }
1105
- case 'requestMessages': {
1106
- void this.handleReEmitRequest(message.only);
1107
- break;
1108
- }
1109
- case 'switchLanguage': {
1110
- void this.localizationDevTools.switchLanguage(message.language);
1111
- break;
1112
- }
1113
- case 'updateLocalization': {
1114
- void this.localizationDevTools.updateLocalizationKeys({
1115
- [message.key]: message.value
1116
- }, message.lang);
1117
- break;
1118
- }
1119
- case 'reloadLocalizationKeys': {
1120
- void this.localizationDevTools.reloadLocalizationKeys(message.lang);
1121
- break;
1122
- }
1123
- default: {
1124
- this.logger.warn('Message ignored by the localization service', message);
1125
- }
1126
- }
1127
- }
1128
- /**
1129
- * Function to connect the plugin to the Otter Chrome DevTools extension
1130
- */
1131
- connectPlugin() {
1132
- this.logger.debug('Otter DevTools is plugged to localization service of the application');
1133
- }
1134
- /** @inheritDoc */
1135
- activate() {
1136
- fromEvent(window, 'message').pipe(takeUntilDestroyed(this.destroyRef), filterMessageContent(isLocalizationMessage)).subscribe((e) => this.handleEvents(e));
1137
- }
1138
- /** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: LocalizationDevtoolsMessageService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
1139
- /** @nocollapse */ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: LocalizationDevtoolsMessageService }); }
1140
- }
1141
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: LocalizationDevtoolsMessageService, decorators: [{
1142
- type: Injectable
1143
- }], ctorParameters: () => [] });
1144
-
1145
- class LocalizationDevtoolsModule {
1146
- /**
1147
- * Initialize Otter Devtools
1148
- * @param options
1149
- */
1150
- static instrument(options) {
1151
- return {
1152
- ngModule: LocalizationDevtoolsModule,
1153
- providers: [
1154
- { provide: OTTER_LOCALIZATION_DEVTOOLS_OPTIONS, useValue: { ...OTTER_LOCALIZATION_DEVTOOLS_DEFAULT_OPTIONS, ...options }, multi: false },
1155
- LocalizationDevtoolsMessageService,
1156
- LocalizationDevtoolsConsoleService,
1157
- OtterLocalizationDevtools
1158
- ]
1159
- };
1160
- }
1161
- /** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: LocalizationDevtoolsModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
1162
- /** @nocollapse */ static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "22.2.0", ngImport: i0, type: LocalizationDevtoolsModule, imports: [LocalizationModule] }); }
1163
- /** @nocollapse */ static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: LocalizationDevtoolsModule, providers: [
1164
- { provide: OTTER_LOCALIZATION_DEVTOOLS_OPTIONS, useValue: OTTER_LOCALIZATION_DEVTOOLS_DEFAULT_OPTIONS },
1165
- LocalizationDevtoolsMessageService,
1166
- LocalizationDevtoolsConsoleService,
1167
- OtterLocalizationDevtools
1168
- ], imports: [LocalizationModule] }); }
1169
- }
1170
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: LocalizationDevtoolsModule, decorators: [{
1171
- type: NgModule,
1172
- args: [{
1173
- imports: [
1174
- LocalizationModule
1175
- ],
1176
- providers: [
1177
- { provide: OTTER_LOCALIZATION_DEVTOOLS_OPTIONS, useValue: OTTER_LOCALIZATION_DEVTOOLS_DEFAULT_OPTIONS },
1178
- LocalizationDevtoolsMessageService,
1179
- LocalizationDevtoolsConsoleService,
1180
- OtterLocalizationDevtools
1181
- ]
1182
- }]
1183
- }] });
1184
-
1185
- /**
1186
- * Generated bundle index. Do not edit.
1187
- */
1188
-
1085
+ var LocalizationDevtoolsMessageService = class LocalizationDevtoolsMessageService {
1086
+ constructor() {
1087
+ this.logger = inject(LoggerService);
1088
+ this.localizationDevTools = inject(OtterLocalizationDevtools);
1089
+ this.localizationService = inject(LocalizationService);
1090
+ this.options = inject(OTTER_LOCALIZATION_DEVTOOLS_OPTIONS, { optional: true }) ?? OTTER_LOCALIZATION_DEVTOOLS_DEFAULT_OPTIONS;
1091
+ this.sendMessage = sendOtterMessage;
1092
+ this.destroyRef = inject(DestroyRef);
1093
+ this.options = {
1094
+ ...OTTER_LOCALIZATION_DEVTOOLS_DEFAULT_OPTIONS,
1095
+ ...this.options
1096
+ };
1097
+ if (this.options.isActivatedOnBootstrap) this.activate();
1098
+ }
1099
+ async sendLocalizationsMetadata() {
1100
+ const metadata = await (await fetch(this.options.metadataFilePath)).json();
1101
+ this.sendMessage("localizations", { localizations: metadata });
1102
+ }
1103
+ async handleReEmitRequest(only) {
1104
+ if (!only || only.includes("localizations")) this.sendLocalizationsMetadata();
1105
+ if (!only || only.includes("switchLanguage")) this.sendMessage("switchLanguage", { language: this.localizationDevTools.getCurrentLanguage() });
1106
+ if (!only || only.includes("languages")) this.sendMessage("languages", { languages: this.localizationService.getLanguages() });
1107
+ if (!only || only.includes("getTranslationValuesContentMessage")) this.sendMessage("getTranslationValuesContentMessage", { translations: await firstValueFrom(this.localizationService.getTranslateService().getTranslation(this.localizationService.getCurrentLanguage())) });
1108
+ if (!only || only.includes("isTranslationDeactivationEnabled")) this.sendMessage("isTranslationDeactivationEnabled", { enabled: this.localizationService.isTranslationDeactivationEnabled() });
1109
+ }
1110
+ handleEvents(message) {
1111
+ this.logger.debug("Message handling by the localization service", message);
1112
+ switch (message.dataType) {
1113
+ case "connect":
1114
+ this.connectPlugin();
1115
+ break;
1116
+ case "displayLocalizationKeys":
1117
+ this.localizationDevTools.showLocalizationKeys(message.toggle);
1118
+ break;
1119
+ case "requestMessages":
1120
+ this.handleReEmitRequest(message.only);
1121
+ break;
1122
+ case "switchLanguage":
1123
+ this.localizationDevTools.switchLanguage(message.language);
1124
+ break;
1125
+ case "updateLocalization":
1126
+ this.localizationDevTools.updateLocalizationKeys({ [message.key]: message.value }, message.lang);
1127
+ break;
1128
+ case "reloadLocalizationKeys":
1129
+ this.localizationDevTools.reloadLocalizationKeys(message.lang);
1130
+ break;
1131
+ default: this.logger.warn("Message ignored by the localization service", message);
1132
+ }
1133
+ }
1134
+ connectPlugin() {
1135
+ this.logger.debug("Otter DevTools is plugged to localization service of the application");
1136
+ }
1137
+ activate() {
1138
+ fromEvent(window, "message").pipe(takeUntilDestroyed(this.destroyRef), filterMessageContent(isLocalizationMessage)).subscribe((e) => this.handleEvents(e));
1139
+ }
1140
+ static {
1141
+ this.ɵfac = i0.ɵɵngDeclareFactory({
1142
+ minVersion: "12.0.0",
1143
+ version: "22.2.3",
1144
+ ngImport: i0,
1145
+ type: LocalizationDevtoolsMessageService,
1146
+ deps: [],
1147
+ target: i0.ɵɵFactoryTarget.Injectable
1148
+ });
1149
+ }
1150
+ static {
1151
+ this.ɵprov = i0.ɵɵngDeclareInjectable({
1152
+ minVersion: "12.0.0",
1153
+ version: "22.2.3",
1154
+ ngImport: i0,
1155
+ type: LocalizationDevtoolsMessageService
1156
+ });
1157
+ }
1158
+ };
1159
+ i0.ɵɵngDeclareClassMetadata({
1160
+ minVersion: "12.0.0",
1161
+ version: "22.2.3",
1162
+ ngImport: i0,
1163
+ type: LocalizationDevtoolsMessageService,
1164
+ decorators: [{ type: Injectable }],
1165
+ ctorParameters: () => []
1166
+ });
1167
+ var LocalizationDevtoolsModule = class LocalizationDevtoolsModule {
1168
+ static instrument(options) {
1169
+ return {
1170
+ ngModule: LocalizationDevtoolsModule,
1171
+ providers: [
1172
+ {
1173
+ provide: OTTER_LOCALIZATION_DEVTOOLS_OPTIONS,
1174
+ useValue: {
1175
+ ...OTTER_LOCALIZATION_DEVTOOLS_DEFAULT_OPTIONS,
1176
+ ...options
1177
+ },
1178
+ multi: false
1179
+ },
1180
+ LocalizationDevtoolsMessageService,
1181
+ LocalizationDevtoolsConsoleService,
1182
+ OtterLocalizationDevtools
1183
+ ]
1184
+ };
1185
+ }
1186
+ static {
1187
+ this.ɵfac = i0.ɵɵngDeclareFactory({
1188
+ minVersion: "12.0.0",
1189
+ version: "22.2.3",
1190
+ ngImport: i0,
1191
+ type: LocalizationDevtoolsModule,
1192
+ deps: [],
1193
+ target: i0.ɵɵFactoryTarget.NgModule
1194
+ });
1195
+ }
1196
+ static {
1197
+ this.ɵmod = i0.ɵɵngDeclareNgModule({
1198
+ minVersion: "14.0.0",
1199
+ version: "22.2.3",
1200
+ ngImport: i0,
1201
+ type: LocalizationDevtoolsModule,
1202
+ imports: [LocalizationModule]
1203
+ });
1204
+ }
1205
+ static {
1206
+ this.ɵinj = i0.ɵɵngDeclareInjector({
1207
+ minVersion: "12.0.0",
1208
+ version: "22.2.3",
1209
+ ngImport: i0,
1210
+ type: LocalizationDevtoolsModule,
1211
+ providers: [
1212
+ {
1213
+ provide: OTTER_LOCALIZATION_DEVTOOLS_OPTIONS,
1214
+ useValue: OTTER_LOCALIZATION_DEVTOOLS_DEFAULT_OPTIONS
1215
+ },
1216
+ LocalizationDevtoolsMessageService,
1217
+ LocalizationDevtoolsConsoleService,
1218
+ OtterLocalizationDevtools
1219
+ ],
1220
+ imports: [LocalizationModule]
1221
+ });
1222
+ }
1223
+ };
1224
+ i0.ɵɵngDeclareClassMetadata({
1225
+ minVersion: "12.0.0",
1226
+ version: "22.2.3",
1227
+ ngImport: i0,
1228
+ type: LocalizationDevtoolsModule,
1229
+ decorators: [{
1230
+ type: NgModule,
1231
+ args: [{
1232
+ imports: [LocalizationModule],
1233
+ providers: [
1234
+ {
1235
+ provide: OTTER_LOCALIZATION_DEVTOOLS_OPTIONS,
1236
+ useValue: OTTER_LOCALIZATION_DEVTOOLS_DEFAULT_OPTIONS
1237
+ },
1238
+ LocalizationDevtoolsMessageService,
1239
+ LocalizationDevtoolsConsoleService,
1240
+ OtterLocalizationDevtools
1241
+ ]
1242
+ }]
1243
+ }]
1244
+ });
1189
1245
  export { CUSTOM_LOCALIZATION_CONFIGURATION_TOKEN, DEFAULT_LOCALIZATION_CONFIGURATION, LOCALIZATION_CONFIGURATION_TOKEN, LOCALIZATION_OVERRIDE_REDUCER_TOKEN, LOCALIZATION_OVERRIDE_STORE_NAME, Localization, LocalizationDevtoolsConsoleService, LocalizationDevtoolsMessageService, LocalizationDevtoolsModule, LocalizationModule, LocalizationOverrideStoreModule, LocalizationService, LocalizationTranslateDirective, LocalizedCurrencyPipe, LocalizedDatePipe, LocalizedDecimalPipe, MESSAGE_FORMAT_CONFIG, O3rLocalizationTranslatePipe, OTTER_LOCALIZATION_DEVTOOLS_DEFAULT_OPTIONS, OTTER_LOCALIZATION_DEVTOOLS_OPTIONS, OtterLocalizationDevtools, TextDirectionService, TextDirectionality, TranslateMessageFormatLazyCompiler, TranslationsLoader, createLocalizationConfiguration, createTranslateLoader, getDefaultLocalizationOverrideReducer, lazyMessageDefaultConfig, localeIdNgBridge, localizationOverrideInitialState, localizationOverrideReducer, localizationOverrideReducerFeatures, localizationOverrideStorageDeserializer, localizationOverrideStorageSync, selectLocalizationOverride, selectLocalizationOverrideState, setLocalizationOverride, translateLoaderProvider };
1190
- //# sourceMappingURL=o3r-localization.mjs.map
1246
+
1247
+ //# sourceMappingURL=o3r-localization.mjs.map