@intlayer/docs 8.4.6 → 8.4.7

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 (31) hide show
  1. package/blog/en/next-i18next_vs_next-intl_vs_intlayer.md +1 -3
  2. package/blog/en-GB/next-i18next_vs_next-intl_vs_intlayer.md +1 -3
  3. package/blog/es/next-i18next_vs_next-intl_vs_intlayer.md +1 -3
  4. package/blog/id/next-i18next_vs_next-intl_vs_intlayer.md +1 -3
  5. package/blog/it/next-i18next_vs_next-intl_vs_intlayer.md +1 -3
  6. package/blog/ja/next-i18next_vs_next-intl_vs_intlayer.md +1 -3
  7. package/blog/ko/next-i18next_vs_next-intl_vs_intlayer.md +1 -3
  8. package/blog/uk/next-i18next_vs_next-intl_vs_intlayer.md +1 -3
  9. package/blog/vi/next-i18next_vs_next-intl_vs_intlayer.md +1 -3
  10. package/blog/zh/next-i18next_vs_next-intl_vs_intlayer.md +1 -3
  11. package/docs/en/configuration.md +115 -137
  12. package/docs/es/configuration.md +14 -6
  13. package/docs/fr/configuration.md +14 -6
  14. package/package.json +6 -6
  15. package/docs/ar/configuration.md +0 -922
  16. package/docs/bn/configuration.md +0 -922
  17. package/docs/de/configuration.md +0 -922
  18. package/docs/en-GB/configuration.md +0 -922
  19. package/docs/hi/configuration.md +0 -922
  20. package/docs/id/configuration.md +0 -922
  21. package/docs/it/configuration.md +0 -923
  22. package/docs/ja/configuration.md +0 -922
  23. package/docs/ko/configuration.md +0 -922
  24. package/docs/pl/configuration.md +0 -922
  25. package/docs/pt/configuration.md +0 -922
  26. package/docs/ru/configuration.md +0 -943
  27. package/docs/tr/configuration.md +0 -922
  28. package/docs/uk/configuration.md +0 -922
  29. package/docs/ur/configuration.md +0 -922
  30. package/docs/vi/configuration.md +0 -922
  31. package/docs/zh/configuration.md +0 -922
