@intlayer/docs 7.0.4-canary.0 → 7.0.5

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 (107) hide show
  1. package/blog/ar/intlayer_with_i18next.md +68 -106
  2. package/blog/ar/intlayer_with_next-i18next.md +84 -288
  3. package/blog/ar/intlayer_with_next-intl.md +58 -337
  4. package/blog/ar/intlayer_with_react-i18next.md +68 -290
  5. package/blog/ar/intlayer_with_react-intl.md +63 -266
  6. package/blog/de/intlayer_with_i18next.md +77 -97
  7. package/blog/de/intlayer_with_next-i18next.md +69 -296
  8. package/blog/de/intlayer_with_next-intl.md +59 -340
  9. package/blog/de/intlayer_with_react-i18next.md +68 -290
  10. package/blog/de/intlayer_with_react-intl.md +62 -264
  11. package/blog/en/intlayer_with_i18next.md +36 -1638
  12. package/blog/en/intlayer_with_next-i18next.md +22 -847
  13. package/blog/en/intlayer_with_next-intl.md +32 -1053
  14. package/blog/en/intlayer_with_react-i18next.md +38 -764
  15. package/blog/en/intlayer_with_react-intl.md +42 -1018
  16. package/blog/en-GB/intlayer_with_i18next.md +67 -103
  17. package/blog/en-GB/intlayer_with_next-i18next.md +71 -292
  18. package/blog/en-GB/intlayer_with_next-intl.md +58 -337
  19. package/blog/en-GB/intlayer_with_react-i18next.md +67 -289
  20. package/blog/en-GB/intlayer_with_react-intl.md +61 -264
  21. package/blog/es/intlayer_with_i18next.md +67 -103
  22. package/blog/es/intlayer_with_next-i18next.md +71 -296
  23. package/blog/es/intlayer_with_next-intl.md +57 -338
  24. package/blog/es/intlayer_with_react-i18next.md +68 -290
  25. package/blog/es/intlayer_with_react-intl.md +62 -265
  26. package/blog/fr/intlayer_with_i18next.md +66 -104
  27. package/blog/fr/intlayer_with_next-i18next.md +82 -285
  28. package/blog/fr/intlayer_with_next-intl.md +57 -338
  29. package/blog/fr/intlayer_with_react-i18next.md +67 -289
  30. package/blog/fr/intlayer_with_react-intl.md +61 -264
  31. package/blog/hi/intlayer_with_i18next.md +68 -104
  32. package/blog/hi/intlayer_with_next-i18next.md +74 -299
  33. package/blog/hi/intlayer_with_next-intl.md +57 -239
  34. package/blog/hi/intlayer_with_react-i18next.md +69 -291
  35. package/blog/hi/intlayer_with_react-intl.md +65 -268
  36. package/blog/id/intlayer_with_i18next.md +126 -0
  37. package/blog/id/intlayer_with_next-i18next.md +142 -0
  38. package/blog/id/intlayer_with_next-intl.md +113 -0
  39. package/blog/id/intlayer_with_react-i18next.md +124 -0
  40. package/blog/id/intlayer_with_react-intl.md +122 -0
  41. package/blog/it/intlayer_with_i18next.md +67 -103
  42. package/blog/it/intlayer_with_next-i18next.md +71 -296
  43. package/blog/it/intlayer_with_next-intl.md +57 -338
  44. package/blog/it/intlayer_with_react-i18next.md +68 -290
  45. package/blog/it/intlayer_with_react-intl.md +62 -265
  46. package/blog/ja/intlayer_with_i18next.md +68 -103
  47. package/blog/ja/intlayer_with_next-i18next.md +85 -283
  48. package/blog/ja/intlayer_with_next-intl.md +58 -336
  49. package/blog/ja/intlayer_with_react-i18next.md +68 -290
  50. package/blog/ja/intlayer_with_react-intl.md +62 -264
  51. package/blog/ko/intlayer_with_i18next.md +80 -96
  52. package/blog/ko/intlayer_with_next-i18next.md +85 -287
  53. package/blog/ko/intlayer_with_next-intl.md +68 -327
  54. package/blog/ko/intlayer_with_react-i18next.md +68 -290
  55. package/blog/ko/intlayer_with_react-intl.md +64 -266
  56. package/blog/pl/intlayer_with_i18next.md +126 -0
  57. package/blog/pl/intlayer_with_next-i18next.md +142 -0
  58. package/blog/pl/intlayer_with_next-intl.md +111 -0
  59. package/blog/pl/intlayer_with_react-i18next.md +124 -0
  60. package/blog/pl/intlayer_with_react-intl.md +122 -0
  61. package/blog/pt/intlayer_with_i18next.md +67 -103
  62. package/blog/pt/intlayer_with_next-i18next.md +72 -293
  63. package/blog/pt/intlayer_with_next-intl.md +57 -256
  64. package/blog/pt/intlayer_with_react-i18next.md +104 -78
  65. package/blog/pt/intlayer_with_react-intl.md +62 -266
  66. package/blog/ru/intlayer_with_i18next.md +66 -104
  67. package/blog/ru/intlayer_with_next-i18next.md +71 -296
  68. package/blog/ru/intlayer_with_next-intl.md +58 -337
  69. package/blog/ru/intlayer_with_react-i18next.md +68 -290
  70. package/blog/ru/intlayer_with_react-intl.md +62 -265
  71. package/blog/tr/intlayer_with_i18next.md +71 -107
  72. package/blog/tr/intlayer_with_next-i18next.md +72 -297
  73. package/blog/tr/intlayer_with_next-intl.md +58 -339
  74. package/blog/tr/intlayer_with_react-i18next.md +69 -291
  75. package/blog/tr/intlayer_with_react-intl.md +63 -285
  76. package/blog/vi/intlayer_with_i18next.md +126 -0
  77. package/blog/vi/intlayer_with_next-i18next.md +142 -0
  78. package/blog/vi/intlayer_with_next-intl.md +111 -0
  79. package/blog/vi/intlayer_with_react-i18next.md +124 -0
  80. package/blog/vi/intlayer_with_react-intl.md +122 -0
  81. package/blog/zh/intlayer_with_i18next.md +67 -102
  82. package/blog/zh/intlayer_with_next-i18next.md +72 -296
  83. package/blog/zh/intlayer_with_next-intl.md +58 -336
  84. package/blog/zh/intlayer_with_react-i18next.md +68 -290
  85. package/blog/zh/intlayer_with_react-intl.md +63 -106
  86. package/docs/ar/plugins/sync-json.md +244 -0
  87. package/docs/de/plugins/sync-json.md +244 -0
  88. package/docs/en/intlayer_cli.md +25 -0
  89. package/docs/en/intlayer_with_nextjs_14.md +2 -0
  90. package/docs/en/intlayer_with_nextjs_15.md +2 -0
  91. package/docs/en/intlayer_with_nextjs_16.md +2 -0
  92. package/docs/en/plugins/sync-json.md +1 -1
  93. package/docs/en-GB/plugins/sync-json.md +244 -0
  94. package/docs/es/plugins/sync-json.md +244 -0
  95. package/docs/fr/plugins/sync-json.md +244 -0
  96. package/docs/hi/plugins/sync-json.md +244 -0
  97. package/docs/id/plugins/sync-json.md +244 -0
  98. package/docs/it/plugins/sync-json.md +244 -0
  99. package/docs/ja/plugins/sync-json.md +244 -0
  100. package/docs/ko/plugins/sync-json.md +244 -0
  101. package/docs/pl/plugins/sync-json.md +244 -0
  102. package/docs/pt/plugins/sync-json.md +244 -0
  103. package/docs/ru/plugins/sync-json.md +244 -0
  104. package/docs/tr/plugins/sync-json.md +245 -0
  105. package/docs/vi/plugins/sync-json.md +244 -0
  106. package/docs/zh/plugins/sync-json.md +244 -0
  107. package/package.json +14 -14
