@flusys/ng-localization 5.0.3 → 5.0.4
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 +27 -24
- package/fesm2022/flusys-ng-localization.mjs +1332 -1325
- package/fesm2022/flusys-ng-localization.mjs.map +1 -1
- package/package.json +3 -3
- package/types/flusys-ng-localization.d.ts +146 -158
package/README.md
CHANGED
|
@@ -15,19 +15,19 @@ npm install @flusys/ng-localization
|
|
|
15
15
|
|
|
16
16
|
## 1. Register Providers
|
|
17
17
|
|
|
18
|
-
Call `provideLocalization()` once in `app.config.ts`. It registers
|
|
18
|
+
Call `provideLocalization()` once in `app.config.ts`. It registers ``(consumed by`TranslatePipe`from`ng-shared`), an `APP_INITIALIZER` that loads translations before the first render, and optionally the topbar language selector.
|
|
19
19
|
|
|
20
20
|
```typescript
|
|
21
21
|
// app.config.ts
|
|
22
|
-
import { provideLocalization } from
|
|
22
|
+
import { provideLocalization } from "@flusys/ng-localization";
|
|
23
23
|
|
|
24
24
|
export const appConfig: ApplicationConfig = {
|
|
25
25
|
providers: [
|
|
26
26
|
provideLocalization({
|
|
27
|
-
defaultLanguageCode:
|
|
28
|
-
loadStrategy:
|
|
29
|
-
initialModules: [],
|
|
30
|
-
enableLayoutSelector: true,
|
|
27
|
+
defaultLanguageCode: "en", // required — fallback when no saved preference
|
|
28
|
+
loadStrategy: "modules", // optional — 'modules' (default) or 'all'
|
|
29
|
+
initialModules: [], // optional — modules to pre-load at startup
|
|
30
|
+
enableLayoutSelector: true, // optional — renders language picker in AppTopbar
|
|
31
31
|
}),
|
|
32
32
|
],
|
|
33
33
|
};
|
|
@@ -39,24 +39,26 @@ export const appConfig: ApplicationConfig = {
|
|
|
39
39
|
|
|
40
40
|
Import `TranslatePipe` from `@flusys/ng-shared` (not from this package). The pipe is signal-reactive and re-renders automatically on language change.
|
|
41
41
|
language
|
|
42
|
+
|
|
42
43
|
```typescript
|
|
43
|
-
import { TranslatePipe } from
|
|
44
|
+
import { TranslatePipe } from "@flusys/ng-shared";
|
|
44
45
|
|
|
45
46
|
@Component({
|
|
46
47
|
imports: [TranslatePipe],
|
|
47
48
|
template: `
|
|
48
|
-
<h1>{{
|
|
49
|
-
<button>{{
|
|
49
|
+
<h1>{{ "dashboard.title" | translate }}</h1>
|
|
50
|
+
<button>{{ "shared.save" | translate }}</button>
|
|
50
51
|
<input [placeholder]="'form.search.placeholder' | translate" />
|
|
51
52
|
|
|
52
53
|
<!-- With interpolation -->
|
|
53
|
-
<p>{{
|
|
54
|
+
<p>{{ "pagination.showing" | translate: { from: 1, to: 10, total: 100 } }}</p>
|
|
54
55
|
`,
|
|
55
56
|
})
|
|
56
57
|
export class DashboardComponent {}
|
|
57
58
|
```
|
|
58
59
|
|
|
59
60
|
Translation values stored in the database use `{{variableName}}` syntax:
|
|
61
|
+
|
|
60
62
|
```
|
|
61
63
|
Key: pagination.showing
|
|
62
64
|
Value: Showing {{from}}-{{to}} of {{total}} results
|
|
@@ -68,21 +70,22 @@ Use `resolveTranslationModule()` in your route definition so translations for a
|
|
|
68
70
|
|
|
69
71
|
```typescript
|
|
70
72
|
// Inside a feature's routes file
|
|
71
|
-
import { resolveTranslationModule } from
|
|
72
|
-
import { MY_FEATURE_MESSAGES } from
|
|
73
|
+
import { resolveTranslationModule } from "@flusys/ng-shared";
|
|
74
|
+
import { MY_FEATURE_MESSAGES } from "./constants/messages";
|
|
73
75
|
|
|
74
76
|
export const MY_ROUTES: Routes = [
|
|
75
77
|
{
|
|
76
|
-
path:
|
|
78
|
+
path: "",
|
|
77
79
|
resolve: {
|
|
78
80
|
translations: resolveTranslationModule({
|
|
79
|
-
modules: [
|
|
81
|
+
modules: ["myFeature"], // module name used by the backend
|
|
80
82
|
fallbackMessages: MY_FEATURE_MESSAGES, // static fallback map
|
|
81
83
|
}),
|
|
82
84
|
},
|
|
83
|
-
loadComponent: () => import(
|
|
84
|
-
|
|
85
|
-
|
|
85
|
+
loadComponent: () => import("./my-feature-container.component").then((m) => m.MyFeatureContainerComponent),
|
|
86
|
+
children: [
|
|
87
|
+
/* ... */
|
|
88
|
+
],
|
|
86
89
|
},
|
|
87
90
|
];
|
|
88
91
|
```
|
|
@@ -94,24 +97,24 @@ Already-loaded modules are cached — navigating back to the same route does not
|
|
|
94
97
|
Inject `TranslateService` when you need a string outside a template (e.g., toast messages, computed labels).
|
|
95
98
|
|
|
96
99
|
```typescript
|
|
97
|
-
import { inject } from
|
|
98
|
-
import { TranslateService } from
|
|
100
|
+
import { inject } from "@angular/core";
|
|
101
|
+
import { TranslateService } from "@flusys/ng-localization";
|
|
99
102
|
|
|
100
103
|
export class MyComponent {
|
|
101
104
|
private readonly translate = inject(TranslateService);
|
|
102
105
|
|
|
103
106
|
// Synchronous — returns fallback key if not found
|
|
104
107
|
getLabel(): string {
|
|
105
|
-
return this.translate.translate(
|
|
108
|
+
return this.translate.translate("shared.save");
|
|
106
109
|
}
|
|
107
110
|
|
|
108
111
|
// With params
|
|
109
112
|
getCountLabel(count: number): string {
|
|
110
|
-
return this.translate.translate(
|
|
113
|
+
return this.translate.translate("items.count", { count });
|
|
111
114
|
}
|
|
112
115
|
|
|
113
116
|
// Signal-based — updates automatically on language change
|
|
114
|
-
readonly pageTitle = this.translate.translateSignal(
|
|
117
|
+
readonly pageTitle = this.translate.translateSignal("dashboard.title");
|
|
115
118
|
|
|
116
119
|
// Read current language code
|
|
117
120
|
readonly lang = this.translate.languageCode; // Signal<string>
|
|
@@ -122,11 +125,11 @@ export class MyComponent {
|
|
|
122
125
|
|
|
123
126
|
```typescript
|
|
124
127
|
// app.routes.ts
|
|
125
|
-
import { LOCALIZATION_ROUTES } from
|
|
128
|
+
import { LOCALIZATION_ROUTES } from "@flusys/ng-localization";
|
|
126
129
|
|
|
127
130
|
export const routes: Routes = [
|
|
128
131
|
{
|
|
129
|
-
path:
|
|
132
|
+
path: "localization",
|
|
130
133
|
loadChildren: () => LOCALIZATION_ROUTES,
|
|
131
134
|
},
|
|
132
135
|
];
|