@gears-frontx/i18n 0.1.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/CLAUDE.md +134 -0
- package/dist/index.cjs +901 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +328 -0
- package/dist/index.d.ts +328 -0
- package/dist/index.js +850 -0
- package/dist/index.js.map +1 -0
- package/dist/types.cjs +98 -0
- package/dist/types.cjs.map +1 -0
- package/dist/types.d.cts +305 -0
- package/dist/types.d.ts +305 -0
- package/dist/types.js +66 -0
- package/dist/types.js.map +1 -0
- package/llms.txt +49 -0
- package/package.json +48 -0
package/CLAUDE.md
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
# @gears-frontx/i18n
|
|
2
|
+
|
|
3
|
+
Internationalization (i18n) system for HAI3 applications with 36 supported languages.
|
|
4
|
+
|
|
5
|
+
## SDK Layer
|
|
6
|
+
|
|
7
|
+
This package is part of the **SDK Layer (L1)** - it has zero dependencies and can be used independently.
|
|
8
|
+
|
|
9
|
+
## Core Concepts
|
|
10
|
+
|
|
11
|
+
### I18nRegistry
|
|
12
|
+
|
|
13
|
+
Central registry for translations:
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
import { i18nRegistry, Language } from '@gears-frontx/i18n';
|
|
17
|
+
|
|
18
|
+
// Register translations directly
|
|
19
|
+
i18nRegistry.register('common', Language.English, {
|
|
20
|
+
'app.title': 'My App',
|
|
21
|
+
'app.welcome': 'Welcome, {name}!'
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
// Or register lazy loaders
|
|
25
|
+
i18nRegistry.registerLoader('screenset.demo', {
|
|
26
|
+
[Language.English]: () => import('./i18n/en.json'),
|
|
27
|
+
[Language.Spanish]: () => import('./i18n/es.json')
|
|
28
|
+
});
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
### Translation Keys
|
|
32
|
+
|
|
33
|
+
Use namespaced keys with colon separator:
|
|
34
|
+
|
|
35
|
+
```typescript
|
|
36
|
+
// Format: namespace:key.subkey
|
|
37
|
+
const title = i18nRegistry.t('common:app.title');
|
|
38
|
+
const welcome = i18nRegistry.t('common:app.welcome', { name: 'John' });
|
|
39
|
+
|
|
40
|
+
// Screenset translations
|
|
41
|
+
const screenTitle = i18nRegistry.t('screen.demo.home:title');
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### Language Management
|
|
45
|
+
|
|
46
|
+
```typescript
|
|
47
|
+
import { i18nRegistry, Language } from '@gears-frontx/i18n';
|
|
48
|
+
|
|
49
|
+
// Set current language (async - loads translations)
|
|
50
|
+
await i18nRegistry.setLanguage(Language.Spanish);
|
|
51
|
+
|
|
52
|
+
// Get current language
|
|
53
|
+
const currentLang = i18nRegistry.getLanguage();
|
|
54
|
+
|
|
55
|
+
// Check text direction
|
|
56
|
+
const isRTL = i18nRegistry.isRTL(); // For current language
|
|
57
|
+
const isArabicRTL = i18nRegistry.isRTL(Language.Arabic); // For specific language
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### Supported Languages
|
|
61
|
+
|
|
62
|
+
36 languages including RTL support:
|
|
63
|
+
|
|
64
|
+
```typescript
|
|
65
|
+
import { Language, SUPPORTED_LANGUAGES, getRTLLanguages } from '@gears-frontx/i18n';
|
|
66
|
+
|
|
67
|
+
// Language enum
|
|
68
|
+
Language.English // 'en'
|
|
69
|
+
Language.Spanish // 'es'
|
|
70
|
+
Language.Arabic // 'ar'
|
|
71
|
+
Language.Japanese // 'ja'
|
|
72
|
+
// ... and 32 more
|
|
73
|
+
|
|
74
|
+
// Get RTL languages
|
|
75
|
+
const rtlLangs = getRTLLanguages();
|
|
76
|
+
// ['ar', 'he', 'fa', 'ur']
|
|
77
|
+
|
|
78
|
+
// Get language metadata
|
|
79
|
+
import { getLanguageMetadata } from '@gears-frontx/i18n';
|
|
80
|
+
const arabic = getLanguageMetadata(Language.Arabic);
|
|
81
|
+
// { code: 'ar', name: 'Arabic', nativeName: 'العربية', rtl: true }
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### Translation Loader Factory
|
|
85
|
+
|
|
86
|
+
Create loaders for screenset translations:
|
|
87
|
+
|
|
88
|
+
```typescript
|
|
89
|
+
import { I18nRegistryImpl, Language } from '@gears-frontx/i18n';
|
|
90
|
+
|
|
91
|
+
const screenTranslations = I18nRegistryImpl.createLoader({
|
|
92
|
+
[Language.English]: () => import('./i18n/en.json'),
|
|
93
|
+
[Language.Spanish]: () => import('./i18n/es.json'),
|
|
94
|
+
[Language.French]: () => import('./i18n/fr.json'),
|
|
95
|
+
// ... all 36 languages
|
|
96
|
+
});
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## Translation Key Conventions
|
|
100
|
+
|
|
101
|
+
| Type | Pattern | Example |
|
|
102
|
+
|------|---------|---------|
|
|
103
|
+
| Screenset-level | `screenset.{id}:key` | `screenset.demo:name` |
|
|
104
|
+
| Screen-level | `screen.{screenset}.{screen}:key` | `screen.demo.home:title` |
|
|
105
|
+
| Common | `common:key` | `common:buttons.save` |
|
|
106
|
+
|
|
107
|
+
## RTL Languages
|
|
108
|
+
|
|
109
|
+
The following languages are RTL:
|
|
110
|
+
- Arabic (ar)
|
|
111
|
+
- Hebrew (he)
|
|
112
|
+
- Persian (fa)
|
|
113
|
+
- Urdu (ur)
|
|
114
|
+
|
|
115
|
+
Use `isRTL()` to check and apply appropriate styles.
|
|
116
|
+
|
|
117
|
+
## Key Rules
|
|
118
|
+
|
|
119
|
+
1. **Namespace translations** - Use `namespace:key` format
|
|
120
|
+
2. **Lazy load screen translations** - Load only when screen mounts
|
|
121
|
+
3. **Use parameter interpolation** - `{param}` syntax for dynamic values
|
|
122
|
+
4. **Handle RTL** - Check `isRTL()` for text direction
|
|
123
|
+
|
|
124
|
+
## Exports
|
|
125
|
+
|
|
126
|
+
- `i18nRegistry` - Singleton registry instance
|
|
127
|
+
- `I18nRegistryImpl` - Registry class (for testing/custom instances)
|
|
128
|
+
- `Language` - Enum of 36 language codes
|
|
129
|
+
- `SUPPORTED_LANGUAGES` - Array of language metadata
|
|
130
|
+
- `getLanguageMetadata` - Get metadata for language
|
|
131
|
+
- `getRTLLanguages` - Get list of RTL languages
|
|
132
|
+
- `isValidLanguage` - Type guard for language codes
|
|
133
|
+
- `TranslationLoader` - Loader function type
|
|
134
|
+
- `TranslationDictionary` - Flat translation object type
|