@@ -1,8 +1,8 @@
1
1
  ---
2
2
  createdAt: 2024-12-24
3
- updatedAt: 2025-06-29
4
- title: Intlayer and i18next
5
- description: Integrate Intlayer with i18next for optimal internationalisation. Compare the two frameworks and learn how to configure them together.
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
- # Internationalization with Intlayer and i18next
28
+ # How to automate your i18next JSON translations using Intlayer
23
29
 
24
- i18next is an open-source internationalization (i18n) framework designed for JavaScript applications. It is widely used for managing translations, localization, and language switching in software projects. However, it has some limitations that can complicate scalability and development.
30
+ ## What is Intlayer?
25
31
 
26
- Intlayer is another internationalization framework that addresses these limitations, offering a more flexible approach to content declaration and management. Let's explore some key differences between i18next and Intlayer, and how to configure both for optimal internationalization.
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
- ## Intlayer vs. i18next: Key Differences
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
- ### 1. Dictionary
36
+ ## Why Combine Intlayer with i18next?
31
37
 
32
- With i18next, translation dictionaries must be declared in a specific folder, which can complicate application scalability. In contrast, Intlayer allows content to be declared within the same directory as your component. This has several advantages:
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
- - **Simplified Content Editing**: Users don't have to search for the correct dictionary to edit, reducing the chance of errors.
35
- - **Automatic Adaptation**: If a component changes location or is removed, Intlayer detects and adapts automatically.
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
- ### 2. Configuration Complexity
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
- Configuring i18next can be complex, especially when integrating with server-side components or configuring middleware for frameworks like Next.js. Intlayer simplifies this process, offering more straightforward configuration.
46
+ This guide shows you how to leverage Intlayer's superior content declaration system while maintaining compatibility with i18next.
40
47
 
