monkey-style-guide 21.2.14 → 21.2.15
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/README.md
CHANGED
|
@@ -15,6 +15,49 @@ Run `ng build monkey-style-guide-v2` to build the project. The build artifacts w
|
|
|
15
15
|
|
|
16
16
|
After building your library with `ng build monkey-style-guide-v2`, go to the dist folder `cd dist/monkey-style-guide-v2` and run `npm publish`.
|
|
17
17
|
|
|
18
|
+
## Internationalization
|
|
19
|
+
|
|
20
|
+
The library ships its own strings (`MonkeyDictionaryService`) in four buckets: `pt-BR`, `es-CL`,
|
|
21
|
+
`es-MX` and `en-US`. `pt-BR` is the default and the per-key fallback.
|
|
22
|
+
|
|
23
|
+
By default the active bucket comes from Angular's `LOCALE_ID`, which is fixed at bootstrap. Apps that
|
|
24
|
+
resolve the language later (whitelabel/program config, a language switcher) should provide
|
|
25
|
+
`MECX_I18N_LANG` and push every language change into it — the dictionary then re-renders mounted
|
|
26
|
+
components without remounting them.
|
|
27
|
+
|
|
28
|
+
```ts
|
|
29
|
+
// app.config.ts
|
|
30
|
+
const i18nLang$ = new BehaviorSubject<string>(env.locale.lang);
|
|
31
|
+
|
|
32
|
+
providers: [
|
|
33
|
+
{ provide: MECX_I18N_LANG, useValue: i18nLang$ },
|
|
34
|
+
{ provide: LOCALE_ID, useValue: env.locale.lang }
|
|
35
|
+
];
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
```ts
|
|
39
|
+
// wherever the app switches language
|
|
40
|
+
handleI18N(lang: string, obj?: any): void {
|
|
41
|
+
if (obj) { this._translateService.setTranslation(lang, obj, true); }
|
|
42
|
+
this._translateService.use(lang);
|
|
43
|
+
this._i18nLang.next(lang);
|
|
44
|
+
}
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
When `MECX_I18N_LANG` is not provided the service behaves as before, reading `LOCALE_ID` once.
|
|
48
|
+
|
|
49
|
+
Notes:
|
|
50
|
+
|
|
51
|
+
- A language outside the four buckets falls back to `pt-BR` per key, never to blank labels. A new
|
|
52
|
+
language needs a full bucket — every key, including the nested `FILTER-BAR.DATE.*`,
|
|
53
|
+
`FILTER-BAR.OPERATOR.*` and `TABLE.ROW.*` groups — or the UI comes out mixed-language.
|
|
54
|
+
- Overrides pushed through `MECX_I18N_WRAPPER` are merged into the bucket that is active when they
|
|
55
|
+
arrive, so push the new language into `MECX_I18N_LANG` **before** pushing its overrides.
|
|
56
|
+
- This covers the dictionary only. `LOCALE_ID` also drives Angular's `date`, `currency`, `number` and
|
|
57
|
+
`percent` pipes, whose locale data is registered at bootstrap and cannot be swapped at runtime — so
|
|
58
|
+
a switched app can show pt-BR labels next to `MM/dd/yyyy` dates. Use `registerLocaleData` and a
|
|
59
|
+
reload for pipe formats.
|
|
60
|
+
|
|
18
61
|
## Running unit tests
|
|
19
62
|
|
|
20
63
|
Run `ng test monkey-style-guide-v2` to execute the unit tests via [Karma](https://karma-runner.github.io).
|
|
@@ -6,7 +6,7 @@ import { Injectable, input, Component, TemplateRef, inject, booleanAttribute, In
|
|
|
6
6
|
import { takeUntilDestroyed, toSignal } from '@angular/core/rxjs-interop';
|
|
7
7
|
import * as i1$1 from '@angular/forms';
|
|
8
8
|
import { Validators, NgControl, FormsModule, ReactiveFormsModule, FormControlDirective, NgModel, FormControlName, FormGroupDirective, NG_VALUE_ACCESSOR, NG_VALIDATORS } from '@angular/forms';
|
|
9
|
-
import { filter, of, map, BehaviorSubject, firstValueFrom, merge, Subject, debounceTime,
|
|
9
|
+
import { filter, of, map, BehaviorSubject, combineLatest, distinctUntilChanged, firstValueFrom, merge, Subject, debounceTime, switchMap, catchError, Subscription } from 'rxjs';
|
|
10
10
|
import * as i1$2 from '@angular/cdk/overlay';
|
|
11
11
|
import { Overlay, OverlayPositionBuilder, OverlayConfig, OverlayRef } from '@angular/cdk/overlay';
|
|
12
12
|
import { ComponentPortal, TemplatePortal } from '@angular/cdk/portal';
|
|
@@ -827,6 +827,7 @@ const MECX_I18N_WRAPPER = new InjectionToken('');
|
|
|
827
827
|
const MECX_POPOVER_OPTIONS = new InjectionToken('MECX_POPOVER_OPTIONS');
|
|
828
828
|
const MECX_COUNTRY_ISO_CODE = new InjectionToken('BR');
|
|
829
829
|
const MECX_GOOGLE_API_KEY = new InjectionToken('');
|
|
830
|
+
const MECX_I18N_LANG = new InjectionToken('MECX_I18N_LANG');
|
|
830
831
|
function injectTokenWithWarning(token, name) {
|
|
831
832
|
const value = inject(token, { optional: true });
|
|
832
833
|
if (!value) {
|
|
@@ -1285,10 +1286,13 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
1285
1286
|
* This style guide was developed by Monkey Exchange Team
|
|
1286
1287
|
* MIT Licence
|
|
1287
1288
|
************************* */
|
|
1289
|
+
const DEFAULT_LOCALE = 'pt-BR';
|
|
1288
1290
|
class MonkeyDictionaryService {
|
|
1289
1291
|
constructor() {
|
|
1290
1292
|
this._localeId = inject(LOCALE_ID);
|
|
1291
1293
|
this._destroyRef = inject(DestroyRef);
|
|
1294
|
+
this._lang$ = inject(MECX_I18N_LANG, { optional: true }) ??
|
|
1295
|
+
new BehaviorSubject(this._localeId || DEFAULT_LOCALE);
|
|
1292
1296
|
this._data$ = new BehaviorSubject({
|
|
1293
1297
|
'pt-BR': {
|
|
1294
1298
|
EDIT: 'Editar',
|
|
@@ -1735,7 +1739,7 @@ class MonkeyDictionaryService {
|
|
|
1735
1739
|
}
|
|
1736
1740
|
handleWrapperValues(value) {
|
|
1737
1741
|
try {
|
|
1738
|
-
const locale = this.
|
|
1742
|
+
const locale = this._lang$.value || DEFAULT_LOCALE;
|
|
1739
1743
|
const wrappedData = JSON.parse(value);
|
|
1740
1744
|
const currentData = this._data$.value;
|
|
1741
1745
|
const updated = {
|
|
@@ -1753,10 +1757,10 @@ class MonkeyDictionaryService {
|
|
|
1753
1757
|
}
|
|
1754
1758
|
}
|
|
1755
1759
|
get(key) {
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
return data[locale]?.[key] ?? null;
|
|
1759
|
-
}));
|
|
1760
|
+
return combineLatest([this._data$, this._lang$]).pipe(map(([data, lang]) => {
|
|
1761
|
+
const locale = lang || DEFAULT_LOCALE;
|
|
1762
|
+
return data[locale]?.[key] ?? data[DEFAULT_LOCALE]?.[key] ?? null;
|
|
1763
|
+
}), distinctUntilChanged());
|
|
1760
1764
|
}
|
|
1761
1765
|
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: MonkeyDictionaryService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
1762
1766
|
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: MonkeyDictionaryService, providedIn: 'root' }); }
|
|
@@ -11980,5 +11984,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
11980
11984
|
* Generated bundle index. Do not edit.
|
|
11981
11985
|
*/
|
|
11982
11986
|
|
|
11983
|
-
export { MECX_COUNTRY_ISO_CODE, MECX_GOOGLE_API_KEY, MECX_I18N_WRAPPER, MECX_MODAL_DATA, MECX_MODAL_DEFAULT_CONFIG, MECX_POPOVER_OPTIONS, MonkeyAccordionComponent, MonkeyActionBarComponent, MonkeyAlertComponent, MonkeyAutocompleteAddressComponent, MonkeyAutocompleteComponent, MonkeyAvatarComponent, MonkeyBadgeComponent, MonkeyBadgeDirective, MonkeyBreadcrumbComponent, MonkeyButtonComponent, MonkeyCheckboxComponent, MonkeyComplexFilterBarComponent, MonkeyDateRangeComponent, MonkeyDictionaryService, MonkeyDisplayDirective, MonkeyDividerComponent, MonkeyDownloadButtonComponent, MonkeyEcxAddressService, MonkeyErrorDirective, MonkeyFilterBarComponent, MonkeyFilterBarService, MonkeyFilterChipComponent, MonkeyFilterMenuComponent, MonkeyFilterMenuItemComponent, MonkeyFilterSegmentComponent, MonkeyFilterTriggerComponent, MonkeyFormDirective, MonkeyFormFieldComponent, MonkeyFormFieldControl, MonkeyFormFieldModule, MonkeyHelperDirective, MonkeyIconButtonComponent, MonkeyInfoDirective, MonkeyInputCodeComponent, MonkeyInputCurrencyDirective, MonkeyInputDateRangeComponent, MonkeyInputDirective, MonkeyInputModule, MonkeyInputPhoneComponent, MonkeyInputUploadComponent, MonkeyLabelDirective, MonkeyModalActionsDirective, MonkeyModalComponent, MonkeyModalConfig, MonkeyModalContentDirective, MonkeyModalModule, MonkeyModalRef, MonkeyModalService, MonkeyModalSubtitleDirective, MonkeyModalTitleDirective, MonkeyOptionComponent, MonkeyPaginationActionComponent, MonkeyPaginationLabelComponent, MonkeyPaginationSizeComponent, MonkeyPassNumberComponent, MonkeyPassSecretNumberComponent, MonkeyPopoverContentComponent, MonkeyPopoverDirective, MonkeyPrefixDirective, MonkeyRadioButtonComponent, MonkeyScrollbarComponent, MonkeySecurityLevelComponent, MonkeySelectComponent, MonkeyStatusComponent, MonkeyStepComponent, MonkeyStepperComponent, MonkeyStepperModule, MonkeyStepperService, MonkeySuffixDirective, MonkeyTabComponent, MonkeyTabLinkDirective, MonkeyTableCellDirective, MonkeyTableColumnDirective, MonkeyTableComponent, MonkeyTableEmptyDirective, MonkeyTableHeaderCellDirective, MonkeyTableLoadingDirective, MonkeyTableRowDetailDirective, MonkeyTabsComponent, MonkeyTabsModule, MonkeyToastComponent, MonkeyToastRef, MonkeyToastService, MonkeyToggleComponent, MonkeyToggleLineButtonComponent, MonkeyToggleLineComponent, MonkeyTooltipComponent, MonkeyTooltipDirective, MonkeyUserProfileButtonComponent, MonkeyUserProfileComponent, addKeys, appliedFrom, ariaSortOf, arityOf, conditionsOf, getCurrencySymbol, indexAtOffset, injectTokenWithWarning, interpolate, isComplete, mergeOrder, offsetOfIndex, panelOf, removeKeys, sameColumnState, selectionState, sortByOrder, toPx, toggleKey, totalHeight, withCondition, withType };
|
|
11987
|
+
export { MECX_COUNTRY_ISO_CODE, MECX_GOOGLE_API_KEY, MECX_I18N_LANG, MECX_I18N_WRAPPER, MECX_MODAL_DATA, MECX_MODAL_DEFAULT_CONFIG, MECX_POPOVER_OPTIONS, MonkeyAccordionComponent, MonkeyActionBarComponent, MonkeyAlertComponent, MonkeyAutocompleteAddressComponent, MonkeyAutocompleteComponent, MonkeyAvatarComponent, MonkeyBadgeComponent, MonkeyBadgeDirective, MonkeyBreadcrumbComponent, MonkeyButtonComponent, MonkeyCheckboxComponent, MonkeyComplexFilterBarComponent, MonkeyDateRangeComponent, MonkeyDictionaryService, MonkeyDisplayDirective, MonkeyDividerComponent, MonkeyDownloadButtonComponent, MonkeyEcxAddressService, MonkeyErrorDirective, MonkeyFilterBarComponent, MonkeyFilterBarService, MonkeyFilterChipComponent, MonkeyFilterMenuComponent, MonkeyFilterMenuItemComponent, MonkeyFilterSegmentComponent, MonkeyFilterTriggerComponent, MonkeyFormDirective, MonkeyFormFieldComponent, MonkeyFormFieldControl, MonkeyFormFieldModule, MonkeyHelperDirective, MonkeyIconButtonComponent, MonkeyInfoDirective, MonkeyInputCodeComponent, MonkeyInputCurrencyDirective, MonkeyInputDateRangeComponent, MonkeyInputDirective, MonkeyInputModule, MonkeyInputPhoneComponent, MonkeyInputUploadComponent, MonkeyLabelDirective, MonkeyModalActionsDirective, MonkeyModalComponent, MonkeyModalConfig, MonkeyModalContentDirective, MonkeyModalModule, MonkeyModalRef, MonkeyModalService, MonkeyModalSubtitleDirective, MonkeyModalTitleDirective, MonkeyOptionComponent, MonkeyPaginationActionComponent, MonkeyPaginationLabelComponent, MonkeyPaginationSizeComponent, MonkeyPassNumberComponent, MonkeyPassSecretNumberComponent, MonkeyPopoverContentComponent, MonkeyPopoverDirective, MonkeyPrefixDirective, MonkeyRadioButtonComponent, MonkeyScrollbarComponent, MonkeySecurityLevelComponent, MonkeySelectComponent, MonkeyStatusComponent, MonkeyStepComponent, MonkeyStepperComponent, MonkeyStepperModule, MonkeyStepperService, MonkeySuffixDirective, MonkeyTabComponent, MonkeyTabLinkDirective, MonkeyTableCellDirective, MonkeyTableColumnDirective, MonkeyTableComponent, MonkeyTableEmptyDirective, MonkeyTableHeaderCellDirective, MonkeyTableLoadingDirective, MonkeyTableRowDetailDirective, MonkeyTabsComponent, MonkeyTabsModule, MonkeyToastComponent, MonkeyToastRef, MonkeyToastService, MonkeyToggleComponent, MonkeyToggleLineButtonComponent, MonkeyToggleLineComponent, MonkeyTooltipComponent, MonkeyTooltipDirective, MonkeyUserProfileButtonComponent, MonkeyUserProfileComponent, addKeys, appliedFrom, ariaSortOf, arityOf, conditionsOf, getCurrencySymbol, indexAtOffset, injectTokenWithWarning, interpolate, isComplete, mergeOrder, offsetOfIndex, panelOf, removeKeys, sameColumnState, selectionState, sortByOrder, toPx, toggleKey, totalHeight, withCondition, withType };
|
|
11984
11988
|
//# sourceMappingURL=monkey-style-guide.mjs.map
|