@intlayer/types 8.4.4 → 8.4.6

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.
Files changed (52) hide show
  1. package/dist/cjs/_virtual/_rolldown/runtime.cjs +19 -0
  2. package/dist/cjs/allLocales.cjs +16 -1
  3. package/dist/cjs/allLocales.cjs.map +1 -1
  4. package/dist/cjs/config.cjs +24 -1
  5. package/dist/cjs/config.cjs.map +1 -1
  6. package/dist/cjs/index.cjs +32 -1
  7. package/dist/cjs/locales.cjs +1223 -1
  8. package/dist/cjs/locales.cjs.map +1 -0
  9. package/dist/cjs/nodeType.cjs +45 -1
  10. package/dist/cjs/nodeType.cjs.map +1 -1
  11. package/dist/esm/_virtual/_rolldown/runtime.mjs +18 -0
  12. package/dist/esm/allLocales.mjs +15 -1
  13. package/dist/esm/allLocales.mjs.map +1 -1
  14. package/dist/esm/config.mjs +22 -1
  15. package/dist/esm/config.mjs.map +1 -1
  16. package/dist/esm/index.mjs +6 -1
  17. package/dist/esm/locales.mjs +915 -1
  18. package/dist/esm/locales.mjs.map +1 -0
  19. package/dist/esm/nodeType.mjs +26 -1
  20. package/dist/esm/nodeType.mjs.map +1 -1
  21. package/dist/types/allLocales.d.ts +10 -2
  22. package/dist/types/allLocales.d.ts.map +1 -0
  23. package/dist/types/config.d.ts +1168 -2
  24. package/dist/types/config.d.ts.map +1 -0
  25. package/dist/types/dictionary.d.ts +376 -2
  26. package/dist/types/dictionary.d.ts.map +1 -0
  27. package/dist/types/filePathPattern.d.ts +29 -2
  28. package/dist/types/filePathPattern.d.ts.map +1 -0
  29. package/dist/types/index.d.ts +9 -5
  30. package/dist/types/keyPath.d.ts +13 -13
  31. package/dist/types/keyPath.d.ts.map +1 -1
  32. package/dist/types/locales.d.ts +610 -2
  33. package/dist/types/locales.d.ts.map +1 -0
  34. package/dist/types/module_augmentation.d.ts +29 -2
  35. package/dist/types/module_augmentation.d.ts.map +1 -0
  36. package/dist/types/nodeType.d.ts +31 -2
  37. package/dist/types/nodeType.d.ts.map +1 -0
  38. package/dist/types/plugin.d.ts +70 -2
  39. package/dist/types/plugin.d.ts.map +1 -0
  40. package/package.json +1 -1
  41. package/dist/cjs/locales-C4UTuU_K.cjs +0 -2
  42. package/dist/cjs/locales-C4UTuU_K.cjs.map +0 -1
  43. package/dist/esm/locales-Df9X3IYy.mjs +0 -2
  44. package/dist/esm/locales-Df9X3IYy.mjs.map +0 -1
  45. package/dist/types/allLocales-DeCezB07.d.ts +0 -10
  46. package/dist/types/allLocales-DeCezB07.d.ts.map +0 -1
  47. package/dist/types/config-CE_7T8Jh.d.ts +0 -1637
  48. package/dist/types/config-CE_7T8Jh.d.ts.map +0 -1
  49. package/dist/types/locales-CojWxvz7.d.ts +0 -610
  50. package/dist/types/locales-CojWxvz7.d.ts.map +0 -1
  51. package/dist/types/nodeType-DIgDogqh.d.ts +0 -32
  52. package/dist/types/nodeType-DIgDogqh.d.ts.map +0 -1