41
- ### 3. Consistency of Translation Dictionaries
48
+ ## Table of Contents
42
49
 
43
- Ensuring that translation dictionaries are consistent across different languages can be challenging with i18next. This inconsistency can lead to application crashes if not handled properly. Intlayer addresses this by enforcing constraints on translated content, ensuring no translation is missed and that the translated content is accurate.
50
+ <TOC/>
44
51
 
45
- ### 4. TypeScript Integration
52
+ ## Step-by-Step Guide to Set Up Intlayer with i18next
46
53
 
47
- Intlayer offers better integration with TypeScript, allowing for auto-suggestions of content in your code, thereby enhancing development efficiency.
54
+ ### Step 1: Install Dependencies
48
55
 
49
- ### 5. Sharing Content Across Applications
56
+ Install the necessary packages:
50
57
 
51
- Intlayer facilitates the sharing of content declaration files across multiple applications and shared libraries. This feature makes it easier to maintain consistent translations across a larger codebase.
52
-
53
- ## How to Generate i18next Dictionaries with Intlayer
58
+ ```bash packageManager="npm"
59
+ npm install intlayer @intlayer/sync-json-plugin
60
+ ```
54
61
 
55
- ### Configuring Intlayer to Export i18next Dictionaries
62
+ ```bash packageManager="pnpm"
63
+ pnpm add intlayer @intlayer/sync-json-plugin
64
+ ```
56
65
 
57
- > Important Notes
66
+ ```bash packageManager="yarn"
67
+ yarn add intlayer @intlayer/sync-json-plugin
68
+ ```
58
69
 
59
- > The exportation of i18next dictionaries is currently in beta and does not ensure a 1: 1 compatibility with other frameworks. It is recommended to stick to a configuration based on Intlayer to minimise issues.
70
+ **Package descriptions:**
60
71
 
