@hakistack/i18n 0.1.0 → 0.2.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.
@@ -1,3 +1,68 @@
1
+ /**
2
+ * The single deep-merge used to assemble every tree built from several
3
+ * translation modules: the runtime keys tree (`buildKeysTree`), the generated
4
+ * `TK` literal (`mergeKeys`) and the per-language trees (`buildLanguageTree`).
5
+ *
6
+ * One implementation means the three can never disagree about which keys exist
7
+ * when modules share a scope or nest under each other. A key defined twice, or
8
+ * a key that is both a translation and a group, is an authoring error and throws
9
+ * instead of letting one module silently win.
10
+ */
11
+ function isTree(value) {
12
+ return typeof value === 'object' && value !== null;
13
+ }
14
+ function cloneTree(tree) {
15
+ const out = {};
16
+ for (const [key, value] of Object.entries(tree))
17
+ out[key] = isTree(value) ? cloneTree(value) : value;
18
+ return out;
19
+ }
20
+ /**
21
+ * Deep-merge `source` into `target` (never mutating `source`). `path` is the
22
+ * dotted location of `target`, used in error messages. With `keysTree`, string
23
+ * leaves are full translation keys and are quoted as-is in errors.
24
+ */
25
+ function mergeInto(target, source, path = '', keysTree = false) {
26
+ for (const [key, value] of Object.entries(source)) {
27
+ const at = path ? `${path}.${key}` : key;
28
+ const existing = target[key];
29
+ if (existing === undefined) {
30
+ target[key] = isTree(value) ? cloneTree(value) : value;
31
+ }
32
+ else if (isTree(existing) && isTree(value)) {
33
+ mergeInto(existing, value, at, keysTree);
34
+ }
35
+ else if (!isTree(existing) && !isTree(value)) {
36
+ throw new Error(`i18n: duplicate translation key '${keysTree ? String(existing) : at}' — it is defined by more than one module.`);
37
+ }
38
+ else {
39
+ throw new Error(`i18n: '${at}' is both a translation and a group of translations (check modules sharing or nesting this scope).`);
40
+ }
41
+ }
42
+ }
43
+ /** Wrap `subtree` in nested objects following a dotted `scope` (`'a.b'` → `{ a: { b: subtree } }`). */
44
+ function nestAtScope(scope, subtree) {
45
+ return scope
46
+ .split('.')
47
+ .reverse()
48
+ .reduce((inner, part) => ({ [part]: inner }), subtree);
49
+ }
50
+ /**
51
+ * Deep-merge several keys objects into one. Emitted by `hakistack-i18n scan`
52
+ * wherever several modules contribute to the same `TK` branch (modules sharing
53
+ * a scope, or a module plus deeper scopes nested under it). The intersection
54
+ * type exposes every contributed key, matching the runtime value exactly.
55
+ *
56
+ * @example
57
+ * mergeKeys(COMMON_A.keys, COMMON_B.keys, { users: ADMIN_USERS.keys })
58
+ */
59
+ function mergeKeys(...parts) {
60
+ const out = {};
61
+ for (const part of parts)
62
+ mergeInto(out, part, '', true);
63
+ return out;
64
+ }
65
+
1
66
  /**
2
67
  * Type-safe translation definitions — the authoring heart of `@hakistack/i18n`.
3
68
  *
@@ -131,49 +196,61 @@ function isTranslationValue(value) {
131
196
  * module's `keys` object at its scope path and deep-merging.
132
197
  *
133
198
  * This is the **runtime** value used by the directive (via the `I18N_KEYS`
134
- * token) — it produces the exact nested shape the scanner emits as the typed
135
- * `TK` literal. The scanner emits a concrete literal for *compile-time*
136
- * autocomplete; this function produces the identical structure at runtime, so
137
- * the two never diverge.
138
- *
139
- * Modules sharing a scope are merged (the scanner emits the same spread for the
140
- * `TK` literal). Throws on scalar/scope conflicts.
199
+ * token). It uses the same deep merge as the scanner-emitted `TK` literal
200
+ * (`mergeKeys`) and the language trees, so all three agree on which keys exist.
201
+ * Throws when a key is defined twice or is both a translation and a group.
141
202
  */
