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