monkey-style-guide 21.2.13 → 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).
|