61
- To export i18next dictionaries, you need to configure Intlayer appropriately. Below is an example of how to set up Intlayer to export both Intlayer and i18next dictionaries.
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
- ```typescript fileName="intlayer.config.ts" codeFormat="typescript"
64
- import { Locales, type IntlayerConfig } from "intlayer";
75
+ ### Step 2: Implement the Intlayer plugin to wrap the JSON
65
76
 
66
- const config: IntlayerConfig = {
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 default config;
76
- ```
79
+ **If you want to also export JSON dictionaries for i18next**, add the `syncJSON` plugin:
77
80
 
78
- ```javascript fileName="intlayer.config.mjs" codeFormat="esm"
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
- /** @type {import('intlayer').IntlayerConfig} */
82
- const config = {
83
- content: {
84
- // Indicate that Intlayer will export both Intlayer and i18next dictionaries
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
- ```javascript fileName="intlayer.config.cjs" codeFormat="commonjs"
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
- By including 'i18next' in the configuration, Intlayer generates dedicated i18next dictionaries in addition to the Intlayer dictionaries. Note that removing 'intlayer' from the configuration may break compatibility with React-Intlayer or Next-Intlayer.
102
+ If you want to make that JSON coexist with Intlayer content declaration files (`.content` files), Intlayer will proceed as follows:
111
103
 
112
- ### Importing Dictionaries into Your i18next Configuration
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
- To import the generated dictionaries into your i18next configuration, you can use 'i18next-resources-to-backend'. Here is an example of how to import your i18next dictionaries:
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
- ```typescript fileName="i18n/client.ts" codeFormat="typescript"
117
- // i18n/client.ts
109
+ ## Git Configuration
118
110
 
119
- import i18next from "i18next";
120
- import resourcesToBackend from "i18next-resources-to-backend";
111
+ It is recommended to ignore auto-generated Intlayer files:
121
112
 
122
- i18next
123
- // Your i18next configuration
124
- .use(
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
- ```javascript fileName="i18n/client.mjs" codeFormat="esm"
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
- import i18next from "i18next";
136
- import resourcesToBackend from "i18next-resources-to-backend";
120
+ ### VS Code Extension
137
121
 
138
- i18next
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
- ```javascript fileName="i18n/client.cjs" codeFormat="commonjs"
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
- const i18next = require("i18next");
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-08-23
3
+ updatedAt: 2025-10-29
4
4
  title: Intlayer and next-i18next
5
- description: Integrate Intlayer with next-i18next for a Next.js app
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 Internationalization (i18n) with next-i18next and Intlayer
24
+ # Next.js Internationalisation (i18n) with next-i18next and Intlayer
21
25
 
22
- Both next-i18next and Intlayer are open-source internationalization (i18n) frameworks designed for Next.js applications. They are widely used for managing translations, localization, and language switching in software projects.
26
+ ## Table of Contents
23
27
 
24
- Both solutions include three principal notions:
28
+ <TOC/>
25
29
 
26
- 1. **Dictionary**: The method for defining the translatable content of your application.
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
- 2. **Utilities**: Tools to build and interpret content declarations in the application, such as `getI18n()`, `useCurrentLocale()`, or `useChangeLocale()` for next-i18next, and `useIntlayer()` or `useLocale()` for Intlayer.
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
- 3. **Plugins and Middlewares**: Features for managing URL redirection, bundling optimization, and more, such as `next-i18next/middleware` for next-i18next or `intlayerMiddleware` for Intlayer.
34
+ However, next-i18next comes with some challenges:
33
35
 
34
- ## Intlayer vs. i18next: Key Differences
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
- To explore the differences between i18next and Intlayer, check out our [next-i18next vs. next-intl vs. Intlayer](https://github.com/aymericzip/intlayer/blob/main/docs/blog/en-GB/i18next_vs_next-intl_vs_intlayer.md) blog post.
41
+ ## What is Intlayer?
37
42
 
38
- ## How to Generate next-i18next Dictionaries with Intlayer
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
- ### Why Use Intlayer with next-i18next?
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
- Intlayer content declaration files generally offer a better developer experience. They are more flexible and maintainable due to two main advantages:
47
+ ## Why Combine Intlayer with next-i18next?
43
48
 
44
- 1. **Flexible Placement**: An Intlayer content declaration file can be placed anywhere in the application's file tree, simplifying the management of duplicated or deleted components without leaving unused content declarations.
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
- Example file structures:
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
- ```bash codeFormat="typescript"
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
- ```bash codeFormat="esm"
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
- ```bash codeFormat="cjs"
67
- .
68
- └── src
69
- └── components
70
- └── MyComponent
71
- ├── index.content.cjs # Content declaration file
72
- └── index.cjx
73
- ```
59
+ ---
74
60
 
75
- ```bash codeFormat="json"
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
- 2. **Centralized Translations**: Intlayer stores all translations in a single file, ensuring no translation is missing. When using TypeScript, missing translations are automatically detected and reported as errors.
63
+ ### Step 1: Install Dependencies
85
64
 