@@ -1,922 +0,0 @@
1
- ---
2
- createdAt: 2024-08-13
3
- updatedAt: 2026-03-20
4
- title: Configuration
5
- description: Learn how to configure Intlayer for your application. Understand the various settings and options available to customise Intlayer according to your needs.
6
- keywords:
7
- - Configuration
8
- - Settings
9
- - Customisation
10
- - Intlayer
11
- - Options
12
- slugs:
13
- - doc
14
- - concept
15
- - configuration
16
- history:
17
- - version: 8.4.0
18
- date: 2026-03-20
19
- changes: Added per-locale object notation for 'compiler.output' and 'dictionary.fill'
20
- - version: 8.3.0
21
- date: 2026-03-11
22
- changes: Moved 'baseDir' from 'content' configuration to 'system' configuration
23
- - version: 8.2.0
24
- date: 2026-03-09
25
- changes: Updated compiler options, added support for 'output' and 'noMetadata'
26
- - version: 8.1.7
27
- date: 2026-02-25
28
- changes: Updated compiler options
29
- - version: 8.1.5
30
- date: 2026-02-23
31
- changes: Added compiler option 'build-only' and dictionary prefix
32
- - version: 8.0.6
33
- date: 2026-02-12
34
- changes: Added support for Open Router, Alibaba, Amazon, Google Vertex Bedrock, Fireworks, Groq, Hugging Face and Together.ai providers
35
- - version: 8.0.5
36
- date: 2026-02-06
37
- changes: Added `dataSerialization` to AI configuration
38
- - version: 8.0.0
39
- date: 2026-01-24
40
- changes: Renamed import mode `live` to `fetch` to better describe the underlying mechanism.
41
- - version: 8.0.0
42
- date: 2026-01-22
43
- changes: Moved build configuration `importMode` to `dictionary` configuration.
44
- - version: 8.0.0
45
- date: 2026-01-22
46
- changes: Added `rewrite` option to routing configuration
47
- - version: 8.0.0
48
- date: 2026-01-18
49
- changes: Separated system configuration from content configuration. Moved internal paths to `system` property. Added `codeDir` to separate content files and code transformation.
50
- - version: 8.0.0
51
- date: 2026-01-18
52
- changes: Added dictionary options `location` and `schema`
53
- - version: 7.5.1
54
- date: 2026-01-10
55
- changes: Added support for JSON5 and JSONC file formats
56
- - version: 7.5.0
57
- date: 2025-12-17
58
- changes: Added `buildMode` option
59
- - version: 7.0.0
60
- date: 2025-10-25
61
- changes: Added `dictionary` configuration
62
- - version: 7.0.0
63
- date: 2025-10-21
64
- changes: Replaced `middleware` by `routing` configuration
65
- - version: 7.0.0
66
- date: 2025-10-12
67
- changes: Added `formatCommand` option
68
- - version: 6.2.0
69
- date: 2025-10-12
70
- changes: Updated `excludedPath` option
71
- - version: 6.0.2
72
- date: 2025-09-23
73
- changes: Added `outputFormat` option
74
- - version: 6.0.0
75
- date: 2025-09-21
76
- changes: Deleted `dictionaryOutput` field and `i18nextResourcesDir` field
77
- - version: 6.0.0
78
- date: 2025-09-16
79
- changes: Added `live` import mode
80
- - version: 6.0.0
81
- date: 2025-09-04
82
- changes: Replaced `hotReload` field with `liveSync` and added `liveSyncPort` and `liveSyncURL` fields
83
- - version: 5.6.1
84
- date: 2025-07-25
85
- changes: Replaced `activateDynamicImport` with `importMode` option
86
- - version: 5.6.0
87
- date: 2025-07-13
88
- changes: Changed default contentDir from `['src']` to `['.']`
89
- - version: 5.5.11
90
- date: 2025-06-29
91
- changes: Added `docs` commands
92
- ---
93
-
94
- # Intlayer Configuration Documentation
95
-
96
- ## Overview
97
-
98
- Intlayer configuration files allow you to customise various aspects of the plugin, such as internationalisation (internationalisation), middleware, and content handling. This documentation provides an in-depth description of each property in the configuration.
99
-
100
- ---
101
-
102
- ## Table of Contents
103
-
104
- <TOC/>
105
-
106
- ---
107
-
108
- ## Supported Configuration File Formats
109
-
110
- Intlayer accepts configuration file formats including JSON, JS, MJS, and TS:
111
-
112
- - `intlayer.config.ts`
113
- - `intlayer.config.js`
114
- - `intlayer.config.json`
115
- - `intlayer.config.json5`
116
- - `intlayer.config.jsonc`
117
- - `intlayer.config.cjs`
118
- - `intlayer.config.mjs`
119
- - `.intlayerrc`
120
-
121
- ---
122
-
123
- ## Configuration File Example
124
-
125
- ````typescript fileName="intlayer.config.ts" codeFormat="typescript"
126
- import { Locales, type IntlayerConfig } from "intlayer";
127
- import { nextjsRewrite } from "intlayer/routing";
128
- import { z } from "zod";
129
-
130
- /**
131
- * Example Intlayer configuration file displaying all available options.
132
- */
133
- const config: IntlayerConfig = {
134
- /**
135
- * Configuration for internationalisation settings.
136
- */
137
- internationalization: {
138
- /**
139
- * List of locales supported in the application.
140
- * Default: [Locales.ENGLISH]
141
- */
142
- locales: [Locales.ENGLISH, Locales.FRENCH, Locales.SPANISH],
143
-
144
- /**
145
- * List of mandatory locales that must be defined in each dictionary.
146
- * If empty, all locales are mandatory in `strict` mode.
147
- * Default: []
148
- */
149
- requiredLocales: [Locales.ENGLISH],
150
-
151
- /**
152
- * Level of strictness for internationalised content.
153
- * - "strict": Error if any declared locale is missing or undeclared.
154
- * - "inclusive": Warning if a declared locale is missing.
155
- * - "loose": Accepts any existing locale.
156
- * Default: "inclusive"
157
- */
158
- strictMode: "inclusive",
159
-
160
- /**
161
- * Default locale used as a fallback if the requested locale is not found.
162
- * Default: Locales.ENGLISH
163
- */
164
- defaultLocale: Locales.ENGLISH,
165
- },
166
-
167
- /**
168
- * Settings controlling dictionary operations and fallback behaviour.
169
- */
170
- dictionary: {
171
- /**
172
- * Controls how dictionaries are imported.
173
- * - "static": Statically imported at build time.
174
- * - "dynamic": Dynamically imported using Suspense.
175
- * - "fetch": Dynamically fetched via the live sync API.
176
- * Default: "static"
177
- */
178
- importMode: "static",
179
-
180
- /**
181
- * Strategy to fill missing translations automatically using AI.
182
- * Can be a boolean value or a path pattern to save the filled content.
183
- * Default: true
184
- */
185
- fill: true,
186
-
187
- /**
188
- * Physical location of dictionary files.
189
- * - "local": Stored in the local filesystem.
190
- * - "remote": Stored in the Intlayer CMS.
191
- * - "hybrid": Stored both locally and in the Intlayer CMS.
192
- * - "plugin" (or any custom string): Provided by a plugin or custom source.
193
- * Default: "local"
194
- */
195
- location: "local",
196
-
197
- /**
198
- * Whether the content should be automatically transformed (e.g. Markdown to HTML).
199
- * Default: false
200
- */
201
- contentAutoTransformation: false,
202
- },
203
-
204
- /**
205
- * Routing and middleware configuration.
206
- */
207
- routing: {
208
- /**
209
- * Locale routing strategy.
210
- * - "prefix-no-default": Prefixes all but the default locale (e.g. /dashboard, /fr/dashboard).
211
- * - "prefix-all": Prefixes all locales (e.g. /en/dashboard, /fr/dashboard).
212
- * - "no-prefix": No locale in URL.
213
- * - "search-params": Uses ?locale=...
214
- * Default: "prefix-no-default"
215
- */
216
- mode: "prefix-no-default",
217
-
218
- /**
219
- * Where to store the user-selected locale.
220
- * Options: 'cookie', 'localStorage', 'sessionStorage', 'header', or an array of these.
221
- * Default: ['cookie', 'header']
222
- */
223
- storage: ["cookie", "header"],
224
-
225
- /**
226
- * Base path for application URLs.
227
- * Default: ""
228
- */
229
- basePath: "",
230
-
231
- /**
232
- * Custom URL rewrite rules for specific paths on a per-locale basis.
233
- */
234
- rewrite: nextjsRewrite({
235
- "/[locale]/about": {
236
- en: "/[locale]/about",
237
- fr: "/[locale]/a-propos",
238
- },
239
- }),
240
- },
241
-
242
- /**
243
- * Settings pertaining to finding and processing content files.
244
- */
245
- content: {
246
- /**
247
- * File extensions for scanning dictionaries.
248
- * Default: ['.content.ts', '.content.js', '.content.json', etc.]
249
- */
250
- fileExtensions: [".content.ts", ".content.js", ".content.json"],
251
-
252
- /**
253
- * Directories where .content files are located.
254
- * Default: ["."]
255
- */
256
- contentDir: ["src"],
257
-
258
- /**
259
- * Where the source code is located.
260
- * Used for build optimisation and code transformation.
261
- * Default: ["."]
262
- */
263
- codeDir: ["src"],
264
-
265
- /**
266
- * Patterns excluded from scanning.
267
- * Default: ['node_modules', '.intlayer', etc.]
268
- */
269
- excludedPath: ["node_modules"],
270
-
271
- /**
272
- * Whether to monitor changes and rebuild dictionaries during development.
273
- * Default: true in development
274
- */
275
- watch: true,
276
-
277
- /**
278
- * Command used to format newly created / updated .content files.
279
- */
280
- formatCommand: 'npx prettier --write "{{file}}"',
281
- },
282
-
283
- /**
284
- * Visual Editor configuration.
285
- */
286
- editor: {
287
- /**
288
- * Whether the visual editor is enabled.
289
- * Default: false
290
- */
291
- enabled: true,
292
-
293
- /**
294
- * The URL of your application for origin validation.
295
- * Default: ""
296
- */
297
- applicationURL: "http://localhost:3000",
298
-
299
- /**
300
- * Port for the local editor server.
301
- * Default: 8000
302
- */
303
- port: 8000,
304
-
305
- /**
306
- * Public URL for the editor.
307
- * Default: "http://localhost:8000"
308
- */
309
- editorURL: "http://localhost:8000",
310
-
311
- /**
312
- * Intlayer CMS URL.
313
- * Default: "https://app.intlayer.org"
314
- */
315
- cmsURL: "https://app.intlayer.org",
316
-
317
- /**
318
- * Backend API URL.
319
- * Default: "https://back.intlayer.org"
320
- */
321
- backendURL: "https://back.intlayer.org",
322
-
323
- /**
324
- * Whether to enable real-time content sync.
325
- * Default: false
326
- */
327
- liveSync: true,
328
- },
329
-
330
- /**
331
- * AI-based translation and construction settings.
332
- */
333
- ai: {
334
- /**
335
- * AI provider to use.
336
- * Options: 'openai', 'anthropic', 'mistral', 'deepseek', 'gemini', 'ollama', 'openrouter', 'alibaba', 'fireworks', 'groq', 'huggingface', 'bedrock', 'googlevertex', 'togetherai'
337
- * Default: 'openai'
338
- */
339
- provider: "openai",
340
-
341
- /**
342
- * Model of the selected provider to use.
343
- */
344
- model: "gpt-4o",
345
-
346
- /**
347
- * Provider API key.
348
- */
349
- apiKey: process.env.OPENAI_API_KEY,
350
-
351
- /**
352
- * Global context to guide AI in generating translations.
353
- */
354
- applicationContext: "This is a travel booking application.",
355
-
356
- /**
357
- * Base URL for AI API.
358
- */
359
- baseURL: "http://localhost:3000",
360
-
361
- /**
362
- * Data Serialization
363
- *
364
- * Options:
365
- * - "json": Default, robust; consumes more tokens.
366
- * - "toon": Consumes fewer tokens, may not be as consistent as JSON.
367
- *
368
- * Default: "json"
369
- */
370
- dataSerialization: "json",
371
- },
372
-
373
- /**
374
- * Build and optimisation settings.
375
- */
376
- build: {
377
- /**
378
- * Build execution mode.
379
- * - "auto": Builds automatically during application build.
380
- * - "manual": Requires an explicit build command.
381
- * Default: "auto"
382
- */
383
- mode: "auto",
384
-
385
- /**
386
- * Whether to optimise final bundle by removing unused dictionaries.
387
- * Default: true in production
388
- */
389
- optimize: true,
390
-
391
- /**
392
- * Output format for generated dictionary files.
393
- * Default: ['cjs', 'esm']
394
- */
395
- outputFormat: ["cjs", "esm"],
396
-
397
- /**
398
- * Indicates whether the build should check TypeScript types.
399
- * Default: false
400
- */
401
- checkTypes: false,
402
- },
403
-
404
- /**
405
- * Logger configuration.
406
- */
407
- log: {
408
- /**
409
- * Logging level.
410
- * - "default": Standard logging.
411
- * - "verbose": In-depth debug logging.
412
- * - "disabled": Disables logging.
413
- * Default: "default"
414
- */
415
- mode: "default",
416
-
417
- /**
418
- * Prefix for all log messages.
419
- * Default: "[intlayer]"
420
- */
421
- prefix: "[intlayer]",
422
- },
423
-
424
- /**
425
- * System Configuration (For advanced use)
426
- */
427
- system: {
428
- /**
429
- * Directory for storing localised dictionaries.
430
- */
431
- dictionariesDir: ".intlayer/dictionary",
432
-
433
- /**
434
- * Directory for TypeScript module augmentation.
435
- */
436
- moduleAugmentationDir: ".intlayer/types",
437
-
438
- /**
439
- * Directory for storing unmerged dictionaries.
440
- */
441
- unmergedDictionariesDir: ".intlayer/unmerged_dictionary",
442
-
443
- /**
444
- * Directory for storing dictionary types.
445
- */
446
- typesDir: ".intlayer/types",
447
-
448
- /**
449
- * Directory where the main application files are stored.
450
- */
451
- mainDir: ".intlayer/main",
452
-
453
- /**
454
- * Directory where the configuration files are stored.
455
- */
456
- configDir: ".intlayer/config",
457
-
458
- /**
459
- * Directory where the cache files are stored.
460
- */
461
- cacheDir: ".intlayer/cache",
462
- },
463
-
464
- /**
465
- * Compiler Configuration (For advanced use)
466
- */
467
- compiler: {
468
- /**
469
- * Indicates whether the compiler should be enabled.
470
- *
471
- * - false: Disables the compiler.
472
- * - true: Enables the compiler.
473
- * - "build-only": Skips the compiler during development and speeds up startup time.
474
- *
475
- * Default: false
476
- */
477
- enabled: true,
478
-
479
- /**
480
- * Defines path for output files. Replaces `outputDir`.
481
- *
482
- * - `./` paths are resolved relative to the component directory.
483
- * - `/` paths are resolved relative to the project root (`baseDir`).
484
- *
485
- * - Including `{{locale}}` variable in path will trigger the creation of separate dictionaries per-language.
486
- *
487
- * Example:
488
- * ```ts
489
- * {
490
- * // Create multilingual .content.ts files next to component
491
- * output: ({ fileName, extension }) => `./${fileName}${extension}`,
492
- *
493
- * // output: './{{fileName}}{{extension}}', // Equivalent using template string
494
- * }
495
- * ```
496
- *
497
- * ```ts
498
- * {
499
- * // Create centralised JSON per language on project root
500
- * output: ({ key, locale }) => `/locales/${locale}/${key}.content.json`,
501
- *
502
- * // output: '/locales/{{locale}}/{{key}}.content.json', // Equivalent using template string
503
- * }
504
- * ```
505
- *
506
- * Variable list:
507
- * - `fileName`: File name.
508
- * - `key`: Content key.
509
- * - `locale`: Content locale.
510
- * - `extension`: File extension.
511
- * - `componentFileName`: Component file name.
512
- * - `componentExtension`: Component file extension.
513
- * - `format`: Dictionary format.
514
- * - `componentFormat`: Component dictionary format.
515
- * - `componentDirPath`: Component directory path.
516
- */
517
- output: ({ locale, key }) => `compiler/${locale}/${key}.json`,
518
-
519
- /**
520
- * Indicates whether components should be saved after being transformed.
521
- * In this way, the compiler can be run only once to transform the application and can then be removed.
522
- */
523
- saveComponents: false,
524
-
525
- /**
526
- * Only insert content into the generated file. Useful for per-language JSON output for i18next or ICU MessageFormat.
527
- */
528
- noMetadata: false,
529
-
530
- /**
531
- * Dictionary key prefix
532
- */
533
- dictionaryKeyPrefix: "", // Add an optional prefix to the extracted dictionary keys
534
- },
535
-
536
- /**
537
- * Custom schemas for validating dictionary content.
538
- */
539
- schemas: {
540
- "my-schema": z.object({
541
- title: z.string(),
542
- }),
543
- },
544
-
545
- /**
546
- * Plugins configuration.
547
- */
548
- plugins: [],
549
- };
550
-
551
- export default config;
552
- ````
553
-
554
- ---
555
-
556
- ## Configuration Reference
557
-
558
- The following sections describe the various configuration settings available in Intlayer.
559
-
560
- ---
561
-
562
- ### Internationalisation Configuration
563
-
564
- Defines settings related to internationalisation, including available locales and the default locale for the application.
565
-
566
- | Field | Type | Description | Example | Note |
567
- | ----------------- | ---------- | -------------------------------------------------------------------------------------------------- | -------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
568
- | `locales` | `string[]` | List of locales supported in the application. Default: `[Locales.ENGLISH]` | `['en', 'fr', 'es']` | |
569
- | `requiredLocales` | `string[]` | List of mandatory locales in the application. Default: `[]` | `[]` | If empty, all locales are mandatory in `strict` mode. Ensure mandatory locales are also defined in the `locales` field. |
570
- | `strictMode` | `string` | Guarantees robust internationalised content implementation using TypeScript. Default: `inclusive` | | If `"strict"`: the `t` function requires every declared locale to be defined — throws an error if any are missing or undeclared. If `"inclusive"`: warns about missing locales but accepts existing undeclared ones. If `"loose"`: accepts any existing locale. |
571
- | `defaultLocale` | `string` | Default locale used as a fallback if the requested locale is not found. Default: `Locales.ENGLISH` | `'en'` | Used to determine the locale when no locale is specified in the URL, cookie, or header. |
572
-
573
- ---
574
-
575
- ### Editor Configuration
576
-
577
- Defines settings related to the integrated editor, including server port and activity state.
578
-
579
- | Field | Type | Description | Example | Note |
580
- | ---------------------------- | ------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
581
- | `applicationURL` | `string` | The URL of your application. Default: `''` | `'http://localhost:3000'`, `'https://example.com'`, `process.env.INTLAYER_EDITOR_URL` | Used to restrict the origin of the editor for security reasons. If set to `'*'`, the editor can be accessed from any origin. |
582
- | `port` | `number` | Port used by the Visual Editor server. Default: `8000` | | |
583
- | `editorURL` | `string` | Editor server URL. Default: `'http://localhost:8000'` | `'http://localhost:3000'`, `'https://example.com'`, `process.env.INTLAYER_EDITOR_URL` | Used to restrict the origins that can interact with the application. If set to `'*'`, accessible from any origin. Must be set if changing the port or if the editor is hosted on a different domain. |
584
- | `cmsURL` | `string` | Intlayer CMS URL. Default: `'https://intlayer.org'` | `'https://intlayer.org'` | |
585
- | `backendURL` | `string` | Backend server URL. Default: `https://back.intlayer.org` | `http://localhost:4000` | |
586
- | `enabled` | `boolean` | Indicates whether the app will interact with the visual editor. Default: `true` | `process.env.NODE_ENV !== 'production'` | If `false`, the editor cannot interact with the app. Disabling it for specific environments strengthens security. |
587
- | `clientId` | `string &#124; undefined` | Enables intlayer packages to authenticate with the backend using oAuth2. To get an access token, go to [intlayer.org/project](https://app.intlayer.org/project). Default: `undefined` | | Keep secret; store in environment variables. |
588
- | `clientSecret` | `string &#124; undefined` | Enables intlayer packages to authenticate with the backend using oAuth2. To get an access token, go to [intlayer.org/project](https://app.intlayer.org/project). Default: `undefined` | | Keep secret; store in environment variables. |
589
- | `dictionaryPriorityStrategy` | `string` | Strategy for prioritising dictionaries when both local and distant dictionaries are present. Default: `'local_first'` | `'distant_first'` | `'distant_first'`: prioritises distant over local. `'local_first'`: prioritises local over distant. |
590
- | `liveSync` | `boolean` | Indicates whether the app server should hot-reload content when a change is detected on the CMS / Visual Editor / Backend. Default: `true` | `true` | When a dictionary is added/updated, the app updates the page content. Live sync outsources content to another server, which may slightly affect performance. It is recommended to host both on the same machine. |
591
- | `liveSyncPort` | `number` | Live sync server port. Default: `4000` | `4000` | |
592
- | `liveSyncURL` | `string` | Live sync server URL. Default: `'http://localhost:{liveSyncPort}'` | `'https://example.com'` | Points to localhost by default; can be changed to a remote live sync server. |
593
-
594
- ### Routing Configuration
595
-
596
- Settings that control routing behaviour, including URL structure, locale storage, and middleware handling.
597
-
598
- | Field | Type | Description | Example | Note |
599
- | ---------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
600
- | `mode` | `'prefix-no-default' &#124; 'prefix-all' &#124; 'no-prefix' &#124; 'search-params'` | URL routing mode for locale handling. Default: `'prefix-no-default'` | `'prefix-no-default'`: `/dashboard` (en) or `/fr/dashboard` (fr). `'prefix-all'`: `/en/dashboard`. `'no-prefix'`: locale is handled by other means. `'search-params'`: `/dashboard?locale=fr` | Does not affect cookie or locale storage management. |
601
- | `storage` | `false &#124; 'cookie' &#124; 'localStorage' &#124; 'sessionStorage' &#124; 'header' &#124; CookiesAttributes &#124; StorageAttributes &#124; Array` | Configuration for storing the locale on the client. Default: `['cookie', 'header']` | `'localStorage'`, `[{ type: 'cookie', name: 'custom-locale', secure: true }]` | See the Storage Options table below. |
602
- | `basePath` | `string` | Base path for application URLs. Default: `''` | `'/my-app'` | If the app is at `https://example.com/my-app`, basePath is `'/my-app'` and URLs become `https://example.com/my-app/en`. |
603
- | `rewrite` | `Record<string, StrictModeLocaleMap<string>>` | Custom URL rewrite rules that override the default routing mode for specific paths. Supports dynamic parameters `[param]`. Default: `undefined` | See example below | Rewrite rules take priority over the `mode`. Works with Next.js and Vite. `getLocalizedUrl()` automatically applies matching rules. See [Custom URL Rewrites](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en-GB/custom_url_rewrites.md). |
604
-
605
- **`rewrite` Example**:
606
-
607
- ```typescript
608
- routing: {
609
- mode: "prefix-no-default", // Fallback strategy
610
- rewrite: nextjsRewrite({
611
- "/about": {
612
- en: "/about",
613
- fr: "/a-propos",
614
- },
615
- "/product/[slug]": {
616
- en: "/product/[slug]",
617
- fr: "/produit/[slug]",
618
- },
619
- "/blog/[category]/[id]": {
620
- en: "/blog/[category]/[id]",
621
- fr: "/journal/[category]/[id]",
622
- },
623
- }),
624
- }
625
- ```
626
-
627
- #### Storage Options
628
-
629
- | Value | Description | Note |
630
- | ------------------ | ---------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
631
- | `'cookie'` | Stores locale in cookies — accessible by both client and server sides. | For GDPR compliance, ensure proper user consent is obtained. Customisable via `CookiesAttributes` (`{ type: 'cookie', name: 'custom-locale', secure: true, httpOnly: false }`). |
632
- | `'localStorage'` | Stores locale in the browser with no expiry date — client-side only. | Does not expire unless explicitly cleared. Intlayer proxy cannot access it. Customisable via `StorageAttributes` (`{ type: 'localStorage', name: 'custom-locale' }`). |
633
- | `'sessionStorage'` | Stores locale for the duration of the page session — client-side only. | Cleared when tab/window is closed. Intlayer proxy cannot access it. Customisable via `StorageAttributes` (`{ type: 'sessionStorage', name: 'custom-locale' }`). |
634
- | `'header'` | Stores or transmits locale via HTTP headers — server-side only. | Useful for API calls. Client-side cannot access it. Customisable via `StorageAttributes` (`{ type: 'header', name: 'custom-locale' }`). |
635
-
636
- #### Cookie Attributes
637
-
638
- When using cookie storage, you can configure additional cookie attributes:
639
-
640
- | Field | Type | Description |
641
- | ---------- | ------------------------------------- | --------------------------------------------------- |
642
- | `name` | `string` | Cookie name. Default: `'INTLAYER_LOCALE'` |
643
- | `domain` | `string` | Cookie domain. Default: `undefined` |
644
- | `path` | `string` | Cookie path. Default: `undefined` |
645
- | `secure` | `boolean` | Requires HTTPS. Default: `undefined` |
646
- | `httpOnly` | `boolean` | HTTP-only flag. Default: `undefined` |
647
- | `sameSite` | `'strict' &#124; 'lax' &#124; 'none'` | SameSite policy. |
648
- | `expires` | `Date &#124; number` | Expiry date or number of days. Default: `undefined` |
649
-
650
- #### Locale Storage Attributes
651
-
652
- When using localStorage or sessionStorage:
653
-
654
- | Field | Type | Description |
655
- | ------ | ---------------------------------------- | ---------------------------------------------- |
656
- | `type` | `'localStorage' &#124; 'sessionStorage'` | Storage type. |
657
- | `name` | `string` | Storage key name. Default: `'INTLAYER_LOCALE'` |
658
-
659
- #### Configuration Examples
660
-
661
- Here are some common configuration examples for the new v7 routing structure:
662
-
663
- **Basic Configuration (Default)**:
664
-
665
- ```typescript
666
- import { Locales, type IntlayerConfig } from "intlayer";
667
- // intlayer.config.ts
668
- const config: IntlayerConfig = {
669
- internationalization: {
670
- locales: ["en", "fr", "es"],
671
- defaultLocale: "en",
672
- },
673
- routing: {
674
- mode: "prefix-no-default",
675
- storage: "localStorage",
676
- basePath: "",
677
- },
678
- };
679
-
680
- export default config;
681
- ```
682
-
683
- **GDPR Compliant Configuration**:
684
-
685
- ```typescript
686
- import { Locales, type IntlayerConfig } from "intlayer";
687
- // intlayer.config.ts
688
- const config: IntlayerConfig = {
689
- internationalization: {
690
- locales: ["en", "fr", "es"],
691
- defaultLocale: "en",
692
- },
693
- routing: {
694
- mode: "prefix-no-default",
695
- storage: [
696
- {
697
- type: "localStorage",
698
- name: "user-locale",
699
- },
700
- {
701
- type: "cookie",
702
- name: "user-locale",
703
- secure: true,
704
- sameSite: "strict",
705
- httpOnly: false,
706
- },
707
- ],
708
- basePath: "",
709
- },
710
- };
711
-
712
- export default config;
713
- ```
714
-
715
- **Search Parameters Mode**:
716
-
717
- ```typescript
718
- import { Locales, type IntlayerConfig } from "intlayer";
719
- // intlayer.config.ts
720
- const config: IntlayerConfig = {
721
- internationalization: {
722
- locales: ["en", "fr", "es"],
723
- defaultLocale: "en",
724
- },
725
- routing: {
726
- mode: "search-params",
727
- storage: "localStorage",
728
- basePath: "",
729
- },
730
- };
731
-
732
- export default config;
733
- ```
734
-
735
- **No Prefix Mode with Custom Storage**:
736
-
737
- ```typescript
738
- import { Locales, type IntlayerConfig } from "intlayer";
739
- // intlayer.config.ts
740
- const config: IntlayerConfig = {
741
- internationalization: {
742
- locales: ["en", "fr", "es"],
743
- defaultLocale: "en",
744
- },
745
- routing: {
746
- mode: "no-prefix",
747
- storage: {
748
- type: "sessionStorage",
749
- name: "app-locale",
750
- },
751
- basePath: "/my-app",
752
- },
753
- };
754
-
755
- export default config;
756
- ```
757
-
758
- **Custom URL Rewrite with Dynamic Paths**:
759
-
760
- ```typescript
761
- // intlayer.config.ts
762
- import { nextjsRewrite } from "intlayer/routing";
763
-
764
- const config: IntlayerConfig = {
765
- internationalization: {
766
- locales: ["en", "fr"],
767
- defaultLocale: "en",
768
- },
769
- routing: {
770
- mode: "prefix-no-default", // Fallback for paths not rewritten
771
- storage: "cookie",
772
- rewrite: nextjsRewrite({
773
- "/about": {
774
- en: "/about",
775
- fr: "/a-propos",
776
- },
777
- "/product/[slug]": {
778
- en: "/product/[slug]",
779
- fr: "/produit/[slug]",
780
- },
781
- "/blog/[category]/[id]": {
782
- en: "/blog/[category]/[id]",
783
- fr: "/journal/[category]/[id]",
784
- },
785
- }),
786
- },
787
- };
788
-
789
- export default config;
790
- ```
791
-
792
- ---
793
-
794
- ### Content Configuration
795
-
796
- Settings pertaining to the processing of content within the application (directory names, file extensions, and derived configurations).
797
-
798
- | Field | Type | Description | Example | Note |
799
- | ---------------- | ---------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------- | --------------------------------------------------------------------------------------------------------------- |
800
- | `watch` | `boolean` | Indicates whether Intlayer should watch for changes in content declaration files to rebuild dictionaries. Default: `process.env.NODE_ENV === 'development'` | | |
801
- | `fileExtensions` | `string[]` | File extensions used for scanning content declaration files. Default: `['.content.ts', '.content.js', '.content.mjs', '.content.cjs', '.content.json', '.content.json5', '.content.jsonc']` | `['.content.ts', '.content.js']` | |
802
- | `contentDir` | `string[]` | Paths to the directories where the content declaration files are located. Default: `['.']` | `['src/content']` | |
803
- | `codeDir` | `string[]` | Paths to the directories where your application's source code files are located. Default: `['.']` | `['src']` | Used to optimise the build and ensure that code transformation and hot reloading only apply to necessary files. |
804
- | `excludedPath` | `string[]` | Paths excluded from content scanning. Default: `['node_modules', '.intlayer', '.next', 'dist', 'build']` | `['src/styles']` | |
805
- | `formatCommand` | `string` | Command that will be run to format newly created or updated content files. Default: `undefined` | `'npx prettier --write "{{file}}"'` | Used during content extraction or through the visual editor. |
806
-
807
- ---
808
-
809
- ### Dictionary Configuration
810
-
811
- Settings that control dictionary operations, including auto-filling behaviour and content creation.
812
-
813
- This dictionary configuration has two main purposes:
814
-
815
- 1. **Default values**: Defining default values when creating content declaration files.
816
- 2. **Fallback behaviour**: Allows setting up the behaviour of dictionary operations globally, providing fallback values when specific fields are not defined.
817
-
818
- For more information on how content declaration files and configuration values are applied, see the [content file documentation](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en-GB/dictionary/content_file.md).
819
-
820
- | Field | Type | Description | Example | Note |
821
- | --------------------------- | ----------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------ | ----------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
822
- | `fill` | `boolean &#124; FilePathPattern &#124; Partial<Record<Locale, boolean &#124; FilePathPattern>>` | Controls how auto-fill (AI translation) output files are generated. Default: `true` | See example below | `true`: default path (same file as source). `false`: disabled. String/function patterns generate files per language. Object per language: each language maps to its own pattern; `false` skips that language. Including a `{{locale}}` variable triggers per-language generation. Dictionary-level `fill` always takes precedence over this global configuration. |
823
- | `importMode` | `'static' &#124; 'dynamic' &#124; 'fetch'` | Controls how dictionaries are imported. Default: `'static'` | `'dynamic'` | `'static'`: Statically imported. `'dynamic'`: Dynamically imported via 'Suspense'. `'fetch'`: Dynamically fetched via 'Live Sync API'. Does not affect `getIntlayer`, `getDictionary`, `useDictionary`, etc. |
824
- | `location` | `'local' &#124; 'remote' &#124; 'hybrid' &#124; string` | Where dictionaries are stored. Default: `'local'` | `'remote'` | `'local'`: filesystem. `'remote'`: Intlayer CMS. `'hybrid'`: both. |
825
- | `contentAutoTransformation` | `boolean` | Indicates whether content files should be automatically transformed (e.g. from Markdown to HTML). Default: `false` | `true` | Useful for processing Markdown fields via @intlayer/markdown. |
826
-
827
- **`fill` example**:
828
-
829
- ```ts
830
- dictionary: {
831
- fill: {
832
- en: '/locales/en/{{key}}.content.json',
833
- fr: ({ key }) => `/locales/fr/${key}.content.json`,
834
- es: false,
835
- }
836
- }
837
- ```
838
-
839
- ---
840
-
841
- ### AI Configuration
842
-
843
- Defines settings for Intlayer's AI-powered features, such as translation construction.
844
-
845
- | Field | Type | Description | Example | Note |
846
- | -------------------- | ---------------------- | ---------------------------------------------------------------- | ------------------------------------------- | ----------------------------------------------------------------------------------------- |
847
- | `provider` | `string` | AI provider to use. | `'openai'`, `'anthropic'`, `'googlevertex'` | |
848
- | `model` | `string` | AI model to use. | `'gpt-4o'`, `'claude-3-5-sonnet-20240620'` | |
849
- | `apiKey` | `string` | API key for the selected provider. | `process.env.OPENAI_API_KEY` | |
850
- | `applicationContext` | `string` | Extra context about your app to improve AI translation accuracy. | `'A learning platform for children.'` | |
851
- | `baseURL` | `string` | Optional base URL for API calls. | | Useful if you are using a proxy or local AI deployment. |
852
- | `dataSerialization` | `'json' &#124; 'toon'` | Defines how data is sent to the AI. Default: `'json'` | `'json'` | `'json'`: more robust and accurate. `'toon'`: uses fewer tokens but might be less stable. |
853
-
854
- ---
855
-
856
- ### Build Configuration
857
-
858
- Settings for the Intlayer build process and optimisations.
859
-
860
- | Field | Type | Description | Example | Note |
861
- | -------------- | ------------------------ | ------------------------------------------------------------------------------------------------------- | ------- | ---- |
862
- | `mode` | `'auto' &#124; 'manual'` | Indicates whether Intlayer should run automatically during the app's pre-build steps. Default: `'auto'` | | |
863
- | `optimize` | `boolean` | Indicates whether compiled dictionaries should be optimised for runtime. Default: `true` in production | | |
864
- | `outputFormat` | `('cjs' &#124; 'esm')[]` | Output format for generated dictionary files. Default: `['cjs', 'esm']` | | |
865
- | `checkTypes` | `boolean` | Indicates whether Intlayer should check types in the generated files. Default: `false` | | |
866
-
867
- ---
868
-
869
- ### System Configuration
870
-
871
- These settings are for advanced use cases and Intlayer's internal configuration.
872
-
873
- | Field | Type | Description | Default |
874
- | ------------------------- | -------- | ----------------------------------------- | --------------------------------- |
875
- | `dictionariesDir` | `string` | Compiled dictionaries directory. | `'.intlayer/dictionary'` |
876
- | `moduleAugmentationDir` | `string` | TypeScript module augmentation directory. | `'.intlayer/types'` |
877
- | `unmergedDictionariesDir` | `string` | Unmerged dictionaries directory. | `'.intlayer/unmerged_dictionary'` |
878
- | `typesDir` | `string` | Generated types directory. | `'.intlayer/types'` |
879
- | `mainDir` | `string` | Main Intlayer file directory. | `'.intlayer/main'` |
880
- | `configDir` | `string` | Compiled configuration files directory. | `'.intlayer/config'` |
881
- | `cacheDir` | `string` | Cache files directory. | `'.intlayer/cache'` |
882
-
883
- ---
884
-
885
- ### Compiler Configuration
886
-
887
- Settings for the Intlayer compiler (`intlayer compiler`).
888
-
889
- | Field | Type | Description | Default |
890
- | --------------------- | ------------------------ | ---------------------------------------------------------------------------------------- | ------- |
891
- | `enabled` | `boolean` | Indicates whether the compiler is active. | `false` |
892
- | `output` | `string &#124; Function` | Output path for extracted dictionaries. | |
893
- | `saveComponents` | `boolean` | Indicates whether original source files should be overwritten with transformed versions. | `false` |
894
- | `noMetadata` | `boolean` | If `true`, the compiler will not include metadata in the generated files. | `false` |
895
- | `dictionaryKeyPrefix` | `string` | Optional dictionary key prefix. | `''` |
896
-
897
- ---
898
-
899
- ### Logger Configuration
900
-
901
- Settings for customising Intlayer log output.
902
-
903
- | Field | Type | Description | Default |
904
- | -------- | ---------------------------------------------- | ------------------- | -------------- |
905
- | `mode` | `'default' &#124; 'verbose' &#124; 'disabled'` | Logging mode. | `'default'` |
906
- | `prefix` | `string` | Log message prefix. | `'[intlayer]'` |
907
-
908
- ---
909
-
910
- ### Custom Schemas
911
-
912
- | Field | Type | Description |
913
- | --------- | --------------------------- | ------------------------------------------------------------------------ |
914
- | `schemas` | `Record<string, ZodSchema>` | Allows defining Zod schemas for validating your dictionaries' structure. |
915
-
916
- ---
917
-
918
- ### Plugins
919
-
920
- | Field | Type | Description |
921
- | --------- | ------------------ | ------------------------------------- |
922
- | `plugins` | `IntlayerPlugin[]` | List of Intlayer plugins to activate. |