@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,325 +1,122 @@
1
1
  ---
2
2
  createdAt: 2025-01-02
3
- updatedAt: 2025-06-29
4
- title: Intlayer and react-intl
5
- description: Integrate Intlayer with react-intl for a React app
3
+ updatedAt: 2025-10-29
4
+ title: How to automate your react-intl JSON translations using Intlayer
5
+ description: Automate your JSON translations with Intlayer and react-intl for enhanced internationalisation in React applications.
6
6
  keywords:
7
7
  - react-intl
8
8
  - Intlayer
9
9
  - Internationalisation
10
10
  - Blog
11
- - Next.js
11
+ - i18n
12
12
  - JavaScript
13
13
  - React
14
+ - FormatJS
14
15
  slugs:
15
16
  - blog
16
17
  - intlayer-with-react-intl
18
+ history:
19
+ - version: 7.0.0
20
+ date: 2025-10-29
21
+ changes: Change to syncJSON plugin
17
22
  ---
18
23
 
19
- # React Internationalization (i18n) with **react-intl** and Intlayer
24
+ # How to automate your react-intl JSON translations using Intlayer
20
25
 
21
- This guide shows how to integrate **Intlayer** with **react-intl** to manage translations in a React application. You’ll declare your translatable content with Intlayer and then consume those messages with **react-intl**, a popular library from the [FormatJS](https://formatjs.io/docs/react-intl) ecosystem.
26
+ ## What is Intlayer?
22
27
 
23
- ## Overview
28
+ **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 React applications.
24
29
 
25
- - **Intlayer** allows you to store translations in **component-level** content declaration files (JSON, JS, TS, etc.) within your project.
26
- - **react-intl** provides React components and hooks (like `<FormattedMessage>` and `useIntl()`) to display localized strings.
30
+ See a concrete comparison with react-intl in our [react-i18next vs. react-intl vs. Intlayer](https://github.com/aymericzip/intlayer/blob/main/docs/blog/en/react-i18next_vs_react-intl_vs_intlayer.md) blog post.
27
31
 
28
- By configuring Intlayer to **export** translations in a **react-intl–compatible** format, you can automatically **generate** and **update** the message files that `<IntlProvider>` (from react-intl) requires.
32
+ ## Why Combine Intlayer with react-intl?
29
33
 
30
- ---
34
+ While Intlayer provides an excellent standalone i18n solution (see our [React integration guide](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/intlayer_with_vite+react.md)), you might want to combine it with react-intl for several reasons:
31
35
 
32
- ## Why Use Intlayer with react-intl?
36
+ 1. **Existing codebase**: You have an established react-intl implementation and want to gradually migrate to Intlayer's improved developer experience.
37
+ 2. **Legacy requirements**: Your project requires compatibility with existing react-intl plugins or workflows.
38
+ 3. **Team familiarity**: Your team is comfortable with react-intl but wants better content management.
33
39
 
34
- 1. **Per-Component Dictionarys**
35
- Intlayer content declaration files can live alongside your React components, preventing “orphaned” translations if components are moved or removed. For example:
40
+ **For that, Intlayer can be implemented as an adapter for react-intl to help automate your JSON translations in CLI or CI/CD pipelines, test your translations, and more.**
36
41
 
37
- ```bash
38
- .
39
- └── src
40
- └── components
41
- └── MyComponent
42
- ├── index.content.ts # Intlayer content declaration
43
- └── index.tsx # React component
44
- ```
42
+ This guide shows you how to leverage Intlayer's superior content declaration system while maintaining compatibility with react-intl.
45
43
 
46
- 2. **Centralized Translations**
47
- Each content declaration file collects all translations needed by a component. This is particularly helpful in TypeScript projects: missing translations can be caught at **compile time**.
44
+ ## Table of Contents
48
45
 
49
- 3. **Automatic Build and Regeneration**
50
- Whenever you add or update translations, Intlayer regenerates message JSON files. You can then pass these into react-intl’s `<IntlProvider>`.
46
+ <TOC/>
51
47
 
52
- ---
48
+ ## Step-by-Step Guide to Set Up Intlayer with react-intl
53
49
 
54
- ## Installation
50
+ ### Step 1: Install Dependencies
55
51
 
56
- In a typical React project, install the following:
52
+ Install the necessary packages:
57
53
 
58
- ```bash
59
- # with npm
60
- npm install intlayer react-intl
54
+ ```bash packageManager="npm"
55
+ npm install intlayer @intlayer/sync-json-plugin
56
+ ```
61
57
 
62
- # with yarn
63
- yarn add intlayer react-intl
58
+ ```bash packageManager="pnpm"
59
+ pnpm add intlayer @intlayer/sync-json-plugin
60
+ ```
64
61
 
65
- # with pnpm
66
- pnpm add intlayer react-intl
62
+ ```bash packageManager="yarn"
63
+ yarn add intlayer @intlayer/sync-json-plugin
67
64
  ```
68
65
 
69
- ### Why These Packages?
66
+ **Package descriptions:**
70
67
 
71
- - **intlayer**: Core CLI and library that scans for content declarations, merges them, and builds dictionary outputs.
72
- - **react-intl**: The main library from FormatJS that provides `<IntlProvider>`, `<FormattedMessage>`, `useIntl()` and other internationalization primitives.
68
+ - **intlayer**: Core library for internationalisation management, content declaration, and building
69
+ - **@intlayer/sync-json-plugin**: Plugin to export Intlayer content declarations to react-intl compatible JSON format
73
70
 
74
- > If you don’t already have React itself installed, you’ll need it, too (`react` and `react-dom`).
71
+ ### Step 2: Implement the Intlayer plugin to wrap the JSON
75
72
 
76
- ## Configuring Intlayer to Export react-intl Messages
73
+ Create an Intlayer configuration file to define your supported locales:
77
74
 
78
- In your project’s root, create **`intlayer.config.ts`** (or `.js`, `.mjs`, `.cjs`) like so:
75
+ **If you want to also export JSON dictionaries for react-intl**, add the `syncJSON` plugin:
79
76
 
80
- ```typescript title="intlayer.config.ts"
77
+ ```typescript fileName="intlayer.config.ts"
81
78
  import { Locales, type IntlayerConfig } from "intlayer";
79
+ import { syncJSON } from "@intlayer/sync-json-plugin";
82
80
 
83
81
  const config: IntlayerConfig = {
84
82
  internationalization: {
85
- // Add as many locales as you wish
86
83
  locales: [Locales.ENGLISH, Locales.FRENCH, Locales.SPANISH],
87
84
  defaultLocale: Locales.ENGLISH,
88
85
  },
89
- content: {
90
- // Tells Intlayer to generate message files for react-intl
91
- dictionaryOutput: ["react-intl"],
92
-
93
- // The directory where Intlayer will write your message JSON files
94
- reactIntlMessagesDir: "./react-intl/messages",
95
- },
96
- };
97
-
98
- export default config;
99
- ```
100
-
101
- > **Note**: For other file extensions (`.mjs`, `.cjs`, `.js`), see the [Intlayer docs](https://intlayer.org/en-GB/doc/concept/configuration) for usage details.
102
-
103
- ---
104
-
105
- ## Creating Your Intlayer Dictionarys
106
-
107
- Intlayer scans your codebase (by default, under `./src`) for files matching `*.content.{ts,tsx,js,jsx,mjs,mjx,cjs,cjx,json}`.
108
- Here’s a **TypeScript** example:
109
-
110
- ```typescript title="src/components/MyComponent/index.content.ts"
111
- import { t, type Dictionary } from "intlayer";
112
-
113
- const content = {
114
- // "key" becomes the top-level message key in your react-intl JSON file
115
- key: "my-component",
116
-
117
- content: {
118
- // Each call to t() declares a translatable field
119
- helloWorld: t({
120
- en: "Hello World",
121
- es: "Hola Mundo",
122
- fr: "Bonjour le monde",
123
- }),
124
- description: t({
125
- en: "This is a description",
126
- fr: "Ceci est une description",
127
- es: "Esta es una descripción",
86
+ plugins: [
87
+ syncJSON({
88
+ source: ({ key, locale }) => `./intl/messages/${locale}/${key}.json`,
128
89
  }),
129
- },
130
- } satisfies Dictionary;
131
-
132
- export default content;
133
- ```
134
-
135
- If you prefer JSON or different JS flavors (`.cjs`, `.mjs`), the structure is largely the same, see [Intlayer docs on content declaration](https://intlayer.org/en-GB/doc/concept/content).
136
-
137
- ---
138
-
139
- ## Building the react-intl Messages
140
-
141
- To generate the actual message JSON files for **react-intl**, run:
142
-
143
- ```bash
144
- # with npm
145
- npx intlayer dictionaries build
146
-
147
- # with yarn
148
- yarn intlayer build
149
-
150
- # with pnpm
151
- pnpm intlayer build
152
- ```
153
-
154
- This scans all `*.content.*` files, compiles them, and writes the results to the directory specified in your **`intlayer.config.ts`** , in this example, `./react-intl/messages`.
155
- A typical output might look like:
156
-
157
- ```bash
158
- .
159
- └── react-intl
160
- └── messages
161
- ├── en-GB.json
162
- ├── fr.json
163
- └── es.json
164
- ```
165
-
166
- Each file is a JSON object whose **top-level keys** correspond to each **`content.key`** from your declarations. The **sub-keys** (like `helloWorld`) reflect the translations declared within that content item.
167
-
168
- For example, the **en-GB.json** might look like:
169
-
170
- ```json fileName="react-intl/messages/en/my-component.json"
171
- {
172
- "helloWorld": "Hello World",
173
- "description": "This is a description"
174
- }
175
- ```
176
-
177
- ---
178
-
179
- ## Initializing react-intl in Your React App
180
-
181
- ### 1. Load the Generated Messages
182
-
183
- Where you configure your app’s root component (e.g., `src/main.tsx` or `src/index.tsx`), you’ll need to:
184
-
185
- 1. **Import** the generated message files (either statically or dynamically).
186
- 2. **Provide** them to `<IntlProvider>` from `react-intl`.
187
-
188
- A simple approach is to import them **statically**:
189
-
190
- ```typescript title="src/index.tsx"
191
- import React from "react";
192
- import ReactDOM from "react-dom/client";
193
- import { IntlProvider } from "react-intl";
194
- import App from "./App";
195
-
196
- // Import the JSON files from the build output.
197
- // Alternatively, you can import dynamically based on the user's chosen locale.
198
- import en from "../react-intl/messages/en-GB.json";
199
- import fr from "../react-intl/messages/fr.json";
200
- import es from "../react-intl/messages/es.json";
201
-
202
- // If you have a mechanism to detect the user's language, set it here.
203
- // For simplicity, let's pick English.
204
- const locale = "en-GB";
205
-
206
- // Collate messages in an object (or pick them dynamically)
207
- const messagesRecord: Record<string, Record<string, any>> = {
208
- en: en,
209
- fr: fr,
210
- es: es,
90
+ ],
211
91
  };
212
92
 
213
- ReactDOM.createRoot(document.getElementById("root") as HTMLElement).render(
214
- <React.StrictMode>
215
- <IntlProvider locale={locale} messages={messagesRecord[locale]}>
216
- <App />
217
- </IntlProvider>
218
- </React.StrictMode>
219
- );
220
- ```
221
-
222
- > **Tip**: For real projects, you might:
223
- >
224
- > - Dynamically load the JSON messages at runtime.
225
- > - Use environment-based, browser-based, or user account–based locale detection.
226
-
227
- ### 2. Use `<FormattedMessage>` or `useIntl()`
228
-
229
- Once your messages are loaded into `<IntlProvider>`, any child component can use react-intl to access localized strings. There are two main approaches:
230
-
231
- - **`<FormattedMessage>`** component
232
- - **`useIntl()`** hook
233
-
234
- ---
235
-
236
- ## Using Translations in React Components
237
-
238
- ### Approach A: `<FormattedMessage>`
239
-
240
- For quick inline usage:
241
-
242
- ```tsx title="src/components/MyComponent/index.tsx"
243
- import React from "react";
244
- import { FormattedMessage } from "react-intl";
245
-
246
- export default function MyComponent() {
247
- return (
248
- <div>
249
- <h1>
250
- {/* “my-component.helloWorld” references the key from en-GB.json, fr.json, etc. */}
251
- <FormattedMessage id="my-component.helloWorld" />
252
- </h1>
253
-
254
- <p>
255
- <FormattedMessage id="my-component.description" />
256
- </p>
257
- </div>
258
- );
259
- }
260
- ```
261
-
262
- > The **`id`** prop in `<FormattedMessage>` must match the **top-level key** (`my-component`) plus any sub-keys (`helloWorld`).
263
-
264
- ### Approach B: `useIntl()`
265
-
266
- For more dynamic usage:
267
-
268
- ```tsx title="src/components/MyComponent/index.tsx"
269
- import React from "react";
270
- import { useIntl } from "react-intl";
271
-
272
- export default function MyComponent() {
273
- const intl = useIntl();
274
-
275
- return (
276
- <div>
277
- <h1>{intl.formatMessage({ id: "my-component.helloWorld" })}</h1>
278
- <p>{intl.formatMessage({ id: "my-component.description" })}</p>
279
- </div>
280
- );
281
- }
93
+ export default config;
282
94
  ```
283
95
 
284
- Either approach is valid , choose whichever style suits your app.
285
-
286
- ---
96
+ The `syncJSON` plugin will automatically wrap the JSON. It will read and write the JSON files without changing the content architecture.
287
97
 
288
- ## Updating or Adding New Translations
98
+ If you want to make that JSON coexist with Intlayer content declaration files (`.content` files), Intlayer will proceed as follows:
289
99
 
290
- 1. **Add or modify** content in any `*.content.*` file.
291
- 2. Rerun `intlayer build` to regenerate the JSON files under `./react-intl/messages`.
292
- 3. React (and react-intl) will pick up the updates next time you rebuild or reload your application.
100
+ 1. load both JSON and content declaration files and transform them into an Intlayer dictionary.
101
+ 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).
293
102
 
294
- ---
103
+ 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.
295
104
 
296
- ## TypeScript Integration (Optional)
105
+ For more details about the `syncJSON` plugin, please refer to the [syncJSON plugin documentation](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en-plugins/sync-json.md).
297
106
 
298
- If you’re using TypeScript, Intlayer can **generate type definitions** for your translations.
107
+ ## Git Configuration
299
108
 
300
- - Make sure `tsconfig.json` includes your `types` folder (or whichever output folder Intlayer generates) in the `"include"` array.
109
+ It is recommended to ignore auto-generated Intlayer files:
301
110
 
302
- ```json5
303
- {
304
- "compilerOptions": {
305
- // ...
306
- },
307
- "include": ["src", "types"],
308
- }
111
+ ```plaintext fileName=".gitignore"
112
+ # Ignore files generated by Intlayer
113
+ .intlayer
309
114
  ```
310
115
 
311
- The generated types can help detect missing translations or invalid keys in your React components at compile time.
312
-
313
- ---
314
-
315
- ## Git Configuration
116
+ These files can be regenerated during your build process and do not need to be committed to version control.
316
117
 
317
- It’s common to **exclude** Intlayer’s internal build artifacts from version control. In your `.gitignore`, add:
118
+ ### VS Code Extension
318
119
 
319
- ```plaintext
320
- # Ignore intlayer build artifacts
321
- .intlayer
322
- react-intl
323
- ```
120
+ For an improved developer experience, install the official **Intlayer VS Code Extension**:
324
121
 
325
- Depending on your workflow, you may also want to ignore or commit the final dictionaries in `./react-intl/messages`. If your CI/CD pipeline regenerates them, you can safely ignore them; otherwise, commit them if you need them for production deployments.
122
+ [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: 2024-12-24
3
- updatedAt: 2025-06-29
4
- title: Intlayer e i18next
5
- description: Integra Intlayer con i18next para una óptima internacionalización. Compara los dos frameworks y aprende cómo configurarlos juntos.
3
+ updatedAt: 2025-10-29
4
+ title: Cómo automatizar tus traducciones JSON de i18next usando Intlayer
5
+ description: Automatiza tus traducciones JSON con Intlayer e i18next para una internacionalización mejorada en aplicaciones JavaScript.
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
+ - Migración
18
+ - Integración
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: Cambio al plugin syncJSON
20
26
  ---
21
27
 
22
- # Internacionalización con Intlayer e i18next
28
+ # Cómo automatizar tus traducciones JSON de i18next usando Intlayer
23
29
 
24
- i18next es un marco de internacionalización (i18n) de código abierto diseñado para aplicaciones JavaScript. Se utiliza ampliamente para gestionar traducciones, localización y cambio de idioma en proyectos de software. Sin embargo, tiene algunas limitaciones que pueden complicar la escalabilidad y el desarrollo.
30
+ ## ¿Qué es Intlayer?
25
31
 
26
- Intlayer es otro marco de internacionalización que aborda estas limitaciones, ofreciendo un enfoque más flexible para la declaración y gestión de contenidos. Exploremos algunas diferencias clave entre i18next e Intlayer, y cómo configurar ambos para una internacionalización óptima.
32
+ **Intlayer** es una biblioteca innovadora y de código abierto para la internacionalización, diseñada para abordar las limitaciones de las soluciones tradicionales de i18n. Ofrece un enfoque moderno para la gestión de contenido en aplicaciones JavaScript.
27
33
 
28
- ## Intlayer vs. i18next: Diferencias Clave
34
+ Consulta una comparación concreta con i18next en nuestro artículo del blog [next-i18next vs. next-intl vs. Intlayer](https://github.com/aymericzip/intlayer/blob/main/docs/blog/es/next-i18next_vs_next-intl_vs_intlayer.md).
29
35
 
30
- ### 1. Declaración de Contenido
36
+ ## ¿Por qué combinar Intlayer con i18next?
31
37
 
32
- Con i18next, los diccionarios de traducción deben declararse en una carpeta específica, lo que puede complicar la escalabilidad de la aplicación. En contraste, Intlayer permite declarar el contenido dentro del mismo directorio que tu componente. Esto tiene varias ventajas:
38
+ Aunque Intlayer proporciona una excelente solución i18n independiente (consulta nuestra [guía de integración con Next.js](https://github.com/aymericzip/intlayer/blob/main/docs/docs/es/intlayer_with_nextjs_16.md)), es posible que desees combinarlo con i18next por varias razones:
33
39
 
34
- - **Edición de Contenido Simplificada**: Los usuarios no tienen que buscar el diccionario correcto para editar, lo que reduce la posibilidad de errores.
35
- - **Adaptación Automática**: Si un componente cambia de ubicación o se elimina, Intlayer detecta y se adapta automáticamente.
40
+ 1. **Base de código existente**: Tienes una implementación establecida de i18next y deseas migrar gradualmente a la mejor experiencia de desarrollo que ofrece Intlayer.
41
+ 2. **Requisitos heredados**: Tu proyecto requiere compatibilidad con plugins o flujos de trabajo existentes de i18next.
42
+ 3. **Familiaridad del equipo**: Tu equipo está cómodo con i18next pero quiere una mejor gestión del contenido.
36
43
 
37
- ### 2. Complejidad de Configuración
44
+ **Para ello, Intlayer puede implementarse como un adaptador para i18next que ayuda a automatizar tus traducciones JSON en la CLI o en pipelines CI/CD, probar tus traducciones y más.**
38
45
 
39
- Configurar i18next puede ser complejo, especialmente al integrarse con componentes del lado del servidor o al configurar middleware para marcos como Next.js. Intlayer simplifica este proceso, ofreciendo una configuración más directa.
46
+ Esta guía te muestra cómo aprovechar el sistema superior de declaración de contenido de Intlayer mientras mantienes la compatibilidad con i18next.
40
47
 
41
- ### 3. Consistencia de los Diccionarios de Traducción
48
+ ## Tabla de Contenidos
42
49
 
43
- Asegurar que los diccionarios de traducción sean consistentes en diferentes idiomas puede ser un desafío con i18next. Esta inconsistencia puede llevar a que la aplicación se bloquee si no se maneja correctamente. Intlayer aborda esto imponiendo restricciones en el contenido traducido, asegurando que no se pierda ninguna traducción y que el contenido traducido sea preciso.
50
+ <TOC/>
44
51
 
45
- ### 4. Integración con TypeScript
52
+ ## Guía paso a paso para configurar Intlayer con i18next
46
53
 
47
- Intlayer ofrece una mejor integración con TypeScript, permitiendo las autocompletaciones de contenido en tu código, mejorando así la eficiencia del desarrollo.
54
+ ### Paso 1: Instalar dependencias
48
55
 
49
- ### 5. Compartir Contenido Entre Aplicaciones
56
+ Instala los paquetes necesarios:
50
57
 
51
- Intlayer facilita el intercambio de archivos de declaración de contenido entre múltiples aplicaciones y bibliotecas compartidas. Esta característica hace que sea más fácil mantener traducciones consistentes en una base de código más grande.
52
-
53
- ## Cómo Generar Diccionarios de i18next con Intlayer
58
+ ```bash packageManager="npm"
59
+ npm install intlayer @intlayer/sync-json-plugin
60
+ ```
54
61
 
55
- ### Configurando Intlayer para Exportar Diccionarios de i18next
62
+ ```bash packageManager="pnpm"
63
+ pnpm add intlayer @intlayer/sync-json-plugin
64
+ ```
56
65
 
57
- > Notas Importantes
66
+ ```bash packageManager="yarn"
67
+ yarn add intlayer @intlayer/sync-json-plugin
68
+ ```
58
69
 
59
- > La exportación de diccionarios de i18next está actualmente en beta y no garantiza una compatibilidad 1: 1 con otros marcos. Se recomienda ceñirse a una configuración basada en Intlayer para minimizar problemas.
70
+ **Descripción de los paquetes:**
60
71
 
61
- Para exportar diccionarios de i18next, necesitas configurar Intlayer adecuadamente. A continuación se muestra un ejemplo de cómo configurar Intlayer para exportar tanto diccionarios de Intlayer como de i18next.
72
+ - **intlayer**: Biblioteca principal para la gestión de internacionalización, declaración de contenido y construcción
73
+ - **@intlayer/sync-json-plugin**: Plugin para exportar las declaraciones de contenido de Intlayer a un formato JSON compatible con i18next
62
74
 
63
- ```typescript fileName="intlayer.config.ts" codeFormat="typescript"
64
- import { Locales, type IntlayerConfig } from "intlayer";
75
+ ### Paso 2: Implementar el plugin de Intlayer para envolver el JSON
65
76
 
66
- const config: IntlayerConfig = {
67
- content: {
68
- // Indica que Intlayer exportará tanto los diccionarios de Intlayer como de i18next
69
- dictionaryOutput: ["intlayer", "i18next"],
70
- // Ruta relativa desde la raíz del proyecto hasta el directorio donde se exportarán los diccionarios de i18n
71
- i18nextResourcesDir: "./i18next/dictionaries",
72
- },
73
- };
77
+ Crea un archivo de configuración de Intlayer para definir tus locales soportados:
74
78
 
75
- export default config;
76
- ```
79
+ **Si también deseas exportar diccionarios JSON para i18next**, agrega el plugin `syncJSON`:
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
- // Indica que Intlayer exportará tanto los diccionarios de Intlayer como de i18next
85
- dictionaryOutput: ["intlayer", "i18next"],
86
- // Ruta relativa desde la raíz del proyecto hasta el directorio donde se exportarán los diccionarios de i18n
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
- // Indica que Intlayer exportará tanto los diccionarios de Intlayer como de i18next
101
- dictionaryOutput: ["intlayer", "i18next"],
102
- // Ruta relativa desde la raíz del proyecto hasta el directorio donde se exportarán los diccionarios de i18n
103
- i18nextResourcesDir: "./i18next/dictionaries",
104
- },
105
- };
106
-
107
- module.exports = config;
108
- ```
100
+ El plugin `syncJSON` envolverá automáticamente el JSON. Leerá y escribirá los archivos JSON sin cambiar la arquitectura del contenido.
109
101
 
110
- Al incluir 'i18next' en la configuración, Intlayer genera diccionarios dedicados de i18next además de los diccionarios de Intlayer. Ten en cuenta que eliminar 'intlayer' de la configuración puede romper la compatibilidad con React-Intlayer o Next-Intlayer.
102
+ Si quieres hacer coexistir ese JSON con los archivos de declaración de contenido de intlayer (`.content` files), Intlayer procederá de la siguiente manera:
111
103
 
112
- ### Importando Diccionarios en tu Configuración de i18next
104
+ 1. cargar tanto los archivos JSON como los archivos de declaración de contenido y transformarlos en un diccionario de intlayer.
105
+ 2. si hay conflictos entre el JSON y los archivos de declaración de contenido, Intlayer procederá a fusionar todos esos diccionarios. Dependiendo de la prioridad de los plugins y la del archivo de declaración de contenido (todos son configurables).
113
106
 
114
- Para importar los diccionarios generados en tu configuración de i18next, puedes usar 'i18next-resources-to-backend'. Aquí hay un ejemplo de cómo importar tus diccionarios de i18next:
107
+ Si se realizan cambios usando la CLI para traducir el JSON, o usando el CMS, Intlayer actualizará el archivo JSON con las nuevas traducciones.
115
108
 
116
- ```typescript fileName="i18n/client.ts" codeFormat="typescript"
117
- // i18n/client.ts
109
+ ## Configuración de Git
118
110
 
119
- import i18next from "i18next";
120
- import resourcesToBackend from "i18next-resources-to-backend";
111
+ Se recomienda ignorar los archivos generados automáticamente por Intlayer:
121
112
 
122
- i18next
123
- // Tu configuración de i18next
124
- .use(
125
- resourcesToBackend(
126
- (language: string, namespace: string) =>
127
- import(`../i18next/dictionaries/${language}/${namespace}.json`)
128
- )
129
- );
113
+ ```plaintext fileName=".gitignore"
114
+ # Ignorar archivos generados por Intlayer
115
+ .intlayer
130
116
  ```
131
117
 
132
- ```javascript fileName="i18n/client.mjs" codeFormat="esm"
133
- // i18n/client.mjs
118
+ Estos archivos pueden ser regenerados durante tu proceso de compilación y no necesitan ser comprometidos en el control de versiones.
134
119
 
135
- import i18next from "i18next";
136
- import resourcesToBackend from "i18next-resources-to-backend";
120
+ ### Extensión para VS Code
137
121
 
138
- i18next
139
- // Tu configuración de i18next
140
- .use(
141
- resourcesToBackend(
142
- (language, namespace) =>
143
- import(`../i18next/dictionaries/${language}/${namespace}.json`)
144
- )
145
- );
146
- ```
122
+ Para mejorar la experiencia del desarrollador, instala la extensión oficial **Intlayer VS Code Extension**:
147
123
 
148
- ```javascript fileName="i18n/client.cjs" codeFormat="commonjs"
149
- // i18n/client.cjs
124
+ [Instalar desde el Marketplace de VS Code](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
- // Tu configuración de i18next
156
- .use(
157
- resourcesToBackend(
158
- (language, namespace) =>
159
- import(`../i18next/dictionaries/${language}/${namespace}.json`)
160
- )
161
- );
162
- ```
126
+ [Instalar desde el Marketplace de VS Code](https://marketplace.visualstudio.com/items?itemName=intlayer.intlayer-vs-code-extension)