@bravobit/bb-foundation 0.22.2 → 0.23.0
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/controls/lib/checkbox/checkbox-group/checkbox-group.component.d.ts +3 -2
- package/controls/lib/checkbox/checkbox.module.d.ts +2 -1
- package/controls/lib/form-control/form-control/form-control.component.d.ts +5 -5
- package/controls/lib/form-control/form-control.module.d.ts +2 -1
- package/dialog/lib/dialog-confirm/dialog-confirm.component.d.ts +4 -2
- package/dialog/lib/dialog.interfaces.d.ts +7 -0
- package/dialog/lib/dialog.service.d.ts +5 -9
- package/elements/lib/date-picker/date-picker.component.d.ts +4 -2
- package/elements/lib/elements.module.d.ts +25 -28
- package/elements/lib/pipes/relative-time.pipe.d.ts +5 -5
- package/elements/public_api.d.ts +0 -4
- package/esm2020/auth/lib/auth.interceptor.mjs +3 -3
- package/esm2020/auth/lib/auth.module.mjs +4 -4
- package/esm2020/auth/lib/auth.service.mjs +3 -3
- package/esm2020/auth/lib/directives/authenticated.directive.mjs +3 -3
- package/esm2020/auth/lib/directives/permission.directive.mjs +3 -3
- package/esm2020/auth/lib/guards/anonymous.guard.mjs +3 -3
- package/esm2020/auth/lib/guards/authenticated.guard.mjs +3 -3
- package/esm2020/auth/lib/guards/permission.guard.mjs +3 -3
- package/esm2020/auth/lib/permissions/permissions.service.mjs +3 -3
- package/esm2020/collections/lib/collections.module.mjs +4 -4
- package/esm2020/collections/lib/components/collections-pager/collections-pager.component.mjs +3 -3
- package/esm2020/collections/lib/components/collections-viewer/collections-viewer.component.mjs +5 -5
- package/esm2020/collections/lib/components/collections.directive.mjs +12 -12
- package/esm2020/controls/lib/checkbox/checkbox/checkbox.component.mjs +3 -3
- package/esm2020/controls/lib/checkbox/checkbox-group/checkbox-group.component.mjs +7 -6
- package/esm2020/controls/lib/checkbox/checkbox.module.mjs +7 -6
- package/esm2020/controls/lib/control-error/control-error/control-error.component.mjs +3 -3
- package/esm2020/controls/lib/control-error/control-error-submit.directive.mjs +3 -3
- package/esm2020/controls/lib/control-error/control-error.module.mjs +4 -4
- package/esm2020/controls/lib/controls.module.mjs +4 -4
- package/esm2020/controls/lib/form-control/form-control/form-control.component.mjs +6 -5
- package/esm2020/controls/lib/form-control/form-control-addon/form-control-addon.component.mjs +3 -3
- package/esm2020/controls/lib/form-control/form-control-input.directive.mjs +3 -3
- package/esm2020/controls/lib/form-control/form-control.module.mjs +8 -7
- package/esm2020/dashboard/lib/dashboard/dashboard.component.mjs +3 -3
- package/esm2020/dashboard/lib/dashboard-header/dashboard-header.component.mjs +3 -3
- package/esm2020/dashboard/lib/dashboard-menu/dashboard-menu.component.mjs +3 -3
- package/esm2020/dashboard/lib/dashboard-menu-item/dashboard-menu-item.component.mjs +3 -3
- package/esm2020/dashboard/lib/dashboard-sidebar/dashboard-sidebar.component.mjs +3 -3
- package/esm2020/dashboard/lib/dashboard-sidebar-group/dashboard-sidebar-group.component.mjs +3 -3
- package/esm2020/dashboard/lib/dashboard-sidebar-item/dashboard-sidebar-item.component.mjs +3 -3
- package/esm2020/dashboard/lib/dashboard.module.mjs +4 -4
- package/esm2020/dialog/lib/dialog-actions/dialog-actions.component.mjs +3 -3
- package/esm2020/dialog/lib/dialog-confirm/dialog-confirm.component.mjs +15 -12
- package/esm2020/dialog/lib/dialog-container/dialog-container.component.mjs +5 -5
- package/esm2020/dialog/lib/dialog-header/dialog-header.component.mjs +3 -3
- package/esm2020/dialog/lib/dialog-link/dialog-link.component.mjs +3 -3
- package/esm2020/dialog/lib/dialog-modal/dialog-modal.component.mjs +3 -3
- package/esm2020/dialog/lib/dialog-overlay/dialog-overlay.component.mjs +3 -3
- package/esm2020/dialog/lib/dialog.insertion.mjs +3 -3
- package/esm2020/dialog/lib/dialog.interfaces.mjs +1 -1
- package/esm2020/dialog/lib/dialog.module.mjs +4 -4
- package/esm2020/dialog/lib/dialog.service.mjs +15 -27
- package/esm2020/elements/lib/avatar/avatar.component.mjs +7 -7
- package/esm2020/elements/lib/button/button.component.mjs +6 -6
- package/esm2020/elements/lib/checkbox/checkbox.component.mjs +3 -3
- package/esm2020/elements/lib/date-picker/date-picker.component.mjs +20 -15
- package/esm2020/elements/lib/directives/addon.directive.mjs +6 -6
- package/esm2020/elements/lib/directives/form-submit.directive.mjs +3 -3
- package/esm2020/elements/lib/directives/form-submitter.directive.mjs +3 -3
- package/esm2020/elements/lib/directives/input.directive.mjs +6 -6
- package/esm2020/elements/lib/dropdown/dropdown.component.mjs +6 -6
- package/esm2020/elements/lib/elements.module.mjs +21 -25
- package/esm2020/elements/lib/file-picker/file-picker.component.mjs +4 -4
- package/esm2020/elements/lib/form-control/form-control.component.mjs +4 -4
- package/esm2020/elements/lib/form-error/form-error.component.mjs +3 -3
- package/esm2020/elements/lib/form-group/form-group.component.mjs +3 -3
- package/esm2020/elements/lib/icon/icon.component.mjs +3 -3
- package/esm2020/elements/lib/image-picker/image-picker.component.mjs +3 -3
- package/esm2020/elements/lib/pipes/file-image.pipe.mjs +3 -3
- package/esm2020/elements/lib/pipes/file-size.pipe.mjs +3 -3
- package/esm2020/elements/lib/pipes/relative-time.pipe.mjs +15 -13
- package/esm2020/elements/lib/spinner/spinner.component.mjs +3 -3
- package/esm2020/elements/lib/tag/tag.component.mjs +3 -3
- package/esm2020/elements/public_api.mjs +1 -5
- package/esm2020/http/lib/classes/http.config.mjs +2 -3
- package/esm2020/http/lib/http.module.mjs +4 -4
- package/esm2020/http/lib/interceptors/base-url.interceptor.mjs +6 -6
- package/esm2020/http/lib/interceptors/error.interceptor.mjs +3 -3
- package/esm2020/lib/core/services/clipboard.service.mjs +3 -3
- package/esm2020/lib/core/services/exif.service.mjs +3 -3
- package/esm2020/lib/core/services/file-loader.service.mjs +3 -3
- package/esm2020/lib/core/services/image-converter.service.mjs +3 -3
- package/esm2020/lib/core/services/languages.service.mjs +3 -3
- package/esm2020/lib/core/services/network.service.mjs +3 -3
- package/esm2020/lib/core/services/patch.service.mjs +3 -3
- package/esm2020/localize/lib/dictionary/dictionary.class.mjs +92 -0
- package/esm2020/localize/lib/dictionary/dictionary.context.mjs +26 -0
- package/esm2020/localize/lib/dictionary/dictionary.data.mjs +6 -0
- package/esm2020/localize/lib/functions/lowercase.function.mjs +2 -2
- package/esm2020/localize/lib/functions/uppercase.function.mjs +2 -2
- package/esm2020/localize/lib/handlers/missing.handler.mjs +2 -2
- package/esm2020/localize/lib/interfaces/config.interfaces.mjs +1 -1
- package/esm2020/localize/lib/interfaces/options.interfaces.mjs +1 -1
- package/esm2020/localize/lib/interfaces/transforms.interfaces.mjs +3 -0
- package/esm2020/localize/lib/localize.module.mjs +19 -13
- package/esm2020/localize/lib/localize.pipe.mjs +7 -8
- package/esm2020/localize/lib/localize.service.mjs +86 -130
- package/esm2020/localize/lib/transforms/abstract.transform.mjs +30 -0
- package/esm2020/localize/lib/transforms/interpolate.transform.mjs +54 -0
- package/esm2020/localize/lib/transforms/reference.transform.mjs +25 -0
- package/esm2020/localize/lib/views/localize-string/localize-string.component.mjs +6 -6
- package/esm2020/localize/lib/views/localize-template.directive.mjs +3 -3
- package/esm2020/localize/public_api.mjs +8 -2
- package/esm2020/masking/lib/directives/currency-mask.directive.mjs +3 -3
- package/esm2020/masking/lib/directives/date-mask.directive.mjs +3 -3
- package/esm2020/masking/lib/directives/input-mask.directive.mjs +3 -3
- package/esm2020/masking/lib/masking.module.mjs +4 -4
- package/esm2020/masking/lib/masking.service.mjs +3 -3
- package/esm2020/notifications/lib/notifications-item/notifications-item.component.mjs +3 -3
- package/esm2020/notifications/lib/notifications-list/notifications-list.component.mjs +3 -3
- package/esm2020/notifications/lib/notifications.module.mjs +4 -4
- package/esm2020/notifications/lib/notifications.service.mjs +22 -26
- package/esm2020/recaptcha/lib/recaptcha/recaptcha.component.mjs +3 -3
- package/esm2020/recaptcha/lib/recaptcha-loader.service.mjs +3 -3
- package/esm2020/recaptcha/lib/recaptcha.module.mjs +4 -4
- package/esm2020/storage/lib/storage.service.mjs +7 -7
- package/esm2020/table/lib/components/table/table.component.mjs +9 -9
- package/esm2020/table/lib/components/table-cell/table-cell.component.mjs +3 -3
- package/esm2020/table/lib/components/table-header-cell/table-header-cell.component.mjs +3 -3
- package/esm2020/table/lib/components/table-pager/table-pager.component.mjs +3 -3
- package/esm2020/table/lib/table.module.mjs +4 -4
- package/esm2020/theming/lib/theming.directive.mjs +3 -3
- package/esm2020/theming/lib/theming.module.mjs +4 -4
- package/esm2020/utils/bravobit-bb-foundation-utils.mjs +5 -0
- package/esm2020/utils/lib/directives/autosize.directive.mjs +72 -0
- package/esm2020/utils/lib/directives/focus-trap.directive.mjs +77 -0
- package/esm2020/utils/lib/directives/focus.directive.mjs +37 -0
- package/esm2020/utils/lib/directives/template.directive.mjs +28 -0
- package/esm2020/utils/lib/utils.module.mjs +35 -0
- package/esm2020/utils/public_api.mjs +6 -0
- package/fesm2015/bravobit-bb-foundation-auth.mjs +28 -28
- package/fesm2015/bravobit-bb-foundation-collections.mjs +23 -23
- package/fesm2015/bravobit-bb-foundation-collections.mjs.map +1 -1
- package/fesm2015/bravobit-bb-foundation-controls.mjs +47 -45
- package/fesm2015/bravobit-bb-foundation-controls.mjs.map +1 -1
- package/fesm2015/bravobit-bb-foundation-dashboard.mjs +25 -25
- package/fesm2015/bravobit-bb-foundation-dashboard.mjs.map +1 -1
- package/fesm2015/bravobit-bb-foundation-dialog.mjs +54 -81
- package/fesm2015/bravobit-bb-foundation-dialog.mjs.map +1 -1
- package/fesm2015/bravobit-bb-foundation-elements.mjs +126 -324
- package/fesm2015/bravobit-bb-foundation-elements.mjs.map +1 -1
- package/fesm2015/bravobit-bb-foundation-http.mjs +14 -14
- package/fesm2015/bravobit-bb-foundation-http.mjs.map +1 -1
- package/fesm2015/bravobit-bb-foundation-localize.mjs +360 -215
- package/fesm2015/bravobit-bb-foundation-localize.mjs.map +1 -1
- package/fesm2015/bravobit-bb-foundation-masking.mjs +16 -16
- package/fesm2015/bravobit-bb-foundation-notifications.mjs +31 -52
- package/fesm2015/bravobit-bb-foundation-notifications.mjs.map +1 -1
- package/fesm2015/bravobit-bb-foundation-recaptcha.mjs +10 -10
- package/fesm2015/bravobit-bb-foundation-storage.mjs +6 -6
- package/fesm2015/bravobit-bb-foundation-storage.mjs.map +1 -1
- package/fesm2015/bravobit-bb-foundation-table.mjs +22 -22
- package/fesm2015/bravobit-bb-foundation-theming.mjs +7 -7
- package/fesm2015/bravobit-bb-foundation-utils.mjs +246 -0
- package/fesm2015/bravobit-bb-foundation-utils.mjs.map +1 -0
- package/fesm2015/bravobit-bb-foundation.mjs +21 -21
- package/fesm2020/bravobit-bb-foundation-auth.mjs +28 -28
- package/fesm2020/bravobit-bb-foundation-collections.mjs +23 -23
- package/fesm2020/bravobit-bb-foundation-collections.mjs.map +1 -1
- package/fesm2020/bravobit-bb-foundation-controls.mjs +47 -45
- package/fesm2020/bravobit-bb-foundation-controls.mjs.map +1 -1
- package/fesm2020/bravobit-bb-foundation-dashboard.mjs +25 -25
- package/fesm2020/bravobit-bb-foundation-dashboard.mjs.map +1 -1
- package/fesm2020/bravobit-bb-foundation-dialog.mjs +53 -79
- package/fesm2020/bravobit-bb-foundation-dialog.mjs.map +1 -1
- package/fesm2020/bravobit-bb-foundation-elements.mjs +124 -322
- package/fesm2020/bravobit-bb-foundation-elements.mjs.map +1 -1
- package/fesm2020/bravobit-bb-foundation-http.mjs +14 -14
- package/fesm2020/bravobit-bb-foundation-http.mjs.map +1 -1
- package/fesm2020/bravobit-bb-foundation-localize.mjs +342 -208
- package/fesm2020/bravobit-bb-foundation-localize.mjs.map +1 -1
- package/fesm2020/bravobit-bb-foundation-masking.mjs +16 -16
- package/fesm2020/bravobit-bb-foundation-notifications.mjs +31 -52
- package/fesm2020/bravobit-bb-foundation-notifications.mjs.map +1 -1
- package/fesm2020/bravobit-bb-foundation-recaptcha.mjs +10 -10
- package/fesm2020/bravobit-bb-foundation-storage.mjs +6 -6
- package/fesm2020/bravobit-bb-foundation-storage.mjs.map +1 -1
- package/fesm2020/bravobit-bb-foundation-table.mjs +22 -22
- package/fesm2020/bravobit-bb-foundation-theming.mjs +7 -7
- package/fesm2020/bravobit-bb-foundation-utils.mjs +244 -0
- package/fesm2020/bravobit-bb-foundation-utils.mjs.map +1 -0
- package/fesm2020/bravobit-bb-foundation.mjs +21 -21
- package/localize/lib/dictionary/dictionary.class.d.ts +28 -0
- package/localize/lib/dictionary/dictionary.context.d.ts +7 -0
- package/localize/lib/dictionary/dictionary.data.d.ts +7 -0
- package/localize/lib/interfaces/config.interfaces.d.ts +4 -6
- package/localize/lib/interfaces/options.interfaces.d.ts +1 -0
- package/localize/lib/interfaces/transforms.interfaces.d.ts +3 -0
- package/localize/lib/localize.module.d.ts +4 -4
- package/localize/lib/localize.pipe.d.ts +1 -1
- package/localize/lib/localize.service.d.ts +25 -21
- package/localize/lib/transforms/abstract.transform.d.ts +13 -0
- package/localize/lib/transforms/interpolate.transform.d.ts +14 -0
- package/localize/lib/transforms/reference.transform.d.ts +10 -0
- package/localize/public_api.d.ts +7 -1
- package/notifications/lib/notifications.service.d.ts +6 -7
- package/package.json +12 -4
- package/utils/index.d.ts +5 -0
- package/{elements → utils}/lib/directives/autosize.directive.d.ts +0 -0
- package/{elements → utils}/lib/directives/focus-trap.directive.d.ts +0 -0
- package/{elements → utils}/lib/directives/focus.directive.d.ts +0 -0
- package/{elements → utils}/lib/directives/template.directive.d.ts +1 -0
- package/utils/lib/utils.module.d.ts +10 -0
- package/utils/public_api.d.ts +5 -0
- package/dialog/lib/dialog.injector.d.ts +0 -8
- package/esm2020/dialog/lib/dialog.injector.mjs +0 -18
- package/esm2020/elements/lib/directives/autosize.directive.mjs +0 -72
- package/esm2020/elements/lib/directives/focus-trap.directive.mjs +0 -77
- package/esm2020/elements/lib/directives/focus.directive.mjs +0 -37
- package/esm2020/elements/lib/directives/template.directive.mjs +0 -28
- package/esm2020/localize/lib/localize.dictionary.mjs +0 -26
- package/esm2020/localize/lib/views/localize-template-or-string.directive.mjs +0 -28
- package/esm2020/notifications/lib/notifications.injector.mjs +0 -18
- package/localize/lib/localize.dictionary.d.ts +0 -7
- package/localize/lib/views/localize-template-or-string.directive.d.ts +0 -10
- package/notifications/lib/notifications.injector.d.ts +0 -8
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
|
-
import { InjectionToken, Directive, Input,
|
|
2
|
+
import { InjectionToken, Optional, Inject, Directive, Input, Component, ChangeDetectionStrategy, ViewEncapsulation, ContentChildren, Injectable, Pipe, APP_INITIALIZER, LOCALE_ID, NgModule } from '@angular/core';
|
|
3
3
|
import * as i1 from '@angular/common';
|
|
4
4
|
import { formatDate, DOCUMENT, CommonModule } from '@angular/common';
|
|
5
|
+
import { __decorate, __param } from 'tslib';
|
|
5
6
|
import { startWith } from 'rxjs/operators';
|
|
6
7
|
import { Subscription } from 'rxjs';
|
|
8
|
+
import * as i2 from '@bravobit/bb-foundation/utils';
|
|
9
|
+
import { UtilsModule } from '@bravobit/bb-foundation/utils';
|
|
10
|
+
import * as i2$1 from '@bravobit/bb-foundation';
|
|
11
|
+
import { WINDOW } from '@bravobit/bb-foundation';
|
|
7
12
|
import * as i1$1 from '@bravobit/bb-foundation/storage';
|
|
8
|
-
import * as i2 from '@bravobit/bb-foundation';
|
|
9
13
|
|
|
10
14
|
//
|
|
11
15
|
// The configuration that can be passed when
|
|
@@ -23,6 +27,8 @@ class LocalizeConfig {
|
|
|
23
27
|
//
|
|
24
28
|
const LOCALIZE_FUNCTION = new InjectionToken('localize_function');
|
|
25
29
|
|
|
30
|
+
const LOCALIZE_TRANSFORM = new InjectionToken('localize_transform');
|
|
31
|
+
|
|
26
32
|
//
|
|
27
33
|
// This function transform the value
|
|
28
34
|
// to a lowercase variant of the value.
|
|
@@ -32,7 +38,7 @@ class LocalizeLowercaseFunction {
|
|
|
32
38
|
return 'lowercase';
|
|
33
39
|
}
|
|
34
40
|
transform(value) {
|
|
35
|
-
return (value
|
|
41
|
+
return (value ?? '').toLowerCase();
|
|
36
42
|
}
|
|
37
43
|
}
|
|
38
44
|
|
|
@@ -45,7 +51,7 @@ class LocalizeUppercaseFunction {
|
|
|
45
51
|
return 'uppercase';
|
|
46
52
|
}
|
|
47
53
|
transform(value) {
|
|
48
|
-
return (value
|
|
54
|
+
return (value ?? '').toUpperCase();
|
|
49
55
|
}
|
|
50
56
|
}
|
|
51
57
|
|
|
@@ -164,13 +170,236 @@ class LocalizeMissingHandler {
|
|
|
164
170
|
// Log to the console when the token was not found
|
|
165
171
|
// if the user did not mark it as optional.
|
|
166
172
|
if (!params?.optional) {
|
|
167
|
-
this.log(`
|
|
173
|
+
this.log(`The token with name: "${params?.token}" was not found.`);
|
|
168
174
|
}
|
|
169
175
|
// Return the default token back.
|
|
170
176
|
return params?.token ?? null;
|
|
171
177
|
}
|
|
172
178
|
}
|
|
173
179
|
|
|
180
|
+
class LocalizeDictionaryData {
|
|
181
|
+
constructor(data) {
|
|
182
|
+
this.data = data;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
class LocalizeDictionaryContext {
|
|
187
|
+
constructor() {
|
|
188
|
+
this.regexp = /^.*$/;
|
|
189
|
+
}
|
|
190
|
+
pattern(regexp) {
|
|
191
|
+
this.regexp = regexp;
|
|
192
|
+
return this;
|
|
193
|
+
}
|
|
194
|
+
matches(value) {
|
|
195
|
+
const formatted = this.formatValue(value);
|
|
196
|
+
const regex = (formatted ?? '')
|
|
197
|
+
.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&')
|
|
198
|
+
.replace(/\\\*/g, '.*');
|
|
199
|
+
return this.pattern(new RegExp(`^${regex}$`));
|
|
200
|
+
}
|
|
201
|
+
group(value) {
|
|
202
|
+
const formatted = this.formatValue(value);
|
|
203
|
+
return this.matches([formatted, '*']);
|
|
204
|
+
}
|
|
205
|
+
formatValue(value) {
|
|
206
|
+
return Array.isArray(value)
|
|
207
|
+
? value.filter(item => !!item).join('.')
|
|
208
|
+
: value;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
class LocalizeDictionary {
|
|
213
|
+
constructor(_id, _locale, _supported, _dataValues, _localize) {
|
|
214
|
+
this._id = _id;
|
|
215
|
+
this._locale = _locale;
|
|
216
|
+
this._supported = _supported;
|
|
217
|
+
this._dataValues = _dataValues;
|
|
218
|
+
this._localize = _localize;
|
|
219
|
+
this._data = this.formatData(this._dataValues);
|
|
220
|
+
}
|
|
221
|
+
get id() {
|
|
222
|
+
return this._id ?? null;
|
|
223
|
+
}
|
|
224
|
+
get locale() {
|
|
225
|
+
return this._locale ?? null;
|
|
226
|
+
}
|
|
227
|
+
get supported() {
|
|
228
|
+
return this._supported ?? [];
|
|
229
|
+
}
|
|
230
|
+
get(token) {
|
|
231
|
+
const key = Array.isArray(token) ? token.join('.') : token;
|
|
232
|
+
return this._data?.[key] ?? null;
|
|
233
|
+
}
|
|
234
|
+
has(token) {
|
|
235
|
+
return !!this.get(token);
|
|
236
|
+
}
|
|
237
|
+
all() {
|
|
238
|
+
return this.some(context => context);
|
|
239
|
+
}
|
|
240
|
+
some(callback) {
|
|
241
|
+
const defaultContext = new LocalizeDictionaryContext();
|
|
242
|
+
const context = !!callback ? callback(defaultContext) : defaultContext;
|
|
243
|
+
return Object.keys(this._data ?? {})
|
|
244
|
+
.filter(key => context.regexp.test(key))
|
|
245
|
+
.reduce((previous, current) => ([
|
|
246
|
+
...previous,
|
|
247
|
+
{ token: current, value: this.get(current) }
|
|
248
|
+
]), []);
|
|
249
|
+
}
|
|
250
|
+
async compare(to) {
|
|
251
|
+
if ((typeof ngDevMode === 'undefined' || ngDevMode)) {
|
|
252
|
+
const dictionaryIds = (Array.isArray(to) ? to : [to]);
|
|
253
|
+
const dictionaries = [];
|
|
254
|
+
for (const dictionaryId of dictionaryIds) {
|
|
255
|
+
console.log(`Making sure dictionary "${dictionaryId}" is loaded.`);
|
|
256
|
+
const dictionary = await this._localize.load(dictionaryId);
|
|
257
|
+
dictionaries.push(dictionary);
|
|
258
|
+
}
|
|
259
|
+
const warnings = [];
|
|
260
|
+
const items = this.all();
|
|
261
|
+
for (const item of items) {
|
|
262
|
+
for (const dictionary of dictionaries) {
|
|
263
|
+
if (!dictionary.has(item?.token)) {
|
|
264
|
+
warnings.push({ dictionary: dictionary?.id, value: item?.token });
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
for (const dictionary of dictionaries) {
|
|
269
|
+
const items = dictionary.all();
|
|
270
|
+
for (const item of items) {
|
|
271
|
+
if (!this.has(item?.token)) {
|
|
272
|
+
warnings.push({ dictionary: this.id, value: item?.token });
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
const compareDictionaryIds = dictionaries.map(dictionary => dictionary?.id).join(', ');
|
|
277
|
+
console.log(`Comparing currency dictionary [${this.id}] with [${compareDictionaryIds}]...`);
|
|
278
|
+
for (const warning of warnings) {
|
|
279
|
+
console?.warn?.(`Dictionary "${warning.dictionary}" is missing token "${warning.value}"`);
|
|
280
|
+
}
|
|
281
|
+
console?.warn?.(`Total of ${warnings.length} warning(s) found.`);
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
count() {
|
|
285
|
+
return Object.keys(this._data ?? {}).length;
|
|
286
|
+
}
|
|
287
|
+
formatData(data, scope = null) {
|
|
288
|
+
return Object.keys(data ?? {}).reduce((previous, current) => {
|
|
289
|
+
const value = data?.[current];
|
|
290
|
+
if (typeof value === 'object' && value !== null) {
|
|
291
|
+
const reformatted = this.formatData(value, current);
|
|
292
|
+
return { ...previous, ...reformatted };
|
|
293
|
+
}
|
|
294
|
+
const token = [scope, current].filter(item => !!item).join('.');
|
|
295
|
+
if (previous[token] && (typeof ngDevMode === 'undefined' || ngDevMode)) {
|
|
296
|
+
console?.warn?.(`Duplicate key "${token}" was found, please verify your translation files.`);
|
|
297
|
+
}
|
|
298
|
+
return { ...previous, [token]: value };
|
|
299
|
+
}, {});
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
class LocalizeTransform {
|
|
304
|
+
getMatches(value, substitutions) {
|
|
305
|
+
// Validate our value exists, else return zero matches.
|
|
306
|
+
if (value === undefined || value === null) {
|
|
307
|
+
return [];
|
|
308
|
+
}
|
|
309
|
+
// Get the matching substitutions.
|
|
310
|
+
const { start, end } = this.getSubstitutions(substitutions);
|
|
311
|
+
// Compose a regex that will find the matches.
|
|
312
|
+
const regex = new RegExp(`${start}([^${end}]+)${end}`, 'g');
|
|
313
|
+
// Execute the regex to find matches.
|
|
314
|
+
let match = regex.exec(value);
|
|
315
|
+
const matches = [];
|
|
316
|
+
while (match !== null) {
|
|
317
|
+
matches.push({ match: match[0], token: match[1] });
|
|
318
|
+
match = regex.exec(value);
|
|
319
|
+
}
|
|
320
|
+
// Return the processed value.
|
|
321
|
+
return matches.filter(item => !!item);
|
|
322
|
+
}
|
|
323
|
+
getSubstitutions(value) {
|
|
324
|
+
// Escape both substitutions so that they can be used.
|
|
325
|
+
const escape = /[.*+?^${}()|[\]\\]/g;
|
|
326
|
+
const start = value[0].replace(escape, '\\$&');
|
|
327
|
+
const end = value[1].replace(escape, '\\$&');
|
|
328
|
+
// Return the substitutions.
|
|
329
|
+
return { start, end };
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
let LocalizeInterpolateTransform = class LocalizeInterpolateTransform extends LocalizeTransform {
|
|
334
|
+
constructor(config, functions) {
|
|
335
|
+
super();
|
|
336
|
+
this.config = config;
|
|
337
|
+
this.functions = functions;
|
|
338
|
+
this.substitutions = this.config?.substitutions?.references ?? ['{{', '}}'];
|
|
339
|
+
this.functionsMap = (this.functions ?? []).reduce((previous, current) => {
|
|
340
|
+
previous[current?.keyword()] = current;
|
|
341
|
+
return previous;
|
|
342
|
+
}, {});
|
|
343
|
+
}
|
|
344
|
+
execute(value, data, localize) {
|
|
345
|
+
const matches = this.getMatches(value, this.substitutions);
|
|
346
|
+
// Replace all matches with the translated value.
|
|
347
|
+
return matches.reduce((previous, current) => {
|
|
348
|
+
// Try to parse the token.
|
|
349
|
+
const interpolatedToken = this.parseInterpolationToken(current?.token, data, localize);
|
|
350
|
+
// Replace the match with the translated token.
|
|
351
|
+
return previous.replace(current?.match, interpolatedToken);
|
|
352
|
+
}, value);
|
|
353
|
+
}
|
|
354
|
+
parseInterpolationToken(value, data, localize) {
|
|
355
|
+
// Get the token and the methods by splitting
|
|
356
|
+
// on the pipe symbol.
|
|
357
|
+
const [token, ...methods] = (value ?? '').split('|').map(item => item.trim());
|
|
358
|
+
// Get the value for the token from
|
|
359
|
+
// the interpolation data.
|
|
360
|
+
const interpolationValue = data?.[token] ?? 'null';
|
|
361
|
+
// Loop through all the middleware methods and try to
|
|
362
|
+
// conform the string to the given parameters.
|
|
363
|
+
return methods.reduce((string, middlewareName) => {
|
|
364
|
+
// Try to retrieve the middleware from the collection.
|
|
365
|
+
const middleware = this.functionsMap?.[middlewareName];
|
|
366
|
+
// If the middleware is missing return an error
|
|
367
|
+
// so that the user knows it was not found.
|
|
368
|
+
if (!middleware) {
|
|
369
|
+
return string;
|
|
370
|
+
}
|
|
371
|
+
// Execute the middleware function with the string.
|
|
372
|
+
return middleware.transform(string, localize?.current?.locale);
|
|
373
|
+
}, `${interpolationValue}`);
|
|
374
|
+
}
|
|
375
|
+
};
|
|
376
|
+
LocalizeInterpolateTransform = __decorate([
|
|
377
|
+
__param(0, Optional()),
|
|
378
|
+
__param(1, Optional()),
|
|
379
|
+
__param(1, Inject(LOCALIZE_FUNCTION))
|
|
380
|
+
], LocalizeInterpolateTransform);
|
|
381
|
+
|
|
382
|
+
let LocalizeReferenceTransform = class LocalizeReferenceTransform extends LocalizeTransform {
|
|
383
|
+
constructor(config) {
|
|
384
|
+
super();
|
|
385
|
+
this.config = config;
|
|
386
|
+
this.substitutions = this.config?.substitutions?.references ?? ['#(', ')'];
|
|
387
|
+
}
|
|
388
|
+
execute(value, _, localize) {
|
|
389
|
+
const matches = this.getMatches(value, this.substitutions);
|
|
390
|
+
// Replace all matches with the translated value.
|
|
391
|
+
return matches.reduce((previous, current) => {
|
|
392
|
+
// Try to translate the token.
|
|
393
|
+
const translatedToken = localize.translate(current?.token);
|
|
394
|
+
// Replace the match with the translated token.
|
|
395
|
+
return previous.replace(current?.match, translatedToken);
|
|
396
|
+
}, value);
|
|
397
|
+
}
|
|
398
|
+
};
|
|
399
|
+
LocalizeReferenceTransform = __decorate([
|
|
400
|
+
__param(0, Optional())
|
|
401
|
+
], LocalizeReferenceTransform);
|
|
402
|
+
|
|
174
403
|
class BbLocalizeTemplate {
|
|
175
404
|
constructor(templateRef) {
|
|
176
405
|
this.templateRef = templateRef;
|
|
@@ -178,9 +407,9 @@ class BbLocalizeTemplate {
|
|
|
178
407
|
this.name = null;
|
|
179
408
|
}
|
|
180
409
|
}
|
|
181
|
-
BbLocalizeTemplate.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.
|
|
182
|
-
BbLocalizeTemplate.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "14.
|
|
183
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.
|
|
410
|
+
BbLocalizeTemplate.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.0", ngImport: i0, type: BbLocalizeTemplate, deps: [{ token: i0.TemplateRef }], target: i0.ɵɵFactoryTarget.Directive });
|
|
411
|
+
BbLocalizeTemplate.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "14.2.0", type: BbLocalizeTemplate, selector: "[bbLocalizeTemplate]", inputs: { name: ["bbLocalizeTemplate", "name"] }, ngImport: i0 });
|
|
412
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.0", ngImport: i0, type: BbLocalizeTemplate, decorators: [{
|
|
184
413
|
type: Directive,
|
|
185
414
|
args: [{
|
|
186
415
|
selector: '[bbLocalizeTemplate]'
|
|
@@ -190,32 +419,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.1.1", ngImpor
|
|
|
190
419
|
args: ['bbLocalizeTemplate']
|
|
191
420
|
}] } });
|
|
192
421
|
|
|
193
|
-
class BbLocalizeTemplateOrString {
|
|
194
|
-
constructor(_templateRef, _viewContainerRef) {
|
|
195
|
-
this._templateRef = _templateRef;
|
|
196
|
-
this._viewContainerRef = _viewContainerRef;
|
|
197
|
-
}
|
|
198
|
-
set bbLocalizeTemplateOrString(content) {
|
|
199
|
-
// Get the template.
|
|
200
|
-
const template = content instanceof TemplateRef
|
|
201
|
-
? content
|
|
202
|
-
: this._templateRef;
|
|
203
|
-
// Clear the view container ref and create the view.
|
|
204
|
-
this._viewContainerRef.clear();
|
|
205
|
-
this._viewContainerRef.createEmbeddedView(template);
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
BbLocalizeTemplateOrString.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.1.1", ngImport: i0, type: BbLocalizeTemplateOrString, deps: [{ token: i0.TemplateRef }, { token: i0.ViewContainerRef }], target: i0.ɵɵFactoryTarget.Directive });
|
|
209
|
-
BbLocalizeTemplateOrString.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "14.1.1", type: BbLocalizeTemplateOrString, selector: "[bbLocalizeTemplateOrString]", inputs: { bbLocalizeTemplateOrString: "bbLocalizeTemplateOrString" }, ngImport: i0 });
|
|
210
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.1.1", ngImport: i0, type: BbLocalizeTemplateOrString, decorators: [{
|
|
211
|
-
type: Directive,
|
|
212
|
-
args: [{
|
|
213
|
-
selector: '[bbLocalizeTemplateOrString]'
|
|
214
|
-
}]
|
|
215
|
-
}], ctorParameters: function () { return [{ type: i0.TemplateRef }, { type: i0.ViewContainerRef }]; }, propDecorators: { bbLocalizeTemplateOrString: [{
|
|
216
|
-
type: Input
|
|
217
|
-
}] } });
|
|
218
|
-
|
|
219
422
|
class BbLocalizeString {
|
|
220
423
|
constructor(_changeDetection) {
|
|
221
424
|
this._changeDetection = _changeDetection;
|
|
@@ -281,13 +484,13 @@ class BbLocalizeString {
|
|
|
281
484
|
];
|
|
282
485
|
}
|
|
283
486
|
}
|
|
284
|
-
BbLocalizeString.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.
|
|
285
|
-
BbLocalizeString.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "14.
|
|
286
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.
|
|
487
|
+
BbLocalizeString.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.0", ngImport: i0, type: BbLocalizeString, deps: [{ token: i0.ChangeDetectorRef }], target: i0.ɵɵFactoryTarget.Component });
|
|
488
|
+
BbLocalizeString.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "14.2.0", type: BbLocalizeString, selector: "bb-localize-string, [bb-localize-string]", inputs: { substitutions: "substitutions", value: "value" }, host: { classAttribute: "bb-localize-string" }, queries: [{ propertyName: "items", predicate: BbLocalizeTemplate }], ngImport: i0, template: "<ng-container *ngFor=\"let component of components\">\n <ng-template [bbTemplate]=\"component\">{{ component }}</ng-template>\n</ng-container>\n", styles: [".bb-localize-string{display:inline}\n"], dependencies: [{ kind: "directive", type: i1.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { kind: "directive", type: i2.BbTemplate, selector: "[bbTemplate]", inputs: ["bbTemplate"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None });
|
|
489
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.0", ngImport: i0, type: BbLocalizeString, decorators: [{
|
|
287
490
|
type: Component,
|
|
288
491
|
args: [{ selector: 'bb-localize-string, [bb-localize-string]', changeDetection: ChangeDetectionStrategy.OnPush, encapsulation: ViewEncapsulation.None, preserveWhitespaces: false, host: {
|
|
289
492
|
'class': 'bb-localize-string'
|
|
290
|
-
}, template: "<ng-container *ngFor=\"let component of components\">\n <ng-template [
|
|
493
|
+
}, template: "<ng-container *ngFor=\"let component of components\">\n <ng-template [bbTemplate]=\"component\">{{ component }}</ng-template>\n</ng-container>\n", styles: [".bb-localize-string{display:inline}\n"] }]
|
|
291
494
|
}], ctorParameters: function () { return [{ type: i0.ChangeDetectorRef }]; }, propDecorators: { items: [{
|
|
292
495
|
type: ContentChildren,
|
|
293
496
|
args: [BbLocalizeTemplate]
|
|
@@ -297,189 +500,104 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.1.1", ngImpor
|
|
|
297
500
|
type: Input
|
|
298
501
|
}] } });
|
|
299
502
|
|
|
300
|
-
class LocalizeDictionary {
|
|
301
|
-
constructor(data) {
|
|
302
|
-
this._data = this.formatData(data);
|
|
303
|
-
}
|
|
304
|
-
get(token) {
|
|
305
|
-
const key = Array.isArray(token) ? token.join('.') : token;
|
|
306
|
-
return this._data?.[key] ?? null;
|
|
307
|
-
}
|
|
308
|
-
formatData(data, scope = null) {
|
|
309
|
-
const devMode = isDevMode();
|
|
310
|
-
return Object.keys(data).reduce((previous, current) => {
|
|
311
|
-
const value = data?.[current];
|
|
312
|
-
if (typeof value === 'object' && value !== null) {
|
|
313
|
-
const reformatted = this.formatData(value, current);
|
|
314
|
-
return { ...previous, ...reformatted };
|
|
315
|
-
}
|
|
316
|
-
const token = [scope, current].filter(item => !!item).join('.');
|
|
317
|
-
if (previous[token] && devMode) {
|
|
318
|
-
console?.warn?.(`Localize: Duplicate key "${token}" was found, please verify your translation files.`);
|
|
319
|
-
}
|
|
320
|
-
return { ...previous, [token]: value };
|
|
321
|
-
}, {});
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
|
|
325
503
|
class Localize {
|
|
326
|
-
constructor(_storage, _languages, _config,
|
|
504
|
+
constructor(_storage, _languages, _missingHandler, _config, _window, _document, _transforms) {
|
|
327
505
|
this._storage = _storage;
|
|
328
506
|
this._languages = _languages;
|
|
329
|
-
this._config = _config;
|
|
330
507
|
this._missingHandler = _missingHandler;
|
|
508
|
+
this._config = _config;
|
|
509
|
+
this._window = _window;
|
|
331
510
|
this._document = _document;
|
|
332
|
-
this.
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
this.
|
|
336
|
-
this.
|
|
511
|
+
this._transforms = _transforms;
|
|
512
|
+
// Readonly data.
|
|
513
|
+
this._storageToken = this._config?.storageToken ?? 'bb-language-dictionary-id';
|
|
514
|
+
this._availableLanguages = this?._config?.languages ?? [];
|
|
515
|
+
this._bestMatchingLanguage = this.retrieveBestMatchingLanguage();
|
|
516
|
+
this._loadedDictionaries = new Map();
|
|
517
|
+
// Current dictionary.
|
|
518
|
+
this._current = null;
|
|
337
519
|
this.convertToParams = (tokenOrParams) => {
|
|
338
520
|
if (typeof tokenOrParams !== 'string') {
|
|
339
521
|
// Destruct the params from the object.
|
|
340
|
-
const { token, optional, data } = tokenOrParams;
|
|
522
|
+
const { token, optional, dictionary, data } = tokenOrParams;
|
|
341
523
|
// Make sure all parameters are valid
|
|
342
524
|
// by type safe adding them.
|
|
343
|
-
return { token: token, optional: optional ?? false, data: data ?? {} };
|
|
525
|
+
return { token: token, optional: optional ?? false, dictionary: dictionary ?? null, data: data ?? {} };
|
|
344
526
|
}
|
|
345
527
|
// If the parameter is a string fill in the blanks.
|
|
346
|
-
return { token: tokenOrParams, optional: false, data: {} };
|
|
347
|
-
};
|
|
348
|
-
this.getMatches = (value, substitutions) => {
|
|
349
|
-
// Get the matching substitutions.
|
|
350
|
-
const { start, end } = substitutions;
|
|
351
|
-
// Compose a regex that will find the matches.
|
|
352
|
-
const regex = new RegExp(`${start}([^${end}]+)${end}`, 'g');
|
|
353
|
-
// Execute the regex to find matches.
|
|
354
|
-
let match = regex.exec(value);
|
|
355
|
-
const matches = [];
|
|
356
|
-
while (match !== null) {
|
|
357
|
-
matches.push({ match: match[0], token: match[1] });
|
|
358
|
-
match = regex.exec(value);
|
|
359
|
-
}
|
|
360
|
-
// Return the processed value.
|
|
361
|
-
return matches.filter(item => !!item);
|
|
528
|
+
return { token: tokenOrParams, optional: false, dictionary: null, data: {} };
|
|
362
529
|
};
|
|
363
|
-
// Check if at least one language was passed in the config.
|
|
364
|
-
this._availableLanguages = this._config.languages;
|
|
365
|
-
if (this._availableLanguages.length < 1) {
|
|
366
|
-
throw new Error('Localize: one or more languages should be supplied.');
|
|
367
|
-
}
|
|
368
|
-
// Gather all the localize functions.
|
|
369
|
-
this._functionMiddleware = this._functions.reduce((previous, current) => {
|
|
370
|
-
previous[current.keyword()] = current;
|
|
371
|
-
return previous;
|
|
372
|
-
}, {});
|
|
373
|
-
// Save the best matching current dictionary.
|
|
374
|
-
this._bestMatchingLanguage = this.retrieveBestMatchingLanguage();
|
|
375
530
|
this.renderDocumentLanguage();
|
|
376
531
|
}
|
|
377
532
|
get languages() {
|
|
378
533
|
return this._availableLanguages ?? [];
|
|
379
534
|
}
|
|
380
535
|
get current() {
|
|
381
|
-
return this.
|
|
382
|
-
}
|
|
383
|
-
async
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
if (this.
|
|
388
|
-
|
|
536
|
+
return this._current;
|
|
537
|
+
}
|
|
538
|
+
async load(id) {
|
|
539
|
+
if (id === null || id === undefined) {
|
|
540
|
+
throw new Error(`Cannot load language with id: "${id}".`);
|
|
541
|
+
}
|
|
542
|
+
if (this._loadedDictionaries.has(id)) {
|
|
543
|
+
return this._loadedDictionaries.get(id);
|
|
389
544
|
}
|
|
390
|
-
|
|
545
|
+
const language = this.languages?.find(language => language?.id === id);
|
|
546
|
+
if (!language || !language?.data) {
|
|
547
|
+
console?.warn?.(`No language was found with id: "${id}"; Defaulting to first available language.`);
|
|
548
|
+
const languageId = this.languages?.[0]?.id ?? null;
|
|
549
|
+
return this.load(languageId);
|
|
550
|
+
}
|
|
551
|
+
const dictionaryDataValues = await language?.data?.();
|
|
552
|
+
const dictionary = this.createDictionary(dictionaryDataValues, language);
|
|
553
|
+
this._loadedDictionaries.set(id, dictionary);
|
|
554
|
+
return dictionary;
|
|
555
|
+
}
|
|
556
|
+
async switch(id, options) {
|
|
557
|
+
this._current = await this.load(id);
|
|
558
|
+
const cache = options?.cache ?? true;
|
|
391
559
|
if (cache) {
|
|
392
|
-
this._storage.cookie.set(this._storageToken, this.
|
|
560
|
+
this._storage.cookie.set(this._storageToken, this._current?.id, {});
|
|
561
|
+
}
|
|
562
|
+
const reload = options?.reload ?? false;
|
|
563
|
+
if (reload) {
|
|
564
|
+
this._window?.location?.reload?.();
|
|
393
565
|
}
|
|
566
|
+
return this._current;
|
|
567
|
+
}
|
|
568
|
+
select(id) {
|
|
569
|
+
if (!this._loadedDictionaries.has(id)) {
|
|
570
|
+
throw new Error(`Dictionary with id: "${id}" not loaded; Load dictionary first before using .select(:id).`);
|
|
571
|
+
}
|
|
572
|
+
return this._loadedDictionaries.get(id);
|
|
394
573
|
}
|
|
395
574
|
initialize() {
|
|
396
|
-
return async () => this.
|
|
575
|
+
return async () => this.switch(this._bestMatchingLanguage?.id, { reload: false, cache: false });
|
|
397
576
|
}
|
|
398
577
|
clear() {
|
|
399
578
|
this._storage.cookie.remove(this._storageToken);
|
|
400
579
|
}
|
|
580
|
+
transform(value, data = {}) {
|
|
581
|
+
return (this._transforms ?? []).reduce((previous, current) => {
|
|
582
|
+
return current.execute(previous, data, this);
|
|
583
|
+
}, value);
|
|
584
|
+
}
|
|
401
585
|
translate(tokenOrParams) {
|
|
402
586
|
// 1. Convert to the params.
|
|
403
587
|
const params = this.convertToParams(tokenOrParams);
|
|
404
588
|
// 2. Try to find the translation in the dictionary.
|
|
405
|
-
const
|
|
589
|
+
const dictionary = this.getDictionary(params?.dictionary);
|
|
590
|
+
const searchResult = !!dictionary ? dictionary.get(params?.token) : null;
|
|
406
591
|
// 3. Verify the translation was found.
|
|
407
592
|
if (!searchResult) {
|
|
408
593
|
return this._missingHandler.handle(params);
|
|
409
594
|
}
|
|
410
|
-
|
|
411
|
-
const processResult = this.findReferencesInTranslation(searchResult);
|
|
412
|
-
// 5. Parse the interpolation data.
|
|
413
|
-
return this.parseInterpolationData(processResult, params?.data);
|
|
414
|
-
}
|
|
415
|
-
parseInterpolationData(value, data) {
|
|
416
|
-
// Get the interpolation substitutions.
|
|
417
|
-
const substitutions = this.getSubstitutions('interpolation', ['{{', '}}']);
|
|
418
|
-
// Get all matches in the value.
|
|
419
|
-
const matches = this.getMatches(value, substitutions);
|
|
420
|
-
// Replace all matches with the parsed value.
|
|
421
|
-
return matches.reduce((previous, current) => {
|
|
422
|
-
// Try to parse the token.
|
|
423
|
-
const interpolatedToken = this.interpolateFunctionData(current?.token, data);
|
|
424
|
-
// Replace the match with the parsed token.
|
|
425
|
-
return previous.replace(current?.match, interpolatedToken);
|
|
426
|
-
}, `${value}`);
|
|
427
|
-
}
|
|
428
|
-
interpolateFunctionData(value, interpolationData) {
|
|
429
|
-
// Get the token and the methods by splitting
|
|
430
|
-
// on the pipe symbol.
|
|
431
|
-
const [token, ...methods] = value.split('|').map(item => item.trim());
|
|
432
|
-
// Get the value for the token from
|
|
433
|
-
// the interpolation data.
|
|
434
|
-
const interpolationValue = interpolationData?.[token] ?? token;
|
|
435
|
-
// Loop through all the middleware methods and try to
|
|
436
|
-
// conform the string to the given parameters.
|
|
437
|
-
return methods.reduce((string, middlewareName) => {
|
|
438
|
-
// Try to retrieve the middleware from the collection.
|
|
439
|
-
const middleware = this._functionMiddleware[middlewareName];
|
|
440
|
-
// If the middleware is missing return an error
|
|
441
|
-
// so that the user knows it was not found.
|
|
442
|
-
if (!middleware) {
|
|
443
|
-
return string;
|
|
444
|
-
}
|
|
445
|
-
// Execute the middleware function with the string.
|
|
446
|
-
return middleware.transform(string, this.current?.locale);
|
|
447
|
-
}, `${interpolationValue}`);
|
|
448
|
-
}
|
|
449
|
-
findReferencesInTranslation(value) {
|
|
450
|
-
// Get the reference substitutions.
|
|
451
|
-
const substitutions = this.getSubstitutions('references', ['#(', ')']);
|
|
452
|
-
// Get all matches in the value.
|
|
453
|
-
const matches = this.getMatches(value, substitutions);
|
|
454
|
-
// Replace all matches with the translated value.
|
|
455
|
-
return matches.reduce((previous, current) => {
|
|
456
|
-
// Try to translate the token.
|
|
457
|
-
const translatedToken = this.translate(current?.token);
|
|
458
|
-
// Replace the match with the translated token.
|
|
459
|
-
return previous.replace(current?.match, translatedToken);
|
|
460
|
-
}, value);
|
|
461
|
-
}
|
|
462
|
-
getSubstitutions(type, defaultValue) {
|
|
463
|
-
// Get the substitutions.
|
|
464
|
-
const substitutions = this._config?.substitutions?.[type] ?? null;
|
|
465
|
-
const value = (!substitutions || substitutions.length !== 2)
|
|
466
|
-
? defaultValue
|
|
467
|
-
: substitutions;
|
|
468
|
-
// Escape both substitutions so that they
|
|
469
|
-
// can be used.
|
|
470
|
-
const escape = /[.*+?^${}()|[\]\\]/g;
|
|
471
|
-
const start = value[0].replace(escape, '\\$&');
|
|
472
|
-
const end = value[1].replace(escape, '\\$&');
|
|
473
|
-
// Return the substitutions.
|
|
474
|
-
return { start, end };
|
|
595
|
+
return this.transform(searchResult, params?.data);
|
|
475
596
|
}
|
|
476
597
|
retrieveBestMatchingLanguage() {
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
const browserLanguage = this.getBestBrowserMatchLanguage();
|
|
481
|
-
// Return the best matching language.
|
|
482
|
-
return storageLanguage ?? browserLanguage ?? this._availableLanguages?.[0];
|
|
598
|
+
return this.getLanguageFromStorage()
|
|
599
|
+
?? this.getBestBrowserMatchLanguage()
|
|
600
|
+
?? this._availableLanguages?.[0];
|
|
483
601
|
}
|
|
484
602
|
getLanguageFromStorage() {
|
|
485
603
|
// Get id from the storage.
|
|
@@ -495,6 +613,15 @@ class Localize {
|
|
|
495
613
|
return this._availableLanguages.find(item => item?.supported?.includes(languageCode));
|
|
496
614
|
}).filter(item => !!item).find((_, index) => index === 0);
|
|
497
615
|
}
|
|
616
|
+
createDictionary(data, language) {
|
|
617
|
+
return new LocalizeDictionary(language?.id, language?.locale, language?.supported, data?.data, this);
|
|
618
|
+
}
|
|
619
|
+
getDictionary(id) {
|
|
620
|
+
if (id === null || id === undefined) {
|
|
621
|
+
return this._current;
|
|
622
|
+
}
|
|
623
|
+
return this.select(id);
|
|
624
|
+
}
|
|
498
625
|
renderDocumentLanguage() {
|
|
499
626
|
const element = this._document?.documentElement;
|
|
500
627
|
if (!element) {
|
|
@@ -503,13 +630,18 @@ class Localize {
|
|
|
503
630
|
element.lang = this._bestMatchingLanguage?.supported?.[0] ?? this._bestMatchingLanguage?.locale;
|
|
504
631
|
}
|
|
505
632
|
}
|
|
506
|
-
Localize.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.
|
|
507
|
-
Localize.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.
|
|
508
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.
|
|
633
|
+
Localize.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.0", ngImport: i0, type: Localize, deps: [{ token: i1$1.Storage }, { token: i2$1.Languages }, { token: LocalizeMissingHandler }, { token: LocalizeConfig, optional: true }, { token: WINDOW, optional: true }, { token: DOCUMENT, optional: true }, { token: LOCALIZE_TRANSFORM, optional: true }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
634
|
+
Localize.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.0", ngImport: i0, type: Localize });
|
|
635
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.0", ngImport: i0, type: Localize, decorators: [{
|
|
509
636
|
type: Injectable
|
|
510
|
-
}], ctorParameters: function () { return [{ type: i1$1.Storage }, { type: i2.Languages }, { type: LocalizeConfig, decorators: [{
|
|
637
|
+
}], ctorParameters: function () { return [{ type: i1$1.Storage }, { type: i2$1.Languages }, { type: LocalizeMissingHandler }, { type: LocalizeConfig, decorators: [{
|
|
511
638
|
type: Optional
|
|
512
|
-
}] }, { type:
|
|
639
|
+
}] }, { type: Window, decorators: [{
|
|
640
|
+
type: Optional
|
|
641
|
+
}, {
|
|
642
|
+
type: Inject,
|
|
643
|
+
args: [WINDOW]
|
|
644
|
+
}] }, { type: Document, decorators: [{
|
|
513
645
|
type: Optional
|
|
514
646
|
}, {
|
|
515
647
|
type: Inject,
|
|
@@ -518,7 +650,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.1.1", ngImpor
|
|
|
518
650
|
type: Optional
|
|
519
651
|
}, {
|
|
520
652
|
type: Inject,
|
|
521
|
-
args: [
|
|
653
|
+
args: [LOCALIZE_TRANSFORM]
|
|
522
654
|
}] }]; } });
|
|
523
655
|
|
|
524
656
|
class BbLocalize {
|
|
@@ -526,8 +658,7 @@ class BbLocalize {
|
|
|
526
658
|
this._localize = _localize;
|
|
527
659
|
}
|
|
528
660
|
transform(tokenOrParams, args) {
|
|
529
|
-
// Validate that the localize service
|
|
530
|
-
// exists in the pipe.
|
|
661
|
+
// Validate that the localize service exists in the pipe.
|
|
531
662
|
if (!this._localize) {
|
|
532
663
|
return tokenOrParams;
|
|
533
664
|
}
|
|
@@ -539,7 +670,7 @@ class BbLocalize {
|
|
|
539
670
|
}
|
|
540
671
|
combineParamsWithOptions(tokenOrParams, args) {
|
|
541
672
|
// Gather the extras.
|
|
542
|
-
const extras = args
|
|
673
|
+
const extras = args ?? {};
|
|
543
674
|
// Loop through all the keys to find the set options.
|
|
544
675
|
const options = Object.keys(extras).reduce((previous, current) => {
|
|
545
676
|
if (typeof extras[current] === 'undefined') {
|
|
@@ -550,15 +681,15 @@ class BbLocalize {
|
|
|
550
681
|
}, {});
|
|
551
682
|
// Convert the string token to a params object.
|
|
552
683
|
const params = typeof tokenOrParams === 'string'
|
|
553
|
-
? { token: tokenOrParams, optional: false, data: {} }
|
|
684
|
+
? { token: tokenOrParams, optional: false, data: {}, dictionary: null }
|
|
554
685
|
: tokenOrParams;
|
|
555
686
|
// Return the combined params and options.
|
|
556
687
|
return { ...params, ...options };
|
|
557
688
|
}
|
|
558
689
|
}
|
|
559
|
-
BbLocalize.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.
|
|
560
|
-
BbLocalize.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "14.
|
|
561
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.
|
|
690
|
+
BbLocalize.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.0", ngImport: i0, type: BbLocalize, deps: [{ token: Localize, optional: true }], target: i0.ɵɵFactoryTarget.Pipe });
|
|
691
|
+
BbLocalize.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "14.2.0", ngImport: i0, type: BbLocalize, name: "bbLocalize" });
|
|
692
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.0", ngImport: i0, type: BbLocalize, decorators: [{
|
|
562
693
|
type: Pipe,
|
|
563
694
|
args: [{
|
|
564
695
|
name: 'bbLocalize'
|
|
@@ -569,12 +700,14 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.1.1", ngImpor
|
|
|
569
700
|
|
|
570
701
|
class LocalizeModule {
|
|
571
702
|
static forRoot(config) {
|
|
572
|
-
|
|
703
|
+
if (config?.languages?.length <= 0) {
|
|
704
|
+
throw new Error('One or more languages should be supplied.');
|
|
705
|
+
}
|
|
573
706
|
return {
|
|
574
707
|
ngModule: LocalizeModule,
|
|
575
708
|
providers: [
|
|
576
709
|
// Angular providers.
|
|
577
|
-
...(automatic ? [
|
|
710
|
+
...(config?.mode === 'automatic' ? [
|
|
578
711
|
{ provide: APP_INITIALIZER, deps: [Localize], useFactory: initializeLocale, multi: true },
|
|
579
712
|
{ provide: LOCALE_ID, deps: [Localize], useFactory: getLocale }
|
|
580
713
|
] : []),
|
|
@@ -584,6 +717,9 @@ class LocalizeModule {
|
|
|
584
717
|
{ provide: LOCALIZE_FUNCTION, useClass: LocalizeLowercaseFunction, multi: true },
|
|
585
718
|
{ provide: LOCALIZE_FUNCTION, useClass: LocalizeUppercaseFunction, multi: true },
|
|
586
719
|
{ provide: LOCALIZE_FUNCTION, useClass: LocalizeDateFunction, multi: true },
|
|
720
|
+
// Transform providers.
|
|
721
|
+
{ provide: LOCALIZE_TRANSFORM, useClass: LocalizeReferenceTransform, deps: [LocalizeConfig], multi: true },
|
|
722
|
+
{ provide: LOCALIZE_TRANSFORM, useClass: LocalizeInterpolateTransform, deps: [LocalizeConfig, LOCALIZE_FUNCTION], multi: true },
|
|
587
723
|
// Handler providers.
|
|
588
724
|
{ provide: LocalizeMissingHandler, useClass: LocalizeMissingHandler },
|
|
589
725
|
// Service providers.
|
|
@@ -592,23 +728,21 @@ class LocalizeModule {
|
|
|
592
728
|
};
|
|
593
729
|
}
|
|
594
730
|
}
|
|
595
|
-
LocalizeModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.
|
|
596
|
-
LocalizeModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "14.
|
|
731
|
+
LocalizeModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.0", ngImport: i0, type: LocalizeModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
|
732
|
+
LocalizeModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "14.2.0", ngImport: i0, type: LocalizeModule, declarations: [BbLocalize,
|
|
597
733
|
BbLocalizeString,
|
|
598
|
-
BbLocalizeTemplate,
|
|
599
|
-
BbLocalizeTemplateOrString], imports: [CommonModule], exports: [BbLocalize,
|
|
734
|
+
BbLocalizeTemplate], imports: [CommonModule, UtilsModule], exports: [BbLocalize,
|
|
600
735
|
BbLocalizeString,
|
|
601
736
|
BbLocalizeTemplate] });
|
|
602
|
-
LocalizeModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "14.
|
|
603
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.
|
|
737
|
+
LocalizeModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "14.2.0", ngImport: i0, type: LocalizeModule, imports: [CommonModule, UtilsModule] });
|
|
738
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.0", ngImport: i0, type: LocalizeModule, decorators: [{
|
|
604
739
|
type: NgModule,
|
|
605
740
|
args: [{
|
|
606
|
-
imports: [CommonModule],
|
|
741
|
+
imports: [CommonModule, UtilsModule],
|
|
607
742
|
declarations: [
|
|
608
743
|
BbLocalize,
|
|
609
744
|
BbLocalizeString,
|
|
610
|
-
BbLocalizeTemplate
|
|
611
|
-
BbLocalizeTemplateOrString
|
|
745
|
+
BbLocalizeTemplate
|
|
612
746
|
],
|
|
613
747
|
exports: [
|
|
614
748
|
BbLocalize,
|
|
@@ -628,5 +762,5 @@ function getLocale(localize) {
|
|
|
628
762
|
* Generated bundle index. Do not edit.
|
|
629
763
|
*/
|
|
630
764
|
|
|
631
|
-
export { BbLocalize, BbLocalizeString, BbLocalizeTemplate, LOCALIZE_FUNCTION, Localize, LocalizeConfig, LocalizeDateFunction, LocalizeDictionary, LocalizeLowercaseFunction, LocalizeMissingHandler, LocalizeModule, LocalizeUppercaseFunction, extraDutchDictionary, extraEnglishDictionary, getLocale, initializeLocale };
|
|
765
|
+
export { BbLocalize, BbLocalizeString, BbLocalizeTemplate, LOCALIZE_FUNCTION, LOCALIZE_TRANSFORM, Localize, LocalizeConfig, LocalizeDateFunction, LocalizeDictionary, LocalizeDictionaryContext, LocalizeDictionaryData, LocalizeInterpolateTransform, LocalizeLowercaseFunction, LocalizeMissingHandler, LocalizeModule, LocalizeReferenceTransform, LocalizeTransform, LocalizeUppercaseFunction, extraDutchDictionary, extraEnglishDictionary, getLocale, initializeLocale };
|
|
632
766
|
//# sourceMappingURL=bravobit-bb-foundation-localize.mjs.map
|