@genesislcap/foundation-i18n 14.408.0 → 14.409.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/README.md CHANGED
@@ -1,308 +1,21 @@
1
- # Genesis Foundation i18n
1
+ # @genesislcap/foundation-i18n
2
2
 
3
- The `@genesislcap/foundation-i18n` package provides a collection of i18n services and utilities for Genesis applications. It leverages the power of [i18next](https://www.i18next.com/) to enable seamless internationalization and localization.
3
+ Documentation for this package is published on the Genesis docs site:
4
4
 
5
- ### API Documentation
5
+ **Docs: [Internationalization](https://docs.genesis.global/docs/develop/client-capabilities/internationalization/)**
6
6
 
7
- For more detailed information on API and configurations, please refer to the [API documentation](docs/api/index.md) in the `docs/api` directory.
7
+ ## Installation
8
8
 
9
- ## Features
10
-
11
- - **Easy integration**: Quick setup with modern JavaScript frameworks and libraries.
12
- - **Dynamic language switching**: Change languages on the fly without reloading the application.
13
- - **Module federation support**: Share and load translations across different micro-frontends or modules dynamically.
14
- - **Dependency injection**: Integrate i18n services into your components using dependency injection.
15
-
16
- ## Project Structure
17
-
18
- - `src/`: Source code for the library, including the core `i18n` functionality and utility functions.
19
- - `i18n/`: Core internationalization logic and configurations.
20
- - `utils/`: Utility functions supporting the core features.
21
- - `docs/`: Documentation, including API details and usage guides.
22
-
23
- ## Getting Started
24
-
25
- ### Installation
26
-
27
- To enable this module in your application, follow the steps below.
28
-
29
- 1. Add `@genesislcap/foundation-i18n` as a dependency in your `package.json` file. Whenever you change the dependencies of your project, ensure you run the `$ npm run bootstrap` command again. You can find more information in the [package.json basics](https://learn.genesis.global/secure/web/basics/package-json-basics/) page.
9
+ Add the package to your `package.json` dependencies. After changing dependencies, run `npm run bootstrap` (or your project's equivalent). See [package.json basics](https://learn.genesis.global/secure/web/basics/package-json-basics/) for more information.
30
10
 
31
11
  ```json
32
12
  {
33
13
  "dependencies": {
34
14
  "@genesislcap/foundation-i18n": "latest"
35
- },
36
- }
37
- ```
38
-
39
- ### I18n Setup
40
-
41
- Import the necessary modules from `@genesislcap/foundation-i18n` and configure your internationalization settings.
42
-
43
- ```typescript
44
- import { defaultI18nextConfig, I18nextConfig } from '@genesislcap/foundation-i18n';
45
-
46
- // Tip: Extend or modify the defaultI18nextConfig as needed.
47
- Registration.instance<I18nextConfig>(I18nextConfig, {
48
- ...defaultI18nextConfig,
49
- lng: 'pt', // en is the default language but you can change it here or by tweaking the defaultI18nextConfig
50
- resources: {
51
- en: {
52
- translation: {
53
- Home: 'Home',
54
- Admin: 'Admin',
55
- Reporting: 'Reporting',
56
- Notifications: 'Notifications',
57
- ['Features Lab']: 'Features Lab',
58
- },
59
- },
60
- pt: {
61
- translation: {
62
- Home: 'Início',
63
- Admin: 'Administração',
64
- Reporting: 'Relatórios',
65
- Notifications: 'Notificações',
66
- ['Features Lab']: 'Laboratório de Funcionalidades',
67
- },
68
- },
69
- },
70
- });
71
- ```
72
-
73
- This could live in your application’s entry point, such as `main.ts` or a similar file.
74
-
75
- ### I18n Setup (JSON)
76
-
77
- You can also use a JSON file to store your translations and load them dynamically:
78
-
79
- ```json
80
- {
81
- "en": {
82
- "translation": {
83
- "Home": "Home",
84
- "Admin": "Admin",
85
- "Reporting": "Reporting",
86
- "Notifications": "Notifications",
87
- "Features Lab": "Features Lab"
88
- }
89
- },
90
- "pt": {
91
- "translation": {
92
- "Home": "Início",
93
- "Admin": "Administração",
94
- "Reporting": "Relatórios",
95
- "Notifications": "Notificações",
96
- "Features Lab": "Laboratório de Funcionalidades"
97
- }
98
15
  }
99
16
  }
100
17
  ```
101
18
 
102
- Then, import the JSON file and use it in your configuration:
103
-
104
- ```typescript
105
- import { defaultI18nextConfig, I18nextConfig } from '@genesislcap/foundation-i18n';
106
- import translations from './translations.json';
107
-
108
- Registration.instance<I18nextConfig>(I18nextConfig, {
109
- ...defaultI18nextConfig,
110
- lng: 'en',
111
- resources: translations,
112
- });
113
- ```
114
-
115
- ### `addResources`
116
-
117
- > :warning: **This will overwrite previously set resources.**
118
-
119
- You can also add resources dynamically and when necessary.
120
-
121
- This is useful when you have a large number of translations or when you need to load translations from a different source or at a different time from the initial setup.
122
-
123
- ```typescript
124
- import { I18next } from '@genesislcap/foundation-i18n';
125
- import translations from './translations.json';
126
-
127
- export class MyExampleClass {
128
- @I18next i18next!: I18next;
129
-
130
- addResources() {
131
- this.i18next.addResources(translations);
132
- }
133
- }
134
- ```
135
-
136
- ### Usage
137
-
138
- `foundation-i18n` also supports changing languages dynamically, allowing your application to switch languages without needing to reload:
139
-
140
- ```typescript
141
- import { I18next } from '@genesislcap/foundation-i18n';
142
- import { customElement, FASTElement, html } from '@microsoft/fast-element';
143
- import translations from './translations.json';
144
-
145
- @customElement({
146
- name: 'my-example-component',
147
- template: html`
148
- <zero-button @click=${() => addResources()}>Add Translation Resources</zero-button>
149
- <zero-button @click=${() => switchLanguage()}>Switch between PT and EN</zero-button>
150
- <zero-button @click=${() => translateWords()}>Translate i18n Resource Words</zero-button>
151
- `,
152
- })
153
- export class MyExampleComponent extends FASTElement {
154
- @I18next i18next!: I18next;
155
-
156
- addResources() {
157
- this.i18next.addResources(translations);
158
- }
159
-
160
- switchLanguage() {
161
- if (this.i18next.language === 'pt') {
162
- this.i18next.changeLanguage('en');
163
- } else {
164
- this.i18next.changeLanguage('pt');
165
- }
166
- }
167
-
168
- translateWords() {
169
- console.log(this.i18next.t('Home')); // if pt, it will log Início, if en, it will log Home
170
- console.log(this.i18next.t('Admin')); // if pt, it will log Administração, if en, it will log Admin
171
- console.log(this.i18next.t('Reporting')); // if pt, it will log Relatórios, if en, it will log Reporting
172
- console.log(this.i18next.t('Notifications')); // if pt, it will log Notificações, if en, it will log Notifications
173
- console.log(this.i18next.t('Features Lab')); // if pt, it will log Laboratório de Funcionalidades, if en, it will log Features Lab
174
- }
175
- }
176
- ```
177
-
178
- ### Integrating with Other Libraries
179
-
180
- #### Angular Example
181
-
182
- To integrate `@genesislcap/foundation-i18n` with an Angular application, you can configure `i18next` in a service and use it throughout your components.
183
-
184
- **i18n.service.ts**
185
-
186
- ```typescript
187
- import { Injectable } from '@angular/core';
188
- import { defaultI18nextConfig, I18next } from '@genesislcap/foundation-i18n';
189
- import translations from './translations.json';
190
- import { DI } from '@microsoft/fast-element';
191
-
192
- @Injectable({
193
- providedIn: 'root',
194
- })
195
- export class I18nService {
196
- private container = DI.getOrCreateDOMContainer();
197
- private i18n = this.container.get(I18nService);
198
-
199
- constructor() {
200
- this.i18n.init({
201
- ...defaultI18nextConfig,
202
- lng: 'en',
203
- resources: translations,
204
- });
205
- }
206
-
207
- switchLanguage() {
208
- const newLanguage = this.i18n.language === 'en' ? 'pt' : 'en';
209
- this.i18n.changeLanguage(newLanguage);
210
- }
211
-
212
- translate(key: string): string {
213
- return this.i18n.t(key);
214
- }
215
- }
216
- ```
217
-
218
- **app.component.ts**
219
-
220
- ```typescript
221
- import { Component } from '@angular/core';
222
- import { I18nService } from './i18n.service';
223
-
224
- @Component({
225
- selector: 'app-root',
226
- template: `
227
- <button (click)="switchLanguage()">Switch Language</button>
228
- <p>{{ translate('Home') }}</p>
229
- <p>{{ translate('Admin') }}</p>
230
- <p>{{ translate('Reporting') }}</p>
231
- `,
232
- })
233
- export class AppComponent {
234
- constructor(private i18nService: I18nService) {}
235
-
236
- switchLanguage() {
237
- this.i18nService.switchLanguage();
238
- }
239
-
240
- translate(key: string): string {
241
- return this.i18nService.translate(key);
242
- }
243
- }
244
- ```
245
-
246
- #### React Example
247
-
248
- To integrate `@genesislcap/foundation-i18n` with a React application, you can create a separate service for handling `i18next` similar to how you would create other services.
249
-
250
- **i18nService.js**
251
-
252
- ```javascript
253
- import { defaultI18nextConfig, I18next } from '@genesislcap/foundation-i18n';
254
- import { DI } from '@microsoft/fast-foundation';
255
- import translations from './translations.json';
256
-
257
- class I18nService {
258
- private container = DI.getOrCreateDOMContainer();
259
- private i18n: Connect = this.container.get(I18next);
260
-
261
- constructor() {
262
- this.i18n.init({
263
- ...defaultI18nextConfig,
264
- lng: 'en',
265
- resources: translations,
266
- });
267
- }
268
-
269
- switchLanguage() {
270
- const newLanguage = this.i18n.language === 'en' ? 'pt' : 'en';
271
- this.i18n.changeLanguage(newLanguage);
272
- }
273
-
274
- translate(key) {
275
- return this.i18n.t(key);
276
- }
277
- }
278
-
279
- export const i18nService = new I18nService();
280
- ```
281
-
282
- **App.js**
283
-
284
- ```jsx
285
- import React from 'react';
286
- import { i18nService } from './i18nService';
287
-
288
- const App = () => {
289
- const switchLanguage = () => {
290
- i18nService.switchLanguage();
291
- };
292
-
293
- return (
294
- <div>
295
- <button onClick={switchLanguage}>Switch Language</button>
296
- <p>{i18nService.translate('Home')}</p>
297
- <p>{i18nService.translate('Admin')}</p>
298
- <p>{i18nService.translate('Reporting')}</p>
299
- </div>
300
- );
301
- };
302
-
303
- export default App;
304
- ```
305
-
306
19
  ## License
307
20
 
308
21
  Note: this project provides front-end dependencies and uses licensed components listed in the next section; thus, licenses for those components are required during development. Contact [Genesis Global](https://genesis.global/contact-us/) for more details.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@genesislcap/foundation-i18n",
3
3
  "description": "Foundation components and services for Internationalization (i18n) support",
4
- "version": "14.408.0",
4
+ "version": "14.409.0",
5
5
  "sideEffects": false,
6
6
  "license": "SEE LICENSE IN license.txt",
7
7
  "main": "dist/esm/index.js",
@@ -33,15 +33,15 @@
33
33
  }
34
34
  },
35
35
  "devDependencies": {
36
- "@genesislcap/genx": "14.408.0",
37
- "@genesislcap/rollup-builder": "14.408.0",
38
- "@genesislcap/ts-builder": "14.408.0",
39
- "@genesislcap/uvu-playwright-builder": "14.408.0",
40
- "@genesislcap/vite-builder": "14.408.0",
41
- "@genesislcap/webpack-builder": "14.408.0"
36
+ "@genesislcap/genx": "14.409.0",
37
+ "@genesislcap/rollup-builder": "14.409.0",
38
+ "@genesislcap/ts-builder": "14.409.0",
39
+ "@genesislcap/uvu-playwright-builder": "14.409.0",
40
+ "@genesislcap/vite-builder": "14.409.0",
41
+ "@genesislcap/webpack-builder": "14.409.0"
42
42
  },
43
43
  "dependencies": {
44
- "@genesislcap/foundation-logger": "14.408.0",
44
+ "@genesislcap/foundation-logger": "14.409.0",
45
45
  "@microsoft/fast-element": "1.14.0",
46
46
  "@microsoft/fast-foundation": "2.50.0",
47
47
  "i18next": "^20.3.0"
@@ -54,5 +54,5 @@
54
54
  "publishConfig": {
55
55
  "access": "public"
56
56
  },
57
- "gitHead": "26b08831fd001b4ee95c8a0d3364a18c0ec4005b"
57
+ "gitHead": "cbe0459d170f27c35a7de18cec415947aedf4da5"
58
58
  }
@@ -1,13 +0,0 @@
1
- <!-- Do not edit this file. It is automatically generated by API Documenter. -->
2
-
3
- [Home](./index.md) &gt; [@genesislcap/foundation-i18n](./foundation-i18n.md) &gt; [DefaultI18next](./foundation-i18n.defaulti18next.md) &gt; [(constructor)](./foundation-i18n.defaulti18next._constructor_.md)
4
-
5
- ## DefaultI18next.(constructor)
6
-
7
- Constructs a new instance of the `DefaultI18next` class
8
-
9
- **Signature:**
10
-
11
- ```typescript
12
- constructor();
13
- ```
@@ -1,50 +0,0 @@
1
- <!-- Do not edit this file. It is automatically generated by API Documenter. -->
2
-
3
- [Home](./index.md) &gt; [@genesislcap/foundation-i18n](./foundation-i18n.md) &gt; [DefaultI18next](./foundation-i18n.defaulti18next.md) &gt; [addResources](./foundation-i18n.defaulti18next.addresources.md)
4
-
5
- ## DefaultI18next.addResources() method
6
-
7
- **Signature:**
8
-
9
- ```typescript
10
- addResources(resources: Resource): void;
11
- ```
12
-
13
- ## Parameters
14
-
15
- <table><thead><tr><th>
16
-
17
- Parameter
18
-
19
-
20
- </th><th>
21
-
22
- Type
23
-
24
-
25
- </th><th>
26
-
27
- Description
28
-
29
-
30
- </th></tr></thead>
31
- <tbody><tr><td>
32
-
33
- resources
34
-
35
-
36
- </td><td>
37
-
38
- Resource
39
-
40
-
41
- </td><td>
42
-
43
-
44
- </td></tr>
45
- </tbody></table>
46
-
47
- **Returns:**
48
-
49
- void
50
-
@@ -1,50 +0,0 @@
1
- <!-- Do not edit this file. It is automatically generated by API Documenter. -->
2
-
3
- [Home](./index.md) &gt; [@genesislcap/foundation-i18n](./foundation-i18n.md) &gt; [DefaultI18next](./foundation-i18n.defaulti18next.md) &gt; [changeLanguageTo](./foundation-i18n.defaulti18next.changelanguageto.md)
4
-
5
- ## DefaultI18next.changeLanguageTo() method
6
-
7
- **Signature:**
8
-
9
- ```typescript
10
- changeLanguageTo(language: string): void;
11
- ```
12
-
13
- ## Parameters
14
-
15
- <table><thead><tr><th>
16
-
17
- Parameter
18
-
19
-
20
- </th><th>
21
-
22
- Type
23
-
24
-
25
- </th><th>
26
-
27
- Description
28
-
29
-
30
- </th></tr></thead>
31
- <tbody><tr><td>
32
-
33
- language
34
-
35
-
36
- </td><td>
37
-
38
- string
39
-
40
-
41
- </td><td>
42
-
43
-
44
- </td></tr>
45
- </tbody></table>
46
-
47
- **Returns:**
48
-
49
- void
50
-
@@ -1,11 +0,0 @@
1
- <!-- Do not edit this file. It is automatically generated by API Documenter. -->
2
-
3
- [Home](./index.md) &gt; [@genesislcap/foundation-i18n](./foundation-i18n.md) &gt; [DefaultI18next](./foundation-i18n.defaulti18next.md) &gt; [config](./foundation-i18n.defaulti18next.config.md)
4
-
5
- ## DefaultI18next.config property
6
-
7
- **Signature:**
8
-
9
- ```typescript
10
- config: I18nextConfig;
11
- ```
@@ -1,66 +0,0 @@
1
- <!-- Do not edit this file. It is automatically generated by API Documenter. -->
2
-
3
- [Home](./index.md) &gt; [@genesislcap/foundation-i18n](./foundation-i18n.md) &gt; [DefaultI18next](./foundation-i18n.defaulti18next.md) &gt; [init](./foundation-i18n.defaulti18next.init.md)
4
-
5
- ## DefaultI18next.init() method
6
-
7
- **Signature:**
8
-
9
- ```typescript
10
- init(options: InitOptions, callback?: Callback): Promise<TFunction>;
11
- ```
12
-
13
- ## Parameters
14
-
15
- <table><thead><tr><th>
16
-
17
- Parameter
18
-
19
-
20
- </th><th>
21
-
22
- Type
23
-
24
-
25
- </th><th>
26
-
27
- Description
28
-
29
-
30
- </th></tr></thead>
31
- <tbody><tr><td>
32
-
33
- options
34
-
35
-
36
- </td><td>
37
-
38
- InitOptions
39
-
40
-
41
- </td><td>
42
-
43
-
44
- </td></tr>
45
- <tr><td>
46
-
47
- callback
48
-
49
-
50
- </td><td>
51
-
52
- Callback
53
-
54
-
55
- </td><td>
56
-
57
- _(Optional)_
58
-
59
-
60
- </td></tr>
61
- </tbody></table>
62
-
63
- **Returns:**
64
-
65
- Promise&lt;TFunction&gt;
66
-
@@ -1,11 +0,0 @@
1
- <!-- Do not edit this file. It is automatically generated by API Documenter. -->
2
-
3
- [Home](./index.md) &gt; [@genesislcap/foundation-i18n](./foundation-i18n.md) &gt; [DefaultI18next](./foundation-i18n.defaulti18next.md) &gt; [language](./foundation-i18n.defaulti18next.language.md)
4
-
5
- ## DefaultI18next.language property
6
-
7
- **Signature:**
8
-
9
- ```typescript
10
- language: string;
11
- ```