@fundamental-ngx/i18n 0.58.0-rc.99 → 0.58.1-rc.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 +96 -15
- package/fesm2022/fundamental-ngx-i18n.mjs +256 -0
- package/fesm2022/fundamental-ngx-i18n.mjs.map +1 -1
- package/index.d.ts +14 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -18,36 +18,117 @@
|
|
|
18
18
|
|
|
19
19
|
## 1. Description
|
|
20
20
|
|
|
21
|
-
`@fundamental-ngx/i18n`
|
|
22
|
-
The library is tailored for the use in `fundamental-ngx` components and can be used for modifying the variety of the
|
|
23
|
-
components' labels, hints, and descriptions.
|
|
21
|
+
`@fundamental-ngx/i18n` provides centralized internationalization for Fundamental-ngx components with support for 37+ languages and runtime translation switching.
|
|
24
22
|
|
|
25
|
-
|
|
26
|
-
where the simple translations are needed.
|
|
23
|
+
### What's Included
|
|
27
24
|
|
|
28
|
-
|
|
29
|
-
|
|
25
|
+
- Pre-compiled translation data for 37+ languages (as `FD_LANGUAGE_*` constants)
|
|
26
|
+
- Translation resolver utilities (signals, observables, and synchronous APIs)
|
|
27
|
+
- `FdTranslatePipe` for template translations
|
|
28
|
+
- Type-safe translation keys via `FdLanguage` interface
|
|
29
|
+
|
|
30
|
+
### How It Works
|
|
31
|
+
|
|
32
|
+
1. **Source**: Translation teams provide `.properties` files (Java-style format)
|
|
33
|
+
2. **Build**: NX executor converts `.properties` → TypeScript modules
|
|
34
|
+
3. **Export**: Language constants (`FD_LANGUAGE_ENGLISH`, `FD_LANGUAGE_GERMAN`, etc.)
|
|
35
|
+
4. **Publish**: Compiled JavaScript (not source `.properties`) published to npm
|
|
36
|
+
5. **Use**: Apps import language constants and translation utilities
|
|
37
|
+
|
|
38
|
+
While designed for Fundamental-ngx components, this library works in any Angular application needing runtime-switchable translations.
|
|
39
|
+
|
|
40
|
+
### Adding New Translation Keys
|
|
41
|
+
|
|
42
|
+
> **This guide is for adding new translation keys (labels, ARIA attributes), NOT for adding new languages.**
|
|
43
|
+
|
|
44
|
+
#### Quick Steps
|
|
45
|
+
|
|
46
|
+
1. **Update interface**: Add key to [`FdLanguage`](src/lib/models/fd-language.ts) interface
|
|
47
|
+
2. **Add to all .properties files**: Same key + English text in all 37+ language files
|
|
48
|
+
3. **Run**: `nx run i18n:transform-translations`
|
|
49
|
+
4. **Use**: Import and use in your component
|
|
50
|
+
|
|
51
|
+
---
|
|
52
|
+
|
|
53
|
+
#### Step 1: Update TypeScript Interface
|
|
54
|
+
|
|
55
|
+
Add your key to `libs/i18n/src/lib/models/fd-language.ts`:
|
|
56
|
+
|
|
57
|
+
```typescript
|
|
58
|
+
export interface FdLanguage {
|
|
59
|
+
coreYourComponent: {
|
|
60
|
+
/** Description */
|
|
61
|
+
yourNewKey: FdLanguageKey;
|
|
62
|
+
keyWithParams: FdLanguageKey<{ count: number }>;
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
> **Note**: `fd-language-key-identifier.ts` is auto-generated - don't edit it manually.
|
|
68
|
+
|
|
69
|
+
#### Step 2: Add to ALL .properties Files
|
|
70
|
+
|
|
71
|
+
Add to **all** files in `libs/i18n/src/lib/translations/` (use English text everywhere):
|
|
72
|
+
|
|
73
|
+
```properties
|
|
74
|
+
#XBUT: Button / #XFLD: Label / #XTIT: Title / #XACT: ARIA / #XMSG: Message
|
|
75
|
+
coreYourComponent.yourNewKey = Your English text
|
|
76
|
+
coreYourComponent.keyWithParams = Item {count}
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
**Why all files?** TypeScript requires identical keys across all languages. Translation teams will replace English placeholders later.
|
|
80
|
+
|
|
81
|
+
#### Step 3: Generate TypeScript Files
|
|
82
|
+
|
|
83
|
+
```bash
|
|
84
|
+
nx run i18n:transform-translations
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
Auto-generates: `translations*.ts`, `fd-language-key-identifier.ts` (union type), test files
|
|
88
|
+
|
|
89
|
+
#### Step 4: Use in Components
|
|
90
|
+
|
|
91
|
+
**Template (pipe):**
|
|
92
|
+
|
|
93
|
+
```typescript
|
|
94
|
+
import { FdTranslatePipe } from '@fundamental-ngx/i18n';
|
|
95
|
+
|
|
96
|
+
@Component({
|
|
97
|
+
imports: [FdTranslatePipe],
|
|
98
|
+
template: `<button>{{ 'coreYourComponent.yourNewKey' | fdTranslate }}</button>`
|
|
99
|
+
})
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
**TypeScript (signal):**
|
|
103
|
+
|
|
104
|
+
```typescript
|
|
105
|
+
import { resolveTranslationSignal } from '@fundamental-ngx/i18n';
|
|
106
|
+
|
|
107
|
+
protected readonly label = resolveTranslationSignal('coreYourComponent.yourNewKey');
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
**Post-merge**: Translation teams will provide proper translations in future releases.
|
|
30
111
|
|
|
31
112
|
## 2. Requirements
|
|
32
113
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
114
|
+
- Node.js and npm
|
|
115
|
+
- Angular 16.2 or newer
|
|
116
|
+
- Prior Angular knowledge recommended
|
|
36
117
|
|
|
37
118
|
## 3. Versioning
|
|
38
119
|
|
|
39
|
-
|
|
120
|
+
See [Breaking Changes](https://github.com/SAP/fundamental-ngx/wiki#breaking-changes) for the latest updates.
|
|
40
121
|
|
|
41
122
|
## 4. Known Issues
|
|
42
123
|
|
|
43
|
-
|
|
124
|
+
See [Issues](https://github.com/SAP/fundamental-ngx/issues).
|
|
44
125
|
|
|
45
126
|
## 5. Support
|
|
46
127
|
|
|
47
|
-
|
|
128
|
+
[Create a ticket](https://github.com/SAP/fundamental-ngx/issues) for issues or questions.
|
|
48
129
|
|
|
49
130
|
## 6. Contributing
|
|
50
131
|
|
|
51
|
-
|
|
132
|
+
Check [CONTRIBUTING.md](https://github.com/SAP/fundamental-ngx/blob/main/CONTRIBUTING.md) for guidelines. Follow [Angular commit message guidelines](https://github.com/angular/angular/blob/main/CONTRIBUTING.md#commit).
|
|
52
133
|
|
|
53
|
-
|
|
134
|
+
See [NEW_COMPONENT.md](https://github.com/SAP/fundamental-ngx/blob/main/NEW_COMPONENT.md) for creating new components.
|