@acorex/core 19.13.0-next.5 → 19.13.0-next.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/fesm2022/acorex-core-format.mjs +17 -16
- package/fesm2022/acorex-core-format.mjs.map +1 -1
- package/fesm2022/acorex-core-translation.mjs +250 -209
- package/fesm2022/acorex-core-translation.mjs.map +1 -1
- package/fesm2022/acorex-core-utils.mjs +140 -15
- package/fesm2022/acorex-core-utils.mjs.map +1 -1
- package/format/lib/format.service.d.ts +8 -7
- package/package.json +1 -1
- package/translation/index.d.ts +1 -1
- package/translation/lib/translation-loader.service.d.ts +20 -0
- package/translation/lib/translation.config.d.ts +19 -6
- package/translation/lib/translation.loader.d.ts +2 -2
- package/translation/lib/translation.parser.d.ts +7 -0
- package/translation/lib/translation.resolver.d.ts +9 -0
- package/translation/lib/translation.service.d.ts +13 -32
- package/translation/lib/translation.types.d.ts +8 -2
- package/translation/lib/translator.directive.d.ts +2 -2
- package/translation/lib/translator.pipe.d.ts +0 -2
- package/utils/index.d.ts +6 -5
- package/utils/lib/execution.utils.d.ts +33 -0
- package/utils/lib/string.utils.d.ts +4 -0
- package/utils/lib/string-util.d.ts +0 -6
- /package/utils/lib/{color-util.d.ts → color.utils.d.ts} +0 -0
- /package/utils/lib/{drawing-util.d.ts → drawing.utils.d.ts} +0 -0
- /package/utils/lib/{html-util.d.ts → html-utils.d.ts} +0 -0
- /package/utils/lib/{auto-unsubscribe.d.ts → lifecycle-helpers.utils.d.ts} +0 -0
@@ -1,9 +1,9 @@
|
|
1
1
|
import * as i0 from '@angular/core';
|
2
2
|
import { InjectionToken, inject, Injectable, Directive, Pipe, provideAppInitializer, NgModule } from '@angular/core';
|
3
|
-
import {
|
4
|
-
import {
|
5
|
-
import {
|
6
|
-
import {
|
3
|
+
import { of, shareReplay, firstValueFrom, BehaviorSubject, switchMap, from } from 'rxjs';
|
4
|
+
import { get } from 'lodash-es';
|
5
|
+
import { AXLocaleService } from '@acorex/core/locale';
|
6
|
+
import { waitFor } from '@acorex/core/utils';
|
7
7
|
|
8
8
|
const AX_TRANSLATION_CONFIG = new InjectionToken('AX_TRANSLATION_CONFIG', {
|
9
9
|
providedIn: 'root',
|
@@ -12,9 +12,17 @@ const AX_TRANSLATION_CONFIG = new InjectionToken('AX_TRANSLATION_CONFIG', {
|
|
12
12
|
},
|
13
13
|
});
|
14
14
|
const AXTranslationDefaultConfig = {
|
15
|
-
|
16
|
-
|
17
|
-
|
15
|
+
defaults: {
|
16
|
+
lang: 'en-US',
|
17
|
+
scope: 'common',
|
18
|
+
},
|
19
|
+
preload: {
|
20
|
+
langs: ['en-US'],
|
21
|
+
scopes: ['common'],
|
22
|
+
},
|
23
|
+
resolver: {
|
24
|
+
scopeKey: 'scope',
|
25
|
+
},
|
18
26
|
};
|
19
27
|
function translationConfig(config = {}) {
|
20
28
|
const result = {
|
@@ -25,7 +33,7 @@ function translationConfig(config = {}) {
|
|
25
33
|
}
|
26
34
|
|
27
35
|
class AXTranslationLoaderDefault {
|
28
|
-
|
36
|
+
load(options) {
|
29
37
|
return of({});
|
30
38
|
}
|
31
39
|
}
|
@@ -36,247 +44,280 @@ const AX_TRANSLATION_LOADER = new InjectionToken('AX_TRANSLATION_LOADER', {
|
|
36
44
|
},
|
37
45
|
});
|
38
46
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
return this.config.defaultLang;
|
46
|
-
}
|
47
|
-
getActiveLang() {
|
48
|
-
return this.activeLang.getValue();
|
47
|
+
class AXTranslationLoaderService {
|
48
|
+
constructor() {
|
49
|
+
this.loader = inject(AX_TRANSLATION_LOADER);
|
50
|
+
this.config = inject(AX_TRANSLATION_CONFIG);
|
51
|
+
this.cache = new Map();
|
52
|
+
this.inflight = new Map();
|
49
53
|
}
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
54
|
+
load(lang, scope) {
|
55
|
+
const key = `${lang}:${scope}`;
|
56
|
+
console.log('load', key);
|
57
|
+
if (this.cache.has(key)) {
|
58
|
+
return of(this.cache.get(key));
|
59
|
+
}
|
60
|
+
if (!this.inflight.has(key)) {
|
61
|
+
const obs = this.loader.load({ lang, scope }).pipe(shareReplay(1));
|
62
|
+
this.inflight.set(key, obs);
|
63
|
+
obs.subscribe({
|
64
|
+
next: (data) => {
|
65
|
+
this.cache.set(key, data);
|
66
|
+
this.inflight.delete(key);
|
67
|
+
},
|
68
|
+
error: () => {
|
69
|
+
this.inflight.delete(key);
|
70
|
+
},
|
56
71
|
});
|
57
72
|
}
|
73
|
+
return this.inflight.get(key);
|
58
74
|
}
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
this.
|
66
|
-
this.
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
singletonInstance = this;
|
74
|
-
//
|
75
|
-
this.localeService.profileChanged$.subscribe((locale) => {
|
76
|
-
if (locale?.localeInfo?.code) {
|
77
|
-
this.setActiveLang(locale.localeInfo.code);
|
78
|
-
}
|
75
|
+
peek(lang, scope, key) {
|
76
|
+
const cacheKey = `${lang}:${scope}`;
|
77
|
+
const data = this.cache.get(cacheKey);
|
78
|
+
return get(data, key, null);
|
79
|
+
}
|
80
|
+
async preload(options) {
|
81
|
+
const langs = [...new Set(options?.langs ?? this.config.preload?.langs ?? [this.config.defaults.lang])];
|
82
|
+
const scopes = [...new Set(options?.scopes ?? this.config.preload?.scopes ?? [this.config.defaults.scope])];
|
83
|
+
const promises = [];
|
84
|
+
langs.forEach(lang => {
|
85
|
+
scopes.forEach(scope => {
|
86
|
+
const p = firstValueFrom(this.load(lang, scope));
|
87
|
+
promises.push(p);
|
88
|
+
});
|
79
89
|
});
|
90
|
+
await Promise.all(promises);
|
80
91
|
}
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
if (this.translationCache[lang]?.[scope]) {
|
85
|
-
return of(this.translationCache[lang][scope]);
|
86
|
-
}
|
87
|
-
// Use the new method to handle ongoing requests and loading
|
88
|
-
return this.fetchTranslationFiles(lang, scope);
|
89
|
-
}));
|
90
|
-
return forkJoin(requests);
|
92
|
+
clear() {
|
93
|
+
this.cache.clear();
|
94
|
+
this.inflight.clear();
|
91
95
|
}
|
92
|
-
|
93
|
-
|
94
|
-
// Return existing observable if the request is already in progress
|
95
|
-
if (this.ongoingRequests.has(requestKey)) {
|
96
|
-
return this.ongoingRequests.get(requestKey);
|
97
|
-
}
|
98
|
-
// Load translations if not in cache or ongoing requests
|
99
|
-
const translationObservable = this.loader.getTranslation({ lang, scope }).pipe(tap((translations) => this.setTranslationCache(lang, scope, translations)), catchError((error) => {
|
100
|
-
this.handleError(`Error loading translations for lang: ${lang}, scope: ${scope}`, error);
|
101
|
-
return of(null);
|
102
|
-
}), finalize(() => {
|
103
|
-
this.eventService.emitEvent({
|
104
|
-
type: AXLocaleEvents.AXLanguageLoaded,
|
105
|
-
payload: lang,
|
106
|
-
});
|
107
|
-
this.ongoingRequests.delete(requestKey);
|
108
|
-
}), shareReplay(1));
|
109
|
-
this.ongoingRequests.set(requestKey, translationObservable);
|
110
|
-
return translationObservable;
|
96
|
+
getFallbackLangs(lang) {
|
97
|
+
return this.config.fallbacks?.langs?.[lang] ?? [];
|
111
98
|
}
|
112
|
-
|
113
|
-
|
114
|
-
* Set translation data into cache
|
115
|
-
*/
|
116
|
-
setTranslationCache(lang, scope, translations) {
|
117
|
-
set(this.translationCache, `${lang}.${scope}`, translations);
|
99
|
+
getFallbackScopes(scope) {
|
100
|
+
return this.config.fallbacks?.scopes?.[scope] ?? [];
|
118
101
|
}
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
102
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.8", ngImport: i0, type: AXTranslationLoaderService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
103
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.8", ngImport: i0, type: AXTranslationLoaderService, providedIn: 'root' }); }
|
104
|
+
}
|
105
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.8", ngImport: i0, type: AXTranslationLoaderService, decorators: [{
|
106
|
+
type: Injectable,
|
107
|
+
args: [{ providedIn: 'root' }]
|
108
|
+
}] });
|
109
|
+
|
110
|
+
class TranslationParserService {
|
111
|
+
constructor() {
|
112
|
+
this.legacyRegex = /t\(["']([^"']+)["']\s*(?:,\s*(\{.*?\}))?\)/g;
|
113
|
+
this.inlineRegex = /@([a-zA-Z\-]+:)?([a-zA-Z0-9_-]+):([a-zA-Z0-9_.:-]+)(?=[\\s.,;!?)]|$)/g;
|
124
114
|
}
|
125
|
-
|
126
|
-
return
|
115
|
+
isExpression(value) {
|
116
|
+
return typeof value === 'string' && (value.includes('t(') || value.includes('@'));
|
127
117
|
}
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
if (params && typeof translation === 'string') {
|
139
|
-
Object.keys(params).forEach((paramKey) => {
|
140
|
-
translation = translation.replace(new RegExp(`{{\\s*${paramKey}\\s*}}`, 'g'), params[paramKey]);
|
141
|
-
});
|
118
|
+
parse(expression, currentLang, currentScope) {
|
119
|
+
const tokens = [];
|
120
|
+
// Extract inline references like @lang:scope:key or @scope:key
|
121
|
+
let inlineMatch;
|
122
|
+
while ((inlineMatch = this.inlineRegex.exec(expression)) !== null) {
|
123
|
+
const langPart = inlineMatch[1]?.replace(':', '') ?? null;
|
124
|
+
const scope = inlineMatch[2] ?? currentScope;
|
125
|
+
const key = inlineMatch[3];
|
126
|
+
const fullMatch = inlineMatch[0];
|
127
|
+
tokens.push({ lang: langPart || currentLang, scope, key, fullMatch });
|
142
128
|
}
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
129
|
+
// Extract legacy expressions
|
130
|
+
let legacyMatch;
|
131
|
+
while ((legacyMatch = this.legacyRegex.exec(expression)) !== null) {
|
132
|
+
const key = legacyMatch[1];
|
133
|
+
const rawOptions = legacyMatch[2];
|
134
|
+
let scope = currentScope;
|
135
|
+
let lang = currentLang;
|
136
|
+
if (rawOptions) {
|
137
|
+
try {
|
138
|
+
const jsonString = rawOptions
|
139
|
+
.replace(/(['"])?([a-zA-Z0-9_]+)(['"])?\s*:/g, '"$2":')
|
140
|
+
.replace(/'/g, '"');
|
141
|
+
const options = JSON.parse(jsonString);
|
142
|
+
scope = options.scope || scope;
|
143
|
+
lang = options.lang || lang;
|
144
|
+
}
|
145
|
+
catch (err) {
|
146
|
+
console.error('Invalid translation expression options:', err);
|
147
|
+
}
|
148
|
+
}
|
149
|
+
tokens.push({ key, scope, lang, fullMatch: legacyMatch[0] });
|
148
150
|
}
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
151
|
+
return tokens;
|
152
|
+
}
|
153
|
+
}
|
154
|
+
|
155
|
+
class TranslationResolverService {
|
156
|
+
constructor() {
|
157
|
+
this.loaderService = inject(AXTranslationLoaderService);
|
158
|
+
this.cache = new Map();
|
159
|
+
this.inflight = new Map();
|
160
|
+
this.parser = new TranslationParserService();
|
161
|
+
}
|
162
|
+
async resolve(lang, scope, key, params) {
|
163
|
+
const cacheKey = `${lang}:${scope}`;
|
164
|
+
// Load and cache if not present
|
165
|
+
if (!this.cache.has(cacheKey)) {
|
166
|
+
if (!this.inflight.has(cacheKey)) {
|
167
|
+
const fetchPromise = firstValueFrom(this.loaderService.load(lang, scope));
|
168
|
+
this.inflight.set(cacheKey, fetchPromise);
|
169
|
+
const data = await fetchPromise;
|
170
|
+
this.cache.set(cacheKey, data);
|
171
|
+
this.inflight.delete(cacheKey);
|
158
172
|
}
|
159
|
-
|
160
|
-
|
161
|
-
.replace(/(['"])?([a-zA-Z0-9_]+)(['"])?\s*:/g, '"$2":') // Ensure keys are quoted
|
162
|
-
.replace(/'/g, '"'); // Replace single quotes with double quotes
|
163
|
-
const options = JSON.parse(jsonString);
|
164
|
-
matches.push({
|
165
|
-
key,
|
166
|
-
scope: options.scope || null,
|
167
|
-
lang: options.lang || null,
|
168
|
-
fullMatch: match[0],
|
169
|
-
});
|
173
|
+
else {
|
174
|
+
await this.inflight.get(cacheKey); // wait for the inflight fetch
|
170
175
|
}
|
171
|
-
|
172
|
-
|
173
|
-
|
176
|
+
}
|
177
|
+
const translations = this.cache.get(cacheKey);
|
178
|
+
let result = get(translations, key, key);
|
179
|
+
// Recursively resolve references
|
180
|
+
if (typeof result === 'string' && this.parser.isExpression(result)) {
|
181
|
+
const tokens = this.parser.parse(result, lang, scope);
|
182
|
+
if (tokens.length > 0) {
|
183
|
+
const first = tokens[0];
|
184
|
+
result = await this.resolve(first.lang || lang, first.scope || scope, first.key, params);
|
174
185
|
}
|
175
186
|
}
|
176
|
-
this.
|
177
|
-
|
187
|
+
return this.format(result, params);
|
188
|
+
}
|
189
|
+
format(text, params) {
|
190
|
+
if (!params || typeof text !== 'string')
|
191
|
+
return text;
|
192
|
+
return Object.keys(params).reduce((out, key) => {
|
193
|
+
const re = new RegExp(`{{\s*${key}\s*}}`, 'g');
|
194
|
+
return out.replace(re, params[key]);
|
195
|
+
}, text);
|
178
196
|
}
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
197
|
+
}
|
198
|
+
|
199
|
+
let singletonInstance;
|
200
|
+
function translateSync(key, options) {
|
201
|
+
return singletonInstance.translateSync(key, options);
|
202
|
+
}
|
203
|
+
class AXTranslationService {
|
204
|
+
constructor() {
|
205
|
+
this.localeService = inject(AXLocaleService);
|
206
|
+
this.config = inject(AX_TRANSLATION_CONFIG);
|
207
|
+
this.loader = inject(AXTranslationLoaderService);
|
208
|
+
this.parser = new TranslationParserService();
|
209
|
+
this.resolver = new TranslationResolverService();
|
210
|
+
this.activeLang = new BehaviorSubject(this.config.defaults.lang);
|
211
|
+
this.langChanges$ = this.activeLang.asObservable();
|
212
|
+
singletonInstance = this;
|
213
|
+
this.localeService.profileChanged$.subscribe((locale) => {
|
214
|
+
if (locale?.localeInfo?.code) {
|
215
|
+
this.setActiveLang(locale.localeInfo.code);
|
216
|
+
}
|
184
217
|
});
|
185
218
|
}
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
if (!this.isExpression(text)) {
|
190
|
-
return this.loadLanguagesAndScopes([contextLang], [contextScope]).pipe(map(() => this.translateKey(text, contextLang, contextScope, params)), catchError((error) => {
|
191
|
-
this.handleError(`Error during translation:`, error);
|
192
|
-
return of(text); // Fallback to the original text
|
193
|
-
}));
|
219
|
+
setActiveLang(lang) {
|
220
|
+
if (lang && lang !== this.activeLang.getValue()) {
|
221
|
+
this.activeLang.next(lang);
|
194
222
|
}
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
return this.loadLanguagesAndScopes(langs, scopes).pipe(map(() => {
|
202
|
-
// Resolve translations after loading
|
203
|
-
const translations = matches.reduce((acc, { key, scope, lang, fullMatch }) => {
|
204
|
-
const resolvedScope = scope || contextScope;
|
205
|
-
const resolvedLang = lang || contextLang;
|
206
|
-
acc[fullMatch] = this.translateKey(key, resolvedLang, resolvedScope, params);
|
207
|
-
return acc;
|
208
|
-
}, {});
|
209
|
-
// Replace all matches in the text with their resolved translations
|
210
|
-
return matches.reduce((result, { fullMatch }) => result.replace(new RegExp(fullMatch.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&'), 'g'), translations[fullMatch]), text);
|
211
|
-
}), catchError((error) => {
|
212
|
-
this.handleError(`Error during translation:`, error);
|
213
|
-
return of(text); // Fallback to the original text
|
214
|
-
}));
|
223
|
+
}
|
224
|
+
getActiveLang() {
|
225
|
+
return this.activeLang.getValue();
|
226
|
+
}
|
227
|
+
getDefaultLang() {
|
228
|
+
return this.config.defaults.lang;
|
215
229
|
}
|
216
230
|
translate$(text, options) {
|
217
|
-
if (
|
218
|
-
return
|
231
|
+
if (!text) {
|
232
|
+
return of('');
|
219
233
|
}
|
220
|
-
|
221
|
-
|
222
|
-
|
234
|
+
const staticOptions = { ...options };
|
235
|
+
const staticScope = staticOptions.scope ?? this.config.defaults.scope;
|
236
|
+
return this.langChanges$.pipe(switchMap(lang => {
|
237
|
+
return from(this.translateAsync(text, {
|
238
|
+
...staticOptions,
|
239
|
+
lang: staticOptions.lang ?? lang,
|
240
|
+
scope: staticScope
|
241
|
+
}));
|
242
|
+
}), shareReplay({ bufferSize: 1, refCount: true }));
|
223
243
|
}
|
224
244
|
async translateAsync(text, options) {
|
225
|
-
|
245
|
+
const lang = options?.lang ?? this.getActiveLang() ?? this.config.defaults.lang;
|
246
|
+
const scope = options?.scope ?? this.config.defaults.scope;
|
247
|
+
const params = options?.params;
|
248
|
+
if (!this.parser.isExpression(text)) {
|
249
|
+
const resolved = await this.resolver.resolve(lang, scope, text, params);
|
250
|
+
return this.resolver.format(resolved, params);
|
251
|
+
}
|
252
|
+
const tokens = this.parser.parse(text, lang, scope);
|
253
|
+
const results = await Promise.all(tokens.map(token => this.resolver.resolve(token.lang ?? lang, token.scope ?? scope, token.key, params)
|
254
|
+
.then(translated => [token.fullMatch, this.resolver.format(translated, params)])));
|
255
|
+
return results.reduce((output, [match, translated]) => output.replace(match, translated), text);
|
226
256
|
}
|
227
|
-
//#endregion
|
228
|
-
//#region Sync Translation Methods
|
229
257
|
translateSync(text, options) {
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
258
|
+
const lang = options?.lang ?? this.getActiveLang() ?? this.config.defaults.lang;
|
259
|
+
const scope = options?.scope ?? this.config.defaults.scope;
|
260
|
+
const params = options?.params;
|
261
|
+
const waitForLoad = options?.waitForLoad ?? false;
|
262
|
+
const timeoutMs = options?.timeoutMs ?? 100;
|
263
|
+
if (!this.parser.isExpression(text)) {
|
264
|
+
let translated = this.loader.peek(lang, scope, text);
|
265
|
+
if (!translated && waitForLoad) {
|
266
|
+
translated = waitFor(() => this.loader.peek(lang, scope, text), () => this.loader.load(lang, scope).subscribe(), timeoutMs);
|
267
|
+
}
|
268
|
+
return this.resolver.format(translated ?? text, params);
|
235
269
|
}
|
236
|
-
|
237
|
-
|
238
|
-
const
|
239
|
-
|
240
|
-
const
|
241
|
-
const
|
242
|
-
|
243
|
-
if (!
|
244
|
-
|
270
|
+
const tokens = this.parser.parse(text, lang, scope);
|
271
|
+
let result = text;
|
272
|
+
for (const token of tokens) {
|
273
|
+
const targetLang = token.lang ?? lang;
|
274
|
+
const targetScope = token.scope ?? scope;
|
275
|
+
const key = token.key;
|
276
|
+
let translation = this.loader.peek(targetLang, targetScope, key);
|
277
|
+
if (!translation) {
|
278
|
+
translation = waitFor(() => this.loader.peek(targetLang, targetScope, key), () => this.loader.load(targetLang, targetScope).subscribe(), waitForLoad ? timeoutMs : 0) ?? key;
|
245
279
|
}
|
246
|
-
|
247
|
-
}
|
248
|
-
|
249
|
-
return matches.reduce((result, { fullMatch }) => result.replace(fullMatch, translations[fullMatch]), text);
|
280
|
+
result = result.replace(token.fullMatch, this.resolver.format(translation, params));
|
281
|
+
}
|
282
|
+
return result;
|
250
283
|
}
|
251
284
|
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.8", ngImport: i0, type: AXTranslationService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
252
285
|
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.8", ngImport: i0, type: AXTranslationService, providedIn: 'root' }); }
|
253
286
|
}
|
254
287
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.8", ngImport: i0, type: AXTranslationService, decorators: [{
|
255
288
|
type: Injectable,
|
256
|
-
args: [{
|
289
|
+
args: [{
|
290
|
+
providedIn: 'root'
|
291
|
+
}]
|
257
292
|
}], ctorParameters: () => [] });
|
258
293
|
|
259
294
|
const loadTranslationScope = (route, state) => {
|
260
|
-
const
|
295
|
+
const translationLoaderService = inject(AXTranslationLoaderService);
|
296
|
+
const translationService = inject(AXTranslationService);
|
261
297
|
const config = inject(AX_TRANSLATION_CONFIG);
|
262
|
-
const scopeValue = route.data[config.
|
298
|
+
const scopeValue = route.data[config.resolver?.scopeKey];
|
263
299
|
const scopes = Array.isArray(scopeValue) ? scopeValue : [scopeValue];
|
264
|
-
return
|
300
|
+
return translationLoaderService.preload({ langs: [translationService.getActiveLang()], scopes });
|
265
301
|
};
|
266
302
|
|
267
303
|
class AXTranslatorDirective {
|
268
|
-
constructor(templateRef,
|
304
|
+
constructor(templateRef, vc, translationService) {
|
269
305
|
this.templateRef = templateRef;
|
270
|
-
this.
|
306
|
+
this.vc = vc;
|
271
307
|
this.translationService = translationService;
|
272
308
|
}
|
273
309
|
ngOnInit() {
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
310
|
+
const cache = new Map();
|
311
|
+
const t = (key, opts) => {
|
312
|
+
const id = `${key}|${opts?.lang ?? this.translationService.getActiveLang()}|${opts?.scope ?? 'common'}`;
|
313
|
+
if (!cache.has(id)) {
|
314
|
+
cache.set(id, this.translationService.translate$(key, opts)
|
315
|
+
.pipe(shareReplay({ bufferSize: 1, refCount: true })));
|
316
|
+
}
|
317
|
+
return cache.get(id);
|
318
|
+
};
|
319
|
+
this.vc.clear();
|
320
|
+
this.vc.createEmbeddedView(this.templateRef, { $implicit: t });
|
280
321
|
}
|
281
322
|
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.8", ngImport: i0, type: AXTranslatorDirective, deps: [{ token: i0.TemplateRef }, { token: i0.ViewContainerRef }, { token: AXTranslationService }], target: i0.ɵɵFactoryTarget.Directive }); }
|
282
323
|
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "19.2.8", type: AXTranslatorDirective, isStandalone: true, selector: "[translate]", ngImport: i0 }); }
|
@@ -287,8 +328,8 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.8", ngImpor
|
|
287
328
|
}], ctorParameters: () => [{ type: i0.TemplateRef }, { type: i0.ViewContainerRef }, { type: AXTranslationService }] });
|
288
329
|
|
289
330
|
class AXTranslatorPipe {
|
290
|
-
constructor(
|
291
|
-
this.service =
|
331
|
+
constructor() {
|
332
|
+
this.service = inject(AXTranslationService);
|
292
333
|
}
|
293
334
|
transform(key, options) {
|
294
335
|
if (!key) {
|
@@ -296,7 +337,7 @@ class AXTranslatorPipe {
|
|
296
337
|
}
|
297
338
|
return this.service.translate$(key, options);
|
298
339
|
}
|
299
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.8", ngImport: i0, type: AXTranslatorPipe, deps: [
|
340
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.8", ngImport: i0, type: AXTranslatorPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe }); }
|
300
341
|
static { this.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "19.2.8", ngImport: i0, type: AXTranslatorPipe, isStandalone: true, name: "translate" }); }
|
301
342
|
}
|
302
343
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.8", ngImport: i0, type: AXTranslatorPipe, decorators: [{
|
@@ -305,11 +346,11 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.8", ngImpor
|
|
305
346
|
name: 'translate',
|
306
347
|
pure: true,
|
307
348
|
}]
|
308
|
-
}]
|
349
|
+
}] });
|
309
350
|
|
310
|
-
function initializeApp(translatorService
|
351
|
+
function initializeApp(translatorService) {
|
311
352
|
return () => {
|
312
|
-
return translatorService.
|
353
|
+
return translatorService.preload();
|
313
354
|
};
|
314
355
|
}
|
315
356
|
class AXTranslationModule {
|
@@ -317,7 +358,7 @@ class AXTranslationModule {
|
|
317
358
|
static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "19.2.8", ngImport: i0, type: AXTranslationModule, imports: [AXTranslatorPipe, AXTranslatorDirective], exports: [AXTranslatorPipe, AXTranslatorDirective] }); }
|
318
359
|
static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "19.2.8", ngImport: i0, type: AXTranslationModule, providers: [
|
319
360
|
provideAppInitializer(() => {
|
320
|
-
const initializerFn = initializeApp(inject(
|
361
|
+
const initializerFn = initializeApp(inject(AXTranslationLoaderService));
|
321
362
|
return initializerFn();
|
322
363
|
}),
|
323
364
|
] }); }
|
@@ -329,7 +370,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.8", ngImpor
|
|
329
370
|
exports: [AXTranslatorPipe, AXTranslatorDirective],
|
330
371
|
providers: [
|
331
372
|
provideAppInitializer(() => {
|
332
|
-
const initializerFn = initializeApp(inject(
|
373
|
+
const initializerFn = initializeApp(inject(AXTranslationLoaderService));
|
333
374
|
return initializerFn();
|
334
375
|
}),
|
335
376
|
],
|