@intlayer/docs 7.0.4-canary.0 → 7.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/blog/ar/intlayer_with_i18next.md +68 -106
- package/blog/ar/intlayer_with_next-i18next.md +84 -288
- package/blog/ar/intlayer_with_next-intl.md +58 -337
- package/blog/ar/intlayer_with_react-i18next.md +68 -290
- package/blog/ar/intlayer_with_react-intl.md +63 -266
- package/blog/de/intlayer_with_i18next.md +77 -97
- package/blog/de/intlayer_with_next-i18next.md +69 -296
- package/blog/de/intlayer_with_next-intl.md +59 -340
- package/blog/de/intlayer_with_react-i18next.md +68 -290
- package/blog/de/intlayer_with_react-intl.md +62 -264
- package/blog/en/intlayer_with_i18next.md +36 -1638
- package/blog/en/intlayer_with_next-i18next.md +22 -847
- package/blog/en/intlayer_with_next-intl.md +32 -1053
- package/blog/en/intlayer_with_react-i18next.md +38 -764
- package/blog/en/intlayer_with_react-intl.md +42 -1018
- package/blog/en-GB/intlayer_with_i18next.md +67 -103
- package/blog/en-GB/intlayer_with_next-i18next.md +71 -292
- package/blog/en-GB/intlayer_with_next-intl.md +58 -337
- package/blog/en-GB/intlayer_with_react-i18next.md +67 -289
- package/blog/en-GB/intlayer_with_react-intl.md +61 -264
- package/blog/es/intlayer_with_i18next.md +67 -103
- package/blog/es/intlayer_with_next-i18next.md +71 -296
- package/blog/es/intlayer_with_next-intl.md +57 -338
- package/blog/es/intlayer_with_react-i18next.md +68 -290
- package/blog/es/intlayer_with_react-intl.md +62 -265
- package/blog/fr/intlayer_with_i18next.md +66 -104
- package/blog/fr/intlayer_with_next-i18next.md +82 -285
- package/blog/fr/intlayer_with_next-intl.md +57 -338
- package/blog/fr/intlayer_with_react-i18next.md +67 -289
- package/blog/fr/intlayer_with_react-intl.md +61 -264
- package/blog/hi/intlayer_with_i18next.md +68 -104
- package/blog/hi/intlayer_with_next-i18next.md +74 -299
- package/blog/hi/intlayer_with_next-intl.md +57 -239
- package/blog/hi/intlayer_with_react-i18next.md +69 -291
- package/blog/hi/intlayer_with_react-intl.md +65 -268
- package/blog/id/intlayer_with_i18next.md +126 -0
- package/blog/id/intlayer_with_next-i18next.md +142 -0
- package/blog/id/intlayer_with_next-intl.md +113 -0
- package/blog/id/intlayer_with_react-i18next.md +124 -0
- package/blog/id/intlayer_with_react-intl.md +122 -0
- package/blog/it/intlayer_with_i18next.md +67 -103
- package/blog/it/intlayer_with_next-i18next.md +71 -296
- package/blog/it/intlayer_with_next-intl.md +57 -338
- package/blog/it/intlayer_with_react-i18next.md +68 -290
- package/blog/it/intlayer_with_react-intl.md +62 -265
- package/blog/ja/intlayer_with_i18next.md +68 -103
- package/blog/ja/intlayer_with_next-i18next.md +85 -283
- package/blog/ja/intlayer_with_next-intl.md +58 -336
- package/blog/ja/intlayer_with_react-i18next.md +68 -290
- package/blog/ja/intlayer_with_react-intl.md +62 -264
- package/blog/ko/intlayer_with_i18next.md +80 -96
- package/blog/ko/intlayer_with_next-i18next.md +85 -287
- package/blog/ko/intlayer_with_next-intl.md +68 -327
- package/blog/ko/intlayer_with_react-i18next.md +68 -290
- package/blog/ko/intlayer_with_react-intl.md +64 -266
- package/blog/pl/intlayer_with_i18next.md +126 -0
- package/blog/pl/intlayer_with_next-i18next.md +142 -0
- package/blog/pl/intlayer_with_next-intl.md +111 -0
- package/blog/pl/intlayer_with_react-i18next.md +124 -0
- package/blog/pl/intlayer_with_react-intl.md +122 -0
- package/blog/pt/intlayer_with_i18next.md +67 -103
- package/blog/pt/intlayer_with_next-i18next.md +72 -293
- package/blog/pt/intlayer_with_next-intl.md +57 -256
- package/blog/pt/intlayer_with_react-i18next.md +104 -78
- package/blog/pt/intlayer_with_react-intl.md +62 -266
- package/blog/ru/intlayer_with_i18next.md +66 -104
- package/blog/ru/intlayer_with_next-i18next.md +71 -296
- package/blog/ru/intlayer_with_next-intl.md +58 -337
- package/blog/ru/intlayer_with_react-i18next.md +68 -290
- package/blog/ru/intlayer_with_react-intl.md +62 -265
- package/blog/tr/intlayer_with_i18next.md +71 -107
- package/blog/tr/intlayer_with_next-i18next.md +72 -297
- package/blog/tr/intlayer_with_next-intl.md +58 -339
- package/blog/tr/intlayer_with_react-i18next.md +69 -291
- package/blog/tr/intlayer_with_react-intl.md +63 -285
- package/blog/vi/intlayer_with_i18next.md +126 -0
- package/blog/vi/intlayer_with_next-i18next.md +142 -0
- package/blog/vi/intlayer_with_next-intl.md +111 -0
- package/blog/vi/intlayer_with_react-i18next.md +124 -0
- package/blog/vi/intlayer_with_react-intl.md +122 -0
- package/blog/zh/intlayer_with_i18next.md +67 -102
- package/blog/zh/intlayer_with_next-i18next.md +72 -296
- package/blog/zh/intlayer_with_next-intl.md +58 -336
- package/blog/zh/intlayer_with_react-i18next.md +68 -290
- package/blog/zh/intlayer_with_react-intl.md +63 -106
- package/docs/ar/plugins/sync-json.md +244 -0
- package/docs/de/plugins/sync-json.md +244 -0
- package/docs/en/intlayer_cli.md +25 -0
- package/docs/en/intlayer_with_nextjs_14.md +2 -0
- package/docs/en/intlayer_with_nextjs_15.md +2 -0
- package/docs/en/intlayer_with_nextjs_16.md +2 -0
- package/docs/en/plugins/sync-json.md +1 -1
- package/docs/en-GB/plugins/sync-json.md +244 -0
- package/docs/es/plugins/sync-json.md +244 -0
- package/docs/fr/plugins/sync-json.md +244 -0
- package/docs/hi/plugins/sync-json.md +244 -0
- package/docs/id/plugins/sync-json.md +244 -0
- package/docs/it/plugins/sync-json.md +244 -0
- package/docs/ja/plugins/sync-json.md +244 -0
- package/docs/ko/plugins/sync-json.md +244 -0
- package/docs/pl/plugins/sync-json.md +244 -0
- package/docs/pt/plugins/sync-json.md +244 -0
- package/docs/ru/plugins/sync-json.md +244 -0
- package/docs/tr/plugins/sync-json.md +245 -0
- package/docs/vi/plugins/sync-json.md +244 -0
- package/docs/zh/plugins/sync-json.md +244 -0
- package/package.json +14 -14
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
---
|
|
2
2
|
createdAt: 2024-12-24
|
|
3
|
-
updatedAt: 2025-
|
|
4
|
-
title:
|
|
5
|
-
description:
|
|
3
|
+
updatedAt: 2025-10-29
|
|
4
|
+
title: How to automate your i18next JSON translations using Intlayer
|
|
5
|
+
description: Automate your JSON translations with Intlayer and i18next for enhanced internationalisation in JavaScript applications.
|
|
6
6
|
keywords:
|
|
7
7
|
- Intlayer
|
|
8
8
|
- i18next
|
|
@@ -14,149 +14,113 @@ keywords:
|
|
|
14
14
|
- Next.js
|
|
15
15
|
- JavaScript
|
|
16
16
|
- TypeScript
|
|
17
|
+
- Migration
|
|
18
|
+
- Integration
|
|
17
19
|
slugs:
|
|
18
20
|
- blog
|
|
19
21
|
- intlayer-with-i18next
|
|
22
|
+
history:
|
|
23
|
+
- version: 7.0.0
|
|
24
|
+
date: 2025-10-29
|
|
25
|
+
changes: Change to syncJSON plugin
|
|
20
26
|
---
|
|
21
27
|
|
|
22
|
-
#
|
|
28
|
+
# How to automate your i18next JSON translations using Intlayer
|
|
23
29
|
|
|
24
|
-
|
|
30
|
+
## What is Intlayer?
|
|
25
31
|
|
|
26
|
-
Intlayer is
|
|
32
|
+
**Intlayer** is an innovative, open-source internationalisation library designed to address the shortcomings of traditional i18n solutions. It offers a modern approach to content management in JavaScript applications.
|
|
27
33
|
|
|
28
|
-
|
|
34
|
+
See a concrete comparison with i18next in our [next-i18next vs. next-intl vs. Intlayer](https://github.com/aymericzip/intlayer/blob/main/docs/blog/en/next-i18next_vs_next-intl_vs_intlayer.md) blog post.
|
|
29
35
|
|
|
30
|
-
|
|
36
|
+
## Why Combine Intlayer with i18next?
|
|
31
37
|
|
|
32
|
-
|
|
38
|
+
While Intlayer provides an excellent standalone i18n solution (see our [Next.js integration guide](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/intlayer_with_nextjs_16.md)), you might want to combine it with i18next for several reasons:
|
|
33
39
|
|
|
34
|
-
|
|
35
|
-
|
|
40
|
+
1. **Existing codebase**: You have an established i18next implementation and want to gradually migrate to Intlayer's improved developer experience.
|
|
41
|
+
2. **Legacy requirements**: Your project requires compatibility with existing i18next plugins or workflows.
|
|
42
|
+
3. **Team familiarity**: Your team is comfortable with i18next but wants better content management.
|
|
36
43
|
|
|
37
|
-
|
|
44
|
+
**For that, Intlayer can be implemented as an adapter for i18next to help automate your JSON translations in CLI or CI/CD pipelines, test your translations, and more.**
|
|
38
45
|
|
|
39
|
-
|
|
46
|
+
This guide shows you how to leverage Intlayer's superior content declaration system while maintaining compatibility with i18next.
|
|
40
47
|
|
|
41
|
-
|
|
48
|
+
## Table of Contents
|
|
42
49
|
|
|
43
|
-
|
|
50
|
+
<TOC/>
|
|
44
51
|
|
|
45
|
-
|
|
52
|
+
## Step-by-Step Guide to Set Up Intlayer with i18next
|
|
46
53
|
|
|
47
|
-
|
|
54
|
+
### Step 1: Install Dependencies
|
|
48
55
|
|
|
49
|
-
|
|
56
|
+
Install the necessary packages:
|
|
50
57
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
58
|
+
```bash packageManager="npm"
|
|
59
|
+
npm install intlayer @intlayer/sync-json-plugin
|
|
60
|
+
```
|
|
54
61
|
|
|
55
|
-
|
|
62
|
+
```bash packageManager="pnpm"
|
|
63
|
+
pnpm add intlayer @intlayer/sync-json-plugin
|
|
64
|
+
```
|
|
56
65
|
|
|
57
|
-
|
|
66
|
+
```bash packageManager="yarn"
|
|
67
|
+
yarn add intlayer @intlayer/sync-json-plugin
|
|
68
|
+
```
|
|
58
69
|
|
|
59
|
-
|
|
70
|
+
**Package descriptions:**
|
|
60
71
|
|
|
61
|
-
|
|
72
|
+
- **intlayer**: Core library for internationalisation management, content declaration, and building
|
|
73
|
+
- **@intlayer/sync-json-plugin**: Plugin to export Intlayer content declarations to i18next compatible JSON format
|
|
62
74
|
|
|
63
|
-
|
|
64
|
-
import { Locales, type IntlayerConfig } from "intlayer";
|
|
75
|
+
### Step 2: Implement the Intlayer plugin to wrap the JSON
|
|
65
76
|
|
|
66
|
-
|
|
67
|
-
content: {
|
|
68
|
-
// Indicate that Intlayer will export both Intlayer and i18next dictionaries
|
|
69
|
-
dictionaryOutput: ["intlayer", "i18next"],
|
|
70
|
-
// Relative path from the project root to the directory where i18n dictionaries will be exported
|
|
71
|
-
i18nextResourcesDir: "./i18next/dictionaries",
|
|
72
|
-
},
|
|
73
|
-
};
|
|
77
|
+
Create an Intlayer configuration file to define your supported locales:
|
|
74
78
|
|
|
75
|
-
export
|
|
76
|
-
```
|
|
79
|
+
**If you want to also export JSON dictionaries for i18next**, add the `syncJSON` plugin:
|
|
77
80
|
|
|
78
|
-
```
|
|
79
|
-
import { Locales } from "intlayer";
|
|
81
|
+
```typescript fileName="intlayer.config.ts"
|
|
82
|
+
import { Locales, type IntlayerConfig } from "intlayer";
|
|
83
|
+
import { syncJSON } from "@intlayer/sync-json-plugin";
|
|
80
84
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
dictionaryOutput: ["intlayer", "i18next"],
|
|
86
|
-
// Relative path from the project root to the directory where i18n dictionaries will be exported
|
|
87
|
-
i18nextResourcesDir: "./i18next/dictionaries",
|
|
85
|
+
const config: IntlayerConfig = {
|
|
86
|
+
internationalization: {
|
|
87
|
+
locales: [Locales.ENGLISH, Locales.FRENCH, Locales.SPANISH],
|
|
88
|
+
defaultLocale: Locales.ENGLISH,
|
|
88
89
|
},
|
|
90
|
+
plugins: [
|
|
91
|
+
syncJSON({
|
|
92
|
+
source: ({ key, locale }) => `./intl/messages/${locale}/${key}.json`,
|
|
93
|
+
}),
|
|
94
|
+
],
|
|
89
95
|
};
|
|
90
96
|
|
|
91
97
|
export default config;
|
|
92
98
|
```
|
|
93
99
|
|
|
94
|
-
|
|
95
|
-
const { Locales } = require("intlayer");
|
|
96
|
-
|
|
97
|
-
/** @type {import('intlayer').IntlayerConfig} */
|
|
98
|
-
const config = {
|
|
99
|
-
content: {
|
|
100
|
-
// Indicate that Intlayer will export both Intlayer and i18next dictionaries
|
|
101
|
-
dictionaryOutput: ["intlayer", "i18next"],
|
|
102
|
-
// Relative path from the project root to the directory where i18n dictionaries will be exported
|
|
103
|
-
i18nextResourcesDir: "./i18next/dictionaries",
|
|
104
|
-
},
|
|
105
|
-
};
|
|
106
|
-
|
|
107
|
-
module.exports = config;
|
|
108
|
-
```
|
|
100
|
+
The `syncJSON` plugin will automatically wrap the JSON. It will read and write the JSON files without changing the content architecture.
|
|
109
101
|
|
|
110
|
-
|
|
102
|
+
If you want to make that JSON coexist with Intlayer content declaration files (`.content` files), Intlayer will proceed as follows:
|
|
111
103
|
|
|
112
|
-
|
|
104
|
+
1. load both JSON and content declaration files and transform them into an Intlayer dictionary.
|
|
105
|
+
2. if there are conflicts between the JSON and the content declaration files, Intlayer will proceed to merge all those dictionaries. This depends on the priority of the plugins and that of the content declaration file (all are configurable).
|
|
113
106
|
|
|
114
|
-
|
|
107
|
+
If changes are made using the CLI to translate the JSON, or using the CMS, Intlayer will update the JSON file with the new translations.
|
|
115
108
|
|
|
116
|
-
|
|
117
|
-
// i18n/client.ts
|
|
109
|
+
## Git Configuration
|
|
118
110
|
|
|
119
|
-
|
|
120
|
-
import resourcesToBackend from "i18next-resources-to-backend";
|
|
111
|
+
It is recommended to ignore auto-generated Intlayer files:
|
|
121
112
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
resourcesToBackend(
|
|
126
|
-
(language: string, namespace: string) =>
|
|
127
|
-
import(`../i18next/dictionaries/${language}/${namespace}.json`)
|
|
128
|
-
)
|
|
129
|
-
);
|
|
113
|
+
```plaintext fileName=".gitignore"
|
|
114
|
+
# Ignore files generated by Intlayer
|
|
115
|
+
.intlayer
|
|
130
116
|
```
|
|
131
117
|
|
|
132
|
-
|
|
133
|
-
// i18n/client.mjs
|
|
118
|
+
These files can be regenerated during your build process and do not need to be committed to version control.
|
|
134
119
|
|
|
135
|
-
|
|
136
|
-
import resourcesToBackend from "i18next-resources-to-backend";
|
|
120
|
+
### VS Code Extension
|
|
137
121
|
|
|
138
|
-
|
|
139
|
-
// Your i18next configuration
|
|
140
|
-
.use(
|
|
141
|
-
resourcesToBackend(
|
|
142
|
-
(language, namespace) =>
|
|
143
|
-
import(`../i18next/dictionaries/${language}/${namespace}.json`)
|
|
144
|
-
)
|
|
145
|
-
);
|
|
146
|
-
```
|
|
122
|
+
For an improved developer experience, install the official **Intlayer VS Code Extension**:
|
|
147
123
|
|
|
148
|
-
|
|
149
|
-
// i18n/client.cjs
|
|
124
|
+
[Install from the VS Code Marketplace](https://marketplace.visualstudio.com/items?itemName=intlayer.intlayer-vs-code-extension)
|
|
150
125
|
|
|
151
|
-
|
|
152
|
-
const resourcesToBackend = require("i18next-resources-to-backend");
|
|
153
|
-
|
|
154
|
-
i18next
|
|
155
|
-
// Your i18next configuration
|
|
156
|
-
.use(
|
|
157
|
-
resourcesToBackend(
|
|
158
|
-
(language, namespace) =>
|
|
159
|
-
import(`../i18next/dictionaries/${language}/${namespace}.json`)
|
|
160
|
-
)
|
|
161
|
-
);
|
|
162
|
-
```
|
|
126
|
+
[Install from the VS Code Marketplace](https://marketplace.visualstudio.com/items?itemName=intlayer.intlayer-vs-code-extension)
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
---
|
|
2
2
|
createdAt: 2025-08-23
|
|
3
|
-
updatedAt: 2025-
|
|
3
|
+
updatedAt: 2025-10-29
|
|
4
4
|
title: Intlayer and next-i18next
|
|
5
|
-
description: Integrate Intlayer with next-i18next for a Next.js
|
|
5
|
+
description: Integrate Intlayer with next-i18next for a comprehensive Next.js internationalisation solution
|
|
6
6
|
keywords:
|
|
7
7
|
- i18next
|
|
8
8
|
- next-i18next
|
|
@@ -15,349 +15,128 @@ keywords:
|
|
|
15
15
|
slugs:
|
|
16
16
|
- blog
|
|
17
17
|
- intlayer-with-next-i18next
|
|
18
|
+
history:
|
|
19
|
+
- version: 7.0.0
|
|
20
|
+
date: 2025-10-29
|
|
21
|
+
changes: Change to syncJSON plugin and comprehensive rewrite
|
|
18
22
|
---
|
|
19
23
|
|
|
20
|
-
# Next.js
|
|
24
|
+
# Next.js Internationalisation (i18n) with next-i18next and Intlayer
|
|
21
25
|
|
|
22
|
-
|
|
26
|
+
## Table of Contents
|
|
23
27
|
|
|
24
|
-
|
|
28
|
+
<TOC/>
|
|
25
29
|
|
|
26
|
-
|
|
27
|
-
- Named `resource` in the case of `i18next`, the content declaration is a structured JSON object containing key-value pairs for translations in one or more languages. See [i18next documentation](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en-GB/translation-function/essentials.md) for more information.
|
|
28
|
-
- Named `content declaration file` in the case of `Intlayer`, the content declaration can be a JSON, JS, or TS file exporting the structured data. See [Intlayer documentation](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en-GB/concept/content.md) for more information.
|
|
30
|
+
## What is next-i18next?
|
|
29
31
|
|
|
30
|
-
|
|
32
|
+
**next-i18next** is one of the most popular internationalisation (i18n) frameworks for Next.js applications. Built on top of the powerful **i18next** ecosystem, it provides a comprehensive solution for managing translations, localisation, and language switching in Next.js projects.
|
|
31
33
|
|
|
32
|
-
|
|
34
|
+
However, next-i18next comes with some challenges:
|
|
33
35
|
|
|
34
|
-
|
|
36
|
+
- **Complex configuration**: Setting up next-i18next requires multiple configuration files and careful setup of server-side and client-side i18n instances.
|
|
37
|
+
- **Scattered translations**: Translation files are typically stored in separate directories from components, making it harder to maintain consistency.
|
|
38
|
+
- **Manual namespace management**: Developers need to manually manage namespaces and ensure proper loading of translation resources.
|
|
39
|
+
- **Limited type safety**: TypeScript support requires additional configuration and does not provide automatic type generation for translations.
|
|
35
40
|
|
|
36
|
-
|
|
41
|
+
## What is Intlayer?
|
|
37
42
|
|
|
38
|
-
|
|
43
|
+
**Intlayer** is an innovative, open-source internationalisation library designed to address the shortcomings of traditional i18n solutions. It offers a modern approach to content management in Next.js applications.
|
|
39
44
|
|
|
40
|
-
|
|
45
|
+
See a concrete comparison with next-intl in our [next-i18next vs. next-intl vs. Intlayer](https://github.com/aymericzip/intlayer/blob/main/docs/blog/en/next-i18next_vs_next-intl_vs_intlayer.md) blog post.
|
|
41
46
|
|
|
42
|
-
|
|
47
|
+
## Why Combine Intlayer with next-i18next?
|
|
43
48
|
|
|
44
|
-
|
|
49
|
+
While Intlayer provides an excellent standalone i18n solution (see our [Next.js integration guide](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en-GB/intlayer_with_nextjs_16.md)), you might want to combine it with next-i18next for several reasons:
|
|
45
50
|
|
|
46
|
-
|
|
51
|
+
1. **Existing codebase**: You have an established next-i18next implementation and want to gradually migrate to Intlayer's improved developer experience.
|
|
52
|
+
2. **Legacy requirements**: Your project requires compatibility with existing i18next plugins or workflows.
|
|
53
|
+
3. **Team familiarity**: Your team is comfortable with next-i18next but wants better content management.
|
|
47
54
|
|
|
48
|
-
|
|
49
|
-
.
|
|
50
|
-
└── src
|
|
51
|
-
└── components
|
|
52
|
-
└── MyComponent
|
|
53
|
-
├── index.content.ts # Content declaration file
|
|
54
|
-
└── index.tsx
|
|
55
|
-
```
|
|
55
|
+
**For that, Intlayer can be implemented as an adapter for next-i18next to help automate your JSON translations in CLI or CI/CD pipelines, test your translations, and more.**
|
|
56
56
|
|
|
57
|
-
|
|
58
|
-
.
|
|
59
|
-
└── src
|
|
60
|
-
└── components
|
|
61
|
-
└── MyComponent
|
|
62
|
-
├── index.content.mjs # Content declaration file
|
|
63
|
-
└── index.mjx
|
|
64
|
-
```
|
|
57
|
+
This guide shows you how to leverage Intlayer's superior content declaration system while maintaining compatibility with next-i18next.
|
|
65
58
|
|
|
66
|
-
|
|
67
|
-
.
|
|
68
|
-
└── src
|
|
69
|
-
└── components
|
|
70
|
-
└── MyComponent
|
|
71
|
-
├── index.content.cjs # Content declaration file
|
|
72
|
-
└── index.cjx
|
|
73
|
-
```
|
|
59
|
+
---
|
|
74
60
|
|
|
75
|
-
|
|
76
|
-
.
|
|
77
|
-
└── src
|
|
78
|
-
└── components
|
|
79
|
-
└── MyComponent
|
|
80
|
-
├── index.content.json # Content declaration file
|
|
81
|
-
└── index.jsx
|
|
82
|
-
```
|
|
61
|
+
## Step-by-Step Guide to Set Up Intlayer with next-i18next
|
|
83
62
|
|
|
84
|
-
|
|
63
|
+
### Step 1: Install Dependencies
|
|
85
64
|
|
|
86
|
-
|
|
65
|
+
Install the necessary packages using your preferred package manager:
|
|
87
66
|
|
|
88
67
|
```bash packageManager="npm"
|
|
89
|
-
npm install intlayer
|
|
90
|
-
```
|
|
91
|
-
|
|
92
|
-
```bash packageManager="yarn"
|
|
93
|
-
yarn add intlayer i18next next-i18next i18next-resources-to-backend
|
|
68
|
+
npm install intlayer @intlayer/sync-json-plugin
|
|
94
69
|
```
|
|
95
70
|
|
|
96
71
|
```bash packageManager="pnpm"
|
|
97
|
-
pnpm add intlayer
|
|
72
|
+
pnpm add intlayer @intlayer/sync-json-plugin
|
|
98
73
|
```
|
|
99
74
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
To export i18next resources, configure Intlayer in a `intlayer.config.ts` file. Example configurations:
|
|
105
|
-
|
|
106
|
-
```typescript fileName="intlayer.config.ts" codeFormat="typescript"
|
|
107
|
-
import { Locales, type IntlayerConfig } from "intlayer";
|
|
75
|
+
```bash packageManager="yarn"
|
|
76
|
+
yarn add intlayer @intlayer/sync-json-plugin
|
|
77
|
+
```
|
|
108
78
|
|
|
109
|
-
|
|
110
|
-
internationalization: {
|
|
111
|
-
locales: [Locales.ENGLISH, Locales.FRENCH, Locales.SPANISH],
|
|
112
|
-
defaultLocale: Locales.ENGLISH,
|
|
113
|
-
},
|
|
114
|
-
content: {
|
|
115
|
-
dictionaryOutput: ["i18next"],
|
|
116
|
-
i18nextResourcesDir: "./i18next/resources",
|
|
117
|
-
},
|
|
118
|
-
};
|
|
79
|
+
**Package explanations:**
|
|
119
80
|
|
|
120
|
-
|
|
121
|
-
|
|
81
|
+
- **intlayer**: Core library for content declaration and management
|
|
82
|
+
- **next-intlayer**: Next.js integration layer with build plugins
|
|
83
|
+
- **i18next**: Core i18n framework
|
|
84
|
+
- **next-i18next**: Next.js wrapper for i18next
|
|
85
|
+
- **i18next-resources-to-backend**: Dynamic resource loading for i18next
|
|
86
|
+
- **@intlayer/sync-json-plugin**: Plugin to synchronise Intlayer content declarations to i18next JSON format
|
|
122
87
|
|
|
123
|
-
|
|
124
|
-
import { Locales } from "intlayer";
|
|
88
|
+
### Step 2: Implement the Intlayer plugin to wrap the JSON
|
|
125
89
|
|
|
126
|
-
|
|
127
|
-
const config = {
|
|
128
|
-
internationalization: {
|
|
129
|
-
locales: [Locales.ENGLISH, Locales.FRENCH, Locales.SPANISH],
|
|
130
|
-
defaultLocale: Locales.ENGLISH,
|
|
131
|
-
},
|
|
132
|
-
content: {
|
|
133
|
-
dictionaryOutput: ["i18next"],
|
|
134
|
-
i18nextResourcesDir: "./i18next/resources",
|
|
135
|
-
},
|
|
136
|
-
};
|
|
90
|
+
Create an Intlayer configuration file to define your supported locales:
|
|
137
91
|
|
|
138
|
-
export
|
|
139
|
-
```
|
|
92
|
+
**If you also want to export JSON dictionaries for i18next**, add the `syncJSON` plugin:
|
|
140
93
|
|
|
141
|
-
```
|
|
142
|
-
|
|
94
|
+
```typescript fileName="intlayer.config.ts"
|
|
95
|
+
import { Locales, type IntlayerConfig } from "intlayer";
|
|
96
|
+
import { syncJSON } from "@intlayer/sync-json-plugin";
|
|
143
97
|
|
|
144
|
-
|
|
145
|
-
const config = {
|
|
98
|
+
const config: IntlayerConfig = {
|
|
146
99
|
internationalization: {
|
|
147
100
|
locales: [Locales.ENGLISH, Locales.FRENCH, Locales.SPANISH],
|
|
148
101
|
defaultLocale: Locales.ENGLISH,
|
|
149
102
|
},
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
},
|
|
154
|
-
};
|
|
155
|
-
|
|
156
|
-
module.exports = config;
|
|
157
|
-
```
|
|
158
|
-
|
|
159
|
-
### Importing Dictionaries into Your i18next Configuration
|
|
160
|
-
|
|
161
|
-
To import the generated resources into your i18next configuration, use `i18next-resources-to-backend`. Below are examples:
|
|
162
|
-
|
|
163
|
-
```typescript fileName="i18n/client.ts" codeFormat="typescript"
|
|
164
|
-
import i18next from "i18next";
|
|
165
|
-
import resourcesToBackend from "i18next-resources-to-backend";
|
|
166
|
-
|
|
167
|
-
i18next.use(
|
|
168
|
-
resourcesToBackend(
|
|
169
|
-
(language: string, namespace: string) =>
|
|
170
|
-
import(`../i18next/resources/${language}/${namespace}.json`)
|
|
171
|
-
)
|
|
172
|
-
);
|
|
173
|
-
```
|
|
174
|
-
|
|
175
|
-
```javascript fileName="i18n/client.mjs" codeFormat="esm"
|
|
176
|
-
import i18next from "i18next";
|
|
177
|
-
import resourcesToBackend from "i18next-resources-to-backend";
|
|
178
|
-
|
|
179
|
-
i18next.use(
|
|
180
|
-
resourcesToBackend(
|
|
181
|
-
(language, namespace) =>
|
|
182
|
-
import(`../i18next/resources/${language}/${namespace}.json`)
|
|
183
|
-
)
|
|
184
|
-
);
|
|
185
|
-
```
|
|
186
|
-
|
|
187
|
-
```javascript fileName="i18n/client.cjs" codeFormat="commonjs"
|
|
188
|
-
const i18next = require("i18next");
|
|
189
|
-
const resourcesToBackend = require("i18next-resources-to-backend");
|
|
190
|
-
|
|
191
|
-
i18next.use(
|
|
192
|
-
resourcesToBackend(
|
|
193
|
-
(language, namespace) =>
|
|
194
|
-
import(`../i18next/resources/${language}/${namespace}.json`)
|
|
195
|
-
)
|
|
196
|
-
);
|
|
197
|
-
```
|
|
198
|
-
|
|
199
|
-
### Dictionary
|
|
200
|
-
|
|
201
|
-
Examples of content declaration files in various formats:
|
|
202
|
-
|
|
203
|
-
```typescript fileName="**/*.content.ts" contentDeclarationFormat="typescript"
|
|
204
|
-
import { t, type Dictionary } from "intlayer";
|
|
205
|
-
|
|
206
|
-
const content = {
|
|
207
|
-
key: "my-content",
|
|
208
|
-
content: {
|
|
209
|
-
myTranslatedContent: t({
|
|
210
|
-
en: "Hello World",
|
|
211
|
-
es: "Hola Mundo",
|
|
212
|
-
fr: "Bonjour le monde",
|
|
213
|
-
}),
|
|
214
|
-
},
|
|
215
|
-
} satisfies Dictionary;
|
|
216
|
-
|
|
217
|
-
export default content;
|
|
218
|
-
```
|
|
219
|
-
|
|
220
|
-
```javascript fileName="**/*.content.mjs" contentDeclarationFormat="esm"
|
|
221
|
-
import { t } from "intlayer";
|
|
222
|
-
|
|
223
|
-
/** @type {import('intlayer').Dictionary} */
|
|
224
|
-
const content = {
|
|
225
|
-
key: "my-content",
|
|
226
|
-
content: {
|
|
227
|
-
myTranslatedContent: t({
|
|
228
|
-
en: "Hello World",
|
|
229
|
-
es: "Hola Mundo",
|
|
230
|
-
fr: "Bonjour le monde",
|
|
231
|
-
}),
|
|
232
|
-
},
|
|
233
|
-
};
|
|
234
|
-
```
|
|
235
|
-
|
|
236
|
-
```javascript fileName="**/*.content.cjs" contentDeclarationFormat="commonjs"
|
|
237
|
-
const { t } = require("intlayer");
|
|
238
|
-
|
|
239
|
-
module.exports = {
|
|
240
|
-
key: "my-content",
|
|
241
|
-
content: {
|
|
242
|
-
myTranslatedContent: t({
|
|
243
|
-
en: "Hello World",
|
|
244
|
-
es: "Hola Mundo",
|
|
245
|
-
fr: "Bonjour le monde",
|
|
103
|
+
plugins: [
|
|
104
|
+
syncJSON({
|
|
105
|
+
source: ({ key, locale }) => `./messages/${locale}/${key}.json`,
|
|
246
106
|
}),
|
|
247
|
-
|
|
107
|
+
],
|
|
248
108
|
};
|
|
249
|
-
```
|
|
250
109
|
|
|
251
|
-
|
|
252
|
-
{
|
|
253
|
-
"$schema": "https://intlayer.org/schema.json",
|
|
254
|
-
"key": "my-content",
|
|
255
|
-
"content": {
|
|
256
|
-
"myTranslatedContent": {
|
|
257
|
-
"nodeType": "translation",
|
|
258
|
-
"translation": {
|
|
259
|
-
"en": "Hello World",
|
|
260
|
-
"fr": "Bonjour le monde",
|
|
261
|
-
"es": "Hola Mundo"
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
```
|
|
267
|
-
|
|
268
|
-
### Build the next-i18next Resources
|
|
269
|
-
|
|
270
|
-
To build the next-i18next resources, run the following command:
|
|
271
|
-
|
|
272
|
-
```bash packageManager="npm"
|
|
273
|
-
npx run intlayer build
|
|
274
|
-
```
|
|
275
|
-
|
|
276
|
-
```bash packageManager="yarn"
|
|
277
|
-
yarn intlayer build
|
|
278
|
-
```
|
|
279
|
-
|
|
280
|
-
```bash packageManager="pnpm"
|
|
281
|
-
pnpm intlayer build
|
|
282
|
-
```
|
|
283
|
-
|
|
284
|
-
This will generate resources in the `./i18next/resources` directory. The expected output:
|
|
285
|
-
|
|
286
|
-
```bash
|
|
287
|
-
.
|
|
288
|
-
└── i18next
|
|
289
|
-
└── resources
|
|
290
|
-
└── en
|
|
291
|
-
└── my-content.json
|
|
292
|
-
└── fr
|
|
293
|
-
└── my-content.json
|
|
294
|
-
└── es
|
|
295
|
-
└── my-content.json
|
|
110
|
+
export default config;
|
|
296
111
|
```
|
|
297
112
|
|
|
298
|
-
|
|
113
|
+
The `syncJSON` plugin will automatically wrap the JSON. It will read and write the JSON files without changing the content architecture.
|
|
299
114
|
|
|
300
|
-
|
|
115
|
+
If you want to make that JSON coexist with Intlayer content declaration files (`.content` files), Intlayer will proceed as follows:
|
|
301
116
|
|
|
302
|
-
|
|
117
|
+
1. load both JSON and content declaration files and transform them into an Intlayer dictionary.
|
|
118
|
+
2. if there are conflicts between the JSON and the content declaration files, Intlayer will proceed to merge all those dictionaries. This depends on the priority of the plugins and that of the content declaration file (all are configurable).
|
|
303
119
|
|
|
304
|
-
|
|
305
|
-
import { withIntlayer } from "next-intlayer/server";
|
|
120
|
+
If changes are made using the CLI to translate the JSON, or using the CMS, Intlayer will update the JSON file with the new translations.
|
|
306
121
|
|
|
307
|
-
|
|
308
|
-
const nextConfig = {};
|
|
309
|
-
|
|
310
|
-
export default withIntlayer(nextConfig);
|
|
311
|
-
```
|
|
312
|
-
|
|
313
|
-
### Using Content in Next.js Components
|
|
314
|
-
|
|
315
|
-
After implementing the Next.js plugin, you can use the content in your components:
|
|
316
|
-
|
|
317
|
-
```typescript fileName="src/components/myComponent/index.tsx" codeFormat="typescript"
|
|
318
|
-
import type { FC } from "react";
|
|
319
|
-
import { useTranslation } from "react-i18next";
|
|
122
|
+
---
|
|
320
123
|
|
|
321
|
-
|
|
322
|
-
const { t } = useTranslation();
|
|
124
|
+
## Git Configuration
|
|
323
125
|
|
|
324
|
-
|
|
325
|
-
<div>
|
|
326
|
-
<h1>{t("my-content.title")}</h1>
|
|
327
|
-
<p>{t("my-content.description")}</p>
|
|
328
|
-
</div>
|
|
329
|
-
);
|
|
330
|
-
};
|
|
126
|
+
Exclude generated files from version control:
|
|
331
127
|
|
|
332
|
-
|
|
128
|
+
```plaintext fileName=".gitignore"
|
|
129
|
+
# Ignore files generated by Intlayer
|
|
130
|
+
.intlayer
|
|
131
|
+
intl
|
|
333
132
|
```
|
|
334
133
|
|
|
335
|
-
|
|
336
|
-
import { useTranslation } from "react-i18next";
|
|
134
|
+
These files are automatically regenerated during the build process and do not need to be committed to your repository.
|
|
337
135
|
|
|
338
|
-
|
|
339
|
-
const { t } = useTranslation();
|
|
136
|
+
### VS Code Extension
|
|
340
137
|
|
|
341
|
-
|
|
342
|
-
<div>
|
|
343
|
-
<h1>{t("my-content.title")}</h1>
|
|
344
|
-
<p>{t("my-content.description")}</p>
|
|
345
|
-
</div>
|
|
346
|
-
);
|
|
347
|
-
};
|
|
348
|
-
```
|
|
349
|
-
|
|
350
|
-
```jsx fileName="src/components/myComponent/index.cjx" codeFormat="commonjs"
|
|
351
|
-
const { useTranslation } = require("react-i18next");
|
|
138
|
+
For an improved developer experience, install the official **Intlayer VS Code Extension**:
|
|
352
139
|
|
|
353
|
-
|
|
354
|
-
const { t } = useTranslation();
|
|
140
|
+
[Install from the VS Code Marketplace](https://marketplace.visualstudio.com/items?itemName=intlayer.intlayer-vs-code-extension)
|
|
355
141
|
|
|
356
|
-
|
|
357
|
-
<div>
|
|
358
|
-
<h1>{t("my-content.title")}</h1>
|
|
359
|
-
<p>{t("my-content.description")}</p>
|
|
360
|
-
</div>
|
|
361
|
-
);
|
|
362
|
-
};
|
|
363
|
-
```
|
|
142
|
+
[Install from the VS Code Marketplace](https://marketplace.visualstudio.com/items?itemName=intlayer.intlayer-vs-code-extension)
|