@hakistack/i18n 0.0.0-stage → 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/LICENSE +21 -0
- package/README.md +151 -2
- package/cli/bin.cjs +940 -0
- package/fesm2022/hakistack-i18n-engine.mjs +339 -0
- package/fesm2022/hakistack-i18n-engine.mjs.map +1 -0
- package/fesm2022/hakistack-i18n.mjs +475 -0
- package/fesm2022/hakistack-i18n.mjs.map +1 -0
- package/package.json +61 -4
- package/schematics/collection.json +15 -0
- package/schematics/ng-add/index.cjs +301 -0
- package/schematics/ng-add/index.cjs.map +1 -0
- package/schematics/ng-add/schema.js +3 -0
- package/schematics/ng-add/schema.js.map +1 -0
- package/schematics/ng-add/schema.json +37 -0
- package/types/hakistack-i18n-engine.d.ts +260 -0
- package/types/hakistack-i18n.d.ts +334 -0
|
@@ -0,0 +1,475 @@
|
|
|
1
|
+
import { buildLanguageTree, buildScopedTree, buildKeysTree } from '@hakistack/i18n/engine';
|
|
2
|
+
export { SOURCE_LANG, TRANSLATION_BRAND, buildEagerTree, buildKeysTree, buildLanguageTree, buildScopedTree, defineTranslations, extractLanguage, getTranslation, isTranslationValue, normalizeScope, scopeToFilesystemPath, setAtScope, t } from '@hakistack/i18n/engine';
|
|
3
|
+
import * as i0 from '@angular/core';
|
|
4
|
+
import { Injectable, InjectionToken, inject, DOCUMENT, signal, isDevMode, provideAppInitializer, makeEnvironmentProviders, TemplateRef, ViewContainerRef, effect, untracked, Directive } from '@angular/core';
|
|
5
|
+
import { TranslocoService, provideTransloco, provideTranslocoInterceptor, provideTranslocoMissingHandler } from '@jsverse/transloco';
|
|
6
|
+
export { translateObjectSignal, translateSignal } from '@jsverse/transloco';
|
|
7
|
+
import { HttpClient } from '@angular/common/http';
|
|
8
|
+
import { firstValueFrom, of } from 'rxjs';
|
|
9
|
+
import { toSignal } from '@angular/core/rxjs-interop';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Strips `<key>.comment` siblings before translations enter Transloco's store.
|
|
13
|
+
*
|
|
14
|
+
* Translator-context comments (added via `t('en', { es: '…' }, { comment })`)
|
|
15
|
+
* are emitted into the runtime tree alongside their target keys — useful for
|
|
16
|
+
* translator review in the JSON, but they must never be looked up at runtime.
|
|
17
|
+
* Without this interceptor, a typo'd translate call could render comment text.
|
|
18
|
+
*/
|
|
19
|
+
class TranslocoCommentInterceptor {
|
|
20
|
+
preSaveTranslation(translation) {
|
|
21
|
+
return stripCommentKeys(translation);
|
|
22
|
+
}
|
|
23
|
+
preSaveTranslationKey(_key, value) {
|
|
24
|
+
return value;
|
|
25
|
+
}
|
|
26
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.10", ngImport: i0, type: TranslocoCommentInterceptor, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
27
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.10", ngImport: i0, type: TranslocoCommentInterceptor });
|
|
28
|
+
}
|
|
29
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.10", ngImport: i0, type: TranslocoCommentInterceptor, decorators: [{
|
|
30
|
+
type: Injectable
|
|
31
|
+
}] });
|
|
32
|
+
function stripCommentKeys(node) {
|
|
33
|
+
if (node === null || typeof node !== 'object')
|
|
34
|
+
return node;
|
|
35
|
+
const out = {};
|
|
36
|
+
for (const [key, value] of Object.entries(node)) {
|
|
37
|
+
if (key.endsWith('.comment'))
|
|
38
|
+
continue;
|
|
39
|
+
out[key] = stripCommentKeys(value);
|
|
40
|
+
}
|
|
41
|
+
return out;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* The merged keys tree (`TK`) provided by {@link provideI18n}.
|
|
46
|
+
*
|
|
47
|
+
* Holds the consumer's nested object of dot-path key strings — the exact shape
|
|
48
|
+
* the scanner emits as the typed `TK` literal. `TranslateDirectiveBase` injects
|
|
49
|
+
* this instead of importing `TK` directly, so the library never depends on a
|
|
50
|
+
* consumer-generated symbol. Casing of keys is irrelevant at runtime: the
|
|
51
|
+
* directive reads string leaves and calls `transloco.translate(leaf)`.
|
|
52
|
+
*/
|
|
53
|
+
const I18N_KEYS = new InjectionToken('I18N_KEYS');
|
|
54
|
+
/** Fully-resolved runtime config, shared with the loader and missing handler. */
|
|
55
|
+
const I18N_RUNTIME_CONFIG = new InjectionToken('I18N_RUNTIME_CONFIG');
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* HTTP-based translation loader — fetches `<assetsPath>/<lang>.json` over HTTP.
|
|
59
|
+
*
|
|
60
|
+
* Selected via `provideI18n({ loader: 'http' })`. Consumes the same JSON files
|
|
61
|
+
* the generator emits, so switching loaders requires no other change.
|
|
62
|
+
*
|
|
63
|
+
* **Prefer the registry loader unless ANY of these are true:**
|
|
64
|
+
* - Translation payload exceeds ~50KB per language (JS bundle bloat matters).
|
|
65
|
+
* - The translation team needs to push updates without a code deploy.
|
|
66
|
+
* - 5+ locales where CDN-cached per-locale loading matters.
|
|
67
|
+
* - `provideTranslocoScope` lazy loading is adopted per route.
|
|
68
|
+
*
|
|
69
|
+
* **Costs:** reintroduces the runtime HTTP fetch (network race, offline issues),
|
|
70
|
+
* SSR needs absolute URLs, and the "JSON drifted from TS" mode returns unless
|
|
71
|
+
* the generator runs in the deploy pipeline.
|
|
72
|
+
*/
|
|
73
|
+
class TranslocoHttpLoader {
|
|
74
|
+
http = inject(HttpClient);
|
|
75
|
+
config = inject(I18N_RUNTIME_CONFIG);
|
|
76
|
+
getTranslation(lang) {
|
|
77
|
+
// Transloco passes scoped requests as `<scope>/<lang>`; our generator emits
|
|
78
|
+
// dotted scopes as nested dirs (`administration.users` → `administration/users/<lang>.json`),
|
|
79
|
+
// so map dots to slashes. Lang codes never contain dots, so this is safe.
|
|
80
|
+
const path = lang.replace(/\./g, '/');
|
|
81
|
+
return this.http.get(`${this.config.assetsPath}/${path}.json`);
|
|
82
|
+
}
|
|
83
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.10", ngImport: i0, type: TranslocoHttpLoader, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
84
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.10", ngImport: i0, type: TranslocoHttpLoader });
|
|
85
|
+
}
|
|
86
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.10", ngImport: i0, type: TranslocoHttpLoader, decorators: [{
|
|
87
|
+
type: Injectable
|
|
88
|
+
}] });
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* App-level active-language wrapper around `TranslocoService` with localStorage
|
|
92
|
+
* persistence and `<html lang>` syncing.
|
|
93
|
+
*
|
|
94
|
+
* Wired automatically when `provideI18n({ persistLanguage: true })` is set
|
|
95
|
+
* (an APP_INITIALIZER restores the stored language on bootstrap). It's also
|
|
96
|
+
* exported for direct use — inject it to build a language switcher:
|
|
97
|
+
*
|
|
98
|
+
* ```ts
|
|
99
|
+
* private readonly i18nLang = inject(LanguageService);
|
|
100
|
+
* switch(lang: string) { this.i18nLang.setLanguage(lang); }
|
|
101
|
+
* ```
|
|
102
|
+
*/
|
|
103
|
+
class LanguageService {
|
|
104
|
+
STORAGE_KEY = 'hakistack_i18n_lang';
|
|
105
|
+
transloco = inject(TranslocoService);
|
|
106
|
+
document = inject(DOCUMENT);
|
|
107
|
+
defaultLanguage = this.transloco.getDefaultLang();
|
|
108
|
+
/** Available languages from Transloco config. */
|
|
109
|
+
availableLanguages = this.transloco.getAvailableLangs();
|
|
110
|
+
/** Current active language (reactive signal). */
|
|
111
|
+
language = signal(this.getStoredLanguage(), ...(ngDevMode ? [{ debugName: "language" }] : /* istanbul ignore next */ []));
|
|
112
|
+
async initializeLanguage() {
|
|
113
|
+
await this.setLanguage(this.getStoredLanguage());
|
|
114
|
+
}
|
|
115
|
+
async setLanguage(lang) {
|
|
116
|
+
try {
|
|
117
|
+
await firstValueFrom(this.transloco.load(lang));
|
|
118
|
+
this.transloco.setActiveLang(lang);
|
|
119
|
+
this.saveLanguage(lang);
|
|
120
|
+
this.language.set(lang);
|
|
121
|
+
this.document.documentElement.setAttribute('lang', lang);
|
|
122
|
+
}
|
|
123
|
+
catch (error) {
|
|
124
|
+
console.warn(`Failed to load language '${lang}', falling back to default`, error);
|
|
125
|
+
if (lang !== this.defaultLanguage) {
|
|
126
|
+
await this.setLanguage(this.defaultLanguage);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
/** Is `lang` one of the configured available languages? */
|
|
131
|
+
isAvailable(lang) {
|
|
132
|
+
return this.availableLanguages.some((l) => (typeof l === 'string' ? l : l.id) === lang);
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Stored language, or the default when nothing is stored, storage is
|
|
136
|
+
* unavailable (SSR), or the stored value is no longer an available language
|
|
137
|
+
* (stale/garbage localStorage must never become the active `<html lang>`).
|
|
138
|
+
*/
|
|
139
|
+
getStoredLanguage() {
|
|
140
|
+
const storage = this.storage();
|
|
141
|
+
if (!storage)
|
|
142
|
+
return this.defaultLanguage;
|
|
143
|
+
try {
|
|
144
|
+
const stored = storage.getItem(this.STORAGE_KEY);
|
|
145
|
+
return stored && this.isAvailable(stored) ? stored : this.defaultLanguage;
|
|
146
|
+
}
|
|
147
|
+
catch (error) {
|
|
148
|
+
console.warn('Failed to read language from localStorage:', error);
|
|
149
|
+
return this.defaultLanguage;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
saveLanguage(lang) {
|
|
153
|
+
const storage = this.storage();
|
|
154
|
+
if (!storage)
|
|
155
|
+
return;
|
|
156
|
+
try {
|
|
157
|
+
storage.setItem(this.STORAGE_KEY, lang);
|
|
158
|
+
}
|
|
159
|
+
catch (error) {
|
|
160
|
+
console.warn('Failed to save language to localStorage:', error);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
/** `localStorage` when it exists (browser); `null` on the server. */
|
|
164
|
+
storage() {
|
|
165
|
+
return typeof localStorage === 'undefined' ? null : localStorage;
|
|
166
|
+
}
|
|
167
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.10", ngImport: i0, type: LanguageService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
168
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.10", ngImport: i0, type: LanguageService, providedIn: 'root' });
|
|
169
|
+
}
|
|
170
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.10", ngImport: i0, type: LanguageService, decorators: [{
|
|
171
|
+
type: Injectable,
|
|
172
|
+
args: [{ providedIn: 'root' }]
|
|
173
|
+
}] });
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Missing-key handler that surfaces failures in dev mode.
|
|
177
|
+
*
|
|
178
|
+
* Default Transloco behavior returns `''` for missing keys, making typos
|
|
179
|
+
* invisible in the UI. With `missingKeyInDev: 'show'` (the default) this returns
|
|
180
|
+
* `[scope.key]` in dev so missing-key bugs jump out immediately. In production,
|
|
181
|
+
* behavior is always `''`.
|
|
182
|
+
*
|
|
183
|
+
* The build-time validator remains the source of truth for *static* keys; this
|
|
184
|
+
* handler catches dynamic / `selectTranslate(varKey)` / typo cases.
|
|
185
|
+
*/
|
|
186
|
+
class TranslocoVisibleMissingHandler {
|
|
187
|
+
config = inject(I18N_RUNTIME_CONFIG);
|
|
188
|
+
handle(key, _data) {
|
|
189
|
+
if (isDevMode() && this.config.missingKeyInDev === 'show') {
|
|
190
|
+
return `[${key}]`;
|
|
191
|
+
}
|
|
192
|
+
return '';
|
|
193
|
+
}
|
|
194
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.10", ngImport: i0, type: TranslocoVisibleMissingHandler, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
195
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.10", ngImport: i0, type: TranslocoVisibleMissingHandler });
|
|
196
|
+
}
|
|
197
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.10", ngImport: i0, type: TranslocoVisibleMissingHandler, decorators: [{
|
|
198
|
+
type: Injectable
|
|
199
|
+
}] });
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Translation loader backed by the in-memory module registry.
|
|
203
|
+
*
|
|
204
|
+
* Reads directly from the registry passed to {@link provideI18n} and assembles
|
|
205
|
+
* a per-language tree on demand. No HTTP request, no `assets/i18n/<lang>.json`
|
|
206
|
+
* fetch at runtime — those JSON files are translator-facing build artifacts only.
|
|
207
|
+
*
|
|
208
|
+
* Wins:
|
|
209
|
+
* - Synchronous-after-import. No race between bootstrap and translation load.
|
|
210
|
+
* - Single source of truth at runtime — the "JSON drifted from TS" failure
|
|
211
|
+
* mode becomes structurally impossible.
|
|
212
|
+
* - Works offline; no service-worker config needed for i18n.
|
|
213
|
+
* - SSR-safe: no absolute-URL gotchas.
|
|
214
|
+
*/
|
|
215
|
+
class TranslocoRegistryLoader {
|
|
216
|
+
config = inject(I18N_RUNTIME_CONFIG);
|
|
217
|
+
getTranslation(input) {
|
|
218
|
+
// Transloco constructs scoped requests as `<scope>/<lang>` (e.g. `'home/en'`).
|
|
219
|
+
// Plain `'en'` is the unscoped root request.
|
|
220
|
+
const slashIdx = input.lastIndexOf('/');
|
|
221
|
+
if (slashIdx === -1) {
|
|
222
|
+
// No scope provider in play — return the full tree (eager + every scoped
|
|
223
|
+
// module merged at its scope path).
|
|
224
|
+
return of(buildLanguageTree(this.config.registry, input, this.config.fallbackLang));
|
|
225
|
+
}
|
|
226
|
+
// Scoped request — return ONLY that scope's data, unwrapped (Transloco
|
|
227
|
+
// namespaces it back under the scope key in its internal store). The scope
|
|
228
|
+
// arrives in slash form (`administration/users`); `buildScopedTree`
|
|
229
|
+
// normalizes it against the registry's dotted scopes.
|
|
230
|
+
const scope = input.substring(0, slashIdx);
|
|
231
|
+
const lang = input.substring(slashIdx + 1);
|
|
232
|
+
const tree = buildScopedTree(this.config.registry, lang, this.config.fallbackLang, scope);
|
|
233
|
+
return of((tree ?? {}));
|
|
234
|
+
}
|
|
235
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.10", ngImport: i0, type: TranslocoRegistryLoader, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
236
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.10", ngImport: i0, type: TranslocoRegistryLoader });
|
|
237
|
+
}
|
|
238
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.10", ngImport: i0, type: TranslocoRegistryLoader, decorators: [{
|
|
239
|
+
type: Injectable
|
|
240
|
+
}] });
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* One-call i18n setup for a consumer app.
|
|
244
|
+
*
|
|
245
|
+
* Collapses what used to be a hand-written `provideTransloco(...)` config plus
|
|
246
|
+
* a list of custom hooks (`provideTranslocoInterceptor`,
|
|
247
|
+
* `provideTranslocoMissingHandler`) into a single provider. Wires:
|
|
248
|
+
* - Transloco with the registry loader (or HTTP loader).
|
|
249
|
+
* - The comment-stripping interceptor + the visible missing-key handler.
|
|
250
|
+
* - `I18N_KEYS` (the runtime `TK` tree) for the translate directive.
|
|
251
|
+
* - `I18N_RUNTIME_CONFIG` (resolved defaults) for the loader/handler.
|
|
252
|
+
* - Optional `LanguageService` localStorage restore on bootstrap.
|
|
253
|
+
*
|
|
254
|
+
* The consumer still imports the generated typed directive and
|
|
255
|
+
* `translateSignal`/`TK` from their local barrel.
|
|
256
|
+
*
|
|
257
|
+
* @example
|
|
258
|
+
* export const appConfig: ApplicationConfig = {
|
|
259
|
+
* providers: [
|
|
260
|
+
* provideI18n({
|
|
261
|
+
* registry: ALL_TRANSLATIONS,
|
|
262
|
+
* languages: [
|
|
263
|
+
* { id: 'en', label: 'English' },
|
|
264
|
+
* { id: 'es', label: 'Español' },
|
|
265
|
+
* ],
|
|
266
|
+
* defaultLang: 'es',
|
|
267
|
+
* fallbackLang: 'en',
|
|
268
|
+
* persistLanguage: true,
|
|
269
|
+
* }),
|
|
270
|
+
* ],
|
|
271
|
+
* };
|
|
272
|
+
*/
|
|
273
|
+
function provideI18n(config) {
|
|
274
|
+
const defaultLang = config.defaultLang ?? config.languages[0]?.id;
|
|
275
|
+
if (!defaultLang) {
|
|
276
|
+
throw new Error('provideI18n: `languages` must contain at least one entry (or set `defaultLang`).');
|
|
277
|
+
}
|
|
278
|
+
const resolved = {
|
|
279
|
+
registry: config.registry,
|
|
280
|
+
defaultLang,
|
|
281
|
+
fallbackLang: config.fallbackLang ?? 'en',
|
|
282
|
+
missingKeyInDev: config.missingKeyInDev ?? 'show',
|
|
283
|
+
assetsPath: (config.assetsPath ?? '/assets/i18n').replace(/\/$/, ''),
|
|
284
|
+
};
|
|
285
|
+
const loaderClass = config.loader === 'http' ? TranslocoHttpLoader : TranslocoRegistryLoader;
|
|
286
|
+
const providers = [
|
|
287
|
+
provideTransloco({
|
|
288
|
+
config: {
|
|
289
|
+
availableLangs: config.languages,
|
|
290
|
+
defaultLang,
|
|
291
|
+
fallbackLang: resolved.fallbackLang,
|
|
292
|
+
reRenderOnLangChange: true,
|
|
293
|
+
prodMode: !isDevMode(),
|
|
294
|
+
missingHandler: {
|
|
295
|
+
useFallbackTranslation: true,
|
|
296
|
+
logMissingKey: isDevMode(),
|
|
297
|
+
},
|
|
298
|
+
},
|
|
299
|
+
loader: loaderClass,
|
|
300
|
+
}),
|
|
301
|
+
provideTranslocoInterceptor(TranslocoCommentInterceptor),
|
|
302
|
+
provideTranslocoMissingHandler(TranslocoVisibleMissingHandler),
|
|
303
|
+
{ provide: I18N_RUNTIME_CONFIG, useValue: resolved },
|
|
304
|
+
{ provide: I18N_KEYS, useValue: buildKeysTree(config.registry) },
|
|
305
|
+
];
|
|
306
|
+
if (config.persistLanguage) {
|
|
307
|
+
providers.push(provideAppInitializer(() => {
|
|
308
|
+
const languageService = inject(LanguageService);
|
|
309
|
+
return languageService.initializeLanguage();
|
|
310
|
+
}));
|
|
311
|
+
}
|
|
312
|
+
return makeEnvironmentProviders(providers);
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
// =============================================================================
|
|
316
|
+
// Directive base
|
|
317
|
+
// =============================================================================
|
|
318
|
+
/**
|
|
319
|
+
* Untyped/generic core of the structural translate directive.
|
|
320
|
+
*
|
|
321
|
+
* The library can't reference a consumer-generated `TK`, so this base injects
|
|
322
|
+
* the keys object via the {@link I18N_KEYS} token (provided by `provideI18n`)
|
|
323
|
+
* and builds its lazy proxy over it. Casing is irrelevant — it reads string
|
|
324
|
+
* leaves and calls `transloco.translate(leaf)`.
|
|
325
|
+
*
|
|
326
|
+
* Consumers don't use this directly. The codegen emits a small wrapper that
|
|
327
|
+
* extends this base, declares the `<selector>Prefix` input (Angular's
|
|
328
|
+
* microsyntax binds `*appTranslate="let t; prefix: 'x'"` to `appTranslatePrefix`,
|
|
329
|
+
* so the input's name must follow the configured selector), and pins the
|
|
330
|
+
* template context type to *their* `typeof TK`:
|
|
331
|
+
*
|
|
332
|
+
* ```ts
|
|
333
|
+
* import { TK } from './definitions';
|
|
334
|
+
* @Directive({ selector: '[appTranslate]' })
|
|
335
|
+
* export class AppTranslateDirective extends TranslateDirectiveBase {
|
|
336
|
+
* readonly appTranslatePrefix = input<string | undefined>(undefined);
|
|
337
|
+
* protected override prefix(): string | undefined {
|
|
338
|
+
* return this.appTranslatePrefix();
|
|
339
|
+
* }
|
|
340
|
+
* static ngTemplateContextGuard(_d: AppTranslateDirective, ctx: unknown): ctx is TranslateContext<typeof TK> {
|
|
341
|
+
* return true;
|
|
342
|
+
* }
|
|
343
|
+
* }
|
|
344
|
+
* ```
|
|
345
|
+
*
|
|
346
|
+
* **Optimizations** (carried over from the original directive):
|
|
347
|
+
* - JS Proxy for lazy property access (no upfront tree building).
|
|
348
|
+
* - Proxy objects cached via WeakMap; translate fns cached per key via Map.
|
|
349
|
+
* - Signal-driven language reactivity (`toSignal` + `effect`), CD only on change.
|
|
350
|
+
*/
|
|
351
|
+
class TranslateDirectiveBase {
|
|
352
|
+
transloco = inject(TranslocoService);
|
|
353
|
+
keys = inject(I18N_KEYS);
|
|
354
|
+
templateRef = inject((TemplateRef));
|
|
355
|
+
viewContainer = inject(ViewContainerRef);
|
|
356
|
+
viewRef = null;
|
|
357
|
+
/** Tracks the current language (auto-updates on language change). */
|
|
358
|
+
currentLang = toSignal(this.transloco.langChanges$, {
|
|
359
|
+
initialValue: this.transloco.getActiveLang(),
|
|
360
|
+
});
|
|
361
|
+
proxyCache = new WeakMap();
|
|
362
|
+
translateFnCache = new Map();
|
|
363
|
+
isDev = typeof ngDevMode !== 'undefined' && !!ngDevMode;
|
|
364
|
+
warnedKeys = this.isDev ? new Set() : null;
|
|
365
|
+
/**
|
|
366
|
+
* Optional prefix prepended to every key (for scoped translations).
|
|
367
|
+
*
|
|
368
|
+
* The base has no input of its own: the microsyntax binding name depends on
|
|
369
|
+
* the selector, so the generated wrapper declares `<selector>Prefix` and
|
|
370
|
+
* overrides this hook to return it. Read lazily (never during construction).
|
|
371
|
+
*/
|
|
372
|
+
prefix() {
|
|
373
|
+
return undefined;
|
|
374
|
+
}
|
|
375
|
+
withPrefix(key) {
|
|
376
|
+
const prefix = this.prefix();
|
|
377
|
+
return prefix ? `${prefix}.${key}` : key;
|
|
378
|
+
}
|
|
379
|
+
constructor() {
|
|
380
|
+
this.createView();
|
|
381
|
+
this.setupLangChangeEffect();
|
|
382
|
+
}
|
|
383
|
+
createLazyTranslationProxy(keysObject) {
|
|
384
|
+
const createProxy = (obj) => {
|
|
385
|
+
const cached = this.proxyCache.get(obj);
|
|
386
|
+
if (cached)
|
|
387
|
+
return cached;
|
|
388
|
+
const proxy = new Proxy(obj, {
|
|
389
|
+
get: (target, prop) => {
|
|
390
|
+
const value = target[prop];
|
|
391
|
+
if (typeof value === 'string') {
|
|
392
|
+
const fullKey = this.withPrefix(value);
|
|
393
|
+
const cachedFn = this.translateFnCache.get(fullKey);
|
|
394
|
+
if (cachedFn)
|
|
395
|
+
return cachedFn;
|
|
396
|
+
const translateFn = ((params) => {
|
|
397
|
+
const result = this.transloco.translate(fullKey, params);
|
|
398
|
+
if (this.isDev && result === fullKey && !this.warnedKeys.has(fullKey)) {
|
|
399
|
+
console.warn(`[TranslateDirective] Missing translation: "${fullKey}"`);
|
|
400
|
+
this.warnedKeys.add(fullKey);
|
|
401
|
+
}
|
|
402
|
+
return result;
|
|
403
|
+
});
|
|
404
|
+
if (this.isDev) {
|
|
405
|
+
Object.defineProperty(translateFn, 'key', { value, writable: false, enumerable: false });
|
|
406
|
+
}
|
|
407
|
+
this.translateFnCache.set(fullKey, translateFn);
|
|
408
|
+
return translateFn;
|
|
409
|
+
}
|
|
410
|
+
if (typeof value === 'object' && value !== null) {
|
|
411
|
+
return createProxy(value);
|
|
412
|
+
}
|
|
413
|
+
if (this.isDev) {
|
|
414
|
+
console.warn(`[TranslateDirective] Invalid property "${String(prop)}" on translation object`);
|
|
415
|
+
}
|
|
416
|
+
return undefined;
|
|
417
|
+
},
|
|
418
|
+
});
|
|
419
|
+
this.proxyCache.set(obj, proxy);
|
|
420
|
+
return proxy;
|
|
421
|
+
};
|
|
422
|
+
return createProxy(keysObject);
|
|
423
|
+
}
|
|
424
|
+
createView() {
|
|
425
|
+
const translationsProxy = this.createLazyTranslationProxy(this.keys);
|
|
426
|
+
const context = {
|
|
427
|
+
$implicit: translationsProxy,
|
|
428
|
+
lang: this.currentLang(),
|
|
429
|
+
translate: (key, params) => this.transloco.translate(this.withPrefix(key), params),
|
|
430
|
+
};
|
|
431
|
+
this.viewRef = this.viewContainer.createEmbeddedView(this.templateRef, context);
|
|
432
|
+
}
|
|
433
|
+
setupLangChangeEffect() {
|
|
434
|
+
effect(() => {
|
|
435
|
+
const newLang = this.currentLang();
|
|
436
|
+
untracked(() => {
|
|
437
|
+
if (this.viewRef) {
|
|
438
|
+
this.viewRef.context.lang = newLang;
|
|
439
|
+
this.viewRef.markForCheck();
|
|
440
|
+
}
|
|
441
|
+
});
|
|
442
|
+
});
|
|
443
|
+
}
|
|
444
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.10", ngImport: i0, type: TranslateDirectiveBase, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
445
|
+
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.2.10", type: TranslateDirectiveBase, isStandalone: true, ngImport: i0 });
|
|
446
|
+
}
|
|
447
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.10", ngImport: i0, type: TranslateDirectiveBase, decorators: [{
|
|
448
|
+
type: Directive
|
|
449
|
+
}], ctorParameters: () => [] });
|
|
450
|
+
|
|
451
|
+
/*
|
|
452
|
+
* @hakistack/i18n
|
|
453
|
+
*
|
|
454
|
+
* TypeScript-first, build-time-generated, type-safe i18n for Angular on top of
|
|
455
|
+
* Transloco. Author translations in `.ts`, get typed keys + JSON for free.
|
|
456
|
+
*
|
|
457
|
+
* Consumer surface:
|
|
458
|
+
* - Authoring: `defineTranslations`, `t`
|
|
459
|
+
* - Runtime: `provideI18n`, `LanguageService`, `translateSignal`
|
|
460
|
+
* - Templates: `TranslateDirectiveBase` + `TranslateContext` (the codegen
|
|
461
|
+
* emits a typed wrapper that extends the base)
|
|
462
|
+
* - Locale type: augment the `I18nLocales` interface to declare your locales.
|
|
463
|
+
*/
|
|
464
|
+
// ============================================================================
|
|
465
|
+
// Authoring engine — re-exported from the Angular-free `/engine` entry point
|
|
466
|
+
// for convenience. Author your *.i18n.ts against `@hakistack/i18n/engine`
|
|
467
|
+
// directly (it loads in Node, which the codegen CLI relies on).
|
|
468
|
+
// ============================================================================
|
|
469
|
+
|
|
470
|
+
/**
|
|
471
|
+
* Generated bundle index. Do not edit.
|
|
472
|
+
*/
|
|
473
|
+
|
|
474
|
+
export { I18N_KEYS, I18N_RUNTIME_CONFIG, LanguageService, TranslateDirectiveBase, TranslocoCommentInterceptor, TranslocoHttpLoader, TranslocoRegistryLoader, TranslocoVisibleMissingHandler, provideI18n };
|
|
475
|
+
//# sourceMappingURL=hakistack-i18n.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hakistack-i18n.mjs","sources":["../../../../projects/hakistack/i18n/src/lib/runtime/comment-interceptor.ts","../../../../projects/hakistack/i18n/src/lib/runtime/tokens.ts","../../../../projects/hakistack/i18n/src/lib/runtime/http-loader.ts","../../../../projects/hakistack/i18n/src/lib/runtime/language.service.ts","../../../../projects/hakistack/i18n/src/lib/runtime/missing-handler.ts","../../../../projects/hakistack/i18n/src/lib/runtime/registry-loader.ts","../../../../projects/hakistack/i18n/src/lib/runtime/provide-i18n.ts","../../../../projects/hakistack/i18n/src/lib/runtime/translate.directive.ts","../../../../projects/hakistack/i18n/src/public-api.ts","../../../../projects/hakistack/i18n/src/hakistack-i18n.ts"],"sourcesContent":["import { Injectable } from '@angular/core';\nimport { Translation, TranslocoInterceptor } from '@jsverse/transloco';\n\n/**\n * Strips `<key>.comment` siblings before translations enter Transloco's store.\n *\n * Translator-context comments (added via `t('en', { es: '…' }, { comment })`)\n * are emitted into the runtime tree alongside their target keys — useful for\n * translator review in the JSON, but they must never be looked up at runtime.\n * Without this interceptor, a typo'd translate call could render comment text.\n */\n@Injectable()\nexport class TranslocoCommentInterceptor implements TranslocoInterceptor {\n preSaveTranslation(translation: Translation): Translation {\n return stripCommentKeys(translation) as Translation;\n }\n\n preSaveTranslationKey(_key: string, value: string): string {\n return value;\n }\n}\n\nfunction stripCommentKeys(node: unknown): unknown {\n if (node === null || typeof node !== 'object') return node;\n const out: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(node as Record<string, unknown>)) {\n if (key.endsWith('.comment')) continue;\n out[key] = stripCommentKeys(value);\n }\n return out;\n}\n","import { InjectionToken } from '@angular/core';\n\nimport { ResolvedI18nRuntimeConfig } from './config';\n\n/**\n * The merged keys tree (`TK`) provided by {@link provideI18n}.\n *\n * Holds the consumer's nested object of dot-path key strings — the exact shape\n * the scanner emits as the typed `TK` literal. `TranslateDirectiveBase` injects\n * this instead of importing `TK` directly, so the library never depends on a\n * consumer-generated symbol. Casing of keys is irrelevant at runtime: the\n * directive reads string leaves and calls `transloco.translate(leaf)`.\n */\nexport const I18N_KEYS = new InjectionToken<Record<string, unknown>>('I18N_KEYS');\n\n/** Fully-resolved runtime config, shared with the loader and missing handler. */\nexport const I18N_RUNTIME_CONFIG = new InjectionToken<ResolvedI18nRuntimeConfig>('I18N_RUNTIME_CONFIG');\n","import { HttpClient } from '@angular/common/http';\nimport { inject, Injectable } from '@angular/core';\nimport { Translation, TranslocoLoader } from '@jsverse/transloco';\n\nimport { I18N_RUNTIME_CONFIG } from './tokens';\n\n/**\n * HTTP-based translation loader — fetches `<assetsPath>/<lang>.json` over HTTP.\n *\n * Selected via `provideI18n({ loader: 'http' })`. Consumes the same JSON files\n * the generator emits, so switching loaders requires no other change.\n *\n * **Prefer the registry loader unless ANY of these are true:**\n * - Translation payload exceeds ~50KB per language (JS bundle bloat matters).\n * - The translation team needs to push updates without a code deploy.\n * - 5+ locales where CDN-cached per-locale loading matters.\n * - `provideTranslocoScope` lazy loading is adopted per route.\n *\n * **Costs:** reintroduces the runtime HTTP fetch (network race, offline issues),\n * SSR needs absolute URLs, and the \"JSON drifted from TS\" mode returns unless\n * the generator runs in the deploy pipeline.\n */\n@Injectable()\nexport class TranslocoHttpLoader implements TranslocoLoader {\n private readonly http = inject(HttpClient);\n private readonly config = inject(I18N_RUNTIME_CONFIG);\n\n getTranslation(lang: string) {\n // Transloco passes scoped requests as `<scope>/<lang>`; our generator emits\n // dotted scopes as nested dirs (`administration.users` → `administration/users/<lang>.json`),\n // so map dots to slashes. Lang codes never contain dots, so this is safe.\n const path = lang.replace(/\\./g, '/');\n return this.http.get<Translation>(`${this.config.assetsPath}/${path}.json`);\n }\n}\n","import { DOCUMENT, inject, Injectable, signal } from '@angular/core';\nimport { AvailableLangs, TranslocoService } from '@jsverse/transloco';\nimport { firstValueFrom } from 'rxjs';\n\n/**\n * App-level active-language wrapper around `TranslocoService` with localStorage\n * persistence and `<html lang>` syncing.\n *\n * Wired automatically when `provideI18n({ persistLanguage: true })` is set\n * (an APP_INITIALIZER restores the stored language on bootstrap). It's also\n * exported for direct use — inject it to build a language switcher:\n *\n * ```ts\n * private readonly i18nLang = inject(LanguageService);\n * switch(lang: string) { this.i18nLang.setLanguage(lang); }\n * ```\n */\n@Injectable({ providedIn: 'root' })\nexport class LanguageService {\n private readonly STORAGE_KEY = 'hakistack_i18n_lang';\n private readonly transloco = inject(TranslocoService);\n private readonly document = inject(DOCUMENT);\n\n private readonly defaultLanguage = this.transloco.getDefaultLang();\n\n /** Available languages from Transloco config. */\n readonly availableLanguages: AvailableLangs = this.transloco.getAvailableLangs();\n\n /** Current active language (reactive signal). */\n readonly language = signal<string>(this.getStoredLanguage());\n\n async initializeLanguage(): Promise<void> {\n await this.setLanguage(this.getStoredLanguage());\n }\n\n async setLanguage(lang: string): Promise<void> {\n try {\n await firstValueFrom(this.transloco.load(lang));\n this.transloco.setActiveLang(lang);\n this.saveLanguage(lang);\n this.language.set(lang);\n this.document.documentElement.setAttribute('lang', lang);\n } catch (error) {\n console.warn(`Failed to load language '${lang}', falling back to default`, error);\n if (lang !== this.defaultLanguage) {\n await this.setLanguage(this.defaultLanguage);\n }\n }\n }\n\n /** Is `lang` one of the configured available languages? */\n isAvailable(lang: string): boolean {\n return this.availableLanguages.some((l) => (typeof l === 'string' ? l : l.id) === lang);\n }\n\n /**\n * Stored language, or the default when nothing is stored, storage is\n * unavailable (SSR), or the stored value is no longer an available language\n * (stale/garbage localStorage must never become the active `<html lang>`).\n */\n private getStoredLanguage(): string {\n const storage = this.storage();\n if (!storage) return this.defaultLanguage;\n try {\n const stored = storage.getItem(this.STORAGE_KEY);\n return stored && this.isAvailable(stored) ? stored : this.defaultLanguage;\n } catch (error) {\n console.warn('Failed to read language from localStorage:', error);\n return this.defaultLanguage;\n }\n }\n\n private saveLanguage(lang: string): void {\n const storage = this.storage();\n if (!storage) return;\n try {\n storage.setItem(this.STORAGE_KEY, lang);\n } catch (error) {\n console.warn('Failed to save language to localStorage:', error);\n }\n }\n\n /** `localStorage` when it exists (browser); `null` on the server. */\n private storage(): Storage | null {\n return typeof localStorage === 'undefined' ? null : localStorage;\n }\n}\n","import { inject, Injectable, isDevMode } from '@angular/core';\nimport { TranslocoMissingHandler, TranslocoMissingHandlerData } from '@jsverse/transloco';\n\nimport { I18N_RUNTIME_CONFIG } from './tokens';\n\n/**\n * Missing-key handler that surfaces failures in dev mode.\n *\n * Default Transloco behavior returns `''` for missing keys, making typos\n * invisible in the UI. With `missingKeyInDev: 'show'` (the default) this returns\n * `[scope.key]` in dev so missing-key bugs jump out immediately. In production,\n * behavior is always `''`.\n *\n * The build-time validator remains the source of truth for *static* keys; this\n * handler catches dynamic / `selectTranslate(varKey)` / typo cases.\n */\n@Injectable()\nexport class TranslocoVisibleMissingHandler implements TranslocoMissingHandler {\n private readonly config = inject(I18N_RUNTIME_CONFIG);\n\n handle(key: string, _data: TranslocoMissingHandlerData): string {\n if (isDevMode() && this.config.missingKeyInDev === 'show') {\n return `[${key}]`;\n }\n return '';\n }\n}\n","import { inject, Injectable } from '@angular/core';\nimport { Translation, TranslocoLoader } from '@jsverse/transloco';\nimport { of } from 'rxjs';\n\nimport { buildLanguageTree, buildScopedTree } from '@hakistack/i18n/engine';\nimport { I18N_RUNTIME_CONFIG } from './tokens';\n\n/**\n * Translation loader backed by the in-memory module registry.\n *\n * Reads directly from the registry passed to {@link provideI18n} and assembles\n * a per-language tree on demand. No HTTP request, no `assets/i18n/<lang>.json`\n * fetch at runtime — those JSON files are translator-facing build artifacts only.\n *\n * Wins:\n * - Synchronous-after-import. No race between bootstrap and translation load.\n * - Single source of truth at runtime — the \"JSON drifted from TS\" failure\n * mode becomes structurally impossible.\n * - Works offline; no service-worker config needed for i18n.\n * - SSR-safe: no absolute-URL gotchas.\n */\n@Injectable()\nexport class TranslocoRegistryLoader implements TranslocoLoader {\n private readonly config = inject(I18N_RUNTIME_CONFIG);\n\n getTranslation(input: string) {\n // Transloco constructs scoped requests as `<scope>/<lang>` (e.g. `'home/en'`).\n // Plain `'en'` is the unscoped root request.\n const slashIdx = input.lastIndexOf('/');\n\n if (slashIdx === -1) {\n // No scope provider in play — return the full tree (eager + every scoped\n // module merged at its scope path).\n return of(buildLanguageTree(this.config.registry, input, this.config.fallbackLang) as Translation);\n }\n\n // Scoped request — return ONLY that scope's data, unwrapped (Transloco\n // namespaces it back under the scope key in its internal store). The scope\n // arrives in slash form (`administration/users`); `buildScopedTree`\n // normalizes it against the registry's dotted scopes.\n const scope = input.substring(0, slashIdx);\n const lang = input.substring(slashIdx + 1);\n const tree = buildScopedTree(this.config.registry, lang, this.config.fallbackLang, scope);\n return of((tree ?? {}) as Translation);\n }\n}\n","import { EnvironmentProviders, inject, isDevMode, makeEnvironmentProviders, provideAppInitializer, Provider } from '@angular/core';\nimport { provideTransloco, provideTranslocoInterceptor, provideTranslocoMissingHandler } from '@jsverse/transloco';\n\nimport { buildKeysTree } from '@hakistack/i18n/engine';\nimport { I18nConfig, ResolvedI18nRuntimeConfig } from './config';\nimport { TranslocoCommentInterceptor } from './comment-interceptor';\nimport { TranslocoHttpLoader } from './http-loader';\nimport { LanguageService } from './language.service';\nimport { TranslocoVisibleMissingHandler } from './missing-handler';\nimport { TranslocoRegistryLoader } from './registry-loader';\nimport { I18N_KEYS, I18N_RUNTIME_CONFIG } from './tokens';\n\n/**\n * One-call i18n setup for a consumer app.\n *\n * Collapses what used to be a hand-written `provideTransloco(...)` config plus\n * a list of custom hooks (`provideTranslocoInterceptor`,\n * `provideTranslocoMissingHandler`) into a single provider. Wires:\n * - Transloco with the registry loader (or HTTP loader).\n * - The comment-stripping interceptor + the visible missing-key handler.\n * - `I18N_KEYS` (the runtime `TK` tree) for the translate directive.\n * - `I18N_RUNTIME_CONFIG` (resolved defaults) for the loader/handler.\n * - Optional `LanguageService` localStorage restore on bootstrap.\n *\n * The consumer still imports the generated typed directive and\n * `translateSignal`/`TK` from their local barrel.\n *\n * @example\n * export const appConfig: ApplicationConfig = {\n * providers: [\n * provideI18n({\n * registry: ALL_TRANSLATIONS,\n * languages: [\n * { id: 'en', label: 'English' },\n * { id: 'es', label: 'Español' },\n * ],\n * defaultLang: 'es',\n * fallbackLang: 'en',\n * persistLanguage: true,\n * }),\n * ],\n * };\n */\nexport function provideI18n(config: I18nConfig): EnvironmentProviders {\n const defaultLang = config.defaultLang ?? config.languages[0]?.id;\n if (!defaultLang) {\n throw new Error('provideI18n: `languages` must contain at least one entry (or set `defaultLang`).');\n }\n\n const resolved: ResolvedI18nRuntimeConfig = {\n registry: config.registry,\n defaultLang,\n fallbackLang: config.fallbackLang ?? 'en',\n missingKeyInDev: config.missingKeyInDev ?? 'show',\n assetsPath: (config.assetsPath ?? '/assets/i18n').replace(/\\/$/, ''),\n };\n\n const loaderClass = config.loader === 'http' ? TranslocoHttpLoader : TranslocoRegistryLoader;\n\n const providers: (Provider | EnvironmentProviders)[] = [\n provideTransloco({\n config: {\n availableLangs: config.languages,\n defaultLang,\n fallbackLang: resolved.fallbackLang,\n reRenderOnLangChange: true,\n prodMode: !isDevMode(),\n missingHandler: {\n useFallbackTranslation: true,\n logMissingKey: isDevMode(),\n },\n },\n loader: loaderClass,\n }),\n provideTranslocoInterceptor(TranslocoCommentInterceptor),\n provideTranslocoMissingHandler(TranslocoVisibleMissingHandler),\n { provide: I18N_RUNTIME_CONFIG, useValue: resolved },\n { provide: I18N_KEYS, useValue: buildKeysTree(config.registry) },\n ];\n\n if (config.persistLanguage) {\n providers.push(\n provideAppInitializer(() => {\n const languageService = inject(LanguageService);\n return languageService.initializeLanguage();\n }),\n );\n }\n\n return makeEnvironmentProviders(providers);\n}\n","import { Directive, EmbeddedViewRef, effect, inject, TemplateRef, untracked, ViewContainerRef } from '@angular/core';\nimport { toSignal } from '@angular/core/rxjs-interop';\nimport { TranslocoService } from '@jsverse/transloco';\n\nimport { I18N_KEYS } from './tokens';\n\n// =============================================================================\n// Type Definitions\n// =============================================================================\n\n/** A translation key string transformed into a callable translate function. */\nexport interface TranslateFn {\n /** Get the translated string. */\n (): string;\n /** Get the translated string with interpolation params. */\n (params: Record<string, unknown>): string;\n /** The raw translation key (dev only, for debugging). */\n readonly key: string;\n}\n\n/**\n * Recursively transforms a keys object (`TK`) shape:\n * - string leaves become {@link TranslateFn}\n * - nested objects remain nested with transformed children\n */\nexport type TranslatedKeys<T> = {\n readonly [K in keyof T]: T[K] extends string ? TranslateFn : T[K] extends Record<string, unknown> ? TranslatedKeys<T[K]> : never;\n};\n\n/**\n * Context exposed to the template by the translate directive.\n *\n * Generic over the consumer's `TK` shape. The library ships the untyped base\n * (`TranslateContext<Record<string, unknown>>`); the scanner-generated consumer\n * wrapper pins `T = typeof TK` so templates get full autocomplete.\n */\nexport interface TranslateContext<T = Record<string, unknown>> {\n /**\n * Typed translation object with full autocomplete.\n *\n * @example\n * {{ t.common.buttons.save() }}\n * {{ t.common.validation.minLength({ min: 3 }) }}\n */\n $implicit: TranslatedKeys<T>;\n /** Current active language code. */\n lang: string;\n /** Raw translate function for dynamic keys (escape hatch). */\n translate: (key: string, params?: Record<string, unknown>) => string;\n}\n\n// =============================================================================\n// Directive base\n// =============================================================================\n\n/**\n * Untyped/generic core of the structural translate directive.\n *\n * The library can't reference a consumer-generated `TK`, so this base injects\n * the keys object via the {@link I18N_KEYS} token (provided by `provideI18n`)\n * and builds its lazy proxy over it. Casing is irrelevant — it reads string\n * leaves and calls `transloco.translate(leaf)`.\n *\n * Consumers don't use this directly. The codegen emits a small wrapper that\n * extends this base, declares the `<selector>Prefix` input (Angular's\n * microsyntax binds `*appTranslate=\"let t; prefix: 'x'\"` to `appTranslatePrefix`,\n * so the input's name must follow the configured selector), and pins the\n * template context type to *their* `typeof TK`:\n *\n * ```ts\n * import { TK } from './definitions';\n * @Directive({ selector: '[appTranslate]' })\n * export class AppTranslateDirective extends TranslateDirectiveBase {\n * readonly appTranslatePrefix = input<string | undefined>(undefined);\n * protected override prefix(): string | undefined {\n * return this.appTranslatePrefix();\n * }\n * static ngTemplateContextGuard(_d: AppTranslateDirective, ctx: unknown): ctx is TranslateContext<typeof TK> {\n * return true;\n * }\n * }\n * ```\n *\n * **Optimizations** (carried over from the original directive):\n * - JS Proxy for lazy property access (no upfront tree building).\n * - Proxy objects cached via WeakMap; translate fns cached per key via Map.\n * - Signal-driven language reactivity (`toSignal` + `effect`), CD only on change.\n */\n@Directive()\nexport class TranslateDirectiveBase {\n private readonly transloco = inject(TranslocoService);\n private readonly keys = inject(I18N_KEYS);\n private readonly templateRef = inject(TemplateRef<TranslateContext>);\n private readonly viewContainer = inject(ViewContainerRef);\n\n private viewRef: EmbeddedViewRef<TranslateContext> | null = null;\n\n /** Tracks the current language (auto-updates on language change). */\n private readonly currentLang = toSignal(this.transloco.langChanges$, {\n initialValue: this.transloco.getActiveLang(),\n });\n\n private readonly proxyCache = new WeakMap<object, unknown>();\n private readonly translateFnCache = new Map<string, TranslateFn>();\n\n private readonly isDev = typeof ngDevMode !== 'undefined' && !!ngDevMode;\n private readonly warnedKeys = this.isDev ? new Set<string>() : null;\n\n /**\n * Optional prefix prepended to every key (for scoped translations).\n *\n * The base has no input of its own: the microsyntax binding name depends on\n * the selector, so the generated wrapper declares `<selector>Prefix` and\n * overrides this hook to return it. Read lazily (never during construction).\n */\n protected prefix(): string | undefined {\n return undefined;\n }\n\n private withPrefix(key: string): string {\n const prefix = this.prefix();\n return prefix ? `${prefix}.${key}` : key;\n }\n\n constructor() {\n this.createView();\n this.setupLangChangeEffect();\n }\n\n private createLazyTranslationProxy(keysObject: Record<string, unknown>): TranslatedKeys<unknown> {\n const createProxy = (obj: Record<string, unknown>): unknown => {\n const cached = this.proxyCache.get(obj);\n if (cached) return cached;\n\n const proxy = new Proxy(obj, {\n get: (target, prop: string) => {\n const value = target[prop];\n\n if (typeof value === 'string') {\n const fullKey = this.withPrefix(value);\n\n const cachedFn = this.translateFnCache.get(fullKey);\n if (cachedFn) return cachedFn;\n\n const translateFn = ((params?: Record<string, unknown>) => {\n const result = this.transloco.translate(fullKey, params);\n if (this.isDev && result === fullKey && !this.warnedKeys!.has(fullKey)) {\n console.warn(`[TranslateDirective] Missing translation: \"${fullKey}\"`);\n this.warnedKeys!.add(fullKey);\n }\n return result;\n }) as TranslateFn;\n\n if (this.isDev) {\n Object.defineProperty(translateFn, 'key', { value, writable: false, enumerable: false });\n }\n\n this.translateFnCache.set(fullKey, translateFn);\n return translateFn;\n }\n\n if (typeof value === 'object' && value !== null) {\n return createProxy(value as Record<string, unknown>);\n }\n\n if (this.isDev) {\n console.warn(`[TranslateDirective] Invalid property \"${String(prop)}\" on translation object`);\n }\n return undefined;\n },\n });\n\n this.proxyCache.set(obj, proxy);\n return proxy;\n };\n\n return createProxy(keysObject) as TranslatedKeys<unknown>;\n }\n\n private createView(): void {\n const translationsProxy = this.createLazyTranslationProxy(this.keys);\n\n const context: TranslateContext = {\n $implicit: translationsProxy as TranslatedKeys<Record<string, unknown>>,\n lang: this.currentLang(),\n translate: (key: string, params?: Record<string, unknown>) => this.transloco.translate(this.withPrefix(key), params),\n };\n\n this.viewRef = this.viewContainer.createEmbeddedView(this.templateRef, context);\n }\n\n private setupLangChangeEffect(): void {\n effect(() => {\n const newLang = this.currentLang();\n untracked(() => {\n if (this.viewRef) {\n this.viewRef.context.lang = newLang;\n this.viewRef.markForCheck();\n }\n });\n });\n }\n}\n","/*\n * @hakistack/i18n\n *\n * TypeScript-first, build-time-generated, type-safe i18n for Angular on top of\n * Transloco. Author translations in `.ts`, get typed keys + JSON for free.\n *\n * Consumer surface:\n * - Authoring: `defineTranslations`, `t`\n * - Runtime: `provideI18n`, `LanguageService`, `translateSignal`\n * - Templates: `TranslateDirectiveBase` + `TranslateContext` (the codegen\n * emits a typed wrapper that extends the base)\n * - Locale type: augment the `I18nLocales` interface to declare your locales.\n */\n\n// ============================================================================\n// Authoring engine — re-exported from the Angular-free `/engine` entry point\n// for convenience. Author your *.i18n.ts against `@hakistack/i18n/engine`\n// directly (it loads in Node, which the codegen CLI relies on).\n// ============================================================================\nexport {\n buildEagerTree,\n buildKeysTree,\n buildLanguageTree,\n buildScopedTree,\n defineTranslations,\n extractLanguage,\n getTranslation,\n isTranslationValue,\n normalizeScope,\n scopeToFilesystemPath,\n setAtScope,\n SOURCE_LANG,\n t,\n TRANSLATION_BRAND,\n} from '@hakistack/i18n/engine';\nexport type {\n AuthoredTranslationNode,\n I18nLocales,\n Language,\n LanguageTree,\n LocaleId,\n OtherLocales,\n SourceLang,\n TranslationModule,\n TranslationValue,\n} from '@hakistack/i18n/engine';\n\n// ============================================================================\n// Runtime setup\n// ============================================================================\nexport { provideI18n } from './lib/runtime/provide-i18n';\nexport type {\n I18nConfig,\n I18nLanguageOption,\n I18nLoaderStrategy,\n MissingKeyDevBehavior,\n ResolvedI18nRuntimeConfig,\n} from './lib/runtime/config';\nexport { I18N_KEYS, I18N_RUNTIME_CONFIG } from './lib/runtime/tokens';\n\n// Loaders / hooks — exported for custom wiring or one-line loader swaps.\nexport { TranslocoRegistryLoader } from './lib/runtime/registry-loader';\nexport { TranslocoHttpLoader } from './lib/runtime/http-loader';\nexport { TranslocoCommentInterceptor } from './lib/runtime/comment-interceptor';\nexport { TranslocoVisibleMissingHandler } from './lib/runtime/missing-handler';\n\n// Active-language service (localStorage persistence + <html lang> sync).\nexport { LanguageService } from './lib/runtime/language.service';\n\n// ============================================================================\n// Template directive (base + context types — codegen emits the typed wrapper)\n// ============================================================================\nexport { TranslateDirectiveBase } from './lib/runtime/translate.directive';\nexport type { TranslateContext, TranslatedKeys, TranslateFn } from './lib/runtime/translate.directive';\n\n// ============================================================================\n// Transloco signal API — re-exported so consumers don't reach into\n// '@jsverse/transloco' directly.\n// ============================================================================\nexport { translateSignal, translateObjectSignal } from '@jsverse/transloco';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;;;;;;;AAGA;;;;;;;AAOG;MAEU,2BAA2B,CAAA;AACtC,IAAA,kBAAkB,CAAC,WAAwB,EAAA;AACzC,QAAA,OAAO,gBAAgB,CAAC,WAAW,CAAgB;IACrD;IAEA,qBAAqB,CAAC,IAAY,EAAE,KAAa,EAAA;AAC/C,QAAA,OAAO,KAAK;IACd;wGAPW,2BAA2B,EAAA,IAAA,EAAA,EAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,UAAA,EAAA,CAAA;4GAA3B,2BAA2B,EAAA,CAAA;;4FAA3B,2BAA2B,EAAA,UAAA,EAAA,CAAA;kBADvC;;AAWD,SAAS,gBAAgB,CAAC,IAAa,EAAA;AACrC,IAAA,IAAI,IAAI,KAAK,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ;AAAE,QAAA,OAAO,IAAI;IAC1D,MAAM,GAAG,GAA4B,EAAE;AACvC,IAAA,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,IAA+B,CAAC,EAAE;AAC1E,QAAA,IAAI,GAAG,CAAC,QAAQ,CAAC,UAAU,CAAC;YAAE;QAC9B,GAAG,CAAC,GAAG,CAAC,GAAG,gBAAgB,CAAC,KAAK,CAAC;IACpC;AACA,IAAA,OAAO,GAAG;AACZ;;AC1BA;;;;;;;;AAQG;MACU,SAAS,GAAG,IAAI,cAAc,CAA0B,WAAW;AAEhF;MACa,mBAAmB,GAAG,IAAI,cAAc,CAA4B,qBAAqB;;ACVtG;;;;;;;;;;;;;;;AAeG;MAEU,mBAAmB,CAAA;AACb,IAAA,IAAI,GAAG,MAAM,CAAC,UAAU,CAAC;AACzB,IAAA,MAAM,GAAG,MAAM,CAAC,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FAAtB,sBAAsB,EAAA,YAAA,EAAA,IAAA,EAAA,QAAA,EAAA,EAAA,EAAA,CAAA;;4FAAtB,sBAAsB,EAAA,UAAA,EAAA,CAAA;kBADlC;;;ACxFD;;;;;;;;;;;;AAYG;AAEH;AACA;AACA;AACA;AACA;;AClBA;;AAEG;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,63 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hakistack/i18n",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "TypeScript-first, build-time-generated, type-safe i18n layer for Angular on top of Transloco. Author translations in .ts, get typed keys and JSON for free.",
|
|
5
|
+
"author": "Hakistack",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/hakistack/i18n.git"
|
|
10
|
+
},
|
|
11
|
+
"homepage": "https://github.com/hakistack/i18n#readme",
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/hakistack/i18n/issues"
|
|
14
|
+
},
|
|
15
|
+
"publishConfig": {
|
|
16
|
+
"access": "public"
|
|
17
|
+
},
|
|
18
|
+
"keywords": [
|
|
19
|
+
"angular",
|
|
20
|
+
"i18n",
|
|
21
|
+
"transloco",
|
|
22
|
+
"translations",
|
|
23
|
+
"type-safe",
|
|
24
|
+
"codegen"
|
|
25
|
+
],
|
|
26
|
+
"bin": {
|
|
27
|
+
"hakistack-i18n": "./cli/bin.cjs"
|
|
28
|
+
},
|
|
29
|
+
"peerDependencies": {
|
|
30
|
+
"@angular/common": ">=21.0.0",
|
|
31
|
+
"@angular/core": ">=21.0.0",
|
|
32
|
+
"@jsverse/transloco": "^8.2.0",
|
|
33
|
+
"rxjs": ">=7.8.0"
|
|
34
|
+
},
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"jiti": "^2.7.0",
|
|
37
|
+
"tslib": "^2.3.0"
|
|
38
|
+
},
|
|
39
|
+
"optionalDependencies": {
|
|
40
|
+
"chokidar": "^5.0.0"
|
|
41
|
+
},
|
|
42
|
+
"sideEffects": false,
|
|
43
|
+
"module": "fesm2022/hakistack-i18n.mjs",
|
|
44
|
+
"typings": "types/hakistack-i18n.d.ts",
|
|
45
|
+
"exports": {
|
|
46
|
+
"./package.json": {
|
|
47
|
+
"default": "./package.json"
|
|
48
|
+
},
|
|
49
|
+
".": {
|
|
50
|
+
"types": "./types/hakistack-i18n.d.ts",
|
|
51
|
+
"default": "./fesm2022/hakistack-i18n.mjs"
|
|
52
|
+
},
|
|
53
|
+
"./engine": {
|
|
54
|
+
"types": "./types/hakistack-i18n-engine.d.ts",
|
|
55
|
+
"default": "./fesm2022/hakistack-i18n-engine.mjs"
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
"type": "module",
|
|
59
|
+
"schematics": "./schematics/collection.json",
|
|
60
|
+
"ng-add": {
|
|
61
|
+
"save": "dependencies"
|
|
62
|
+
}
|
|
63
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "../../../../node_modules/@angular-devkit/schematics/collection-schema.json",
|
|
3
|
+
"schematics": {
|
|
4
|
+
"ng-add": {
|
|
5
|
+
"description": "Set up @hakistack/i18n: install transloco, write i18n.config.json, add codegen scripts, scaffold a sample module.",
|
|
6
|
+
"factory": "./ng-add/index.cjs#ngAdd",
|
|
7
|
+
"schema": "./ng-add/schema.json"
|
|
8
|
+
},
|
|
9
|
+
"setup": {
|
|
10
|
+
"description": "Same as ng-add — run anytime on an installed library (ng generate @hakistack/i18n:setup).",
|
|
11
|
+
"factory": "./ng-add/index.cjs#ngAdd",
|
|
12
|
+
"schema": "./ng-add/schema.json"
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|