@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 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 `TRANSLATE_ADAPTER` (consumed by `TranslatePipe` from `ng-shared`), an `APP_INITIALIZER` that loads translations before the first render, and optionally the topbar language selector.
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 '@flusys/ng-localization';
22
+ import { provideLocalization } from "@flusys/ng-localization";
23
23
 
24
24
  export const appConfig: ApplicationConfig = {
25
25
  providers: [
26
26
  provideLocalization({
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
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 '@flusys/ng-shared';
44
+ import { TranslatePipe } from "@flusys/ng-shared";
44
45
 
45
46
  @Component({
46
47
  imports: [TranslatePipe],
47
48
  template: `
48
- <h1>{{ 'dashboard.title' | translate }}</h1>
49
- <button>{{ 'shared.save' | translate }}</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>{{ 'pagination.showing' | translate: { from: 1, to: 10, total: 100 } }}</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 '@flusys/ng-shared';
72
- import { MY_FEATURE_MESSAGES } from './constants/messages';
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: ['myFeature'], // module name used by the backend
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('./my-feature-container.component')
84
- .then(m => m.MyFeatureContainerComponent),
85
- children: [/* ... */],
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 '@angular/core';
98
- import { TranslateService } from '@flusys/ng-localization';
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('shared.save');
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('items.count', { count });
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('dashboard.title');
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 '@flusys/ng-localization';
128
+ import { LOCALIZATION_ROUTES } from "@flusys/ng-localization";
126
129
 
127
130
  export const routes: Routes = [
128
131
  {
129
- path: 'localization',
132
+ path: "localization",
130
133
  loadChildren: () => LOCALIZATION_ROUTES,
131
134
  },
132
135
  ];