@@ -1,1637 +0,0 @@
1
- import { n as Locale } from "./allLocales-DeCezB07.js";
2
- import { t as NodeType } from "./nodeType-DIgDogqh.js";
3
- import { __DeclaredLocalesRegistry, __DictionaryRegistry, __EditorRegistry, __RequiredLocalesRegistry, __SchemaRegistry, __StrictModeRegistry } from "intlayer";
4
-
5
- //#region src/module_augmentation.d.ts
6
- type SchemaKeys = keyof __SchemaRegistry extends never ? string : keyof __SchemaRegistry;
7
- type Schema$1<T extends SchemaKeys> = [string] extends [T] ? any : T extends keyof __SchemaRegistry ? __SchemaRegistry[T] : any;
8
- type DictionaryKeys = keyof __DictionaryRegistry extends never ? string : keyof __DictionaryRegistry;
9
- type DictionaryRegistry = __DictionaryRegistry[keyof __DictionaryRegistry] extends never ? Record<string, Dictionary> : __DictionaryRegistry;
10
- type DictionaryRegistryElement<T extends DictionaryKeys> = [string] extends [T] ? Dictionary : T extends keyof __DictionaryRegistry ? __DictionaryRegistry[T] extends Dictionary ? __DictionaryRegistry[T] : Dictionary : Dictionary;
11
- type DictionaryRegistryContent<T extends PropertyKey> = [T] extends [keyof __DictionaryRegistry] ? __DictionaryRegistry[T] extends {
12
- content: infer C;
13
- } ? C : Dictionary["content"] : Dictionary["content"];
14
- type NarrowStringKeys<T> = string extends keyof T ? never : Extract<keyof T, string>;
15
- type DeclaredLocales = [NarrowStringKeys<__DeclaredLocalesRegistry>] extends [never] ? Locale : NarrowStringKeys<__DeclaredLocalesRegistry>;
16
- type RequiredLocales = [NarrowStringKeys<__RequiredLocalesRegistry>] extends [never] ? never : NarrowStringKeys<__RequiredLocalesRegistry>;
17
- /** Define MyType using the ValueOf utility type on Locales */
18
- type LocalesValues = DeclaredLocales | (string & {});
19
- type ResolvedStrictMode = __StrictModeRegistry extends {
20
- mode: infer M;
21
- } ? M : "inclusive";
22
- type StrictModeLocaleMap<Content = unknown, Mode extends StrictMode = ResolvedStrictMode> = RequiredLocales extends never ? Partial<Record<Locale, Content>> : Mode extends "strict" ? Required<Record<RequiredLocales, Content>> & Partial<Record<DeclaredLocales, Content>> : Mode extends "inclusive" ? Required<Record<RequiredLocales, Content>> & Partial<Record<Locale, Content>> : Partial<Record<Locale, Content>>;
23
- type ResolvedEditor<Node, Editor> = __EditorRegistry extends {
24
- enabled: true;
25
- } ? Editor : Node;
26
- //#endregion
27
- //#region src/filePathPattern.d.ts
28
- type ContentExtension = `.${string}.${"json" | "js" | "ts" | "jsx" | "tsx" | "cjs" | "mjs"}`;
29
- type FilePathPatternContext = {
30
- locale?: DeclaredLocales;
31
- key: DictionaryKey;
32
- fileName: string;
33
- extension: ContentExtension | (string & {});
34
- format: "ts" | "cjs" | "esm" | "json" | "jsonc" | "json5";
35
- componentExtension?: ".json" | ".js" | ".ts" | ".jsx" | ".tsx" | ".cjs" | ".mjs";
36
- componentFormat?: "ts" | "cjs" | "esm";
37
- componentFileName?: string;
38
- componentDirPath?: string;
39
- };
40
- /**
41
- * Syntax for resolving file paths.
42
- */
43
- type FilePathPatternFunction = (context: FilePathPatternContext) => string | Promise<string>;
44
- /**
45
- * Global syntax for defining file paths and patterns.
46
- * Can be a static string, a templated string (e.g. `path/{{locale}}/{{key}}{{extension}}`),
47
- * or a function evaluating the path dynamically.
48
- */
49
- type FilePathPattern = string | FilePathPatternFunction;
50
- //#endregion
51
- //#region src/dictionary.d.ts
52
- type BaseNode = number | string | boolean | null | undefined;
53
- type TypedNodeBase = {
54
- nodeType: NodeType | `${NodeType}`;
55
- };
56
- interface TypedNode<_NodeType = undefined> extends TypedNodeBase {}
57
- type FetchableContentNode<NodeType> = (args?: any) => ContentNode<NodeType> | Promise<ContentNode<NodeType>>;
58
- type ContentNode<T = undefined, FetchableNode = false, NodeType = (T extends undefined ? BaseNode : T)> = NodeType | TypedNode<NodeType> | ((args?: any) => ContentNode<NodeType>) | (FetchableNode extends true ? FetchableContentNode<NodeType> : undefined);
59
- type IsArray<T> = T extends any[] ? true : false;
60
- type ReplaceContentValueArray<T, FetchableNode> = T extends (infer U)[] ? ContentNode<T, FetchableNode> | ReplaceContentValue<U, FetchableNode>[] : never;
61
- type ReplaceContentValueObject<T, FetchableNode> = { [K in keyof T]: ReplaceContentValue<T[K], FetchableNode> };
62
- type ReplaceContentValue<NodeType, FetchableNode = true> = NodeType extends object ? IsArray<NodeType> extends true ? ReplaceContentValueArray<NodeType, FetchableNode> : ContentNode<NodeType, FetchableNode> | ReplaceContentValueObject<NodeType, FetchableNode> : ContentNode<NodeType, FetchableNode>;
63
- /**
64
- * Indicate how the dictionary should be filled using AI.
65
- *
66
- * Default: `true`
67
- *
68
- * - If `true`, will consider the `compiler.output` field.
69
- * - If `false`, will skip the fill process.
70
- *
71
- * - `./` paths are resolved relative to the component directory.
72
- * - `/` paths are resolved relative to the project root (`baseDir`).
73
- *
74
- * - If includes `{{locale}}` variable in the path, will trigger the generation of separate dictionaries per locale.
75
- *
76
- * Example:
77
- * ```ts
78
- * {
79
- * // Create Multilingual .content.ts files close to the component
80
- * fill: ({ fileName, extension }) => `./${fileName}${extension}`,
81
- *
82
- * // fill: './{{fileName}}{{extension}}', // Equivalent using template string
83
- * }
84
- * ```
85
- *
86
- * ```ts
87
- * {
88
- * // Create centralize per-locale JSON at the root of the project
89
- * fill: ({ key, locale }) => `/locales/${locale}/${key}.content.json`,
90
- *
91
- * // fill: '/locales/{{locale}}/{{key}}.content.json', // Equivalent using template string
92
- * }
93
- * ```
94
- *
95
- * ```ts
96
- * {
97
- * // Create custom output based on the locale
98
- * fill: {
99
- * en: ({ key }) => `/locales/en/${key}.content.json`,
100
- * fr: '/locales/fr/{{key}}.content.json',
101
- * es: false,
102
- * de: true,
103
- * },
104
- * }
105
- * ```
106
- *
107
- *
108
- * Variable list:
109
- * - `fileName`: The name of the file.
110
- * - `key`: The key of the content.
111
- * - `locale`: The locale of the content.
112
- * - `extension`: The extension of the file.
113
- * - `componentFileName`: The name of the component file.
114
- * - `componentExtension`: The extension of the component file.
115
- * - `format`: The format of the dictionary.
116
- * - `componentFormat`: The format of the component dictionary.
117
- * - `componentDirPath`: The directory path of the component.
118
- */
119
- type Fill = boolean | FilePathPattern | Partial<Record<DeclaredLocales, boolean | FilePathPattern>>;
120
- type DictionaryId = string;
121
- type DictionaryKey = string;
122
- type DictionaryLocation = "remote" | "local" | "hybrid" | "plugin" | (string & {});
123
- type LocalDictionaryId = `${DictionaryKey}::${Dictionary["location"]}::${Dictionary["filePath"] | DictionaryId}`;
124
- type DictionaryFormat = "intlayer" | "icu" | "i18next" | "vue-i18n";
125
- /**
126
- * Indicates the mode of import to use for the dictionary.
127
- *
128
- * Available modes:
129
- * - "static": The dictionaries are imported statically.
130
- * In that case, Intlayer will replace all calls to `useIntlayer` with `useDictionary`.
131
- * - "dynamic": The dictionaries are imported dynamically in a synchronous component using the suspense API.
132
- * In that case, Intlayer will replace all calls to `useIntlayer` with `useDictionaryDynamic`.
133
- * - "live": The dictionaries are imported dynamically using the live sync API.
134
- * In that case, Intlayer will replace all calls to `useIntlayer` with `useDictionaryDynamic`.
135
- * Live mode will use the live sync API to fetch the dictionaries. If the API call fails, the dictionaries will be imported dynamically as "dynamic" mode.
136
- *
137
- * Default: "static"
138
- */
139
- type ImportMode = "static" | "dynamic" | "fetch";
140
- type ContentAutoTransformation = boolean | {
141
- /**
142
- * Indicates if the content should be automatically transformed to a markdown node.
143
- * Default: true
144
- */
145
- markdown?: boolean;
146
- /**
147
- * Indicates if the content should be automatically transformed to an HTML node.
148
- * Default: true
149
- */
150
- html?: boolean;
151
- /**
152
- * Indicates if the content should be automatically transformed to an insertion node.
153
- * Default: true
154
- */
155
- insertion?: boolean;
156
- };
157
- /**
158
- * Common properties shared by all Dictionary variants.
159
- */
160
- type DictionaryBase = {
161
- /**
162
- * _Auto generated by the intlayer, do not modify it_
163
- *
164
- * The schema of the dictionary, used for JSON validation
165
- */
166
- $schema?: "https://intlayer.org/schema.json";
167
- /**
168
- * _Auto generated by the intlayer, do not modify it_
169
- *
170
- * For remote dictionaries, the id is the id of the dictionary in the remote server
171
- */
172
- id?: DictionaryId;
173
- /**
174
- * _Auto generated by the intlayer, do not modify it_
175
- *
176
- * For remote dictionaries, the projectIds is the ids of the projects that can use this dictionary
177
- * A remote dictionary can be shared between multiple projects
178
- */
179
- projectIds?: string[];
180
- /**
181
- * _Auto generated by the intlayer, do not modify it_
182
- *
183
- * Unique Identifier for the dictionaries. Auto generated by the intlayer, it helps to identify the dictionary and know if it is a local or remote dictionary, and his location.
184
- */
185
- localId?: LocalDictionaryId;
186
- /**
187
- * _Auto generated by the intlayer, do not modify it_
188
- *
189
- * For merged dictionaries, the localIds is the ids of the dictionaries that are merged
190
- */
191
- localIds?: LocalDictionaryId[];
192
- /**
193
- * The formatter to use for the dictionary.
194
- *
195
- * Default: 'intlayer'
196
- *
197
- * The formatter to use for the dictionary content.
198
- */
199
- format?: DictionaryFormat;
200
- /**
201
- * The key of the dictionary. If multiple dictionaries have the same key, intlayer will merge them.
202
- *
203
- * As convention, use '-' to separate the words in the key.
204
- *
205
- * Example:
206
- * ```json
207
- * {
208
- * "key": "about-page-meta",
209
- * "content": { ... }
210
- * }
211
- * ```
212
- */
213
- key: DictionaryKey;
214
- /**
215
- * The title of the dictionary. Helps to identify the dictionary in the editor, and the CMS.
216
- *
217
- * Example:
218
- * ```json
219
- * {
220
- * "key": "about-page-meta",
221
- * "title": "About Page",
222
- * "content": { ... }
223
- * }
224
- * ```
225
- */
226
- title?: string;
227
- /**
228
- * The description of the dictionary. Helps to understand the purpose of the dictionary in the editor, and the CMS.
229
- * The description is also used as context for translations generation.
230
- *
231
- * Example:
232
- * ```ts
233
- * {
234
- * "key": "about-page-meta",
235
- * "description":[
236
- * "This dictionary is manage the metadata of the About Page",
237
- * "Consider good practices for SEO:",
238
- * "- The title should be between 50 and 60 characters",
239
- * "- The description should be between 150 and 160 characters",
240
- * ].join('\n'),
241
- * "content": { ... }
242
- * }
243
- * ```
244
- */
245
- description?: string;
246
- /**
247
- * _Auto generated by the intlayer, do not modify it_
248
- *
249
- * The available versions of the remote dictionary. Helps to know the versions of the dictionary that are available.
250
- */
251
- versions?: string[];
252
- /**
253
- * _Managable on the CMS, do not modify it locally_
254
- *
255
- * The version of the remote dictionary. Helps to know the version of the dictionary that is currently used.
256
- */
257
- version?: string;
258
- /**
259
- * _Auto generated by the intlayer, do not modify it_
260
- *
261
- * The file path of the local dictionary. Helps to know from what .content file the dictionary has been generated.
262
- */
263
- filePath?: string;
264
- /**
265
- * Helps to categorize the dictionaries. The tags can provide more context and instructions for the dictionary.
266
- *
267
- * Example:
268
- * ```json
269
- * {
270
- * "key": "about-page-meta",
271
- * "tags": ["metadata","about-page"]
272
- * }
273
- * ```
274
- */
275
- tags?: string[];
276
- /**
277
- * Transform the dictionary in a per-locale dictionary.
278
- * Each field declared in a per-locale dictionary will be transformed in a translation node.
279
- * If missing, the dictionary will be treated as a multilingual dictionary.
280
- * If declared, do not use translation nodes in the content.
281
- *
282
- * Example:
283
- * ```json
284
- * {
285
- * "key": "about-page",
286
- * "locale": "en",
287
- * "content": {
288
- * "multilingualContent": "English content"
289
- * }
290
- * }
291
- * ```
292
- */
293
- locale?: LocalesValues;
294
- /**
295
- * Indicators if the content of the dictionary should be automatically transformed.
296
- * If true, the content will be transformed to the corresponding node type.
297
- * - Markdown: `### Title` -> `md('### Title')`
298
- * - HTML: `<div>Title</div>` -> `html('<div>Title</div>')`
299
- * - Insertion: `Hello {{name}}` -> `insert('Hello {{name}}')`
300
- *
301
- * If an object is provided, you can specify which transformations should be enabled.
302
- *
303
- * Default: false
304
- */
305
- contentAutoTransformation?: ContentAutoTransformation;
306
- /**
307
- * Indicate how the dictionary should be filled using AI.
308
- *
309
- * Default: `true`
310
- *
311
- * - If `true`, will consider the `compiler.output` field.
312
- * - If `false`, will skip the fill process.
313
- *
314
- * - `./` paths are resolved relative to the component directory.
315
- * - `/` paths are resolved relative to the project root (`baseDir`).
316
- *
317
- * - If includes `{{locale}}` variable in the path, will trigger the generation of separate dictionaries per locale.
318
- *
319
- * Example:
320
- * ```ts
321
- * {
322
- * // Create Multilingual .content.ts files close to the component
323
- * fill: ({ fileName, extension }) => `./${fileName}${extension}`,
324
- *
325
- * // fill: './{{fileName}}{{extension}}', // Equivalent using template string
326
- * }
327
- * ```
328
- *
329
- * ```ts
330
- * {
331
- * // Create centralize per-locale JSON at the root of the project
332
- * fill: ({ key, locale }) => `/locales/${locale}/${key}.content.json`,
333
- *
334
- * // fill: '/locales/{{locale}}/{{key}}.content.json', // Equivalent using template string
335
- * }
336
- * ```
337
- *
338
- * ```ts
339
- * {
340
- * // Create custom output based on the locale
341
- * fill: {
342
- * en: ({ key }) => `/locales/en/${key}.content.json`,
343
- * fr: '/locales/fr/{{key}}.content.json',
344
- * es: false,
345
- * de: true,
346
- * },
347
- * }
348
- * ```
349
- *
350
- *
351
- * Variable list:
352
- * - `fileName`: The name of the file.
353
- * - `key`: The key of the content.
354
- * - `locale`: The locale of the content.
355
- * - `extension`: The extension of the file.
356
- * - `componentFileName`: The name of the component file.
357
- * - `componentExtension`: The extension of the component file.
358
- * - `format`: The format of the dictionary.
359
- * - `componentFormat`: The format of the component dictionary.
360
- * - `componentDirPath`: The directory path of the component.
361
- */
362
- fill?: Fill;
363
- /**
364
- * _Auto generated by the intlayer, do not modify it_
365
- *
366
- * Indicates if the dictionary has been auto filled.
367
- * In the case of conflicts, base dictionaryed will override auto filled dictionary.
368
- */
369
- filled?: true;
370
- /**
371
- * Indicates the priority of the dictionary.
372
- * In the case of conflicts, the dictionary with the highest priority will override the other dictionaries.
373
- */
374
- priority?: number;
375
- /**
376
- * Indicates the mode of import to use for the dictionary.
377
- *
378
- * Available modes:
379
- * - "static": The dictionaries are imported statically.
380
- * In that case, Intlayer will replace all calls to `useIntlayer` with `useDictionary`.
381
- * - "dynamic": The dictionaries are imported dynamically in a synchronous component using the suspense API.
382
- * In that case, Intlayer will replace all calls to `useIntlayer` with `useDictionaryDynamic`.
383
- * - "live": The dictionaries are imported dynamically using the live sync API.
384
- * In that case, Intlayer will replace all calls to `useIntlayer` with `useDictionaryDynamic`.
385
- * Live mode will use the live sync API to fetch the dictionaries. If the API call fails, the dictionaries will be imported dynamically as "dynamic" mode.
386
- *
387
- * Default: "static"
388
- */
389
- importMode?: ImportMode;
390
- /**
391
- * Indicates the location of the dictionary and controls how it synchronizes with the CMS.
392
- *
393
- * - 'hybrid': The dictionary is managed locally and remotely. Once pushed on the CMS, it will be synchronized from the local one. The local dictionary will be pulled from the CMS.
394
- * - 'remote': The dictionary is managed remotely only. Once pushed on the CMS, it will be detached from the local one. At content load time, the remote dictionary will be pulled from the CMS. A '.content' file with remote location will be ignored.
395
- * - 'local': The dictionary is managed locally. It will not be pushed to the remote CMS.
396
- * - 'plugin' (or any custom string): The dictionary is managed by a plugin, or a custom source. When you will try to push it, the system will ask an action to the user.
397
- */
398
- location?: DictionaryLocation;
399
- };
400
- /**
401
- * Strict Schema Branch:
402
- * If a schema is provided, it MUST be one of the SchemaKeys.
403
- */
404
- type DictionaryWithSchema<ContentType, FetchableNode, K extends SchemaKeys = SchemaKeys> = K extends any ? {
405
- schema: K;
406
- content: ContentType extends undefined ? ReplaceContentValue<Schema$1<K>, FetchableNode> | Schema$1<K> : ReplaceContentValue<ContentType & Schema$1<K>, FetchableNode> | (ContentType & Schema$1<K>);
407
- } : never;
408
- /**
409
- * Strict Discrimination Branch
410
- */
411
- type DictionaryWithoutSchema<ContentType, FetchableNode> = {
412
- schema?: never;
413
- content: ContentType extends undefined ? any : ReplaceContentValue<ContentType, FetchableNode> | ContentType;
414
- };
415
- /**
416
- * The Final Dictionary Type
417
- */
418
- type Dictionary<ContentType = undefined, SchemaKey extends SchemaKeys | undefined = undefined, FetchableNode = false> = DictionaryBase & (SchemaKey extends SchemaKeys ? DictionaryWithSchema<ContentType, FetchableNode, SchemaKey> : undefined extends SchemaKey ? DictionaryWithoutSchema<ContentType, FetchableNode> | DictionaryWithSchema<ContentType, FetchableNode> : never);
419
- type GetSubPath<T, P> = P extends `${infer K}.${infer Rest}` ? K extends keyof T ? GetSubPath<T[K], Rest> : never : P extends keyof T ? T[P] : T;
420
- //#endregion
421
- //#region src/plugin.d.ts
422
- /**
423
- * This is a temporary type to avoid cross-package type coupling.
424
- *
425
- * Use Module augmentation to extend the Dictionary type.
426
- */
427
- interface PluginDictionary {
428
- key: string;
429
- locale?: LocalesValues;
430
- location?: string;
431
- content: unknown;
432
- filePath?: string;
433
- }
434
- type UnmergedDictionaryResult = {
435
- dictionaryPath: string;
436
- dictionaries: PluginDictionary[];
437
- };
438
- type UnmergedDictionaryOutput = Record<string, UnmergedDictionaryResult>;
439
- type MergedDictionaryResult = {
440
- dictionary: PluginDictionary;
441
- };
442
- type MergedDictionaryOutput = Record<string, MergedDictionaryResult>;
443
- /**
444
- * Extension points for Intlayer plugins.
445
- *
446
- * Typical use-cases:
447
- * - loadDictionaries: ingest external formats (e.g., ICU JSON) and convert to Intlayer `Dictionary[]`
448
- * - afterBuild: transform/write back merged dictionaries to external formats/locations (e.g., write ICU JSON)
449
- */
450
- type Plugin = {
451
- /**
452
- * Name of the plugin
453
- */
454
- name: string;
455
- /**
456
- * Optional hook to load dictionaries from custom sources.
457
- * Return additional dictionaries derived from the provided declaration file paths.
458
- * The returned dictionaries will be merged alongside local and remote ones.
459
- */
460
- loadDictionaries?: (args: {
461
- configuration: IntlayerConfig;
462
- }) => Promise<PluginDictionary[]> | PluginDictionary[];
463
- /**
464
- * Optional hook called after dictionaries have been built/merged.
465
- * Implementations can write the final content back to custom destinations (e.g., ICU files).
466
- *
467
- * buildOutput is intentionally untyped here to avoid cross-package type coupling.
468
- */
469
- afterBuild?: (args: {
470
- dictionaries: {
471
- unmergedDictionaries: UnmergedDictionaryOutput;
472
- mergedDictionaries: MergedDictionaryOutput;
473
- };
474
- configuration: IntlayerConfig;
475
- }) => Promise<void> | void;
476
- /**
477
- * Optional hook called after dictionaries have been formatted.
478
- * Implementations can transform the final content before it is written to the output.
479
- */
480
- formatOutput?: (args: {
481
- dictionary: PluginDictionary;
482
- configuration: IntlayerConfig;
483
- }) => unknown;
484
- };
485
- //#endregion
486
- //#region src/config.d.ts
487
- /**
488
- * Structural type for schema validation, compatible with Zod and other
489
- * schema libraries that implement safeParse. Avoids a hard dependency on Zod.
490
- */
491
- type Schema = {
492
- safeParse(data: unknown): {
493
- success: boolean;
494
- data?: unknown;
495
- error?: unknown;
496
- };
497
- };
498
- type StrictMode = "strict" | "inclusive" | "loose";
499
- type Protocol = "http" | "https";
500
- type URLPath = `/${string}`;
501
- type OptionalURLPath = `/${string}` | "";
502
- type LocalhostURL = `${Protocol}://localhost:${number}${OptionalURLPath}`;
503
- type IPUrl = `${Protocol}://${number}.${string}${OptionalURLPath}` | `${Protocol}://${number}.${string}:${number}${OptionalURLPath}`;
504
- type DomainURL = `${Protocol}://${string}.${string}${OptionalURLPath}`;
505
- type URLType = LocalhostURL | IPUrl | DomainURL | (string & {});
506
- /**
507
- * Configuration for internationalization settings
508
- */
509
- type InternationalizationConfig = {
510
- /**
511
- * Locales available in the application
512
- *
513
- * Default: [Locales.ENGLISH]
514
- *
515
- * You can define a list of available locales to support in the application.
516
- */
517
- locales: Locale[];
518
- /**
519
- * Locales required by TypeScript to ensure strong implementations of internationalized content using typescript.
520
- *
521
- * Default: []
522
- *
523
- * If empty, all locales are required in `strict` mode.
524
- *
525
- * Ensure required locales are also defined in the `locales` field.
526
- */
527
- requiredLocales: Locale[];
528
- /**
529
- * Ensure strong implementations of internationalized content using typescript.
530
- * - If set to "strict", the translation `t` function will require each declared locales to be defined. If one locale is missing, or if a locale is not declared in your config, it will throw an error.
531
- * - If set to "inclusive", the translation `t` function will require each declared locales to be defined. If one locale is missing, it will throw a warning. But will accept if a locale is not declared in your config, but exist.
532
- * - If set to "loose", the translation `t` function will accept any existing locale.
533
- *
534
- * Default: "inclusive"
535
- */
536
- strictMode: StrictMode;
537
- /**
538
- * Default locale of the application for fallback
539
- *
540
- * Default: Locales.ENGLISH
541
- *
542
- * Used to specify a fallback locale in case no other locale is set.
543
- */
544
- defaultLocale: Locale;
545
- };
546
- type CookiesAttributes = {
547
- /**
548
- * Type of the storage
549
- *
550
- * The type of the storage. It can be 'cookie'.
551
- */
552
- type: "cookie";
553
- /**
554
- * Cookie name to store the locale information
555
- *
556
- * Default: 'INTLAYER_LOCALE'
557
- *
558
- * The cookie key where the locale information is stored.
559
- */
560
- name?: string;
561
- /**
562
- * Cookie domain to store the locale information
563
- *
564
- * Default: undefined
565
- *
566
- * Define the domain where the cookie is available. Defaults to
567
- * the domain of the page where the cookie was created.
568
- */
569
- domain?: string;
570
- /**
571
- * Cookie path to store the locale information
572
- *
573
- * Default: undefined
574
- *
575
- * Define the path where the cookie is available. Defaults to '/'
576
- */
577
- path?: string;
578
- /**
579
- * Cookie secure to store the locale information
580
- *
581
- * Default: undefined
582
- *
583
- * A Boolean indicating if the cookie transmission requires a
584
- * secure protocol (https). Defaults to false.
585
- */
586
- secure?: boolean;
587
- /**
588
- * Cookie httpOnly to store the locale information
589
- *
590
- * Default: undefined
591
- *
592
- * The cookie httpOnly where the locale information is stored.
593
- */
594
- httpOnly?: boolean;
595
- /**
596
- * Cookie sameSite to store the locale information
597
- *
598
- * Default: undefined
599
- *
600
- * Asserts that a cookie must not be sent with cross-origin requests,
601
- * providing some protection against cross-site request forgery
602
- * attacks (CSRF)
603
- */
604
- sameSite?: "strict" | "lax" | "none";
605
- /**
606
- * Cookie expires to store the locale information
607
- *
608
- * Default: undefined
609
- *
610
- * Define when the cookie will be removed. Value can be a Number
611
- * which will be interpreted as days from time of creation or a
612
- * Date instance. If omitted, the cookie becomes a session cookie.
613
- */
614
- expires?: Date | number | undefined;
615
- };
616
- type StorageAttributes = {
617
- /**
618
- * Storage type where the locale is stored
619
- *
620
- * Determines whether the locale is persisted in `localStorage` (across sessions)
621
- * or `sessionStorage` (cleared when the browser session ends) or `header` (from the request header).
622
- */
623
- type: "localStorage" | "sessionStorage" | "header";
624
- /**
625
- * Storage key to store the locale information
626
- *
627
- * Default: 'INTLAYER_LOCALE'
628
- *
629
- * The key name used in the client storage to save the locale.
630
- */
631
- name?: string;
632
- };
633
- type RewriteRule<T extends string = string> = {
634
- canonical: T;
635
- localized: StrictModeLocaleMap<string>;
636
- };
637
- type RewriteRules = {
638
- rules: RewriteRule[];
639
- };
640
- type RewriteObject = {
641
- /**
642
- * Used for client-side URL generation (e.g., getLocalizedUrl).
643
- * Patterns are usually stripped of locale prefixes as the core logic handles prefixing.
644
- */
645
- url: RewriteRules;
646
- /**
647
- * Used for Next.js middleware / proxy.
648
- * Patterns usually include [locale] or :locale to match incoming full URLs.
649
- */
650
- nextjs?: RewriteRules;
651
- /**
652
- * Used for Vite proxy middleware.
653
- */
654
- vite?: RewriteRules;
655
- };
656
- /**
657
- * Configuration for routing behaviors
658
- */
659
- type RoutingConfig = {
660
- /**
661
- * Rewrite the URLs to a localized path
662
- *
663
- * Example:
664
- * ```ts
665
- * // ...
666
- * routing: {
667
- * rewrite: nextjsRewrite({
668
- * '[locale]/about': {
669
- * fr: '[locale]/a-propos'
670
- * }
671
- * })
672
- * }
673
- * ```
674
- */
675
- rewrite?: Record<URLPath, StrictModeLocaleMap<URLPath>> | RewriteObject;
676
- /**
677
- * URL routing mode for locale handling
678
- *
679
- * Controls how locales are represented in application URLs:
680
- * - 'prefix-no-default': Prefix all locales except the default locale
681
- * - 'prefix-all': Prefix all locales including the default locale
682
- * - 'no-prefix': No locale prefixing in URLs
683
- * - 'search-params': Use search parameters for locale handling
684
- *
685
- * Examples with defaultLocale = 'en':
686
- * - 'prefix-no-default': /dashboard (en) or /fr/dashboard (fr)
687
- * - 'prefix-all': /en/dashboard (en) or /fr/dashboard (fr)
688
- * - 'no-prefix': /dashboard (locale handled via other means)
689
- * - 'search-params': /dashboard?locale=fr
690
- *
691
- * Note: This setting do not impact the cookie, or locale storage management.
692
- *
693
- * Default: 'prefix-no-default'
694
- */
695
- mode: "prefix-no-default" | "prefix-all" | "no-prefix" | "search-params";
696
- /**
697
- * Configuration for storing the locale in the client (localStorage or sessionStorage)
698
- *
699
- * If false, the locale will not be stored by the middleware.
700
- * If true, the locale storage will consider all default values.
701
- *
702
- * Default: ['cookie', 'header]
703
- *
704
- * Note: Check out GDPR compliance for cookies. See https://gdpr.eu/cookies/
705
- * Note: useLocale hook includes a prop to disable the cookie storage.
706
- * Note: Even if storage is disabled, the middleware will still detect the locale from the request header (1- check for `x-intlayer-locale`, 2- fallback to the `accept-language`).
707
- *
708
- * Recommendation:
709
- * - Config both localStorage and cookies for the storage of the locale if you want to support GDPR compliance.
710
- * - Disable the cookie storage by default on the useLocale hook by waiting for the user to consent to the cookie storage.
711
- */
712
- storage: false | "cookie" | "localStorage" | "sessionStorage" | "header" | CookiesAttributes | StorageAttributes | ("cookie" | "localStorage" | "sessionStorage" | "header" | CookiesAttributes | StorageAttributes)[];
713
- /**
714
- * Base path for application URLs
715
- *
716
- * Default: ''
717
- *
718
- * Defines the base path where the application is accessible from.
719
- */
720
- basePath: string;
721
- };
722
- /**
723
- * Configuration for intlayer editor
724
- */
725
- type EditorConfig = {
726
- /**
727
- * URL of the application. Used to restrict the origin of the editor for security reasons.
728
- *
729
- * Default: ''
730
- */
731
- applicationURL?: URLType;
732
- editorURL?: URLType;
733
- cmsURL?: URLType;
734
- backendURL?: URLType;
735
- /**
736
- * Indicates if the application interact with the visual editor
737
- *
738
- * Default: false;
739
- *
740
- * If true, the editor will be able to interact with the application.
741
- * If false, the editor will not be able to interact with the application.
742
- * In any case, the editor can only be enabled by the visual editor.
743
- * Disabling the editor for specific environments is a way to enforce the security.
744
- *
745
- * Usage:
746
- * ```js
747
- * {
748
- * // Other configurations
749
- * editor: {
750
- * enabled: process.env.NODE_ENV !== 'production',
751
- * }
752
- * };
753
- * ```
754
- *
755
- */
756
- enabled: boolean;
757
- /** Port of the editor server
758
- *
759
- * Default: 8000
760
- */
761
- port: number;
762
- /**
763
- * clientId and clientSecret allow the intlayer packages to authenticate with the backend using oAuth2 authentication.
764
- * An access token is use to authenticate the user related to the project.
765
- * To get an access token, go to https://app.intlayer.org/project and create an account.
766
- *
767
- * Default: undefined
768
- *
769
- * > Important: The clientId and clientSecret should be kept secret and not shared publicly. Please ensure to keep them in a secure location, such as environment variables.
770
- */
771
- clientId?: string;
772
- /**
773
- * clientId and clientSecret allow the intlayer packages to authenticate with the backend using oAuth2 authentication.
774
- * An access token is use to authenticate the user related to the project.
775
- * To get an access token, go to https://app.intlayer.org/project and create an account.
776
- *
777
- * Default: undefined
778
- *
779
- * > Important: The clientId and clientSecret should be kept secret and not shared publicly. Please ensure to keep them in a secure location, such as environment variables.
780
- */
781
- clientSecret?: string;
782
- /**
783
- * Strategy for prioritizing dictionaries. If a dictionary is both present online and locally, the content will be merge.
784
- * However, is a field is defined in both dictionary, this setting determines which fields takes the priority over the other.
785
- *
786
- * Default: 'local_first'
787
- *
788
- * The strategy for prioritizing dictionaries. It can be either 'local_first' or 'distant_first'.
789
- * - 'local_first': The first dictionary found in the locale is used.
790
- * - 'distant_first': The first dictionary found in the distant locales is used.
791
- */
792
- dictionaryPriorityStrategy: "local_first" | "distant_first";
793
- /**
794
- * Indicates if the application should hot reload the locale configurations when a change is detected.
795
- * For example, when a new dictionary is added or updated, the application will update the content tu display in the page.
796
- *
797
- * Default: true
798
- */
799
- liveSync: boolean;
800
- /**
801
- * Port of the live sync server
802
- *
803
- * Default: 4000
804
- */
805
- liveSyncPort: number;
806
- /**
807
- * URL of the live sync server in case of remote live sync server
808
- *
809
- * Default: `http://localhost:${liveSyncPort}`
810
- */
811
- liveSyncURL: URLType;
812
- };
813
- declare enum AiProviders {
814
- OPENAI = "openai",
815
- ANTHROPIC = "anthropic",
816
- MISTRAL = "mistral",
817
- DEEPSEEK = "deepseek",
818
- GEMINI = "gemini",
819
- OLLAMA = "ollama",
820
- OPENROUTER = "openrouter",
821
- ALIBABA = "alibaba",
822
- FIREWORKS = "fireworks",
823
- GROQ = "groq",
824
- HUGGINGFACE = "huggingface",
825
- BEDROCK = "bedrock",
826
- GOOGLEVERTEX = "googlevertex",
827
- GOOGLEGENERATIVEAI = "googlegenerativeai",
828
- TOGETHERAI = "togetherai"
829
- }
830
- type CommonAiConfig = {
831
- /**
832
- * API model
833
- *
834
- * The model to use for the AI features of Intlayer.
835
- *
836
- * Example: 'gpt-4o-2024-11-20'
837
- *
838
- */
839
- model?: string;
840
- /**
841
- * temperature
842
- *
843
- * The temperature to use for the AI features of Intlayer.
844
- * The temperature controls the randomness of the AI's responses.
845
- * A higher temperature will make the AI more creative and less predictable.
846
- *
847
- * Example: 0.1
848
- */
849
- temperature?: number;
850
- /**
851
- * API key
852
- *
853
- * Use your own OpenAI API key to use the AI features of Intlayer.
854
- * If you don't have an OpenAI API key, you can get one for free at https://openai.com/api/.
855
- *
856
- */
857
- apiKey?: string;
858
- /**
859
- * Application context
860
- *
861
- * The context of the application to use for the AI features of Intlayer.
862
- *
863
- * Example: 'This is a website for a company that sells products online.'
864
- */
865
- applicationContext?: string;
866
- /**
867
- * Base URL
868
- *
869
- * The base URL to use for the AI features of Intlayer.
870
- *
871
- * Example: 'https://api.openai.com/v1'
872
- */
873
- baseURL?: string;
874
- /**
875
- * Data serialization
876
- *
877
- * The data serialization format to use for the AI features of Intlayer.
878
- *
879
- * Default: 'json'
880
- */
881
- dataSerialization?: "json" | "toon";
882
- };
883
- type AiProviderConfigMap = {};
884
- type AiConfigUnion = { [P in keyof AiProviderConfigMap]: {
885
- provider: P | `${P}`;
886
- } & AiProviderConfigMap[P] }[keyof AiProviderConfigMap];
887
- type AiConfig = CommonAiConfig & (AiConfigUnion | {
888
- provider?: AiProviders | `${AiProviders}`;
889
- });
890
- type BuildConfig = {
891
- /**
892
- * Indicates the mode of the build
893
- *
894
- * Default: 'auto'
895
- *
896
- * If 'auto', the build will be enabled automatically when the application is built.
897
- * If 'manual', the build will be set only when the build command is executed.
898
- *
899
- * Can be used to disable dictionaries build, for instance when execution on Node.js environment should be avoided.
900
- */
901
- mode: "auto" | "manual";
902
- /**
903
- * Indicates if the build should be optimized
904
- *
905
- * Default: undefined
906
- *
907
- * If true, the build will be optimized.
908
- * If false, the build will not be optimized.
909
- *
910
- * Intlayer will replace all calls of dictionaries to optimize chunking. That way the final bundle will import only the dictionaries that are used.
911
- * All imports will stay as static import to avoid async processing when loading the dictionaries.
912
- *
913
- * Note:
914
- * - Intlayer will replace all call of `useIntlayer` with the defined mode by the `importMode` option.
915
- * - Intlayer will replace all call of `getIntlayer` with `getDictionary`.
916
- * - This option relies on the `@intlayer/babel` and `@intlayer/swc` plugins.
917
- * - Ensure all keys are declared statically in the `useIntlayer` calls. e.g. `useIntlayer('navbar')`.
918
- */
919
- optimize?: boolean;
920
- /**
921
- * Indicates the mode of import to use for the dictionaries.
922
- *
923
- * Available modes:
924
- * - "static": The dictionaries are imported statically.
925
- * In that case, Intlayer will replace all calls to `useIntlayer` with `useDictionary`.
926
- * - "dynamic": The dictionaries are imported dynamically in a synchronous component using the suspense API.
927
- * In that case, Intlayer will replace all calls to `useIntlayer` with `useDictionaryDynamic`.
928
- * - "fetch": The dictionaries are imported dynamically using the live sync API.
929
- * In that case, Intlayer will replace all calls to `useIntlayer` with `useDictionaryDynamic`.
930
- * Fetch mode will use the live sync API to fetch the dictionaries. If the API call fails, the dictionaries will be imported dynamically as "dynamic" mode.
931
- *
932
- * Default: "static"
933
- *
934
- * By default, when a dictionary is loaded, it imports content for all locales as it's imported statically.
935
- *
936
- * Note:
937
- * - Dynamic imports rely on Suspense and may slightly impact rendering performance.
938
- * - If desabled all locales will be loaded at once, even if they are not used.
939
- * - This option relies on the `@intlayer/babel` and `@intlayer/swc` plugins.
940
- * - Ensure all keys are declared statically in the `useIntlayer` calls. e.g. `useIntlayer('navbar')`.
941
- * - This option will be ignored if `optimize` is disabled.
942
- * - This option will not impact the `getIntlayer`, `getDictionary`, `useDictionary`, `useDictionaryAsync` and `useDictionaryDynamic` functions. You can still use them to refine you code on manual optimization.
943
- * - The "fetch" allows to sync the dictionaries to the live sync server.
944
- * - Require static key to work. Example of invalid code: `const navbarKey = "my-key"; useIntlayer(navbarKey)`.
945
- *
946
- * @deprecated Use `dictionary.importMode` instead.
947
- */
948
- importMode?: "static" | "dynamic" | "fetch";
949
- /**
950
- * Pattern to traverse the code to optimize.
951
- *
952
- * Allows to avoid to traverse the code that is not relevant to the optimization.
953
- * Improve build performance.
954
- *
955
- * Default: ['**\/*.{js,ts,mjs,cjs,jsx,tsx}', '!**\/node_modules/**']
956
- *
957
- * Example: `['src/**\/*.{ts,tsx}', '../ui-library/**\/*.{ts,tsx}', '!**\/node_modules/**']`
958
- *
959
- * Note:
960
- * - This option will be ignored if `optimize` is disabled.
961
- * - Use glob pattern.
962
- */
963
- traversePattern: string[];
964
- /**
965
- * Output format of the dictionaries
966
- *
967
- * Default: ['cjs', 'esm']
968
- *
969
- * The output format of the dictionaries. It can be either 'cjs' or 'esm'. Even if dictionaries are written in JSON, entry point to access the dictionaries are generated.
970
- * This function will use the output format defined using this option.
971
- * The default format is 'cjs' as it allows better interoperability with other libraries, scripts, and applications. But some build tools, such as Vite, require ES modules.
972
- */
973
- outputFormat: ("cjs" | "esm")[];
974
- /**
975
- * Indicates if the cache should be enabled
976
- *
977
- * Default: true
978
- *
979
- * If true, the cache will be enabled.
980
- * If false, the cache will not be enabled.
981
- */
982
- cache: boolean;
983
- /**
984
- * Require function
985
- *
986
- * In some environments, as VSCode extension, the require function should be set relatively to the project root to work properly.
987
- *
988
- * Default: undefined
989
- *
990
- * If undefined, the require function will be set to the default require function.
991
- * If defined, the require function will be set to the defined require function.
992
- *
993
- * Example:
994
- * ```js
995
- * {
996
- * require: require
997
- * }
998
- * ```
999
- */
1000
- require?: NodeJS.Require;
1001
- /**
1002
- * Indicates if the build should check TypeScript types
1003
- *
1004
- * Default: false
1005
- *
1006
- * If true, the build will check TypeScript types and log errors.
1007
- * Note: This can slow down the build.
1008
- */
1009
- checkTypes: boolean;
1010
- };
1011
- type CompilerConfig = {
1012
- /**
1013
- * Indicates if the compiler should be enabled.
1014
- * If 'build-only', the compiler will be skipped during development mode to speed up start times.
1015
- */
1016
- enabled: boolean | "build-only";
1017
- /**
1018
- * Prefix for the extracted dictionary keys.
1019
- * Default: ''
1020
- */
1021
- dictionaryKeyPrefix?: string;
1022
- /**
1023
- * Pattern to traverse the code to optimize.
1024
- *
1025
- * Allows to avoid to traverse the code that is not relevant to the optimization.
1026
- * Improve build performance.
1027
- *
1028
- * Default: ['**\/*.{ts,tsx,jsx,js,cjs,mjs,svelte,vue}', '!**\/node_modules/**']
1029
- *
1030
- * Example: `['src/**\/*.{ts,tsx}', '../ui-library/**\/*.{ts,tsx}', '!**\/node_modules/**']`
1031
- *
1032
- * Note:
1033
- * - This option will be ignored if `optimize` is disabled.
1034
- * - Use glob pattern.
1035
- *
1036
- * @deprecated use build.traversePattern instead
1037
- */
1038
- transformPattern?: string | string[];
1039
- /**
1040
- * Pattern to exclude from the optimization.
1041
- *
1042
- * Allows to exclude files from the optimization.
1043
- *
1044
- * Default: ['**\/node_modules/**']
1045
- *
1046
- * Example: `['**\/node_modules/**', '!**\/node_modules/react/**']`
1047
- *
1048
- * @deprecated use build.traversePattern instead
1049
- */
1050
- excludePattern?: string | string[];
1051
- /**
1052
- * Defines the output files path. Replaces `outputDir`.
1053
- *
1054
- * - `./` paths are resolved relative to the component directory.
1055
- * - `/` paths are resolved relative to the project root (`baseDir`).
1056
- *
1057
- * - Including the `{{locale}}` variable in the path will trigger the generation of separate dictionaries per locale.
1058
- *
1059
- * Example:
1060
- * ```ts
1061
- * {
1062
- * // Create Multilingual .content.ts files close to the component
1063
- * output: ({ fileName, extension }) => `./${fileName}${extension}`,
1064
- *
1065
- * // output: './{{fileName}}{{extension}}', // Equivalent using template string
1066
- * }
1067
- * ```
1068
- *
1069
- * ```ts
1070
- * {
1071
- * // Create centralize per-locale JSON at the root of the project
1072
- * output: ({ key, locale }) => `/locales/${locale}/${key}.content.json`,
1073
- *
1074
- * // output: '/locales/{{locale}}/{{key}}.content.json', // Equivalent using template string
1075
- * }
1076
- * ```
1077
- *
1078
- * Variable list:
1079
- * - `fileName`: The name of the file.
1080
- * - `key`: The key of the content.
1081
- * - `locale`: The locale of the content.
1082
- * - `extension`: The extension of the file.
1083
- * - `componentFileName`: The name of the component file.
1084
- * - `componentExtension`: The extension of the component file.
1085
- * - `format`: The format of the dictionary.
1086
- * - `componentFormat`: The format of the component dictionary.
1087
- * - `componentDirPath`: The directory path of the component.
1088
- */
1089
- output?: FilePathPattern;
1090
- /**
1091
- * Indicates if the metadata should be saved in the file.
1092
- *
1093
- * If true, the compiler will not save the metadata of the dictionaries.
1094
- *
1095
- * If true:
1096
- *
1097
- * ```json
1098
- * {
1099
- * "key": "value"
1100
- * }
1101
- * ```
1102
- *
1103
- * If false:
1104
- *
1105
- * ```json
1106
- * {
1107
- * "key": "value",
1108
- * "content": {
1109
- * "key": "value"
1110
- * }
1111
- * }
1112
- * ```
1113
- *
1114
- * Default: false
1115
- *
1116
- * Note: Useful if used with loadJSON plugin
1117
- *
1118
- */
1119
- noMetadata?: boolean;
1120
- /**
1121
- * Indicates if the components should be saved after being transformed.
1122
- *
1123
- * If true, the compiler will replace the original files with the transformed files.
1124
- * That way, the compiler can be run only once to transform the app, and then it can be removed.
1125
- *
1126
- * Default: false
1127
- */
1128
- saveComponents: boolean;
1129
- };
1130
- /**
1131
- * Custom configuration that can be provided to override default settings
1132
- */
1133
- type CustomIntlayerConfig = {
1134
- /**
1135
- * Custom internationalization configuration
1136
- */
1137
- internationalization?: Partial<InternationalizationConfig>;
1138
- /**
1139
- * Custom dictionary configuration
1140
- */
1141
- dictionary?: Partial<DictionaryConfig>;
1142
- /**
1143
- * Custom routing configuration
1144
- */
1145
- routing?: Partial<RoutingConfig>;
1146
- /**
1147
- * Custom content configuration
1148
- */
1149
- content?: Partial<ContentConfig>;
1150
- /**
1151
- * Custom editor configuration
1152
- */
1153
- editor?: Partial<EditorConfig>;
1154
- /**
1155
- * Custom log configuration
1156
- */
1157
- log?: Partial<LogConfig>;
1158
- /**
1159
- * Custom AI configuration
1160
- */
1161
- ai?: Partial<AiConfig>;
1162
- /**
1163
- * Custom build configuration
1164
- */
1165
- build?: Partial<BuildConfig>;
1166
- /**
1167
- * Custom compiler configuration
1168
- */
1169
- compiler?: Partial<CompilerConfig>;
1170
- /**
1171
- * Custom system configuration
1172
- */
1173
- system?: Partial<SystemConfig>;
1174
- /**
1175
- * Custom schemas to validate the dictionaries content.
1176
- *
1177
- * Example:
1178
- * ```ts
1179
- * {
1180
- * schemas: {
1181
- * 'my-schema': z.object({
1182
- * title: z.string(),
1183
- * description: z.string(),
1184
- * }),
1185
- * }
1186
- * }
1187
- * ```
1188
- */
1189
- schemas?: Record<string, Schema>;
1190
- /**
1191
- * Custom plugins configuration
1192
- */
1193
- plugins?: (Plugin | Promise<Plugin>)[];
1194
- };
1195
- type DictionaryConfig = {
1196
- /**
1197
- * Indicate how the dictionary should be filled using AI.
1198
- *
1199
- * Default: `true`
1200
- *
1201
- * - If `true`, will consider the `compiler.output` field.
1202
- * - If `false`, will skip the fill process.
1203
- *
1204
- * - `./` paths are resolved relative to the component directory.
1205
- * - `/` paths are resolved relative to the project root (`baseDir`).
1206
- *
1207
- * - If includes `{{locale}}` variable in the path, will trigger the generation of separate dictionaries per locale.
1208
- *
1209
- * Example:
1210
- * ```ts
1211
- * {
1212
- * // Create Multilingual .content.ts files close to the component
1213
- * fill: ({ fileName, extension }) => `./${fileName}${extension}`,
1214
- *
1215
- * // fill: './{{fileName}}{{extension}}', // Equivalent using template string
1216
- * }
1217
- * ```
1218
- *
1219
- * ```ts
1220
- * {
1221
- * // Create centralize per-locale JSON at the root of the project
1222
- * fill: ({ key, locale }) => `/locales/${locale}/${key}.content.json`,
1223
- *
1224
- * // fill: '/locales/{{locale}}/{{key}}.content.json', // Equivalent using template string
1225
- * }
1226
- * ```
1227
- *
1228
- * ```ts
1229
- * {
1230
- * // Create custom output based on the locale
1231
- * fill: {
1232
- * en: ({ key }) => `/locales/en/${key}.content.json`,
1233
- * fr: '/locales/fr/{{key}}.content.json',
1234
- * es: false,
1235
- * de: true,
1236
- * },
1237
- * }
1238
- * ```
1239
- *
1240
- *
1241
- * Variable list:
1242
- * - `fileName`: The name of the file.
1243
- * - `key`: The key of the content.
1244
- * - `locale`: The locale of the content.
1245
- * - `extension`: The extension of the file.
1246
- * - `componentFileName`: The name of the component file.
1247
- * - `componentExtension`: The extension of the component file.
1248
- * - `format`: The format of the dictionary.
1249
- * - `componentFormat`: The format of the component dictionary.
1250
- * - `componentDirPath`: The directory path of the component.
1251
- */
1252
- fill?: Fill;
1253
- /**
1254
- * The description of the dictionary. Helps to understand the purpose of the dictionary in the editor, and the CMS.
1255
- * The description is also used as context for translations generation.
1256
- *
1257
- * Example:
1258
- * ```ts
1259
- * {
1260
- * "key": "about-page-meta",
1261
- * "description":[
1262
- * "This dictionary is manage the metadata of the About Page",
1263
- * "Consider good practices for SEO:",
1264
- * "- The title should be between 50 and 60 characters",
1265
- * "- The description should be between 150 and 160 characters",
1266
- * ].join('\n'),
1267
- * "content": { ... }
1268
- * }
1269
- * ```
1270
- */
1271
- description?: string;
1272
- /**
1273
- * Transform the dictionary in a per-locale dictionary.
1274
- * Each field declared in a per-locale dictionary will be transformed in a translation node.
1275
- * If missing, the dictionary will be treated as a multilingual dictionary.
1276
- * If declared, do not use translation nodes in the content.
1277
- *
1278
- * Example:
1279
- * ```json
1280
- * {
1281
- * "key": "about-page",
1282
- * "locale": "en",
1283
- * "content": {
1284
- * "multilingualContent": "English content"
1285
- * }
1286
- * }
1287
- * ```
1288
- */
1289
- locale?: LocalesValues;
1290
- /**
1291
- * Indicators if the content of the dictionary should be automatically transformed.
1292
- * If true, the content will be transformed to the corresponding node type.
1293
- * - Markdown: `### Title` -> `md('### Title')`
1294
- * - HTML: `<div>Title</div>` -> `html('<div>Title</div>')`
1295
- * - Insertion: `Hello {{name}}` -> `insert('Hello {{name}}')`
1296
- *
1297
- * If an object is provided, you can specify which transformations should be enabled.
1298
- *
1299
- * Default: false
1300
- */
1301
- contentAutoTransformation?: ContentAutoTransformation;
1302
- /**
1303
- * Indicates the priority of the dictionary.
1304
- * In the case of conflicts, the dictionary with the highest priority will override the other dictionaries.
1305
- */
1306
- priority?: number;
1307
- /**
1308
- * Indicates the mode of import to use for the dictionaries.
1309
- *
1310
- * Available modes:
1311
- * - "static": The dictionaries are imported statically.
1312
- * In that case, Intlayer will replace all calls to `useIntlayer` with `useDictionary`.
1313
- * - "dynamic": The dictionaries are imported dynamically in a synchronous component using the suspense API.
1314
- * In that case, Intlayer will replace all calls to `useIntlayer` with `useDictionaryDynamic`.
1315
- * - "fetch": The dictionaries are imported dynamically using the live sync API.
1316
- * In that case, Intlayer will replace all calls to `useIntlayer` with `useDictionaryDynamic`.
1317
- * Fetch mode will use the live sync API to fetch the dictionaries. If the API call fails, the dictionaries will be imported dynamically as "dynamic" mode.
1318
- *
1319
- * Default: "static"
1320
- *
1321
- * By default, when a dictionary is loaded, it imports content for all locales as it's imported statically.
1322
- *
1323
- * Note:
1324
- * - Dynamic imports rely on Suspense and may slightly impact rendering performance.
1325
- * - If disabled all locales will be loaded at once, even if they are not used.
1326
- * - This option relies on the `@intlayer/babel` and `@intlayer/swc` plugins.
1327
- * - Ensure all keys are declared statically in the `useIntlayer` calls. e.g. `useIntlayer('navbar')`.
1328
- * - This option will be ignored if `optimize` is disabled.
1329
- * - This option will not impact the `getIntlayer`, `getDictionary`, `useDictionary`, `useDictionaryAsync` and `useDictionaryDynamic` functions. You can still use them to refine you code on manual optimization.
1330
- * - The "fetch" allows to sync the dictionaries to the live sync server.
1331
- * - Require static key to work. Example of invalid code: `const navbarKey = "my-key"; useIntlayer(navbarKey)`.
1332
- */
1333
- importMode?: "static" | "dynamic" | "fetch";
1334
- /**
1335
- * The title of the dictionary. Helps to identify the dictionary in the editor, and the CMS.
1336
- *
1337
- * Example:
1338
- * ```json
1339
- * {
1340
- * "key": "about-page-meta",
1341
- * "title": "About Page",
1342
- * "content": { ... }
1343
- * }
1344
- * ```
1345
- */
1346
- title?: string;
1347
- /**
1348
- * Helps to categorize the dictionaries. The tags can provide more context and instructions for the dictionary.
1349
- *
1350
- * Example:
1351
- * ```json
1352
- * {
1353
- * "key": "about-page-meta",
1354
- * "tags": ["metadata","about-page"]
1355
- * }
1356
- * ```
1357
- */
1358
- tags?: string[];
1359
- /**
1360
- * Indicates the location of the dictionary and controls how it synchronizes with the CMS.
1361
- *
1362
- * - 'hybrid': The dictionary is managed locally and remotely. Once pushed on the CMS, it will be synchronized from the local one. The local dictionary will be pulled from the CMS.
1363
- * - 'remote': The dictionary is managed remotely only. Once pushed on the CMS, it will be detached from the local one. At content load time, the remote dictionary will be pulled from the CMS. A '.content' file with remote location will be ignored.
1364
- * - 'local': The dictionary is managed locally. It will not be pushed to the remote CMS.
1365
- * - 'plugin' (or any custom string): The dictionary is managed by a plugin, or a custom source. When you will try to push it, the system will ask an action to the user.
1366
- */
1367
- location?: DictionaryLocation;
1368
- };
1369
- /**
1370
- * Combined configuration for internationalization, middleware, and content
1371
- */
1372
- type IntlayerConfig = {
1373
- /**
1374
- * Internationalization configuration
1375
- */
1376
- internationalization: InternationalizationConfig;
1377
- /**
1378
- * Default dictionary configuration
1379
- */
1380
- dictionary?: Partial<DictionaryConfig>;
1381
- /**
1382
- * Routing configuration
1383
- */
1384
- routing: RoutingConfig;
1385
- /**
1386
- * Content configuration
1387
- */
1388
- content: ContentConfig;
1389
- /**
1390
- * System configuration
1391
- */
1392
- system: SystemConfig;
1393
- /**
1394
- * Intlayer editor configuration
1395
- */
1396
- editor: EditorConfig;
1397
- /**
1398
- * Logger configuration
1399
- */
1400
- log: LogConfig;
1401
- /**
1402
- * AI configuration
1403
- */
1404
- ai?: Partial<AiConfig>;
1405
- /**
1406
- * Build configuration
1407
- */
1408
- build: BuildConfig;
1409
- /**
1410
- * Compiler configuration
1411
- */
1412
- compiler: CompilerConfig;
1413
- /**
1414
- * Custom schemas to validate the dictionaries content.
1415
- */
1416
- schemas?: Record<string, Schema>;
1417
- /**
1418
- * Plugins configuration
1419
- */
1420
- plugins?: Plugin[];
1421
- /**
1422
- * Metadata of the project
1423
- */
1424
- metadata: {
1425
- name: string;
1426
- version: string;
1427
- doc: string;
1428
- };
1429
- };
1430
- /**
1431
- * Configuration for content handling
1432
- */
1433
- type ContentConfig = {
1434
- /**
1435
- * File extensions of content to look for
1436
- *
1437
- * Default: ['.content.ts', '.content.js', '.content.cjs', '.content.mjs', '.content.json', '.content.tsx', '.content.jsx']
1438
- *
1439
- * List of file extensions to scan for content.
1440
- */
1441
- fileExtensions: string[];
1442
- /**
1443
- * Directory where the content is stored, relative to the base directory
1444
- *
1445
- * Default: ['.']
1446
- *
1447
- * Derived content directory based on the base configuration.
1448
- *
1449
- * Note: This is used to watch for content files.
1450
- */
1451
- contentDir: string[];
1452
- /**
1453
- * Directory where the code is stored, relative to the base directory
1454
- *
1455
- * Default: ['.']
1456
- *
1457
- * Derived code directory based on the base configuration.
1458
- *
1459
- * Note: This is used to watch for code files to transform.
1460
- */
1461
- codeDir: string[];
1462
- /**
1463
- * Directories to be excluded from content processing
1464
- *
1465
- * Default: ['node_modules', '.intlayer']
1466
- *
1467
- * A list of directories to exclude from content processing.
1468
- */
1469
- excludedPath: string[];
1470
- /**
1471
- * Indicates if Intlayer should watch for changes in the content declaration files in the app to rebuild the related dictionaries.
1472
- *
1473
- * Default: process.env.NODE_ENV === 'development'
1474
- */
1475
- watch: boolean;
1476
- /**
1477
- * Command to format the content. When intlayer write your .content files locally, this command will be used to format the content.
1478
- *
1479
- * Example:
1480
- *
1481
- * ```bash
1482
- * npx prettier --write {{file}}
1483
- * ```
1484
- *
1485
- * ```bash
1486
- * bunx biome format {{file}}
1487
- * ```
1488
- *
1489
- * ```bash
1490
- * bun format {{file}}
1491
- * ```
1492
- *
1493
- * ```bash
1494
- * npx eslint --fix {{file}}
1495
- * ```
1496
- *
1497
- * Intlayer will replace the {{file}} with the path of the file to format.
1498
- *
1499
- * Default: undefined
1500
- */
1501
- formatCommand: string | undefined;
1502
- };
1503
- type SystemConfig = {
1504
- /**
1505
- * Absolute path of the project's base directory
1506
- *
1507
- * Default: process.cwd()
1508
- *
1509
- * The root directory of the project, typically used for resolving other paths.
1510
- */
1511
- baseDir: string;
1512
- /**
1513
- * Directory for module augmentation, relative to the base directory
1514
- *
1515
- * Default: .intlayer/types
1516
- *
1517
- * Defines the derived path for module augmentation.
1518
- */
1519
- moduleAugmentationDir: string;
1520
- /**
1521
- * Directory where unmerged dictionaries are stored, relative to the result directory
1522
- *
1523
- * Default: .intlayer/unmerged_dictionary
1524
- *
1525
- * Specifies the derived path for unmerged dictionaries relative to the result directory.
1526
- */
1527
- unmergedDictionariesDir: string;
1528
- /**
1529
- * Directory where remote dictionaries are stored, relative to the result directory
1530
- *
1531
- * Default: .intlayer/remote_dictionary
1532
- *
1533
- * Specifies the derived path for remote dictionaries relative to the result directory.
1534
- */
1535
- remoteDictionariesDir: string;
1536
- /**
1537
- * Directory where final dictionaries are stored, relative to the result directory
1538
- *
1539
- * Default: .intlayer/dictionary
1540
- *
1541
- * Specifies the derived path for dictionaries relative to the result directory.
1542
- */
1543
- dictionariesDir: string;
1544
- /**
1545
- * Directory where dynamic dictionaries are stored, relative to the result directory
1546
- *
1547
- * Default: .intlayer/dynamic_dictionary
1548
- *
1549
- * Specifies the derived path for dynamic dictionaries relative to the result directory.
1550
- */
1551
- dynamicDictionariesDir: string;
1552
- /**
1553
- * Directory where fetch dictionaries are stored, relative to the result directory
1554
- *
1555
- * Default: .intlayer/fetch_dictionary
1556
- *
1557
- * Specifies the derived path for fetch dictionaries relative to the result directory.
1558
- */
1559
- fetchDictionariesDir: string;
1560
- /**
1561
- * Directory where dictionary types are stored, relative to the result directory
1562
- *
1563
- * Default: .intlayer/types
1564
- *
1565
- * Specifies the derived path for dictionary types relative to the result directory.
1566
- */
1567
- typesDir: string;
1568
- /**
1569
- * Directory where the main files are stored, relative to the result directory
1570
- *
1571
- * Default: .intlayer/main
1572
- *
1573
- * Specifies the derived path for the main files relative to the result directory.
1574
- */
1575
- mainDir: string;
1576
- /**
1577
- * Directory where the configuration files are stored, relative to the result directory
1578
- *
1579
- * Default: .intlayer/config
1580
- *
1581
- * Specifies the derived path for the configuration files relative to the result directory.
1582
- */
1583
- configDir: string;
1584
- /**
1585
- * Directory where the cache files are stored, relative to the result directory
1586
- *
1587
- * Default: .intlayer/cache
1588
- *
1589
- * Specifies the derived path for the cache files relative to the result directory.
1590
- */
1591
- cacheDir: string;
1592
- /**
1593
- * Directory where the temp files are stored, relative to the result directory
1594
- *
1595
- * Default: .intlayer/tmp
1596
- *
1597
- * Specifies the derived path for the tmp files relative to the result directory.
1598
- */
1599
- tempDir: string;
1600
- };
1601
- type LogFunctions = {
1602
- error?: typeof console.error;
1603
- log?: typeof console.log;
1604
- info?: typeof console.info;
1605
- warn?: typeof console.warn;
1606
- };
1607
- type LogConfig = {
1608
- /**
1609
- * Indicates if the logger is enabled
1610
- *
1611
- * Default: true
1612
- *
1613
- * If 'default', the logger is enabled and can be used.
1614
- * If 'verbose', the logger will be enabled and can be used, but will log more information.
1615
- * If 'disabled', the logger is disabled and cannot be used.
1616
- */
1617
- mode: "default" | "verbose" | "disabled";
1618
- /**
1619
- * Prefix of the logger
1620
- *
1621
- * Default: '[intlayer]'
1622
- *
1623
- * The prefix of the logger.
1624
- */
1625
- prefix: string;
1626
- /**
1627
- * Functions to log
1628
- */
1629
- error?: typeof console.error;
1630
- log?: typeof console.log;
1631
- info?: typeof console.info;
1632
- warn?: typeof console.warn;
1633
- debug?: typeof console.debug;
1634
- };
1635
- //#endregion
1636
- export { Schema$1 as $, ContentAutoTransformation as A, LocalDictionaryId as B, SystemConfig as C, Plugin as D, MergedDictionaryResult as E, DictionaryKey as F, DeclaredLocales as G, FilePathPattern as H, DictionaryLocation as I, DictionaryRegistryContent as J, DictionaryKeys as K, Fill as L, Dictionary as M, DictionaryFormat as N, UnmergedDictionaryOutput as O, DictionaryId as P, ResolvedEditor as Q, GetSubPath as R, StrictMode as S, MergedDictionaryOutput as T, FilePathPatternContext as U, TypedNode as V, FilePathPatternFunction as W, LocalesValues as X, DictionaryRegistryElement as Y, RequiredLocales as Z, RewriteRule as _, CommonAiConfig as a, Schema as b, CookiesAttributes as c, EditorConfig as d, SchemaKeys as et, InternationalizationConfig as f, RewriteObject as g, LogFunctions as h, BuildConfig as i, ContentNode as j, UnmergedDictionaryResult as k, CustomIntlayerConfig as l, LogConfig as m, AiProviderConfigMap as n, CompilerConfig as o, IntlayerConfig as p, DictionaryRegistry as q, AiProviders as r, ContentConfig as s, AiConfig as t, StrictModeLocaleMap as tt, DictionaryConfig as u, RewriteRules as v, URLType as w, StorageAttributes as x, RoutingConfig as y, ImportMode as z };
1637
- //# sourceMappingURL=config-CE_7T8Jh.d.ts.map