142
203
  function buildKeysTree(modules) {
143
204
  const tree = {};
144
- // Sort by scope depth so parent scopes are placed before children — guarantees
145
- // a deeper scope descends through an already-copied parent slot.
146
- const sorted = [...modules].sort((a, b) => a.scope.split('.').length - b.scope.split('.').length);
147
- for (const mod of sorted) {
148
- placeAtScope(tree, mod.scope, mod.keys);
205
+ for (const mod of modules) {
206
+ mergeInto(tree, nestAtScope(mod.scope, mod.keys), '', true);
149
207
  }
150
208
  return tree;
151
209
  }
152
- function placeAtScope(tree, scope, keys) {
153
- const path = scope.split('.');
154
- let current = tree;
155
- for (let i = 0; i < path.length - 1; i++) {
156
- const part = path[i];
157
- const slot = current[part];
158
- if (slot === undefined) {
159
- current[part] = {};
160
- }
161
- else if (typeof slot !== 'object' || slot === null) {
162
- throw new Error(`i18n: scope conflict at '${path.slice(0, i + 1).join('.')}': scalar where nested scope expected`);
210
+ /**
211
+ * Find every key collision across the registry, including the ones a deep
212
+ * merge cannot see: a dotted key name (`'a.b'`) colliding with a nested group
213
+ * (`a: { b }`) produces the same Transloco key.
214
+ */
215
+ function findKeyConflicts(modules) {
216
+ const leaves = [];
217
+ const walk = (node, prefix, scope) => {
218
+ for (const [key, value] of Object.entries(node)) {
219
+ const full = `${prefix}.${key}`;
220
+ if (isTranslationValue(value))
221
+ leaves.push({ key: full, scope });
222
+ else if (typeof value === 'object' && value !== null)
223
+ walk(value, full, scope);
163
224
  }
164
- current = current[part];
165
- }
166
- const leaf = path[path.length - 1];
167
- const existing = current[leaf];
168
- if (existing === undefined) {
169
- current[leaf] = { ...keys };
170
- }
171
- else if (typeof existing === 'object' && existing !== null) {
172
- current[leaf] = { ...keys, ...existing };
225
+ };
226
+ for (const mod of modules)
227
+ walk(mod.translations, mod.scope, mod.scope);
228
+ return conflictsFromLeaves(leaves);
229
+ }
230
+ /**
231
+ * Conflict detection over a flat list of full keys (one entry per definition).
232
+ * Shared by {@link findKeyConflicts} (runtime registry) and the CLI scanner
233
+ * (keys read statically from source).
234
+ */
235
+ function conflictsFromLeaves(leaves) {
236
+ const byKey = new Map();
237
+ const groups = new Map();
238
+ const add = (map, key, scope) => map.set(key, [...(map.get(key) ?? []), scope]);
239
+ for (const { key, scope } of leaves) {
240
+ add(byKey, key, scope);
241
+ const parts = key.split('.');
242
+ for (let i = 1; i < parts.length; i++)
243
+ add(groups, parts.slice(0, i).join('.'), scope);
173
244
  }
174
- else {
175
- throw new Error(`i18n: scope conflict at '${scope}': scalar where nested scope expected`);
245
+ const conflicts = [];
246
+ for (const [key, scopes] of byKey) {
247
+ if (scopes.length > 1)
248
+ conflicts.push({ key, kind: 'duplicate', scopes });
249
+ const groupScopes = groups.get(key);
250
+ if (groupScopes)
251
+ conflicts.push({ key, kind: 'translation-and-group', scopes: [...new Set([...scopes, ...groupScopes])] });
176
252
  }
253
+ return conflicts.sort((a, b) => a.key.localeCompare(b.key));
177
254
  }
178
255
 
179
256
  /**
@@ -208,49 +285,33 @@ function getTranslation(value, lang, defaultLang) {
208
285
  * Walk a normalized translation subtree (all leaves are `TranslationValue`s) and
209
286
  * emit a string-only tree for the given language.
210
287
  *
211
- * If a leaf carries a `__comment` (set via `t(en, others, { comment })`), a
212
- * sibling entry `<key>.comment` is added at the same level. Translators see it;
213
- * the runtime interceptor strips it before it reaches the store.
288
+ * If a leaf carries a `__comment` (set via `t(en, others, { comment })`) and
289
+ * `options.comments` is not `false`, a sibling entry `<key>.comment` is added at
290
+ * the same level for translators.
214
291
  */
215
- function extractLanguage(translations, lang, defaultLang) {
292
+ function extractLanguage(translations, lang, defaultLang, options = {}) {
293
+ const comments = options.comments ?? true;
216
294
  const result = {};
217
295
  for (const [key, value] of Object.entries(translations)) {
218
296
  if (isTranslationValue(value)) {
219
297
  result[key] = getTranslation(value, lang, defaultLang);
220
- if (value.__comment) {
298
+ if (comments && value.__comment) {
221
299
  result[`${key}.comment`] = value.__comment;
222
300
  }
223
301
  }
224
302
  else if (typeof value === 'object' && value !== null) {
225
- result[key] = extractLanguage(value, lang, defaultLang);
303
+ result[key] = extractLanguage(value, lang, defaultLang, options);
226
304
  }
227
305
  }
228
306
  return result;
229
307
  }
230
308
  /**
231
- * Place a subtree at a dot-delimited scope path in the target tree, creating
232
- * intermediate objects as needed. If the path already holds an object, the new
233
- * subtree's leaves are merged into it.
309
+ * Deep-merge a subtree into the target at a dot-delimited scope path, creating
310
+ * intermediate objects as needed. Throws when a key would be defined twice or
311
+ * when a translation and a group collide (see `mergeInto`).
234
312
  */
235
313
  function setAtScope(target, scope, subtree) {
236
- const parts = scope.split('.');
237
- let current = target;
238
- for (let i = 0; i < parts.length - 1; i++) {
239
- const part = parts[i];
240
- const slot = current[part];
241
- if (slot === undefined || typeof slot === 'string') {
242
- current[part] = {};
243
- }
244
- current = current[part];
245
- }
246
- const leaf = parts[parts.length - 1];
247
- const existing = current[leaf];
248
- if (existing && typeof existing === 'object') {
249
- Object.assign(existing, subtree);
250
- }
251
- else {
252
- current[leaf] = subtree;
253
- }
314
+ mergeInto(target, nestAtScope(scope, subtree));
254
315
  }
255
316
  /**
256
317
  * Build the complete translation tree for a single language from the registry.
@@ -258,11 +319,10 @@ function setAtScope(target, scope, subtree) {
258
319
  * and fallbacks — so a consumer cannot tell whether the data came from the
259
320
  * registry or from disk.
260
321
  */
261
- function buildLanguageTree(registry, lang, defaultLang) {
322
+ function buildLanguageTree(registry, lang, defaultLang, options) {
262
323
  const tree = {};
263
324
  for (const mod of registry) {
264
- const subtree = extractLanguage(mod.translations, lang, defaultLang);
265
- setAtScope(tree, mod.scope, subtree);
325
+ setAtScope(tree, mod.scope, extractLanguage(mod.translations, lang, defaultLang, options));
266
326
  }
267
327
  return tree;
268
328
  }
@@ -270,34 +330,29 @@ function buildLanguageTree(registry, lang, defaultLang) {
270
330
  * Build the eager (root) tree — only modules declared without `{ scoped: true }`.
271
331
  * Used by the generator when route-level scope providers are adopted.
272
332
  */
273
- function buildEagerTree(registry, lang, defaultLang) {
274
- const tree = {};
275
- for (const mod of registry) {
276
- if (mod.scoped)
277
- continue;
278
- const subtree = extractLanguage(mod.translations, lang, defaultLang);
279
- setAtScope(tree, mod.scope, subtree);
280
- }
281
- return tree;
333
+ function buildEagerTree(registry, lang, defaultLang, options) {
334
+ return buildLanguageTree(registry.filter((mod) => !mod.scoped), lang, defaultLang, options);
282
335
  }
283
336
  /**
284
- * Build the per-scope tree for a single scoped module — returned unwrapped
285
- * (no scope key around it), matching the layout `provideTranslocoScope` expects
286
- * to load from `<scope-with-slashes>/<lang>.json`.
337
+ * Build the per-scope tree for a scope — returned unwrapped (no scope key
338
+ * around it), matching the layout `provideTranslocoScope` expects to load from
339
+ * `<scope-with-slashes>/<lang>.json`. Every scoped module declaring that scope
340
+ * is merged in.
287
341
  *
288
342
  * `scope` may be given in dotted (`administration.users`) or slash form
289
343
  * (`administration/users` — what Transloco hands a loader); both match.
290
344
  *
291
- * Returns `null` if no module with the given scope exists, or if it's eager.
345
+ * Returns `null` if no scoped module declares the scope.
292
346
  */
293
- function buildScopedTree(registry, lang, defaultLang, scope) {
347
+ function buildScopedTree(registry, lang, defaultLang, scope, options) {
294
348
  const wanted = normalizeScope(scope);
295
- for (const mod of registry) {
296
- if (mod.scoped && normalizeScope(mod.scope) === wanted) {
297
- return extractLanguage(mod.translations, lang, defaultLang);
298
- }
299
- }
300
- return null;
349
+ const modules = registry.filter((mod) => mod.scoped && normalizeScope(mod.scope) === wanted);
350
+ if (modules.length === 0)
351
+ return null;
352
+ const tree = {};
353
+ for (const mod of modules)
354
+ mergeInto(tree, extractLanguage(mod.translations, lang, defaultLang, options), wanted);
355
+ return tree;
301
356
  }
302
357
  /**
303
358
  * Convert a dot-separated scope to its filesystem path.
@@ -335,5 +390,5 @@ function normalizeScope(scope) {
335
390
  * Generated bundle index. Do not edit.
336
391
  */
337
392
 
338
- export { SOURCE_LANG, TRANSLATION_BRAND, buildEagerTree, buildKeysTree, buildLanguageTree, buildScopedTree, defineTranslations, extractLanguage, getTranslation, isTranslationValue, normalizeScope, scopeToFilesystemPath, setAtScope, t };
393
+ export { SOURCE_LANG, TRANSLATION_BRAND, buildEagerTree, buildKeysTree, buildLanguageTree, buildScopedTree, defineTranslations, extractLanguage, findKeyConflicts, getTranslation, isTranslationValue, mergeKeys, normalizeScope, scopeToFilesystemPath, setAtScope, t };
339
394
  //# sourceMappingURL=hakistack-i18n-engine.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"hakistack-i18n-engine.mjs","sources":["../../../../projects/hakistack/i18n/engine/define-translations.ts","../../../../projects/hakistack/i18n/engine/build-tree.ts","../../../../projects/hakistack/i18n/engine/public-api.ts","../../../../projects/hakistack/i18n/engine/hakistack-i18n-engine.ts"],"sourcesContent":["/**\n * Type-safe translation definitions — the authoring heart of `@hakistack/i18n`.\n *\n * Consumers author translations in `.ts` files (`*.i18n.ts`) using\n * `defineTranslations()` + `t()`. English is the required source locale; every\n * other locale is optional. The companion `keys` object gives type-safe\n * dot-path access at the value level, and the scanner derives a merged `TK`\n * literal from these modules.\n *\n * Unlike the original app-local engine, locales here are **not hardcoded**.\n * Consumers declare their locale union by augmenting the {@link I18nLocales}\n * interface (the scanner / schematic can emit this augmentation), so `t()` gets\n * autocomplete on exactly the locales the project supports.\n */\n\n// =============================================================================\n// Locale configuration (consumer-augmented)\n// =============================================================================\n\n/**\n * The set of locales a project supports, as a type.\n *\n * `en` is the always-present source locale (English is the source of truth).\n * Consumers add their other locales by declaration-merging this interface:\n *\n * ```ts\n * declare module '@hakistack/i18n/engine' {\n * interface I18nLocales {\n * es: string;\n * fr: string;\n * }\n * }\n * ```\n *\n * After augmentation, `t('Hello', { es: '…', fr: '…' })` autocompletes `es`/`fr`\n * and `Language` resolves to `'en' | 'es' | 'fr'`.\n */\nexport interface I18nLocales {\n /** Source locale — always required on every translation value. */\n en: string;\n}\n\n/** Union of every declared locale id (e.g. `'en' | 'es'`). */\nexport type LocaleId = keyof I18nLocales & string;\n\n/**\n * The source locale. `t()` stores its first argument here, every other locale\n * is optional, and build-time + runtime fallbacks end here. This is fixed by\n * the engine's types (`TranslationValue.en`), so it is not configurable.\n */\nexport const SOURCE_LANG = 'en';\nexport type SourceLang = typeof SOURCE_LANG;\n\n/**\n * Runtime brand stamped (non-enumerably) on every `TranslationValue` produced\n * by `t()` or by bare-string normalization.\n *\n * Without a brand, a *group* whose child happens to be named `en` — e.g.\n * `languages: { en: 'English', es: 'Español' }` in a language picker — is\n * indistinguishable from a leaf. `Symbol.for` (global registry) is used so the\n * codegen CLI (which bundles its own copy of the engine) recognizes values\n * created by the consumer's installed copy.\n */\nexport const TRANSLATION_BRAND: unique symbol = Symbol.for('@hakistack/i18n:translation-value');\n\n/** Alias kept for ergonomics — the active/target language id. */\nexport type Language = LocaleId;\n\n// =============================================================================\n// Type Definitions\n// =============================================================================\n\n/**\n * A single translation value across all declared locales.\n *\n * English (`en`) is required; every other declared locale is optional and falls\n * back to English at build time and runtime. The optional `__comment` field\n * stores translator-facing context — it is emitted as a sibling `<key>.comment`\n * entry in the JSON and stripped by the runtime interceptor so it never renders.\n */\nexport type TranslationValue = OtherLocales & {\n en: string;\n /** Internal — translator-context comment, attached via `t(en, others, { comment })`. */\n __comment?: string;\n /** Internal — runtime brand; only `t()` / normalization create branded values. */\n readonly [TRANSLATION_BRAND]: true;\n};\n\n/** Optional non-source locale fields, derived from the augmented locale set. */\nexport type OtherLocales = {\n [K in Exclude<LocaleId, 'en'>]?: string;\n};\n\n/**\n * Define a single translation value.\n *\n * @param en - English (source) translation — required.\n * @param translations - Other-locale translations — optional, autocompletes the\n * consumer's declared locales.\n * @param options.comment - Translator-facing context. Emitted as a sibling\n * `<key>.comment` entry in the JSON for translator review; stripped at runtime\n * by the comment interceptor so it never renders.\n *\n * @example\n * t('Hello', { es: 'Hola' })\n * t('Save') // English only — other locales fall back to English\n * t('Welcome', { es: '¡Bienvenido!' }, { comment: 'Greeting on home dashboard' })\n */\nexport function t(en: string, translations?: OtherLocales, options?: { comment?: string }): TranslationValue {\n const value = brand({ en, ...translations });\n if (options?.comment) {\n value.__comment = options.comment;\n }\n return value;\n}\n\n/** Stamp the non-enumerable brand on a plain `{ en, … }` record. */\nfunction brand(value: OtherLocales & { en: string; __comment?: string }): TranslationValue {\n Object.defineProperty(value, TRANSLATION_BRAND, { value: true, enumerable: false, writable: false, configurable: false });\n return value as TranslationValue;\n}\n\n/**\n * Authored translation node — what callers write inside `defineTranslations()`.\n * Accepts:\n * - `TranslationValue` (full form, from `t()`)\n * - `string` (shorthand for English-only — equivalent to `t(value)`)\n * - nested object of either\n *\n * Only `t()` produces a leaf. A hand-written `{ en: '…', es: '…' }` object is a\n * *group* with children named `en`/`es` — which is what a language picker wants.\n *\n * Strings are normalized to `TranslationValue` at module construction so the\n * rest of the pipeline (generator, validator, keys builder) only ever sees the\n * canonical `{ en, … }` shape.\n *\n * Note: any leaf string containing `{{…}}` placeholders MUST use `t()` — the\n * validator rejects bare placeholder strings because parity across locales\n * cannot be expressed with the shorthand.\n */\nexport type AuthoredTranslationNode = TranslationValue | string | { [key: string]: AuthoredTranslationNode };\n\n/** Canonical (post-normalization) translation node — internal use only. */\ntype TranslationNode = TranslationValue | { [key: string]: TranslationNode };\n\n/**\n * Recursively builds dot-notation key strings from the authored object shape.\n * Treats both `TranslationValue` and `string` as leaves (string is shorthand).\n */\ntype BuildKeyObject<T, Prefix extends string = ''> = {\n readonly [K in keyof T]: K extends string\n ? T[K] extends TranslationValue | string\n ? Prefix extends ''\n ? K\n : `${Prefix}.${K}`\n : T[K] extends Record<string, unknown>\n ? BuildKeyObject<T[K], Prefix extends '' ? K : `${Prefix}.${K}`>\n : never\n : never;\n};\n\n/**\n * Translation module returned by {@link defineTranslations}.\n *\n * `translations` stores the normalized form (every bare string promoted to\n * `{ en: value }`); `keys` is the type-derived companion of dot-paths.\n */\nexport interface TranslationModule<T extends Record<string, AuthoredTranslationNode> = Record<string, AuthoredTranslationNode>> {\n /** Scope/prefix for these translations (e.g. `'common'`, `'administration.users'`). */\n scope: string;\n /** Normalized translation definitions (strings promoted to `{ en: value }`). */\n translations: T;\n /** Auto-generated keys object for type-safe usage. */\n keys: BuildKeyObject<T>;\n /**\n * If `true`, the generator emits this module's data to a subdirectory matching\n * its scope path (`administration.users` → `administration/users/<lang>.json`)\n * rather than merging into the root `<lang>.json`. Future-proofs\n * `provideTranslocoScope`-based lazy loading. Default: `false` (eager).\n */\n scoped: boolean;\n}\n\n/**\n * Define a translation module with auto-generated keys.\n *\n * @param scope - The scope/prefix for these translations.\n * @param translations - The translation definitions (full `t()` form or\n * bare-string shorthand, nested freely).\n * @param options.scoped - Emit to a per-scope JSON file (see {@link TranslationModule.scoped}).\n *\n * @example\n * export const COMMON = defineTranslations('common', {\n * buttons: {\n * save: t('Save', { es: 'Guardar' }),\n * cancel: t('Cancel', { es: 'Cancelar' }),\n * reset: 'Reset', // shorthand\n * },\n * });\n * // COMMON.keys.buttons.save === 'common.buttons.save'\n */\nexport function defineTranslations<T extends Record<string, AuthoredTranslationNode>>(\n scope: string,\n translations: T,\n options?: { scoped?: boolean },\n): TranslationModule<T> {\n const normalized = normalizeTree(translations) as Record<string, TranslationNode>;\n const keys = buildKeys(normalized, scope) as BuildKeyObject<T>;\n return {\n scope,\n translations: normalized as unknown as T,\n keys,\n scoped: options?.scoped ?? false,\n };\n}\n\n// =============================================================================\n// Internal Utilities\n// =============================================================================\n\n/**\n * Normalize an authored tree by replacing every bare-string leaf with\n * `{ en: value }`. The output contains only `TranslationValue` leaves and\n * nested records — the canonical shape consumed by the generator/validator.\n */\nfunction normalizeTree(node: AuthoredTranslationNode): TranslationNode {\n if (typeof node === 'string') {\n return brand({ en: node });\n }\n if (isTranslationValue(node)) {\n return node;\n }\n const result: Record<string, TranslationNode> = {};\n for (const [key, value] of Object.entries(node)) {\n result[key] = normalizeTree(value as AuthoredTranslationNode);\n }\n return result;\n}\n\n/** Recursively builds the dot-path keys object from a normalized tree. */\nfunction buildKeys(obj: Record<string, unknown>, prefix: string): Record<string, unknown> {\n const result: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(obj)) {\n const fullKey = prefix ? `${prefix}.${key}` : key;\n if (isTranslationValue(value)) {\n result[key] = fullKey;\n } else if (typeof value === 'object' && value !== null) {\n result[key] = buildKeys(value as Record<string, unknown>, fullKey);\n }\n }\n return result;\n}\n\n/** Type guard: is this value a branded `TranslationValue` (created by `t()` or normalization)? */\nexport function isTranslationValue(value: unknown): value is TranslationValue {\n return value !== null && typeof value === 'object' && (value as Record<symbol, unknown>)[TRANSLATION_BRAND] === true;\n}\n\n// =============================================================================\n// Auto-derive a merged keys tree from module scopes (value-level)\n// =============================================================================\n\n/**\n * Build a merged keys tree from a list of translation modules by placing each\n * module's `keys` object at its scope path and deep-merging.\n *\n * This is the **runtime** value used by the directive (via the `I18N_KEYS`\n * token) — it produces the exact nested shape the scanner emits as the typed\n * `TK` literal. The scanner emits a concrete literal for *compile-time*\n * autocomplete; this function produces the identical structure at runtime, so\n * the two never diverge.\n *\n * Modules sharing a scope are merged (the scanner emits the same spread for the\n * `TK` literal). Throws on scalar/scope conflicts.\n */\nexport function buildKeysTree(modules: readonly TranslationModule[]): Record<string, unknown> {\n const tree: Record<string, unknown> = {};\n\n // Sort by scope depth so parent scopes are placed before children — guarantees\n // a deeper scope descends through an already-copied parent slot.\n const sorted = [...modules].sort((a, b) => a.scope.split('.').length - b.scope.split('.').length);\n\n for (const mod of sorted) {\n placeAtScope(tree, mod.scope, mod.keys);\n }\n return tree;\n}\n\nfunction placeAtScope(tree: Record<string, unknown>, scope: string, keys: unknown): void {\n const path = scope.split('.');\n let current = tree;\n\n for (let i = 0; i < path.length - 1; i++) {\n const part = path[i];\n const slot = current[part];\n if (slot === undefined) {\n current[part] = {};\n } else if (typeof slot !== 'object' || slot === null) {\n throw new Error(`i18n: scope conflict at '${path.slice(0, i + 1).join('.')}': scalar where nested scope expected`);\n }\n current = current[part] as Record<string, unknown>;\n }\n\n const leaf = path[path.length - 1];\n const existing = current[leaf];\n\n if (existing === undefined) {\n current[leaf] = { ...(keys as object) };\n } else if (typeof existing === 'object' && existing !== null) {\n current[leaf] = { ...(keys as object), ...(existing as object) };\n } else {\n throw new Error(`i18n: scope conflict at '${scope}': scalar where nested scope expected`);\n }\n}\n","/**\n * Build a per-language translation tree from the in-memory module registry.\n *\n * Shared by:\n * - the generator CLI — writes the tree as JSON to `<outputDir>/<lang>.json`\n * for translator-facing tooling (build artifacts, not a runtime dependency).\n * - the runtime `TranslocoRegistryLoader` — returns the tree synchronously to\n * Transloco, eliminating the HTTP fetch.\n *\n * Producing the tree from the registry guarantees the runtime sees the exact\n * shape the generator emits — there's no \"JSON drifted from TS\" failure mode.\n *\n * Locale handling is parameterized: every function takes the `defaultLang`\n * (source/fallback locale) explicitly rather than reading a hardcoded constant,\n * so the engine is reusable across consumers with different locale sets.\n */\n\nimport { AuthoredTranslationNode, isTranslationValue, TranslationModule, TranslationValue } from './define-translations';\n\n/** A nested string-tree as Transloco / the JSON files consume it. */\nexport interface LanguageTree {\n [key: string]: string | LanguageTree;\n}\n\n/**\n * Resolve a single `TranslationValue` for a given language.\n * Falls back to `defaultLang` for any locale that didn't supply a translation —\n * mirrors `useFallbackTranslation: true` in the runtime Transloco config.\n */\nexport function getTranslation(value: TranslationValue, lang: string, defaultLang: string): string {\n const byLang = value as Record<string, string | undefined>;\n if (lang === defaultLang) {\n return byLang[defaultLang] ?? value.en;\n }\n return byLang[lang] ?? byLang[defaultLang] ?? value.en;\n}\n\n/**\n * Walk a normalized translation subtree (all leaves are `TranslationValue`s) and\n * emit a string-only tree for the given language.\n *\n * If a leaf carries a `__comment` (set via `t(en, others, { comment })`), a\n * sibling entry `<key>.comment` is added at the same level. Translators see it;\n * the runtime interceptor strips it before it reaches the store.\n */\nexport function extractLanguage(translations: Record<string, unknown>, lang: string, defaultLang: string): LanguageTree {\n const result: LanguageTree = {};\n for (const [key, value] of Object.entries(translations)) {\n if (isTranslationValue(value)) {\n result[key] = getTranslation(value, lang, defaultLang);\n if (value.__comment) {\n result[`${key}.comment`] = value.__comment;\n }\n } else if (typeof value === 'object' && value !== null) {\n result[key] = extractLanguage(value as Record<string, unknown>, lang, defaultLang);\n }\n }\n return result;\n}\n\n/**\n * Place a subtree at a dot-delimited scope path in the target tree, creating\n * intermediate objects as needed. If the path already holds an object, the new\n * subtree's leaves are merged into it.\n */\nexport function setAtScope(target: LanguageTree, scope: string, subtree: LanguageTree): void {\n const parts = scope.split('.');\n let current: LanguageTree = target;\n\n for (let i = 0; i < parts.length - 1; i++) {\n const part = parts[i];\n const slot = current[part];\n if (slot === undefined || typeof slot === 'string') {\n current[part] = {};\n }\n current = current[part] as LanguageTree;\n }\n\n const leaf = parts[parts.length - 1];\n const existing = current[leaf];\n if (existing && typeof existing === 'object') {\n Object.assign(existing, subtree);\n } else {\n current[leaf] = subtree;\n }\n}\n\n/**\n * Build the complete translation tree for a single language from the registry.\n * The returned tree matches the JSON file layout exactly — same keys, nesting,\n * and fallbacks — so a consumer cannot tell whether the data came from the\n * registry or from disk.\n */\nexport function buildLanguageTree(\n registry: readonly TranslationModule<Record<string, AuthoredTranslationNode>>[],\n lang: string,\n defaultLang: string,\n): LanguageTree {\n const tree: LanguageTree = {};\n for (const mod of registry) {\n const subtree = extractLanguage(mod.translations, lang, defaultLang);\n setAtScope(tree, mod.scope, subtree);\n }\n return tree;\n}\n\n/**\n * Build the eager (root) tree — only modules declared without `{ scoped: true }`.\n * Used by the generator when route-level scope providers are adopted.\n */\nexport function buildEagerTree(\n registry: readonly TranslationModule<Record<string, AuthoredTranslationNode>>[],\n lang: string,\n defaultLang: string,\n): LanguageTree {\n const tree: LanguageTree = {};\n for (const mod of registry) {\n if (mod.scoped) continue;\n const subtree = extractLanguage(mod.translations, lang, defaultLang);\n setAtScope(tree, mod.scope, subtree);\n }\n return tree;\n}\n\n/**\n * Build the per-scope tree for a single scoped module — returned unwrapped\n * (no scope key around it), matching the layout `provideTranslocoScope` expects\n * to load from `<scope-with-slashes>/<lang>.json`.\n *\n * `scope` may be given in dotted (`administration.users`) or slash form\n * (`administration/users` — what Transloco hands a loader); both match.\n *\n * Returns `null` if no module with the given scope exists, or if it's eager.\n */\nexport function buildScopedTree(\n registry: readonly TranslationModule<Record<string, AuthoredTranslationNode>>[],\n lang: string,\n defaultLang: string,\n scope: string,\n): LanguageTree | null {\n const wanted = normalizeScope(scope);\n for (const mod of registry) {\n if (mod.scoped && normalizeScope(mod.scope) === wanted) {\n return extractLanguage(mod.translations, lang, defaultLang);\n }\n }\n return null;\n}\n\n/**\n * Convert a dot-separated scope to its filesystem path.\n * 'administration.users' → 'administration/users'\n */\nexport function scopeToFilesystemPath(scope: string): string {\n return scope.replace(/\\./g, '/');\n}\n\n/**\n * Canonical dotted form of a scope, accepting either separator.\n * 'administration/users' → 'administration.users'\n */\nexport function normalizeScope(scope: string): string {\n return scope.replace(/\\//g, '.');\n}\n","/*\n * @hakistack/i18n/engine\n *\n * The Angular-free authoring + tree-building engine. This entry point has NO\n * Angular dependency, so it loads in a plain Node context — which is what lets\n * the codegen CLI execute your `*.i18n.ts` modules via a TS loader.\n *\n * Author your translation modules against THIS entry point:\n *\n * ```ts\n * import { defineTranslations, t } from '@hakistack/i18n/engine';\n * ```\n *\n * Runtime APIs (`provideI18n`, `translateSignal`, the directive base) live on\n * the main `@hakistack/i18n` entry point.\n */\n\nexport { buildKeysTree, defineTranslations, isTranslationValue, SOURCE_LANG, t, TRANSLATION_BRAND } from './define-translations';\nexport type {\n AuthoredTranslationNode,\n I18nLocales,\n Language,\n LocaleId,\n OtherLocales,\n SourceLang,\n TranslationModule,\n TranslationValue,\n} from './define-translations';\n\nexport {\n buildEagerTree,\n buildLanguageTree,\n buildScopedTree,\n extractLanguage,\n getTranslation,\n normalizeScope,\n scopeToFilesystemPath,\n setAtScope,\n} from './build-tree';\nexport type { LanguageTree } from './build-tree';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;AAaG;AAgCH;;;;AAIG;AACI,MAAM,WAAW,GAAG;AAG3B;;;;;;;;;AASG;AACI,MAAM,iBAAiB,GAAkB,MAAM,CAAC,GAAG,CAAC,mCAAmC;AA8B9F;;;;;;;;;;;;;;AAcG;SACa,CAAC,CAAC,EAAU,EAAE,YAA2B,EAAE,OAA8B,EAAA;IACvF,MAAM,KAAK,GAAG,KAAK,CAAC,EAAE,EAAE,EAAE,GAAG,YAAY,EAAE,CAAC;AAC5C,IAAA,IAAI,OAAO,EAAE,OAAO,EAAE;AACpB,QAAA,KAAK,CAAC,SAAS,GAAG,OAAO,CAAC,OAAO;IACnC;AACA,IAAA,OAAO,KAAK;AACd;AAEA;AACA,SAA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KAAK,EAAE,OAAO,CAAC;IACtC;AACA,IAAA,OAAO,IAAI;AACb;AAEA;;;;;;;;;AASG;AACG,SAAU,eAAe,CAC7B,QAA+E,EAC/E,IAAY,EACZ,WAAmB,EACnB,KAAa,EAAA;AAEb,IAAA,MAAM,MAAM,GAAG,cAAc,CAAC,KAAK,CAAC;AACpC,IAAA,KAAK,MAAM,GAAG,IAAI,QAAQ,EAAE;AAC1B,QAAA,IAAI,GAAG,CAAC,MAAM,IAAI,cAAc,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,MAAM,EAAE;YACtD,OAAO,eAAe,CAAC,GAAG,CAAC,YAAY,EAAE,IAAI,EAAE,WAAW,CAAC;QAC7D;IACF;AACA,IAAA,OAAO,IAAI;AACb;AAEA;;;AAGG;AACG,SAAU,qBAAqB,CAAC,KAAa,EAAA;IACjD,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC;AAClC;AAEA;;;AAGG;AACG,SAAU,cAAc,CAAC,KAAa,EAAA;IAC1C,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC;AAClC;;ACnKA;;;;;;;;;;;;;;;AAeG;;ACfH;;AAEG;;;;"}
1
+ {"version":3,"file":"hakistack-i18n-engine.mjs","sources":["../../../../projects/hakistack/i18n/engine/merge.ts","../../../../projects/hakistack/i18n/engine/define-translations.ts","../../../../projects/hakistack/i18n/engine/build-tree.ts","../../../../projects/hakistack/i18n/engine/public-api.ts","../../../../projects/hakistack/i18n/engine/hakistack-i18n-engine.ts"],"sourcesContent":["/**\n * The single deep-merge used to assemble every tree built from several\n * translation modules: the runtime keys tree (`buildKeysTree`), the generated\n * `TK` literal (`mergeKeys`) and the per-language trees (`buildLanguageTree`).\n *\n * One implementation means the three can never disagree about which keys exist\n * when modules share a scope or nest under each other. A key defined twice, or\n * a key that is both a translation and a group, is an authoring error and throws\n * instead of letting one module silently win.\n */\n\ntype Tree = Record<string, unknown>;\n\nfunction isTree(value: unknown): value is Tree {\n return typeof value === 'object' && value !== null;\n}\n\nfunction cloneTree(tree: Tree): Tree {\n const out: Tree = {};\n for (const [key, value] of Object.entries(tree)) out[key] = isTree(value) ? cloneTree(value) : value;\n return out;\n}\n\n/**\n * Deep-merge `source` into `target` (never mutating `source`). `path` is the\n * dotted location of `target`, used in error messages. With `keysTree`, string\n * leaves are full translation keys and are quoted as-is in errors.\n */\nexport function mergeInto(target: Tree, source: Tree, path = '', keysTree = false): void {\n for (const [key, value] of Object.entries(source)) {\n const at = path ? `${path}.${key}` : key;\n const existing = target[key];\n if (existing === undefined) {\n target[key] = isTree(value) ? cloneTree(value) : value;\n } else if (isTree(existing) && isTree(value)) {\n mergeInto(existing, value, at, keysTree);\n } else if (!isTree(existing) && !isTree(value)) {\n throw new Error(`i18n: duplicate translation key '${keysTree ? String(existing) : at}' — it is defined by more than one module.`);\n } else {\n throw new Error(`i18n: '${at}' is both a translation and a group of translations (check modules sharing or nesting this scope).`);\n }\n }\n}\n\n/** Wrap `subtree` in nested objects following a dotted `scope` (`'a.b'` → `{ a: { b: subtree } }`). */\nexport function nestAtScope(scope: string, subtree: Tree): Tree {\n return scope\n .split('.')\n .reverse()\n .reduce<Tree>((inner, part) => ({ [part]: inner }), subtree);\n}\n\ntype Intersect<T extends readonly unknown[]> = T extends readonly [infer Head, ...infer Rest] ? Head & Intersect<Rest> : unknown;\n\n/**\n * Deep-merge several keys objects into one. Emitted by `hakistack-i18n scan`\n * wherever several modules contribute to the same `TK` branch (modules sharing\n * a scope, or a module plus deeper scopes nested under it). The intersection\n * type exposes every contributed key, matching the runtime value exactly.\n *\n * @example\n * mergeKeys(COMMON_A.keys, COMMON_B.keys, { users: ADMIN_USERS.keys })\n */\nexport function mergeKeys<const T extends readonly object[]>(...parts: T): Intersect<T> {\n const out: Tree = {};\n for (const part of parts) mergeInto(out, part as Tree, '', true);\n return out as Intersect<T>;\n}\n","/**\n * Type-safe translation definitions — the authoring heart of `@hakistack/i18n`.\n *\n * Consumers author translations in `.ts` files (`*.i18n.ts`) using\n * `defineTranslations()` + `t()`. English is the required source locale; every\n * other locale is optional. The companion `keys` object gives type-safe\n * dot-path access at the value level, and the scanner derives a merged `TK`\n * literal from these modules.\n *\n * Unlike the original app-local engine, locales here are **not hardcoded**.\n * Consumers declare their locale union by augmenting the {@link I18nLocales}\n * interface (the scanner / schematic can emit this augmentation), so `t()` gets\n * autocomplete on exactly the locales the project supports.\n */\n\nimport { mergeInto, nestAtScope } from './merge';\n\n// =============================================================================\n// Locale configuration (consumer-augmented)\n// =============================================================================\n\n/**\n * The set of locales a project supports, as a type.\n *\n * `en` is the always-present source locale (English is the source of truth).\n * Consumers add their other locales by declaration-merging this interface:\n *\n * ```ts\n * declare module '@hakistack/i18n/engine' {\n * interface I18nLocales {\n * es: string;\n * fr: string;\n * }\n * }\n * ```\n *\n * After augmentation, `t('Hello', { es: '…', fr: '…' })` autocompletes `es`/`fr`\n * and `Language` resolves to `'en' | 'es' | 'fr'`.\n */\nexport interface I18nLocales {\n /** Source locale — always required on every translation value. */\n en: string;\n}\n\n/** Union of every declared locale id (e.g. `'en' | 'es'`). */\nexport type LocaleId = keyof I18nLocales & string;\n\n/**\n * The source locale. `t()` stores its first argument here, every other locale\n * is optional, and build-time + runtime fallbacks end here. This is fixed by\n * the engine's types (`TranslationValue.en`), so it is not configurable.\n */\nexport const SOURCE_LANG = 'en';\nexport type SourceLang = typeof SOURCE_LANG;\n\n/**\n * Runtime brand stamped (non-enumerably) on every `TranslationValue` produced\n * by `t()` or by bare-string normalization.\n *\n * Without a brand, a *group* whose child happens to be named `en` — e.g.\n * `languages: { en: 'English', es: 'Español' }` in a language picker — is\n * indistinguishable from a leaf. `Symbol.for` (global registry) is used so the\n * codegen CLI (which bundles its own copy of the engine) recognizes values\n * created by the consumer's installed copy.\n */\nexport const TRANSLATION_BRAND: unique symbol = Symbol.for('@hakistack/i18n:translation-value');\n\n/** Alias kept for ergonomics — the active/target language id. */\nexport type Language = LocaleId;\n\n// =============================================================================\n// Type Definitions\n// =============================================================================\n\n/**\n * A single translation value across all declared locales.\n *\n * English (`en`) is required; every other declared locale is optional and falls\n * back to English at build time and runtime. The optional `__comment` field\n * stores translator-facing context — it is emitted as a sibling `<key>.comment`\n * entry in the JSON and stripped by the runtime interceptor so it never renders.\n */\nexport type TranslationValue = OtherLocales & {\n en: string;\n /** Internal — translator-context comment, attached via `t(en, others, { comment })`. */\n __comment?: string;\n /** Internal — runtime brand; only `t()` / normalization create branded values. */\n readonly [TRANSLATION_BRAND]: true;\n};\n\n/** Optional non-source locale fields, derived from the augmented locale set. */\nexport type OtherLocales = {\n [K in Exclude<LocaleId, 'en'>]?: string;\n};\n\n/**\n * Define a single translation value.\n *\n * @param en - English (source) translation — required.\n * @param translations - Other-locale translations — optional, autocompletes the\n * consumer's declared locales.\n * @param options.comment - Translator-facing context. Emitted as a sibling\n * `<key>.comment` entry in the JSON for translator review; stripped at runtime\n * by the comment interceptor so it never renders.\n *\n * @example\n * t('Hello', { es: 'Hola' })\n * t('Save') // English only — other locales fall back to English\n * t('Welcome', { es: '¡Bienvenido!' }, { comment: 'Greeting on home dashboard' })\n */\nexport function t(en: string, translations?: OtherLocales, options?: { comment?: string }): TranslationValue {\n const value = brand({ en, ...translations });\n if (options?.comment) {\n value.__comment = options.comment;\n }\n return value;\n}\n\n/** Stamp the non-enumerable brand on a plain `{ en, … }` record. */\nfunction brand(value: OtherLocales & { en: string; __comment?: string }): TranslationValue {\n Object.defineProperty(value, TRANSLATION_BRAND, { value: true, enumerable: false, writable: false, configurable: false });\n return value as TranslationValue;\n}\n\n/**\n * Authored translation node — what callers write inside `defineTranslations()`.\n * Accepts:\n * - `TranslationValue` (full form, from `t()`)\n * - `string` (shorthand for English-only — equivalent to `t(value)`)\n * - nested object of either\n *\n * Only `t()` produces a leaf. A hand-written `{ en: '…', es: '…' }` object is a\n * *group* with children named `en`/`es` — which is what a language picker wants.\n *\n * Strings are normalized to `TranslationValue` at module construction so the\n * rest of the pipeline (generator, validator, keys builder) only ever sees the\n * canonical `{ en, … }` shape.\n *\n * Note: any leaf string containing `{{…}}` placeholders MUST use `t()` — the\n * validator rejects bare placeholder strings because parity across locales\n * cannot be expressed with the shorthand.\n */\nexport type AuthoredTranslationNode = TranslationValue | string | { [key: string]: AuthoredTranslationNode };\n\n/** Canonical (post-normalization) translation node — internal use only. */\ntype TranslationNode = TranslationValue | { [key: string]: TranslationNode };\n\n/**\n * Recursively builds dot-notation key strings from the authored object shape.\n * Treats both `TranslationValue` and `string` as leaves (string is shorthand).\n */\ntype BuildKeyObject<T, Prefix extends string = ''> = {\n readonly [K in keyof T]: K extends string\n ? T[K] extends TranslationValue | string\n ? Join<Prefix, K>\n : T[K] extends Record<string, unknown>\n ? BuildKeyObject<T[K], Join<Prefix, K>>\n : never\n : never;\n};\n\ntype Join<Prefix extends string, K extends string> = Prefix extends '' ? K : `${Prefix}.${K}`;\n\n/**\n * Translation module returned by {@link defineTranslations}.\n *\n * `translations` stores the normalized form (every bare string promoted to\n * `{ en: value }`); `keys` is the type-derived companion of dot-paths.\n */\nexport interface TranslationModule<\n T extends Record<string, AuthoredTranslationNode> = Record<string, AuthoredTranslationNode>,\n S extends string = string,\n> {\n /** Scope/prefix for these translations (e.g. `'common'`, `'administration.users'`). */\n scope: S;\n /** Normalized translation definitions (strings promoted to `{ en: value }`). */\n translations: T;\n /** Auto-generated keys object for type-safe usage (full keys, scope included: `'common.buttons.save'`). */\n keys: BuildKeyObject<T, S>;\n /**\n * If `true`, the generator emits this module's data to a subdirectory matching\n * its scope path (`administration.users` → `administration/users/<lang>.json`)\n * rather than merging into the root `<lang>.json`. Future-proofs\n * `provideTranslocoScope`-based lazy loading. Default: `false` (eager).\n */\n scoped: boolean;\n}\n\n/**\n * Define a translation module with auto-generated keys.\n *\n * @param scope - The scope/prefix for these translations.\n * @param translations - The translation definitions (full `t()` form or\n * bare-string shorthand, nested freely).\n * @param options.scoped - Emit to a per-scope JSON file (see {@link TranslationModule.scoped}).\n *\n * @example\n * export const COMMON = defineTranslations('common', {\n * buttons: {\n * save: t('Save', { es: 'Guardar' }),\n * cancel: t('Cancel', { es: 'Cancelar' }),\n * reset: 'Reset', // shorthand\n * },\n * });\n * // COMMON.keys.buttons.save === 'common.buttons.save'\n */\nexport function defineTranslations<T extends Record<string, AuthoredTranslationNode>, const S extends string = string>(\n scope: S,\n translations: T,\n options?: { scoped?: boolean },\n): TranslationModule<T, S> {\n const normalized = normalizeTree(translations) as Record<string, TranslationNode>;\n const keys = buildKeys(normalized, scope) as BuildKeyObject<T, S>;\n return {\n scope,\n translations: normalized as unknown as T,\n keys,\n scoped: options?.scoped ?? false,\n };\n}\n\n// =============================================================================\n// Internal Utilities\n// =============================================================================\n\n/**\n * Normalize an authored tree by replacing every bare-string leaf with\n * `{ en: value }`. The output contains only `TranslationValue` leaves and\n * nested records — the canonical shape consumed by the generator/validator.\n */\nfunction normalizeTree(node: AuthoredTranslationNode): TranslationNode {\n if (typeof node === 'string') {\n return brand({ en: node });\n }\n if (isTranslationValue(node)) {\n return node;\n }\n const result: Record<string, TranslationNode> = {};\n for (const [key, value] of Object.entries(node)) {\n result[key] = normalizeTree(value as AuthoredTranslationNode);\n }\n return result;\n}\n\n/** Recursively builds the dot-path keys object from a normalized tree. */\nfunction buildKeys(obj: Record<string, unknown>, prefix: string): Record<string, unknown> {\n const result: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(obj)) {\n const fullKey = prefix ? `${prefix}.${key}` : key;\n if (isTranslationValue(value)) {\n result[key] = fullKey;\n } else if (typeof value === 'object' && value !== null) {\n result[key] = buildKeys(value as Record<string, unknown>, fullKey);\n }\n }\n return result;\n}\n\n/** Type guard: is this value a branded `TranslationValue` (created by `t()` or normalization)? */\nexport function isTranslationValue(value: unknown): value is TranslationValue {\n return value !== null && typeof value === 'object' && (value as Record<symbol, unknown>)[TRANSLATION_BRAND] === true;\n}\n\n// =============================================================================\n// Auto-derive a merged keys tree from module scopes (value-level)\n// =============================================================================\n\n/**\n * Build a merged keys tree from a list of translation modules by placing each\n * module's `keys` object at its scope path and deep-merging.\n *\n * This is the **runtime** value used by the directive (via the `I18N_KEYS`\n * token). It uses the same deep merge as the scanner-emitted `TK` literal\n * (`mergeKeys`) and the language trees, so all three agree on which keys exist.\n * Throws when a key is defined twice or is both a translation and a group.\n */\nexport function buildKeysTree(modules: readonly TranslationModule[]): Record<string, unknown> {\n const tree: Record<string, unknown> = {};\n for (const mod of modules) {\n mergeInto(tree, nestAtScope(mod.scope, mod.keys as Record<string, unknown>), '', true);\n }\n return tree;\n}\n\n// =============================================================================\n// Key conflicts (reported by the CLI before anything is generated)\n// =============================================================================\n\n/** A key defined by more than one module, or used both as a translation and as a group. */\nexport interface KeyConflict {\n /** Full dotted key, e.g. `'common.buttons.save'`. */\n key: string;\n kind: 'duplicate' | 'translation-and-group';\n /** Scopes of the modules involved (one entry per contributing module). */\n scopes: string[];\n}\n\n/**\n * Find every key collision across the registry, including the ones a deep\n * merge cannot see: a dotted key name (`'a.b'`) colliding with a nested group\n * (`a: { b }`) produces the same Transloco key.\n */\nexport function findKeyConflicts(modules: readonly TranslationModule[]): KeyConflict[] {\n const leaves: { key: string; scope: string }[] = [];\n const walk = (node: Record<string, unknown>, prefix: string, scope: string): void => {\n for (const [key, value] of Object.entries(node)) {\n const full = `${prefix}.${key}`;\n if (isTranslationValue(value)) leaves.push({ key: full, scope });\n else if (typeof value === 'object' && value !== null) walk(value as Record<string, unknown>, full, scope);\n }\n };\n for (const mod of modules) walk(mod.translations as Record<string, unknown>, mod.scope, mod.scope);\n return conflictsFromLeaves(leaves);\n}\n\n/**\n * Conflict detection over a flat list of full keys (one entry per definition).\n * Shared by {@link findKeyConflicts} (runtime registry) and the CLI scanner\n * (keys read statically from source).\n */\nexport function conflictsFromLeaves(leaves: Iterable<{ key: string; scope: string }>): KeyConflict[] {\n const byKey = new Map<string, string[]>();\n const groups = new Map<string, string[]>();\n const add = (map: Map<string, string[]>, key: string, scope: string) => map.set(key, [...(map.get(key) ?? []), scope]);\n for (const { key, scope } of leaves) {\n add(byKey, key, scope);\n const parts = key.split('.');\n for (let i = 1; i < parts.length; i++) add(groups, parts.slice(0, i).join('.'), scope);\n }\n\n const conflicts: KeyConflict[] = [];\n for (const [key, scopes] of byKey) {\n if (scopes.length > 1) conflicts.push({ key, kind: 'duplicate', scopes });\n const groupScopes = groups.get(key);\n if (groupScopes) conflicts.push({ key, kind: 'translation-and-group', scopes: [...new Set([...scopes, ...groupScopes])] });\n }\n return conflicts.sort((a, b) => a.key.localeCompare(b.key));\n}\n","/**\n * Build a per-language translation tree from the in-memory module registry.\n *\n * Shared by:\n * - the generator CLI — writes the tree as JSON to `<outputDir>/<lang>.json`\n * for translator-facing tooling (build artifacts, not a runtime dependency).\n * - the runtime `TranslocoRegistryLoader` — returns the tree synchronously to\n * Transloco, eliminating the HTTP fetch.\n *\n * Producing the tree from the registry guarantees the runtime sees the exact\n * shape the generator emits — there's no \"JSON drifted from TS\" failure mode.\n *\n * Locale handling is parameterized: every function takes the `defaultLang`\n * (source/fallback locale) explicitly rather than reading a hardcoded constant,\n * so the engine is reusable across consumers with different locale sets.\n */\n\nimport { AuthoredTranslationNode, isTranslationValue, TranslationModule, TranslationValue } from './define-translations';\nimport { mergeInto, nestAtScope } from './merge';\n\n/** A nested string-tree as Transloco / the JSON files consume it. */\nexport interface LanguageTree {\n [key: string]: string | LanguageTree;\n}\n\n/** Options for building string trees from the registry. */\nexport interface LanguageTreeOptions {\n /**\n * Emit translator comments as `<key>.comment` siblings. Default `true` (the\n * translator-facing JSON). The runtime registry loader passes `false` so\n * comments never reach Transloco's store.\n */\n comments?: boolean;\n}\n\n/**\n * Resolve a single `TranslationValue` for a given language.\n * Falls back to `defaultLang` for any locale that didn't supply a translation —\n * mirrors `useFallbackTranslation: true` in the runtime Transloco config.\n */\nexport function getTranslation(value: TranslationValue, lang: string, defaultLang: string): string {\n const byLang = value as Record<string, string | undefined>;\n if (lang === defaultLang) {\n return byLang[defaultLang] ?? value.en;\n }\n return byLang[lang] ?? byLang[defaultLang] ?? value.en;\n}\n\n/**\n * Walk a normalized translation subtree (all leaves are `TranslationValue`s) and\n * emit a string-only tree for the given language.\n *\n * If a leaf carries a `__comment` (set via `t(en, others, { comment })`) and\n * `options.comments` is not `false`, a sibling entry `<key>.comment` is added at\n * the same level for translators.\n */\nexport function extractLanguage(\n translations: Record<string, unknown>,\n lang: string,\n defaultLang: string,\n options: LanguageTreeOptions = {},\n): LanguageTree {\n const comments = options.comments ?? true;\n const result: LanguageTree = {};\n for (const [key, value] of Object.entries(translations)) {\n if (isTranslationValue(value)) {\n result[key] = getTranslation(value, lang, defaultLang);\n if (comments && value.__comment) {\n result[`${key}.comment`] = value.__comment;\n }\n } else if (typeof value === 'object' && value !== null) {\n result[key] = extractLanguage(value as Record<string, unknown>, lang, defaultLang, options);\n }\n }\n return result;\n}\n\n/**\n * Deep-merge a subtree into the target at a dot-delimited scope path, creating\n * intermediate objects as needed. Throws when a key would be defined twice or\n * when a translation and a group collide (see `mergeInto`).\n */\nexport function setAtScope(target: LanguageTree, scope: string, subtree: LanguageTree): void {\n mergeInto(target, nestAtScope(scope, subtree));\n}\n\ntype Registry = readonly TranslationModule<Record<string, AuthoredTranslationNode>>[];\n\n/**\n * Build the complete translation tree for a single language from the registry.\n * The returned tree matches the JSON file layout exactly — same keys, nesting,\n * and fallbacks — so a consumer cannot tell whether the data came from the\n * registry or from disk.\n */\nexport function buildLanguageTree(registry: Registry, lang: string, defaultLang: string, options?: LanguageTreeOptions): LanguageTree {\n const tree: LanguageTree = {};\n for (const mod of registry) {\n setAtScope(tree, mod.scope, extractLanguage(mod.translations, lang, defaultLang, options));\n }\n return tree;\n}\n\n/**\n * Build the eager (root) tree — only modules declared without `{ scoped: true }`.\n * Used by the generator when route-level scope providers are adopted.\n */\nexport function buildEagerTree(registry: Registry, lang: string, defaultLang: string, options?: LanguageTreeOptions): LanguageTree {\n return buildLanguageTree(\n registry.filter((mod) => !mod.scoped),\n lang,\n defaultLang,\n options,\n );\n}\n\n/**\n * Build the per-scope tree for a scope — returned unwrapped (no scope key\n * around it), matching the layout `provideTranslocoScope` expects to load from\n * `<scope-with-slashes>/<lang>.json`. Every scoped module declaring that scope\n * is merged in.\n *\n * `scope` may be given in dotted (`administration.users`) or slash form\n * (`administration/users` — what Transloco hands a loader); both match.\n *\n * Returns `null` if no scoped module declares the scope.\n */\nexport function buildScopedTree(\n registry: Registry,\n lang: string,\n defaultLang: string,\n scope: string,\n options?: LanguageTreeOptions,\n): LanguageTree | null {\n const wanted = normalizeScope(scope);\n const modules = registry.filter((mod) => mod.scoped && normalizeScope(mod.scope) === wanted);\n if (modules.length === 0) return null;\n const tree: LanguageTree = {};\n for (const mod of modules) mergeInto(tree, extractLanguage(mod.translations, lang, defaultLang, options), wanted);\n return tree;\n}\n\n/**\n * Convert a dot-separated scope to its filesystem path.\n * 'administration.users' → 'administration/users'\n */\nexport function scopeToFilesystemPath(scope: string): string {\n return scope.replace(/\\./g, '/');\n}\n\n/**\n * Canonical dotted form of a scope, accepting either separator.\n * 'administration/users' → 'administration.users'\n */\nexport function normalizeScope(scope: string): string {\n return scope.replace(/\\//g, '.');\n}\n","/*\n * @hakistack/i18n/engine\n *\n * The Angular-free authoring + tree-building engine. This entry point has NO\n * Angular dependency, so it loads in a plain Node context — which is what lets\n * the codegen CLI execute your `*.i18n.ts` modules via a TS loader.\n *\n * Author your translation modules against THIS entry point:\n *\n * ```ts\n * import { defineTranslations, t } from '@hakistack/i18n/engine';\n * ```\n *\n * Runtime APIs (`provideI18n`, `translateSignal`, the directive base) live on\n * the main `@hakistack/i18n` entry point.\n */\n\nexport {\n buildKeysTree,\n defineTranslations,\n findKeyConflicts,\n isTranslationValue,\n SOURCE_LANG,\n t,\n TRANSLATION_BRAND,\n} from './define-translations';\nexport type {\n AuthoredTranslationNode,\n I18nLocales,\n KeyConflict,\n Language,\n LocaleId,\n OtherLocales,\n SourceLang,\n TranslationModule,\n TranslationValue,\n} from './define-translations';\n\nexport {\n buildEagerTree,\n buildLanguageTree,\n buildScopedTree,\n extractLanguage,\n getTranslation,\n normalizeScope,\n scopeToFilesystemPath,\n setAtScope,\n} from './build-tree';\nexport type { LanguageTree, LanguageTreeOptions } from './build-tree';\n\nexport { mergeKeys } from './merge';\nexport type { I18nKey, KeyParams, ParamsOf } from './key-types';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":"AAAA;;;;;;;;;AASG;AAIH,SAAS,MAAM,CAAC,KAAc,EAAA;IAC5B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI;AACpD;AAEA,SAAS,SAAS,CAAC,IAAU,EAAA;IAC3B,MAAM,GAAG,GAAS,EAAE;AACpB,IAAA,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC;AAAE,QAAA,GAAG,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,GAAG,SAAS,CAAC,KAAK,CAAC,GAAG,KAAK;AACpG,IAAA,OAAO,GAAG;AACZ;AAEA;;;;AAIG;AACG,SAAU,SAAS,CAAC,MAAY,EAAE,MAAY,EAAE,IAAI,GAAG,EAAE,EAAE,QAAQ,GAAG,KAAK,EAAA;AAC/E,IAAA,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE;AACjD,QAAA,MAAM,EAAE,GAAG,IAAI,GAAG,CAAA,EAAG,IAAI,CAAA,CAAA,EAAI,GAAG,CAAA,CAAE,GAAG,GAAG;AACxC,QAAA,MAAM,QAAQ,GAAG,MAAM,CAAC,GAAG,CAAC;AAC5B,QAAA,IAAI,QAAQ,KAAK,SAAS,EAAE;AAC1B,YAAA,MAAM,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,GAAG,SAAS,CAAC,KAAK,CAAC,G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