86
- ### Installation
65
+ Install the necessary packages using your preferred package manager:
87
66
 
88
67
  ```bash packageManager="npm"
89
- npm install intlayer i18next next-i18next i18next-resources-to-backend
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 i18next next-i18next i18next-resources-to-backend
72
+ pnpm add intlayer @intlayer/sync-json-plugin
98
73
  ```
99
74
 
100
- ### Configuring Intlayer to Export i18next Dictionaries
101
-
102
- > Exporting i18next resources does not ensure 1:1 compatibility with other frameworks. It's recommended to stick to an Intlayer-based configuration to minimise issues.
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
- const config: IntlayerConfig = {
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
- export default config;
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
- ```javascript fileName="intlayer.config.mjs" codeFormat="esm"
124
- import { Locales } from "intlayer";
88
+ ### Step 2: Implement the Intlayer plugin to wrap the JSON
125
89
 
126
- /** @type {import('intlayer').IntlayerConfig} */
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 default config;
139
- ```
92
+ **If you also want to export JSON dictionaries for i18next**, add the `syncJSON` plugin:
140
93
 
141
- ```javascript fileName="intlayer.config.cjs" codeFormat="commonjs"
142
- const { Locales } = require("intlayer");
94
+ ```typescript fileName="intlayer.config.ts"
95
+ import { Locales, type IntlayerConfig } from "intlayer";
96
+ import { syncJSON } from "@intlayer/sync-json-plugin";
143
97
 
144
- /** @type {import('intlayer').IntlayerConfig} */
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
- content: {
151
- dictionaryOutput: ["i18next"],
152
- i18nextResourcesDir: "./i18next/resources",
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
- ```json fileName="**/*.content.json" contentDeclarationFormat="json"
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
- Note: The i18next namespace corresponds to the Intlayer declaration key.
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
- ### Implement Next.js Plugin
115
+ If you want to make that JSON coexist with Intlayer content declaration files (`.content` files), Intlayer will proceed as follows:
301
116
 
302
- Once configured, implement the Next.js plugin to rebuild your i18next resources whenever Intlayer content declaration files are updated.
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
- ```typescript fileName="next.config.mjs"
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
- /** @type {import('next').NextConfig} */
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
- const IndexPage: FC = () => {
322
- const { t } = useTranslation();
124
+ ## Git Configuration
323
125
 
324
- return (
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
- export default IndexPage;
128
+ ```plaintext fileName=".gitignore"
129
+ # Ignore files generated by Intlayer
130
+ .intlayer
131
+ intl
333
132
  ```
334
133
 
335
- ```jsx fileName="src/components/myComponent/index.mjx" codeFormat="esm"
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
- const IndexPage = () => {
339
- const { t } = useTranslation();
136
+ ### VS Code Extension
340
137
 
341
- return (
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
- const IndexPage = () => {
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
- return (
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)