@acorex/core 7.17.26 → 7.17.27
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/dateTime/index.d.ts +2 -0
- package/dateTime/lib/calendar.service.d.ts +6 -1
- package/dateTime/lib/datetime.class.d.ts +6 -5
- package/dateTime/lib/datetime.module.d.ts +0 -2
- package/dateTime/lib/datetime.pipe.d.ts +3 -0
- package/dateTime/lib/formatters/datetime-formatter.d.ts +19 -0
- package/dateTime/lib/formatters/timeleft-formatter.d.ts +16 -0
- package/esm2022/dateTime/index.mjs +3 -1
- package/esm2022/dateTime/lib/calendar.service.mjs +17 -9
- package/esm2022/dateTime/lib/dateTime.config.mjs +5 -28
- package/esm2022/dateTime/lib/datetime.class.mjs +66 -14
- package/esm2022/dateTime/lib/datetime.module.mjs +9 -11
- package/esm2022/dateTime/lib/datetime.pipe.mjs +5 -7
- package/esm2022/dateTime/lib/formatters/datetime-formatter.mjs +30 -0
- package/esm2022/dateTime/lib/formatters/timeleft-formatter.mjs +91 -0
- package/esm2022/file/lib/file-size-formatter.mjs +2 -2
- package/esm2022/file/lib/file.module.mjs +8 -10
- package/esm2022/format/index.mjs +3 -2
- package/esm2022/format/lib/format.config.mjs +3 -2
- package/esm2022/format/lib/format.module.mjs +22 -9
- package/esm2022/format/lib/format.pipe.mjs +5 -6
- package/esm2022/format/lib/format.service.mjs +57 -12
- package/esm2022/format/lib/format.types.mjs +2 -0
- package/esm2022/format/lib/formatters/number-formatter.mjs +75 -0
- package/esm2022/translation/index.mjs +7 -2
- package/esm2022/translation/lib/translation-scope.resolver.mjs +11 -0
- package/esm2022/translation/lib/translation.config.mjs +20 -0
- package/esm2022/translation/lib/translation.loader.mjs +14 -0
- package/esm2022/translation/lib/translation.module.mjs +29 -7
- package/esm2022/translation/lib/translation.service.mjs +105 -0
- package/esm2022/translation/lib/translation.types.mjs +2 -0
- package/esm2022/translation/lib/translator.directive.mjs +28 -0
- package/esm2022/translation/lib/translator.pipe.mjs +33 -7
- package/esm2022/validation/index.mjs +2 -2
- package/esm2022/validation/lib/rules/between-rule.mjs +8 -1
- package/esm2022/validation/lib/rules/callback-rule.mjs +8 -1
- package/esm2022/validation/lib/rules/equal-rule.mjs +8 -1
- package/esm2022/validation/lib/rules/greater-than.mjs +8 -1
- package/esm2022/validation/lib/rules/length-rule.mjs +9 -1
- package/esm2022/validation/lib/rules/less-than-rule.mjs +8 -1
- package/esm2022/validation/lib/rules/maxlength-rule.mjs +8 -1
- package/esm2022/validation/lib/rules/minlength-rule.mjs +8 -1
- package/esm2022/validation/lib/rules/regex-rule.mjs +13 -2
- package/esm2022/validation/lib/rules/required-rule.mjs +13 -3
- package/esm2022/validation/lib/validation.config.mjs +3 -4
- package/esm2022/validation/lib/validation.module.mjs +38 -12
- package/esm2022/validation/lib/validation.service.mjs +30 -16
- package/esm2022/validation/lib/validation.types.mjs +3 -0
- package/fesm2022/acorex-core-dateTime.mjs +110 -68
- package/fesm2022/acorex-core-dateTime.mjs.map +1 -1
- package/fesm2022/acorex-core-file.mjs +8 -9
- package/fesm2022/acorex-core-file.mjs.map +1 -1
- package/fesm2022/acorex-core-format.mjs +147 -55
- package/fesm2022/acorex-core-format.mjs.map +1 -1
- package/fesm2022/acorex-core-translation.mjs +212 -45
- package/fesm2022/acorex-core-translation.mjs.map +1 -1
- package/fesm2022/acorex-core-validation.mjs +131 -32
- package/fesm2022/acorex-core-validation.mjs.map +1 -1
- package/file/lib/file-size-formatter.d.ts +10 -2
- package/file/lib/file.module.d.ts +2 -3
- package/format/index.d.ts +2 -1
- package/format/lib/format.config.d.ts +4 -3
- package/format/lib/format.module.d.ts +9 -3
- package/format/lib/format.pipe.d.ts +2 -1
- package/format/lib/format.service.d.ts +26 -2
- package/format/lib/format.types.d.ts +4 -0
- package/format/lib/formatters/number-formatter.d.ts +23 -0
- package/package.json +1 -7
- package/translation/index.d.ts +6 -1
- package/translation/lib/translation-scope.resolver.d.ts +2 -0
- package/translation/lib/translation.config.d.ts +14 -0
- package/translation/lib/translation.loader.d.ts +14 -0
- package/translation/lib/translation.module.d.ts +2 -1
- package/translation/lib/translation.service.d.ts +26 -0
- package/translation/lib/translation.types.d.ts +10 -0
- package/translation/lib/translator.directive.d.ts +12 -0
- package/translation/lib/translator.pipe.d.ts +12 -4
- package/validation/index.d.ts +1 -1
- package/validation/lib/rules/between-rule.d.ts +5 -2
- package/validation/lib/rules/callback-rule.d.ts +5 -2
- package/validation/lib/rules/equal-rule.d.ts +5 -2
- package/validation/lib/rules/greater-than.d.ts +5 -2
- package/validation/lib/rules/length-rule.d.ts +5 -2
- package/validation/lib/rules/less-than-rule.d.ts +5 -2
- package/validation/lib/rules/maxlength-rule.d.ts +5 -2
- package/validation/lib/rules/minlength-rule.d.ts +5 -2
- package/validation/lib/rules/regex-rule.d.ts +6 -2
- package/validation/lib/rules/required-rule.d.ts +6 -2
- package/validation/lib/validation.config.d.ts +3 -3
- package/validation/lib/validation.module.d.ts +10 -4
- package/validation/lib/validation.service.d.ts +8 -3
- package/validation/lib/{validation.d.ts → validation.types.d.ts} +3 -3
- package/dateTime/lib/datetime-formatter.d.ts +0 -15
- package/esm2022/dateTime/lib/datetime-formatter.mjs +0 -109
- package/esm2022/format/lib/number-formatter.mjs +0 -16
- package/esm2022/format/lib/string-formatter.mjs +0 -26
- package/esm2022/intl/acorex-core-intl.mjs +0 -5
- package/esm2022/intl/index.mjs +0 -3
- package/esm2022/intl/lib/numbers/number-format-options.mjs +0 -10
- package/esm2022/intl/lib/numbers/numbers-utils.mjs +0 -39
- package/esm2022/translation/lib/translator.mjs +0 -42
- package/esm2022/validation/lib/validation.mjs +0 -2
- package/fesm2022/acorex-core-intl.mjs +0 -54
- package/fesm2022/acorex-core-intl.mjs.map +0 -1
- package/format/lib/number-formatter.d.ts +0 -5
- package/format/lib/string-formatter.d.ts +0 -5
- package/intl/README.md +0 -3
- package/intl/index.d.ts +0 -2
- package/intl/lib/numbers/number-format-options.d.ts +0 -7
- package/intl/lib/numbers/numbers-utils.d.ts +0 -3
- package/translation/lib/translator.d.ts +0 -11
@@ -1,17 +1,28 @@
|
|
1
1
|
import * as i0 from '@angular/core';
|
2
|
-
import { Injectable, inject, Pipe, APP_INITIALIZER, NgModule } from '@angular/core';
|
2
|
+
import { Injector, Injectable, inject, Pipe, APP_INITIALIZER, NgModule } from '@angular/core';
|
3
|
+
import { defaults, padStart, isInteger } from 'lodash-es';
|
4
|
+
|
5
|
+
class AXFormatter {
|
6
|
+
}
|
3
7
|
|
4
8
|
class AXFormatterRegistryService {
|
5
|
-
constructor() {
|
9
|
+
constructor(injector) {
|
6
10
|
this.plugins = [];
|
11
|
+
this.injector = injector;
|
7
12
|
}
|
8
|
-
register(...
|
9
|
-
|
13
|
+
register(...plugins) {
|
14
|
+
plugins.forEach(t => {
|
15
|
+
const childInjector = Injector.create({ providers: [{ provide: t, useClass: t, deps: [] }], parent: this.injector });
|
16
|
+
const v = childInjector.get(t);
|
17
|
+
if (v && !this.plugins.some(p => p.name == v.name)) {
|
18
|
+
this.plugins.push(v);
|
19
|
+
}
|
20
|
+
});
|
10
21
|
}
|
11
22
|
get formatters() {
|
12
23
|
return this.plugins;
|
13
24
|
}
|
14
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.8", ngImport: i0, type: AXFormatterRegistryService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
25
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.8", ngImport: i0, type: AXFormatterRegistryService, deps: [{ token: i0.Injector }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
15
26
|
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.0.8", ngImport: i0, type: AXFormatterRegistryService, providedIn: 'root' }); }
|
16
27
|
}
|
17
28
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.8", ngImport: i0, type: AXFormatterRegistryService, decorators: [{
|
@@ -19,17 +30,32 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.8", ngImpor
|
|
19
30
|
args: [{
|
20
31
|
providedIn: 'root'
|
21
32
|
}]
|
22
|
-
}] });
|
33
|
+
}], ctorParameters: () => [{ type: i0.Injector }] });
|
23
34
|
class AXFormatService {
|
24
35
|
constructor(pluginRegistry) {
|
25
36
|
this.pluginRegistry = pluginRegistry;
|
26
37
|
}
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
38
|
+
/**
|
39
|
+
* Resolves a formatter by its name.
|
40
|
+
* @param name The name of the formatter.
|
41
|
+
* @returns The formatter if found, otherwise throws an error.
|
42
|
+
*/
|
43
|
+
resolveFormatter(name) {
|
44
|
+
const formatter = this.pluginRegistry.formatters.find((c) => c.name == name);
|
45
|
+
if (!formatter) {
|
46
|
+
throw new Error(`Formatter not found: ${name}`);
|
47
|
+
}
|
48
|
+
return formatter;
|
49
|
+
}
|
50
|
+
// Implementation of the format method
|
51
|
+
format(value, formatter, options) {
|
52
|
+
if (typeof formatter === 'string') {
|
53
|
+
const formatterRef = this.resolveFormatter(formatter);
|
54
|
+
return formatterRef.format(value, options);
|
55
|
+
}
|
56
|
+
else {
|
57
|
+
return new AXFormatFluent(this, value);
|
31
58
|
}
|
32
|
-
return format.format(value, ...args);
|
33
59
|
}
|
34
60
|
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.8", ngImport: i0, type: AXFormatService, deps: [{ token: AXFormatterRegistryService }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
35
61
|
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.0.8", ngImport: i0, type: AXFormatService, providedIn: 'root' }); }
|
@@ -38,87 +64,153 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.8", ngImpor
|
|
38
64
|
type: Injectable,
|
39
65
|
args: [{ providedIn: 'root' }]
|
40
66
|
}], ctorParameters: () => [{ type: AXFormatterRegistryService }] });
|
67
|
+
class AXFormatFluent {
|
68
|
+
constructor(formatService, initialValue) {
|
69
|
+
this.formatService = formatService;
|
70
|
+
this.initialValue = initialValue;
|
71
|
+
}
|
72
|
+
/**
|
73
|
+
* Formats the value using the specified formatter and options.
|
74
|
+
* @param formatter The name of the formatter to use.
|
75
|
+
* @param options The options to pass to the formatter.
|
76
|
+
* @returns The formatted string.
|
77
|
+
*/
|
78
|
+
to(formatter, options) {
|
79
|
+
try {
|
80
|
+
const formatterRef = this.formatService.resolveFormatter(formatter);
|
81
|
+
return formatterRef.format(this.initialValue, options);
|
82
|
+
}
|
83
|
+
catch (error) {
|
84
|
+
// Handle or log the error as needed
|
85
|
+
console.error(error);
|
86
|
+
return String(this.initialValue);
|
87
|
+
}
|
88
|
+
}
|
89
|
+
}
|
41
90
|
|
42
91
|
class AXFormatPipe {
|
43
92
|
constructor() {
|
44
93
|
this.formatService = inject(AXFormatService);
|
45
94
|
}
|
46
|
-
transform(value,
|
47
|
-
|
48
|
-
return this.formatService.format(value, name, ...args.slice(1));
|
95
|
+
transform(value, name, options) {
|
96
|
+
return this.formatService.format(value, name, options);
|
49
97
|
}
|
50
98
|
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.8", ngImport: i0, type: AXFormatPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe }); }
|
51
|
-
static { this.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "17.0.8", ngImport: i0, type: AXFormatPipe, name: "format" }); }
|
99
|
+
static { this.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "17.0.8", ngImport: i0, type: AXFormatPipe, name: "format", pure: false }); }
|
52
100
|
}
|
53
101
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.8", ngImport: i0, type: AXFormatPipe, decorators: [{
|
54
102
|
type: Pipe,
|
55
103
|
args: [{
|
56
104
|
name: 'format',
|
57
|
-
pure:
|
105
|
+
pure: false,
|
58
106
|
}]
|
59
107
|
}] });
|
60
108
|
|
61
109
|
class AXNumberFormatter {
|
110
|
+
constructor() {
|
111
|
+
this.separatorsCache = {};
|
112
|
+
}
|
62
113
|
get name() {
|
63
114
|
return 'number';
|
64
115
|
}
|
65
|
-
format(value,
|
66
|
-
const
|
67
|
-
|
68
|
-
|
116
|
+
format(value, options) {
|
117
|
+
const { thousandSeparator, decimalSeparator } = this.getLocaleSeparators(options?.locale);
|
118
|
+
// Merge user options with default options
|
119
|
+
const effectiveOptions = defaults({}, options, {
|
120
|
+
thousandSeparator,
|
121
|
+
decimalSeparator,
|
122
|
+
zeroPadLength: 0,
|
123
|
+
locale: navigator.language
|
124
|
+
});
|
125
|
+
const sign = value < 0 ? '-' : '';
|
126
|
+
const absoluteValue = Math.abs(value);
|
127
|
+
// Handling zero padding for integer part
|
128
|
+
let integerPart = Math.floor(absoluteValue).toString();
|
129
|
+
if (effectiveOptions.zeroPadLength && effectiveOptions.zeroPadLength > integerPart.length) {
|
130
|
+
integerPart = padStart(integerPart, effectiveOptions.zeroPadLength, '0');
|
69
131
|
}
|
70
|
-
|
71
|
-
|
132
|
+
// Applying thousand separator to integer part
|
133
|
+
if (effectiveOptions.thousandSeparator) {
|
134
|
+
integerPart = integerPart.replace(/\B(?=(\d{3})+(?!\d))/g, effectiveOptions.thousandSeparator);
|
72
135
|
}
|
73
|
-
|
136
|
+
// Constructing the final formatted value
|
137
|
+
let formattedValue = sign + integerPart;
|
138
|
+
if (effectiveOptions.decimalPlaces !== undefined) {
|
139
|
+
// Limiting decimal places if specified
|
140
|
+
const decimalPart = absoluteValue.toFixed(effectiveOptions.decimalPlaces).split('.')[1];
|
141
|
+
formattedValue += effectiveOptions.decimalSeparator + decimalPart;
|
142
|
+
}
|
143
|
+
else if (!isInteger(value)) {
|
144
|
+
// Showing full decimal part if decimalPlaces is not specified
|
145
|
+
const decimalPart = absoluteValue.toString().split('.')[1] || '';
|
146
|
+
if (decimalPart.length > 0) {
|
147
|
+
formattedValue += effectiveOptions.decimalSeparator + decimalPart;
|
148
|
+
}
|
149
|
+
}
|
150
|
+
return formattedValue;
|
74
151
|
}
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
const
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
return value ?? match;
|
97
|
-
// }
|
98
|
-
});
|
99
|
-
return result;
|
152
|
+
getLocaleSeparators(locale = navigator.language) {
|
153
|
+
// Use cache if available
|
154
|
+
if (this.separatorsCache[locale]) {
|
155
|
+
return this.separatorsCache[locale];
|
156
|
+
}
|
157
|
+
console.log('getLocaleSeparators', locale);
|
158
|
+
const numberFormat = new Intl.NumberFormat(locale);
|
159
|
+
const parts = numberFormat.formatToParts(1234567.89);
|
160
|
+
let thousandSeparator = '';
|
161
|
+
let decimalSeparator = '';
|
162
|
+
for (const part of parts) {
|
163
|
+
if (part.type === 'group') {
|
164
|
+
thousandSeparator = part.value;
|
165
|
+
}
|
166
|
+
else if (part.type === 'decimal') {
|
167
|
+
decimalSeparator = part.value;
|
168
|
+
}
|
169
|
+
}
|
170
|
+
// Cache the result
|
171
|
+
this.separatorsCache[locale] = { thousandSeparator, decimalSeparator };
|
172
|
+
return this.separatorsCache[locale];
|
100
173
|
}
|
174
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.8", ngImport: i0, type: AXNumberFormatter, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
175
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.0.8", ngImport: i0, type: AXNumberFormatter }); }
|
101
176
|
}
|
177
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.8", ngImport: i0, type: AXNumberFormatter, decorators: [{
|
178
|
+
type: Injectable
|
179
|
+
}] });
|
102
180
|
|
181
|
+
const BUILT_IN_RULES = [
|
182
|
+
AXNumberFormatter,
|
183
|
+
];
|
103
184
|
class AXFormatModule {
|
104
|
-
static forRoot(
|
185
|
+
static forRoot(configs) {
|
105
186
|
return {
|
106
187
|
ngModule: AXFormatModule,
|
107
188
|
providers: [
|
189
|
+
...(configs?.formatters || []),
|
108
190
|
{
|
109
191
|
provide: APP_INITIALIZER,
|
110
|
-
useFactory: (pluginRegistry) => () =>
|
111
|
-
if (config?.formatters?.length)
|
112
|
-
pluginRegistry.register(...config.formatters);
|
113
|
-
},
|
192
|
+
useFactory: (pluginRegistry) => () => pluginRegistry.register(...[...BUILT_IN_RULES, ...(configs?.formatters || [])]),
|
114
193
|
deps: [AXFormatterRegistryService],
|
115
194
|
multi: true
|
116
195
|
}
|
117
196
|
]
|
118
197
|
};
|
119
198
|
}
|
199
|
+
static forChild(configs) {
|
200
|
+
AXFormatModule.registry.register(...[...BUILT_IN_RULES, ...(configs?.formatters || [])]);
|
201
|
+
return {
|
202
|
+
ngModule: AXFormatModule,
|
203
|
+
providers: [
|
204
|
+
...(configs?.formatters || [])
|
205
|
+
]
|
206
|
+
};
|
207
|
+
}
|
208
|
+
/**
|
209
|
+
* @ignore
|
210
|
+
*/
|
120
211
|
constructor(pluginRegistry) {
|
121
|
-
|
212
|
+
AXFormatModule.registry = pluginRegistry;
|
213
|
+
AXFormatModule.registry.register(...BUILT_IN_RULES);
|
122
214
|
}
|
123
215
|
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.8", ngImport: i0, type: AXFormatModule, deps: [{ token: AXFormatterRegistryService }], target: i0.ɵɵFactoryTarget.NgModule }); }
|
124
216
|
static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "17.0.8", ngImport: i0, type: AXFormatModule, declarations: [AXFormatPipe], exports: [AXFormatPipe] }); }
|
@@ -137,5 +229,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.8", ngImpor
|
|
137
229
|
* Generated bundle index. Do not edit.
|
138
230
|
*/
|
139
231
|
|
140
|
-
export { AXFormatModule, AXFormatPipe, AXFormatService, AXFormatterRegistryService, AXNumberFormatter };
|
232
|
+
export { AXFormatModule, AXFormatPipe, AXFormatService, AXFormatter, AXFormatterRegistryService, AXNumberFormatter };
|
141
233
|
//# sourceMappingURL=acorex-core-format.mjs.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"acorex-core-format.mjs","sources":["../../../../libs/core/format/src/lib/format.service.ts","../../../../libs/core/format/src/lib/format.pipe.ts","../../../../libs/core/format/src/lib/number-formatter.ts","../../../../libs/core/format/src/lib/string-formatter.ts","../../../../libs/core/format/src/lib/format.module.ts","../../../../libs/core/format/src/acorex-core-format.ts"],"sourcesContent":["import { Injectable } from '@angular/core';\nimport { AXFormatter } from './format.config';\n\n@Injectable({\n providedIn: 'root'\n})\nexport class AXFormatterRegistryService {\n private plugins: AXFormatter[] = [];\n\n\n register(...plugin: AXFormatter[]) {\n this.plugins.push(...plugin.filter(p => !this.plugins.some(c => c.name == p.name)));\n }\n\n get formatters(): AXFormatter[] {\n return this.plugins;\n }\n}\n\n@Injectable({ providedIn: 'root' })\nexport class AXFormatService {\n constructor(\n private pluginRegistry: AXFormatterRegistryService\n ) { }\n\n format(value: unknown, name: string, ...args: unknown[]): string {\n const format = this.pluginRegistry.formatters.find((c) => c.name == name);\n if (!format) {\n return String(value);\n }\n return format.format(value, ...args);\n }\n}\n","import { Pipe, PipeTransform, inject } from '@angular/core';\nimport { AXFormatService } from './format.service';\n\n@Pipe({\n name: 'format',\n pure: true,\n})\nexport class AXFormatPipe implements PipeTransform {\n private formatService = inject(AXFormatService);\n\n transform(value: unknown, ...args: unknown[]): string {\n const name = args[0] as string;\n return this.formatService.format(value, name, ...args.slice(1));\n }\n}\n","import { AXFormatter } from './format.config';\n\nexport class AXNumberFormatter implements AXFormatter {\n get name(): string {\n return 'number';\n }\n\n format(value: unknown, ...args: unknown[]): string {\n const formatStr: string = (args.length ? args[0] : null) as string;\n if (formatStr?.match(/^.{2}-.{2}$/)) {\n return Number(value).toLocaleString(formatStr);\n }\n if (formatStr?.match(/^D\\d+$/)) {\n return String(value).padStart(Number(formatStr.slice(1)), '0');\n }\n return String(value);\n }\n}\n","import { AXFormatter } from './format.config';\n\nexport class AXStringFormatter implements AXFormatter {\n get name(): string {\n return 'string';\n }\n\n format(value: unknown, ...args: unknown[]): string {\n if (typeof value != 'string') return String(value);\n const data: string = (args.length ? args[0] : null) as string;\n const result = value.replace(/{{\\s*([^}]+)\\s*}}/g, (match, variable) => {\n // if (variable?.match(/^\\w+:\\w+:\\w+$/g)) {\n //\n // const formatData = data[variable[0]];\n // const formatType = data[variable[1]];\n // const formatArg = data[variable[2]];\n // const value = this.formatService.format(formatData, formatType, formatArg);\n // return value ?? match;\n // }\n // else {\n const value = data[variable] as string;\n return value ?? match;\n // }\n });\n return result;\n }\n\n // private format(inputString: string, data: { [key: string]: string }): string {\n // return inputString.replace(/{{\\s*([^}]+)\\s*}}/g, (match, variable) => {\n // const value = data[variable];\n // return value !== undefined ? value : match;\n // });\n // }\n}\n","import { APP_INITIALIZER, ModuleWithProviders, NgModule } from '@angular/core';\nimport { AXFormatPipe } from './format.pipe';\nimport { AXNumberFormatter } from './number-formatter';\nimport { AXStringFormatter } from './string-formatter';\nimport { AXFormatterRegistryService } from './format.service';\nimport { AXFormatter } from './format.config';\n\n\n@NgModule({\n imports: [],\n exports: [AXFormatPipe],\n declarations: [AXFormatPipe],\n})\nexport class AXFormatModule {\n\n static forRoot(config?: { formatters?: AXFormatter[] }): ModuleWithProviders<AXFormatModule> {\n return {\n ngModule: AXFormatModule,\n providers: [\n {\n provide: APP_INITIALIZER,\n useFactory: (pluginRegistry: AXFormatterRegistryService) => () => {\n if (config?.formatters?.length)\n pluginRegistry.register(...config.formatters);\n },\n deps: [AXFormatterRegistryService],\n multi: true\n }\n ]\n };\n }\n\n constructor(pluginRegistry: AXFormatterRegistryService) {\n pluginRegistry.register(new AXNumberFormatter(), new AXStringFormatter())\n }\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":["i1.AXFormatterRegistryService"],"mappings":";;;MAMa,0BAA0B,CAAA;AAHvC,IAAA,WAAA,GAAA;QAIU,IAAO,CAAA,OAAA,GAAkB,EAAE,CAAC;AAUrC,KAAA;IAPC,QAAQ,CAAC,GAAG,MAAqB,EAAA;AAC/B,QAAA,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;KACrF;AAED,IAAA,IAAI,UAAU,GAAA;QACZ,OAAO,IAAI,CAAC,OAAO,CAAC;KACrB;8GAVU,0BAA0B,EAAA,IAAA,EAAA,EAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,UAAA,EAAA,CAAA,CAAA,EAAA;AAA1B,IAAA,SAAA,IAAA,CAAA,KAAA,GAAA,EAAA,CAAA,qBAAA,CAAA,EAAA,UAAA,EAAA,QAAA,EAAA,OAAA,EAAA,QAAA,EAAA,QAAA,EAAA,EAAA,EAAA,IAAA,EAAA,0BAA0B,cAFzB,MAAM,EAAA,CAAA,CAAA,EAAA;;2FAEP,0BAA0B,EAAA,UAAA,EAAA,CAAA;kBAHtC,UAAU;AAAC,YAAA,IAAA,EAAA,CAAA;AACV,oBAAA,UAAU,EAAE,MAAM;AACnB,iBAAA,CAAA;;MAeY,eAAe,CAAA;AAC1B,IAAA,WAAA,CACU,cAA0C,EAAA;QAA1C,IAAc,CAAA,cAAA,GAAd,cAAc,CAA4B;KAC/C;AAEL,IAAA,MAAM,CAA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B,QAAQ;AAAC,YAAA,IAAA,EAAA,CAAA;AACR,oBAAA,OAAO,EAAE,EAAE;oBACX,OAAO,EAAE,CAAC,YAAY,CAAC;oBACvB,YAAY,EAAE,CAAC,YAAY,CAAC;AAC7B,iBAAA,CAAA;;;ACZD;;AAEG;;;;"}
|
1
|
+
{"version":3,"file":"acorex-core-format.mjs","sources":["../../../../libs/core/format/src/lib/format.config.ts","../../../../libs/core/format/src/lib/format.service.ts","../../../../libs/core/format/src/lib/format.pipe.ts","../../../../libs/core/format/src/lib/formatters/number-formatter.ts","../../../../libs/core/format/src/lib/format.module.ts","../../../../libs/core/format/src/acorex-core-format.ts"],"sourcesContent":["import { AXFormatOptions } from \"./format.types\";\n\nexport abstract class AXFormatter {\n abstract get name(): string;\n abstract format(value: unknown, options?: AXFormatOptions | string): string;\n}\n","import { Injectable, Injector } from '@angular/core';\nimport { AXFormatter } from './format.config';\nimport { AXFormatOptionsMap } from './format.types';\n\n@Injectable({\n providedIn: 'root'\n})\nexport class AXFormatterRegistryService {\n private plugins: AXFormatter[] = [];\n\n private injector: Injector;\n\n constructor(injector: Injector) {\n this.injector = injector;\n }\n\n register(...plugins: (new () => AXFormatter)[]) {\n plugins.forEach(t => {\n const childInjector = Injector.create({ providers: [{ provide: t, useClass: t, deps: [] }], parent: this.injector });\n const v = childInjector.get(t);\n\n if (v && !this.plugins.some(p => p.name == v.name)) {\n this.plugins.push(v);\n }\n })\n }\n\n get formatters(): AXFormatter[] {\n return this.plugins;\n }\n}\n\n@Injectable({ providedIn: 'root' })\nexport class AXFormatService {\n constructor(\n private pluginRegistry: AXFormatterRegistryService\n ) { }\n\n /**\n * Resolves a formatter by its name.\n * @param name The name of the formatter.\n * @returns The formatter if found, otherwise throws an error.\n */\n resolveFormatter(name: string): AXFormatter {\n const formatter = this.pluginRegistry.formatters.find((c) => c.name == name);\n if (!formatter) {\n throw new Error(`Formatter not found: ${name}`);\n }\n return formatter;\n }\n\n // Overload for traditional formatting\n format<K extends keyof AXFormatOptionsMap>(\n value: unknown,\n name: K,\n options?: AXFormatOptionsMap[K]\n ): string;\n\n // Overload for starting fluent API chain\n format(value: unknown): AXFormatFluent;\n\n // Implementation of the format method\n format<K extends keyof AXFormatOptionsMap>(\n value: unknown,\n formatter?: K,\n options?: AXFormatOptionsMap[K]\n ): string | AXFormatFluent {\n if (typeof formatter === 'string') {\n const formatterRef = this.resolveFormatter(formatter);\n return formatterRef.format(value, options);\n } else {\n return new AXFormatFluent(this, value);\n }\n }\n}\n\n\nclass AXFormatFluent {\n\n constructor(private formatService: AXFormatService, private initialValue: unknown) { }\n\n /**\n * Formats the value using the specified formatter and options.\n * @param formatter The name of the formatter to use.\n * @param options The options to pass to the formatter.\n * @returns The formatted string.\n */\n to<K extends keyof AXFormatOptionsMap>(formatter: K, options?: AXFormatOptionsMap[K]): string {\n try {\n const formatterRef = this.formatService.resolveFormatter(formatter);\n return formatterRef.format(this.initialValue, options);\n } catch (error) {\n // Handle or log the error as needed\n console.error(error);\n return String(this.initialValue);\n }\n }\n\n}\n","import { Pipe, PipeTransform, inject } from '@angular/core';\nimport { AXFormatService } from './format.service';\nimport { AXFormatOptions } from './format.types';\n\n@Pipe({\n name: 'format',\n pure: false,\n})\nexport class AXFormatPipe implements PipeTransform {\n private formatService = inject(AXFormatService);\n\n transform(value: unknown, name: string, options?: AXFormatOptions | string): string {\n return this.formatService.format(value, name as any, options);\n }\n}\n","import { Injectable } from '@angular/core';\nimport { AXFormatter } from '../format.config';\nimport { AXFormatOptions } from '../format.types';\nimport { isInteger, defaults, padStart } from 'lodash-es';\n\n\nexport interface AXNumberFormatterOptions extends AXFormatOptions {\n decimalPlaces?: number;\n thousandSeparator?: string;\n decimalSeparator?: string;\n zeroPadLength?: number; // New option for zero padding,\n locale?: string\n}\n\ndeclare module '../format.types' {\n interface AXFormatOptionsMap {\n 'number': AXNumberFormatterOptions;\n }\n}\n\n@Injectable()\nexport class AXNumberFormatter implements AXFormatter {\n\n private separatorsCache = {};\n\n get name(): string {\n return 'number';\n }\n\n format(value: number, options: AXNumberFormatterOptions): string {\n const { thousandSeparator, decimalSeparator } = this.getLocaleSeparators(options?.locale);\n // Merge user options with default options\n const effectiveOptions = defaults({}, options, {\n thousandSeparator,\n decimalSeparator,\n zeroPadLength: 0,\n locale: navigator.language\n });\n\n const sign = value < 0 ? '-' : '';\n const absoluteValue = Math.abs(value);\n\n // Handling zero padding for integer part\n let integerPart = Math.floor(absoluteValue).toString();\n if (effectiveOptions.zeroPadLength && effectiveOptions.zeroPadLength > integerPart.length) {\n integerPart = padStart(integerPart, effectiveOptions.zeroPadLength, '0');\n }\n\n // Applying thousand separator to integer part\n if (effectiveOptions.thousandSeparator) {\n integerPart = integerPart.replace(/\\B(?=(\\d{3})+(?!\\d))/g, effectiveOptions.thousandSeparator);\n }\n\n // Constructing the final formatted value\n let formattedValue = sign + integerPart;\n if (effectiveOptions.decimalPlaces !== undefined) {\n // Limiting decimal places if specified\n const decimalPart = absoluteValue.toFixed(effectiveOptions.decimalPlaces).split('.')[1];\n formattedValue += effectiveOptions.decimalSeparator + decimalPart;\n } else if (!isInteger(value)) {\n // Showing full decimal part if decimalPlaces is not specified\n const decimalPart = absoluteValue.toString().split('.')[1] || '';\n if (decimalPart.length > 0) {\n formattedValue += effectiveOptions.decimalSeparator + decimalPart;\n }\n }\n\n return formattedValue;\n }\n\n private getLocaleSeparators(locale = navigator.language): { thousandSeparator: string, decimalSeparator: string } {\n // Use cache if available\n if (this.separatorsCache[locale]) {\n return this.separatorsCache[locale];\n }\n\n console.log('getLocaleSeparators', locale)\n const numberFormat = new Intl.NumberFormat(locale);\n const parts = numberFormat.formatToParts(1234567.89);\n let thousandSeparator = '';\n let decimalSeparator = '';\n\n for (const part of parts) {\n if (part.type === 'group') {\n thousandSeparator = part.value;\n } else if (part.type === 'decimal') {\n decimalSeparator = part.value;\n }\n }\n\n // Cache the result\n this.separatorsCache[locale] = { thousandSeparator, decimalSeparator };\n return this.separatorsCache[locale];\n }\n}\n","import { APP_INITIALIZER, ModuleWithProviders, NgModule } from '@angular/core';\nimport { AXFormatPipe } from './format.pipe';\nimport { AXNumberFormatter } from './formatters/number-formatter';\nimport { AXFormatterRegistryService } from './format.service';\nimport { AXFormatter } from './format.config';\n\n\nconst BUILT_IN_RULES = [\n AXNumberFormatter,\n]\n\nexport interface AXFormatModuleConfigs {\n formatters: (new () => AXFormatter)[]\n}\n\n@NgModule({\n imports: [],\n exports: [AXFormatPipe],\n declarations: [AXFormatPipe],\n})\nexport class AXFormatModule {\n\n private static registry: AXFormatterRegistryService;\n\n static forRoot(configs?: AXFormatModuleConfigs): ModuleWithProviders<AXFormatModule> {\n return {\n ngModule: AXFormatModule,\n providers: [\n ...(configs?.formatters || []),\n {\n provide: APP_INITIALIZER,\n useFactory: (pluginRegistry: AXFormatterRegistryService) => () =>\n pluginRegistry.register(...[...BUILT_IN_RULES, ...(configs?.formatters || [])]),\n deps: [AXFormatterRegistryService],\n multi: true\n }\n ]\n };\n }\n\n static forChild(configs?: AXFormatModuleConfigs): ModuleWithProviders<AXFormatModule> {\n AXFormatModule.registry.register(...[...BUILT_IN_RULES, ...(configs?.formatters || [])]);\n return {\n ngModule: AXFormatModule,\n providers: [\n ...(configs?.formatters || [])\n ]\n };\n }\n\n /**\n * @ignore\n */\n constructor(pluginRegistry: AXFormatterRegistryService) {\n AXFormatModule.registry = pluginRegistry;\n AXFormatModule.registry.register(...BUILT_IN_RULES);\n }\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":["i1.AXFormatterRegistryService"],"mappings":";;;;MAEsB,WAAW,CAAA;AAGhC;;MCEY,0BAA0B,CAAA;AAKrC,IAAA,WAAA,CAAY,QAAkB,EAAA;QAJtB,IAAO,CAAA,OAAA,GAAkB,EAAE,CAAC;AAKlC,QAAA,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;KAC1B;IAED,QAAQ,CAAC,GAAG,OAAkC,EAAA;AAC5C,QAAA,OAAO,CAAC,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,cAA0C,EAAA;AACpD,QAAA,cAAc,CAAC,QAAQ,GAAG,cAAc,CAAC;QACzC,cAAc,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,cAAc,CAAC,CAAC;KACrD;8GApCU,cAAc,EAAA,IAAA,EAAA,CAAA,EAAA,KAAA,EAAAA,0BAAA,EAAA,CAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,QAAA,EAAA,CAAA,CAAA,EAAA;+GAAd,cAAc,EAAA,YAAA,EAAA,CAFV,YAAY,CAAA,EAAA,OAAA,EAAA,CADjB,YAAY,CAAA,EAAA,CAAA,CAAA,EAAA;+GAGX,cAAc,EAAA,CAAA,CAAA,EAAA;;2FAAd,cAAc,EAAA,UAAA,EAAA,CAAA;kBAL1B,QAAQ;AAAC,YAAA,IAAA,EAAA,CAAA;AACR,oBAAA,OAAO,EAAE,EAAE;oBACX,OAAO,EAAE,CAAC,YAAY,CAAC;oBACvB,YAAY,EAAE,CAAC,YAAY,CAAC;AAC7B,iBAAA,CAAA;;;ACnBD;;AAEG;;;;"}
|
@@ -1,78 +1,245 @@
|
|
1
1
|
import * as i0 from '@angular/core';
|
2
|
-
import { Pipe, NgModule } from '@angular/core';
|
3
|
-
import {
|
4
|
-
import {
|
2
|
+
import { InjectionToken, inject, Injectable, ChangeDetectorRef, Pipe, Directive, APP_INITIALIZER, NgModule } from '@angular/core';
|
3
|
+
import { of, BehaviorSubject, tap, catchError, forkJoin, map, switchMap } from 'rxjs';
|
4
|
+
import { set, get } from 'lodash-es';
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
6
|
+
const AX_TRANSLATION_CONFIG = new InjectionToken('AX_TRANSLATION_CONFIG', {
|
7
|
+
providedIn: 'root',
|
8
|
+
factory: () => {
|
9
|
+
return AXTranslationDefaultConfig;
|
10
|
+
},
|
11
|
+
});
|
12
|
+
const AXTranslationDefaultConfig = {
|
13
|
+
defaultLang: 'en',
|
14
|
+
defaultScope: 'common',
|
15
|
+
scopeResolverKey: 'scope',
|
16
|
+
};
|
17
|
+
function translationConfig(config = {}) {
|
18
|
+
const result = {
|
19
|
+
...AXTranslationDefaultConfig,
|
20
|
+
...config,
|
21
|
+
};
|
22
|
+
return result;
|
23
|
+
}
|
24
|
+
|
25
|
+
class AXTranslationLoaderDefault {
|
26
|
+
getTranslation(options) {
|
27
|
+
return of({});
|
28
|
+
}
|
29
|
+
}
|
30
|
+
const AX_TRANSLATION_LOADER = new InjectionToken('AX_TRANSLATION_LOADER', {
|
31
|
+
providedIn: 'root',
|
32
|
+
factory: () => {
|
33
|
+
return new AXTranslationLoaderDefault();
|
34
|
+
},
|
35
|
+
});
|
36
|
+
|
37
|
+
let service;
|
38
|
+
function translateSync(key, options) {
|
39
|
+
return service.translateSync(key, options);
|
40
|
+
}
|
41
|
+
class AXTranslationService {
|
42
|
+
/**
|
43
|
+
* @ignore
|
44
|
+
*/
|
45
|
+
constructor() {
|
46
|
+
this.loader = inject(AX_TRANSLATION_LOADER);
|
47
|
+
this.config = inject(AX_TRANSLATION_CONFIG);
|
48
|
+
this.translationCache = {};
|
49
|
+
this.activeLang = new BehaviorSubject(this.getDefaultLang());
|
50
|
+
this.langChanges$ = this.activeLang.asObservable();
|
51
|
+
service = this;
|
52
|
+
}
|
53
|
+
loadLanguagesAndScopes(languages, scopes) {
|
54
|
+
const requests = languages.flatMap(lang => scopes.map(scope => {
|
55
|
+
if (this.translationCache[lang]?.[scope]) {
|
56
|
+
return of(this.translationCache[lang][scope]);
|
19
57
|
}
|
20
|
-
|
21
|
-
|
58
|
+
return this.loader.getTranslation({ lang, scope }).pipe(tap(translations => this.cacheTranslations(lang, scope, translations)), catchError(error => {
|
59
|
+
console.error(`Error loading translations for lang: ${lang}, scope: ${scope}`, error);
|
60
|
+
return of(null); // You can return 'null' or any other fallback value
|
61
|
+
}));
|
62
|
+
}));
|
63
|
+
return forkJoin(...requests);
|
22
64
|
}
|
23
|
-
|
24
|
-
|
25
|
-
}
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
65
|
+
cacheTranslations(lang, scope, translations) {
|
66
|
+
set(this.translationCache, `${lang}.${scope}`, translations);
|
67
|
+
}
|
68
|
+
getDefaultLang() {
|
69
|
+
return this.config.defaultLang;
|
70
|
+
}
|
71
|
+
getActiveLang() {
|
72
|
+
return this.activeLang.getValue();
|
73
|
+
}
|
74
|
+
setActiveLang(lang) {
|
75
|
+
this.activeLang.next(lang);
|
76
|
+
}
|
77
|
+
load(key, options = {}) {
|
78
|
+
const { lang = this.getActiveLang(), scope = this.config.defaultScope } = options;
|
79
|
+
const fetchTranslation = (language) => {
|
80
|
+
// Check if translations are available in the cache
|
81
|
+
if (this.translationCache[language]?.[scope]) {
|
82
|
+
return of(this.getTranslation(key, language, scope, options.params));
|
83
|
+
}
|
84
|
+
// Load translations for the language and scope
|
85
|
+
return this.loadLanguagesAndScopes([language], [scope]).pipe(map(() => {
|
86
|
+
const translation = this.translationCache[language]?.[scope]?.[key] || key;
|
87
|
+
return this.getTranslation(translation, language, scope, options.params);
|
88
|
+
}), switchMap(translatedText => {
|
89
|
+
if (translatedText === key && language !== this.getDefaultLang()) {
|
90
|
+
// If the translation is not found and the language is not default,
|
91
|
+
// try fetching from the default language
|
92
|
+
return fetchTranslation(this.getDefaultLang());
|
39
93
|
}
|
94
|
+
return of(translatedText);
|
95
|
+
}));
|
96
|
+
};
|
97
|
+
// Return the translation or initiate fetching process
|
98
|
+
return fetchTranslation(lang);
|
99
|
+
}
|
100
|
+
getTranslation(key, lang, scope, params) {
|
101
|
+
let translation = (get(this.translationCache, `${lang}.${scope}.${key}`) || key);
|
102
|
+
// Replace params like {{ name }}
|
103
|
+
if (params) {
|
104
|
+
Object.keys(params).forEach(paramKey => {
|
105
|
+
const paramValue = params[paramKey];
|
106
|
+
translation = translation.replace(new RegExp(`{{\\s*${paramKey}\\s*}}`, 'g'), paramValue);
|
40
107
|
});
|
41
108
|
}
|
42
|
-
|
109
|
+
// Replace translations like {{ t('key') }}
|
110
|
+
const translationPattern = /{{\s*t\('([^']+)'\)\s*}}/g;
|
111
|
+
translation = translation.replace(translationPattern, (match, innerKey) => {
|
112
|
+
return this.getTranslation(innerKey, lang, scope, params);
|
113
|
+
});
|
114
|
+
return translation;
|
115
|
+
}
|
116
|
+
translate(key, options) {
|
117
|
+
if (options?.lang) {
|
118
|
+
return this.load(key, options);
|
119
|
+
}
|
120
|
+
return this.langChanges$.pipe(switchMap((lang) => {
|
121
|
+
return this.load(key, { ...options, lang: lang });
|
122
|
+
}));
|
43
123
|
}
|
124
|
+
translateSync(key, options) {
|
125
|
+
const { lang = this.getActiveLang(), scope = this.config.defaultScope } = options || {};
|
126
|
+
return this.getTranslation(key, lang, scope, options?.params);
|
127
|
+
}
|
128
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.8", ngImport: i0, type: AXTranslationService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
129
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.0.8", ngImport: i0, type: AXTranslationService, providedIn: 'root' }); }
|
44
130
|
}
|
131
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.8", ngImport: i0, type: AXTranslationService, decorators: [{
|
132
|
+
type: Injectable,
|
133
|
+
args: [{ providedIn: 'root' }]
|
134
|
+
}], ctorParameters: () => [] });
|
45
135
|
|
46
136
|
class AXTranslatorPipe {
|
47
|
-
|
48
|
-
|
137
|
+
constructor() {
|
138
|
+
this.service = inject(AXTranslationService);
|
139
|
+
this.cdr = inject(ChangeDetectorRef);
|
140
|
+
this.value = '';
|
141
|
+
this.lastKey = null;
|
142
|
+
this.subscription = null;
|
143
|
+
}
|
144
|
+
transform(key, options) {
|
145
|
+
if (!key || key === this.lastKey) {
|
146
|
+
return this.value;
|
147
|
+
}
|
148
|
+
this.lastKey = key;
|
149
|
+
this.value = key;
|
150
|
+
this.dispose();
|
151
|
+
this.subscription = this.service.translate(key, options).subscribe(translatedValue => {
|
152
|
+
this.value = translatedValue;
|
153
|
+
this.cdr.markForCheck();
|
154
|
+
});
|
155
|
+
return this.value;
|
156
|
+
}
|
157
|
+
ngOnDestroy() {
|
158
|
+
this.dispose();
|
159
|
+
}
|
160
|
+
dispose() {
|
161
|
+
if (this.subscription) {
|
162
|
+
this.subscription.unsubscribe();
|
163
|
+
this.subscription = null;
|
164
|
+
}
|
49
165
|
}
|
50
166
|
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.8", ngImport: i0, type: AXTranslatorPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe }); }
|
51
|
-
static { this.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "17.0.8", ngImport: i0, type: AXTranslatorPipe, name: "
|
167
|
+
static { this.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "17.0.8", ngImport: i0, type: AXTranslatorPipe, name: "translate", pure: false }); }
|
52
168
|
}
|
53
169
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.8", ngImport: i0, type: AXTranslatorPipe, decorators: [{
|
54
170
|
type: Pipe,
|
55
|
-
args: [{ name: '
|
171
|
+
args: [{ name: 'translate', pure: false }]
|
56
172
|
}] });
|
57
173
|
|
174
|
+
class AXTranslatorDirective {
|
175
|
+
constructor(templateRef, viewContainer, translationService) {
|
176
|
+
this.templateRef = templateRef;
|
177
|
+
this.viewContainer = viewContainer;
|
178
|
+
this.translationService = translationService;
|
179
|
+
}
|
180
|
+
ngOnInit() {
|
181
|
+
this.viewContainer.clear();
|
182
|
+
this.viewContainer.createEmbeddedView(this.templateRef, {
|
183
|
+
$implicit: (key, options) => {
|
184
|
+
return this.translationService.translate(key, options);
|
185
|
+
}
|
186
|
+
});
|
187
|
+
}
|
188
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.8", ngImport: i0, type: AXTranslatorDirective, deps: [{ token: i0.TemplateRef }, { token: i0.ViewContainerRef }, { token: AXTranslationService }], target: i0.ɵɵFactoryTarget.Directive }); }
|
189
|
+
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "17.0.8", type: AXTranslatorDirective, selector: "[translate]", ngImport: i0 }); }
|
190
|
+
}
|
191
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.8", ngImport: i0, type: AXTranslatorDirective, decorators: [{
|
192
|
+
type: Directive,
|
193
|
+
args: [{
|
194
|
+
selector: '[translate]',
|
195
|
+
}]
|
196
|
+
}], ctorParameters: () => [{ type: i0.TemplateRef }, { type: i0.ViewContainerRef }, { type: AXTranslationService }] });
|
197
|
+
|
198
|
+
function initializeApp(translatorService, config) {
|
199
|
+
return () => {
|
200
|
+
return translatorService.loadLanguagesAndScopes(config.preloadLangs ?? [config.defaultLang], config.preloadScopes ?? [config.defaultScope]);
|
201
|
+
};
|
202
|
+
}
|
58
203
|
class AXTranslationModule {
|
59
204
|
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.8", ngImport: i0, type: AXTranslationModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
|
60
|
-
static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "17.0.8", ngImport: i0, type: AXTranslationModule, declarations: [AXTranslatorPipe], exports: [AXTranslatorPipe] }); }
|
61
|
-
static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "17.0.8", ngImport: i0, type: AXTranslationModule
|
205
|
+
static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "17.0.8", ngImport: i0, type: AXTranslationModule, declarations: [AXTranslatorPipe, AXTranslatorDirective], exports: [AXTranslatorPipe, AXTranslatorDirective] }); }
|
206
|
+
static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "17.0.8", ngImport: i0, type: AXTranslationModule, providers: [
|
207
|
+
{
|
208
|
+
provide: APP_INITIALIZER,
|
209
|
+
useFactory: initializeApp,
|
210
|
+
deps: [AXTranslationService, AX_TRANSLATION_CONFIG],
|
211
|
+
multi: true
|
212
|
+
}
|
213
|
+
] }); }
|
62
214
|
}
|
63
215
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.8", ngImport: i0, type: AXTranslationModule, decorators: [{
|
64
216
|
type: NgModule,
|
65
217
|
args: [{
|
66
218
|
imports: [],
|
67
|
-
exports: [AXTranslatorPipe],
|
68
|
-
declarations: [AXTranslatorPipe],
|
69
|
-
providers: [
|
219
|
+
exports: [AXTranslatorPipe, AXTranslatorDirective],
|
220
|
+
declarations: [AXTranslatorPipe, AXTranslatorDirective],
|
221
|
+
providers: [
|
222
|
+
{
|
223
|
+
provide: APP_INITIALIZER,
|
224
|
+
useFactory: initializeApp,
|
225
|
+
deps: [AXTranslationService, AX_TRANSLATION_CONFIG],
|
226
|
+
multi: true
|
227
|
+
}
|
228
|
+
],
|
70
229
|
}]
|
71
230
|
}] });
|
72
231
|
|
232
|
+
const loadTranslationScope = (route, state) => {
|
233
|
+
const translatorService = inject(AXTranslationService);
|
234
|
+
const config = inject(AX_TRANSLATION_CONFIG);
|
235
|
+
const scopeValue = route.data[config.scopeResolverKey];
|
236
|
+
const scopes = Array.isArray(scopeValue) ? scopeValue : [scopeValue];
|
237
|
+
return translatorService.loadLanguagesAndScopes([translatorService.getActiveLang()], scopes);
|
238
|
+
};
|
239
|
+
|
73
240
|
/**
|
74
241
|
* Generated bundle index. Do not edit.
|
75
242
|
*/
|
76
243
|
|
77
|
-
export { AXTranslationModule,
|
244
|
+
export { AXTranslationDefaultConfig, AXTranslationLoaderDefault, AXTranslationModule, AXTranslationService, AXTranslatorDirective, AXTranslatorPipe, AX_TRANSLATION_CONFIG, AX_TRANSLATION_LOADER, loadTranslationScope, translateSync, translationConfig };
|
78
245
|
//# sourceMappingURL=acorex-core-translation.mjs.map
|