@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.
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 et react-intl
5
- description: Intégrez Intlayer avec react-intl pour une application React
3
+ updatedAt: 2025-10-29
4
+ title: Comment automatiser vos traductions JSON react-intl avec Intlayer
5
+ description: Automatisez vos traductions JSON avec Intlayer et react-intl pour une internationalisation améliorée dans les applications React.
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: Passage au plugin syncJSON
17
22
  ---
18
23
 
19
- # Internationalisation React (i18n) avec **react-intl** et Intlayer
24
+ # Comment automatiser vos traductions JSON react-intl avec Intlayer
20
25
 
21
- Ce guide montre comment intégrer **Intlayer** avec **react-intl** pour gérer les traductions dans une application React. Vous déclarerez votre contenu traduisible avec Intlayer, puis consommerez ces messages avec **react-intl**, une bibliothèque populaire de l'écosystème [FormatJS](https://formatjs.io/docs/react-intl).
26
+ ## Qu'est-ce que Intlayer ?
22
27
 
23
- ## Vue d'ensemble
28
+ **Intlayer** est une bibliothèque d'internationalisation innovante et open-source conçue pour pallier les limites des solutions i18n traditionnelles. Elle propose une approche moderne de la gestion de contenu dans les applications React.
24
29
 
25
- - **Intlayer** vous permet de stocker des traductions dans des fichiers de déclaration de contenu **au niveau des composants** (JSON, JS, TS, etc.) au sein de votre projet.
26
- - **react-intl** fournit des composants React et des hooks (comme `<FormattedMessage>` et `useIntl()`) pour afficher des chaînes localisées.
30
+ Consultez une comparaison concrète avec react-intl dans notre article de blog [react-i18next vs. react-intl vs. Intlayer](https://github.com/aymericzip/intlayer/blob/main/docs/blog/fr/react-i18next_vs_react-intl_vs_intlayer.md).
27
31
 
28
- En configurant Intlayer pour **exporter** des traductions dans un format **compatible avec react-intl**, vous pouvez automatiquement **générer** et **mettre à jour** les fichiers de messages que `<IntlProvider>` (de react-intl) exige.
32
+ ## Pourquoi combiner Intlayer avec react-intl ?
29
33
 
30
- ---
34
+ Bien qu'Intlayer offre une excellente solution i18n autonome (voir notre [guide d'intégration React](https://github.com/aymericzip/intlayer/blob/main/docs/docs/fr/intlayer_with_vite+react.md)), vous pourriez vouloir le combiner avec react-intl pour plusieurs raisons :
31
35
 
32
- ## Pourquoi utiliser Intlayer avec react-intl ?
36
+ 1. **Code existant** : Vous disposez d'une implémentation react-intl établie et souhaitez migrer progressivement vers la meilleure expérience développeur d'Intlayer.
37
+ 2. **Contraintes héritées** : Votre projet nécessite une compatibilité avec les plugins ou workflows react-intl existants.
38
+ 3. **Familiarité de l'équipe** : Votre équipe est à l'aise avec react-intl mais souhaite une meilleure gestion du contenu.
33
39
 
34
- 1. **Déclarations de contenu par composant**
35
- Les fichiers de déclaration de contenu d'Intlayer peuvent coexister avec vos composants React, empêchant les traductions « orphelines » si des composants sont déplacés ou supprimés. Par exemple :
40
+ **Pour cela, Intlayer peut être implémenté comme un adaptateur pour react-intl afin d'automatiser vos traductions JSON dans les pipelines CLI ou CI/CD, tester vos traductions, et plus encore.**
36
41
 
37
- ```bash
38
- .
39
- └── src
40
- └── components
41
- └── MyComponent
42
- ├── index.content.ts # Déclaration de contenu d'Intlayer
43
- └── index.tsx # Composant React
44
- ```
42
+ Ce guide vous montre comment tirer parti du système supérieur de déclaration de contenu d'Intlayer tout en maintenant la compatibilité avec react-intl.
45
43
 
46
- 2. **Traductions centralisées**
47
- Chaque fichier de déclaration de contenu collecte toutes les traductions nécessaires pour un composant. C'est particulièrement utile dans les projets TypeScript : les traductions manquantes peuvent être détectées à **l'heure de la compilation**.
44
+ ## Table des matières
48
45
 
49
- 3. **Construction et régénération automatiques**
50
- Chaque fois que vous ajoutez ou mettez à jour des traductions, Intlayer régénère les fichiers JSON de messages. Vous pouvez ensuite les passer dans le `<IntlProvider>` de react-intl.
46
+ <TOC/>
51
47
 
52
- ---
48
+ ## Guide étape par étape pour configurer Intlayer avec react-intl
53
49
 
54
- ## Installation
50
+ ### Étape 1 : Installer les dépendances
55
51
 
56
- Dans un projet React typique, installez les éléments suivants :
52
+ Installez les paquets nécessaires :
57
53
 
58
- ```bash
59
- # avec npm
60
- npm install intlayer react-intl
54
+ ```bash packageManager="npm"
55
+ npm install intlayer @intlayer/sync-json-plugin
56
+ ```
61
57
 
62
- # avec yarn
63
- yarn add intlayer react-intl
58
+ ```bash packageManager="pnpm"
59
+ pnpm add intlayer @intlayer/sync-json-plugin
60
+ ```
64
61
 
65
- # avec pnpm
66
- pnpm add intlayer react-intl
62
+ ```bash packageManager="yarn"
63
+ yarn add intlayer @intlayer/sync-json-plugin
67
64
  ```
68
65
 
69
- ### Pourquoi ces paquets ?
66
+ **Descriptions des paquets :**
70
67
 
71
- - **intlayer** : CLI et bibliothèque de base qui recherche des déclarations de contenu, les fusionne et construit des sorties de dictionnaire.
72
- - **react-intl** : La bibliothèque principale de FormatJS qui fournit `<IntlProvider>`, `<FormattedMessage>`, `useIntl()` et d'autres primitives d'internationalisation.
68
+ - **intlayer** : Bibliothèque principale pour la gestion de l'internationalisation, la déclaration de contenu et la compilation
69
+ - **@intlayer/sync-json-plugin** : Plugin pour exporter les déclarations de contenu Intlayer au format JSON compatible react-intl
73
70
 
74
- > Si vous n'avez pas déjà installé React lui-même, vous en aurez également besoin (`react` et `react-dom`).
71
+ ### Étape 2 : Implémenter le plugin Intlayer pour envelopper le JSON
75
72
 
76
- ## Configuration d'Intlayer pour exporter les messages react-intl
73
+ Créez un fichier de configuration Intlayer pour définir vos locales supportées :
77
74
 
78
- Dans le répertoire racine de votre projet, créez **`intlayer.config.ts`** (ou `.js`, `.mjs`, `.cjs`) comme suit :
75
+ **Si vous souhaitez également exporter des dictionnaires JSON pour react-intl**, ajoutez le plugin `syncJSON` :
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
- // Ajoutez autant de locales que vous le souhaitez
86
83
  locales: [Locales.ENGLISH, Locales.FRENCH, Locales.SPANISH],
87
84
  defaultLocale: Locales.ENGLISH,
88
85
  },
89
- content: {
90
- // Indique à Intlayer de générer des fichiers de messages pour react-intl
91
- dictionaryOutput: ["react-intl"],
92
-
93
- // Le répertoire où Intlayer écrira vos fichiers JSON de messages
94
- reactIntlMessagesDir: "./react-intl/messages",
95
- },
96
- };
97
-
98
- export default config;
99
- ```
100
-
101
- > **Remarque** : Pour d'autres extensions de fichiers (`.mjs`, `.cjs`, `.js`), consultez la [documentation d'Intlayer](https://intlayer.org/fr/doc/concept/configuration) pour des détails d'utilisation.
102
-
103
- ---
104
-
105
- ## Création de vos déclarations de contenu Intlayer
106
-
107
- Intlayer parcourt votre base de code (par défaut, sous `./src`) à la recherche de fichiers correspondant à `*.content.{ts,tsx,js,jsx,mjs,mjx,cjs,cjx,json}`.
108
- Voici un exemple **TypeScript** :
109
-
110
- ```typescript title="src/components/MyComponent/index.content.ts"
111
- import { t, type Dictionary } from "intlayer";
112
-
113
- const content = {
114
- // "key" devient la clé de message de niveau supérieur dans votre fichier JSON de react-intl
115
- key: "my-component",
116
-
117
- content: {
118
- // Chaque appel à t() déclare un champ traduisible
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
- Si vous préférez JSON ou différentes variantes JS (`.cjs`, `.mjs`), la structure est essentiellement la même, voir [les docs Intlayer sur la déclaration de contenu](https://intlayer.org/fr/doc/concept/content).
136
-
137
- ---
138
-
139
- ## Génération des messages react-intl
140
-
141
- Pour générer les fichiers JSON de messages réels pour **react-intl**, exécutez :
142
-
143
- ```bash
144
- # avec npm
145
- npx intlayer dictionaries build
146
-
147
- # avec yarn
148
- yarn intlayer build
149
-
150
- # avec pnpm
151
- pnpm intlayer build
152
- ```
153
-
154
- Cela parcourt tous les fichiers `*.content.*`, les compile et écrit les résultats dans le répertoire spécifié dans votre **`intlayer.config.ts`** , dans cet exemple, `./react-intl/messages`.
155
- Une sortie typique pourrait ressembler à ceci :
156
-
157
- ```bash
158
- .
159
- └── react-intl
160
- └── messages
161
- ├── en.json
162
- ├── fr.json
163
- └── es.json
164
- ```
165
-
166
- Chaque fichier est un objet JSON dont les **clés de niveau supérieur** correspondent à chaque **`content.key`** de vos déclarations. Les **sous-clés** (comme `helloWorld`) reflètent les traductions déclarées dans cet élément de contenu.
167
-
168
- Par exemple, le **en.json** pourrait ressembler à :
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
- ## Initialisation de react-intl dans votre application React
180
-
181
- ### 1. Charger les messages générés
182
-
183
- À l'endroit où vous configurez le composant racine de votre application (par exemple, `src/main.tsx` ou `src/index.tsx`), vous devrez :
184
-
185
- 1. **Importer** les fichiers de messages générés (soit statiquement soit dynamiquement).
186
- 2. **Les fournir** au `<IntlProvider>` de `react-intl`.
187
-
188
- Une approche simple consiste à les importer **statiquement** :
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
- // Importez les fichiers JSON de la sortie de construction.
197
- // Alternativement, vous pouvez les importer dynamiquement en fonction de la langue choisie par l'utilisateur.
198
- import en from "../react-intl/messages/en.json";
199
- import fr from "../react-intl/messages/fr.json";
200
- import es from "../react-intl/messages/es.json";
201
-
202
- // Si vous avez un mécanisme pour détecter la langue de l'utilisateur, définissez-la ici.
203
- // Pour simplifier, choisissons l'anglais.
204
- const locale = "en";
205
-
206
- // Rassemblez les messages dans un objet (ou choisissez-les dynamiquement)
207
- const messagesRecord: Record<string, Record<string, any>> = {
208
- en,
209
- fr,
210
- 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
- > **Astuce** : Pour de vrais projets, vous pourriez :
223
- >
224
- > - Charger dynamiquement les messages JSON au moment de l'exécution.
225
- > - Utiliser une détection de locale basée sur l'environnement, le navigateur ou le compte utilisateur.
226
-
227
- ### 2. Utiliser `<FormattedMessage>` ou `useIntl()`
228
-
229
- Une fois vos messages chargés dans `<IntlProvider>`, n'importe quel composant enfant peut utiliser react-intl pour accéder à des chaînes localisées. Il existe deux principales approches :
230
-
231
- - **Le composant `<FormattedMessage>`**
232
- - **Le hook `useIntl()`**
233
-
234
- ---
235
-
236
- ## Utilisation des traductions dans les composants React
237
-
238
- ### Approche A : `<FormattedMessage>`
239
-
240
- Pour une utilisation rapide en ligne :
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” fait référence à la clé du fichier en.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
- > La prop **`id`** dans `<FormattedMessage>` doit correspondre à la **clé de niveau supérieur** (`my-component`) plus toutes les sous-clés (`helloWorld`).
263
-
264
- ### Approche B : `useIntl()`
265
-
266
- Pour une utilisation plus dynamique :
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
- Les deux approches sont valides : choisissez le style qui convient le mieux à votre application.
285
-
286
- ---
96
+ Le plugin `syncJSON` enveloppera automatiquement le JSON. Il lira et écrira les fichiers JSON sans modifier l'architecture du contenu.
287
97
 
288
- ## Mise à jour ou ajout de nouvelles traductions
98
+ Si vous souhaitez faire coexister ce JSON avec les fichiers de déclaration de contenu intlayer (`.content`), Intlayer procédera de la manière suivante :
289
99
 
290
- 1. **Ajouter ou modifier** du contenu dans n'importe quel fichier `*.content.*`.
291
- 2. Relancez `intlayer build` pour régénérer les fichiers JSON sous `./react-intl/messages`.
292
- 3. React (et react-intl) détecteront les mises à jour la prochaine fois que vous reconstruirez ou rechargerez votre application.
100
+ 1. charger à la fois les fichiers JSON et les fichiers de déclaration de contenu et les transformer en un dictionnaire intlayer.
101
+ 2. s'il y a des conflits entre le JSON et les fichiers de déclaration de contenu, Intlayer procédera à la fusion de tous ces dictionnaires. Cela dépendra de la priorité des plugins, ainsi que de celle du fichier de déclaration de contenu (tout est configurable).
293
102
 
294
- ---
103
+ Si des modifications sont effectuées via la CLI pour traduire le JSON, ou en utilisant le CMS, Intlayer mettra à jour le fichier JSON avec les nouvelles traductions.
295
104
 
296
- ## Intégration TypeScript (Optionnelle)
105
+ Pour plus de détails sur le plugin `syncJSON`, veuillez consulter la [documentation du plugin syncJSON](https://github.com/aymericzip/intlayer/blob/main/docs/docs/fr/plugins/sync-json.md).
297
106
 
298
- Si vous utilisez TypeScript, Intlayer peut **générer des définitions de types** pour vos traductions.
107
+ ## Configuration Git
299
108
 
300
- - Assurez-vous que `tsconfig.json` inclut votre dossier `types` (ou quel que soit le dossier de sortie qu'Intlayer génère) dans le tableau `"include"`.
109
+ Il est recommandé d'ignorer les fichiers Intlayer générés automatiquement :
301
110
 
302
- ```json5
303
- {
304
- "compilerOptions": {
305
- // ...
306
- },
307
- "include": ["src", "types"],
308
- }
111
+ ```plaintext fileName=".gitignore"
112
+ # Ignorer les fichiers générés par Intlayer
113
+ .intlayer
309
114
  ```
310
115
 
311
- Les types générés peuvent aider à détecter les traductions manquantes ou les clés invalides dans vos composants React à l'heure de la compilation.
312
-
313
- ---
314
-
315
- ## Configuration Git
116
+ Ces fichiers peuvent être régénérés lors de votre processus de build et n'ont pas besoin d'être commités dans le contrôle de version.
316
117
 
317
- Il est courant d'**exclure** les artefacts de construction internes d'Intlayer du contrôle de version. Dans votre `.gitignore`, ajoutez :
118
+ ### Extension VS Code
318
119
 
319
- ```plaintext
320
- # Ignorer les artefacts de construction d'intlayer
321
- .intlayer
322
- react-intl
323
- ```
120
+ Pour une meilleure expérience développeur, installez l'extension officielle **Intlayer VS Code Extension** :
324
121
 
325
- En fonction de votre flux de travail, vous voudrez peut-être également ignorer ou valider les dictionnaires finaux dans `./react-intl/messages`. Si votre pipeline CI/CD les régénère, vous pouvez les ignorer en toute sécurité ; sinon, validez-les si vous en avez besoin pour des déploiements en production.
122
+ [Installer depuis le Marketplace VS Code](https://marketplace.visualstudio.com/items?itemName=intlayer.intlayer-vs-code-extension)
@@ -1,12 +1,12 @@
1
1
  ---
2
2
  createdAt: 2024-12-24
3
- updatedAt: 2025-06-29
4
- title: Intlayer और i18next
5
- description: इष्टतम अंतर्राष्ट्रीयकरण के लिए Intlayer को i18next के साथ एकीकृत करें। दोनों फ्रेमवर्क की तुलना करें और उन्हें एक साथ कैसे कॉन्फ़िगर करें यह जानें।
3
+ updatedAt: 2025-10-29
4
+ title: Intlayer का उपयोग करके अपने i18next JSON अनुवादों को स्वचालित कैसे करें
5
+ description: JavaScript अनुप्रयोगों में बेहतर अंतरराष्ट्रीयकरण के लिए Intlayer और i18next के साथ अपने JSON अनुवादों को स्वचालित करें।
6
6
  keywords:
7
7
  - Intlayer
8
8
  - i18next
9
- - अंतर्राष्ट्रीयकरण
9
+ - अंतरराष्ट्रीयकरण
10
10
  - i18n
11
11
  - स्थानीयकरण
12
12
  - अनुवाद
@@ -14,149 +14,113 @@ keywords:
14
14
  - Next.js
15
15
  - JavaScript
16
16
  - TypeScript
17
+ - माइग्रेशन
18
+ - एकीकरण
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: syncJSON प्लगइन में बदलाव
20
26
  ---
21
27
 
22
- # अंतर्राष्ट्रीयकरण Intlayer और i18next के साथ
28
+ # Intlayer का उपयोग करके अपने i18next JSON अनुवादों को स्वचालित कैसे करें
23
29
 
24
- i18next एक ओपन-सोर्स अंतर्राष्ट्रीयकरण (i18n) ढांचा है जो जावास्क्रिप्ट अनुप्रयोगों के लिए डिज़ाइन किया गया है। इसका व्यापक रूप से सॉफ़्टवेयर परियोजनाओं में अनुवाद, स्थानीयकरण और भाषा स्विचिंग को प्रबंधित करने के लिए उपयोग किया जाता है। हालाँकि, इसमें कुछ सीमाएँ हैं जो बढ़ने और विकास को जटिल बना सकती हैं।
30
+ ## Intlayer क्या है?
25
31
 
26
- Intlayer एक अन्य अंतर्राष्ट्रीयकरण ढांचा है जो इन सीमाओं का समाधान करता है, सामग्री स्पष्टता और प्रबंधन के लिए अधिक लचीला दृष्टिकोण प्रदान करता है। चलिए हम i18next और Intlayer के बीच कुछ प्रमुख अंतरों का पता लगाते हैं, और अंतर्राष्ट्रीयकरण के लिए दोनों को कैसे कॉन्फ़िगर करें।
32
+ **Intlayer** एक अभिनव, ओपन-सोर्स अंतरराष्ट्रीयकरण लाइब्रेरी है जिसे पारंपरिक i18n समाधानों की कमियों को दूर करने के लिए डिज़ाइन किया गया है। यह JavaScript अनुप्रयोगों में सामग्री प्रबंधन के लिए एक आधुनिक दृष्टिकोण प्रदान करता है।
27
33
 
28
- ## Intlayer बनाम i18next: प्रमुख अंतर
34
+ i18next के साथ एक ठोस तुलना के लिए हमारे [next-i18next vs. next-intl vs. Intlayer](https://github.com/aymericzip/intlayer/blob/main/docs/blog/hi/next-i18next_vs_next-intl_vs_intlayer.md) ब्लॉग पोस्ट देखें।
29
35
 
30
- ### 1. सामग्री की घोषणा
36
+ ## Intlayer को i18next के साथ क्यों मिलाएं?
31
37
 
32
- i18next के साथ, अनुवाद शब्दकोष को एक विशिष्ट फ़ोल्डर में घोषित किया जाना चाहिए, जिससे अनुप्रयोग की स्केलेबिलिटी जटिल हो सकती है। इसके विपरीत, Intlayer आपकी संकुल के समान निर्देशिका में सामग्री की घोषणा करने की अनुमति देता है। इसके कई फायदे हैं:
38
+ जबकि Intlayer एक उत्कृष्ट स्वतंत्र i18n समाधान प्रदान करता है (हमारे [Next.js एकीकरण गाइड](https://github.com/aymericzip/intlayer/blob/main/docs/docs/hi/intlayer_with_nextjs_16.md) देखें), आप इसे कई कारणों से i18next के साथ मिलाना चाह सकते हैं:
33
39
 
34
- - **सरल सामग्री संपादन**: उपयोगकर्ताओं को संपादित करने के लिए सही शब्दकोश खोजने की आवश्यकता नहीं होती, जिससे त्रुटियों की संभावना कम होती है।
35
- - **स्वचालित अनुकूलन**: यदि कोई संकुल स्थानांतरित होता है या हटा दिया जाता है, तो Intlayer स्वचालित रूप से पता लगाता है और अनुकूलित करता है।
40
+ 1. **मौजूदा कोडबेस**: आपके पास एक स्थापित i18next कार्यान्वयन है और आप धीरे-धीरे Intlayer के बेहतर डेवलपर अनुभव की ओर माइग्रेट करना चाहते हैं।
41
+ 2. **पुराने आवश्यकताएँ**: आपके प्रोजेक्ट को मौजूदा i18next प्लगइन्स या वर्कफ़्लोज़ के साथ संगतता की आवश्यकता है।
42
+ 3. **टीम की परिचितता**: आपकी टीम i18next के साथ सहज है लेकिन बेहतर सामग्री प्रबंधन चाहती है।
36
43
 
37
- ### 2. कॉन्फ़िगरेशन जटिलता
44
+ **इसके लिए, Intlayer को i18next के लिए एक एडेप्टर के रूप में लागू किया जा सकता है जो CLI या CI/CD पाइपलाइनों में आपके JSON अनुवादों को स्वचालित करने, आपके अनुवादों का परीक्षण करने, और अधिक में मदद करता है।**
38
45
 
39
- i18next को कॉन्फ़िगर करना जटिल हो सकता है, विशेष रूप से सर्वर-साइड संकुलों के साथ या Next.js जैसे फ़्रेमवर्क के लिए मिडलवेयर कॉन्फ़िगर करते समय। Intlayer इस प्रक्रिया को सरल बनाता है, और अधिक सरल कॉन्फ़िगरेशन प्रदान करता है।
46
+ यह गाइड आपको दिखाता है कि कैसे Intlayer की श्रेष्ठ सामग्री घोषणा प्रणाली का लाभ उठाते हुए i18next के साथ संगतता बनाए रखी जाए।
40
47
 
41
- ### 3. अनुवाद शब्दकोष की स्थिरता
48
+ ## सामग्री सूची
42
49
 
43
- विभिन्न भाषाओं में अनुवाद शब्दकोषों की स्थिरता सुनिश्चित करना i18next के साथ चुनौतीपूर्ण हो सकता है। अगर इसे ठीक से नहीं संभाला गया तो यह अनुप्रयोग को क्रैश कर सकता है। Intlayer इस समस्या का समाधान करके अनुवादित सामग्री पर बाधाएँ लागू करता है, सुनिश्चित करता है कि कोई अनुवाद छूटा नहीं है और अनुवादित सामग्री सटीक है।
50
+ <TOC/>
44
51
 
45
- ### 4. TypeScript एकीकरण
52
+ ## i18next के साथ Intlayer सेटअप करने के लिए चरण-दर-चरण मार्गदर्शिका
46
53
 
47
- Intlayer को TypeScript के साथ बेहतर एकीकरण प्रदान करता है, जो आपके कोड में सामग्री के स्वचालित सुझावों की अनुमति देता है, जिससे विकास की दक्षता बढ़ती है।
54
+ ### चरण 1: निर्भरताएँ स्थापित करें
48
55
 
49
- ### 5. अनुप्रयोगों में सामग्री साझा करना
56
+ आवश्यक पैकेज इंस्टॉल करें:
50
57
 
51
- Intlayer कई अनुप्रयोगों और साझा पुस्तकालयों के बीच सामग्री घोषणा फ़ाइलों को साझा करने की सुविधा देता है। यह सुविधा बड़े कोडबेस में सुसंगत अनुवाद बनाए रखना सरल बनाती है।
52
-
53
- ## Intlayer के साथ i18next शब्दकोष कैसे उत्पन्न करें
58
+ ```bash packageManager="npm"
59
+ npm install intlayer @intlayer/sync-json-plugin
60
+ ```
54
61
 
55
- ### Intlayer को i18next शब्दकोष निर्यात करने के लिए कॉन्फ़िगर करना
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
- > i18next शब्दकोषों का निर्यात वर्तमान में बीटा में है और अन्य ढांचों के साथ 1: 1 संगतता सुनिश्चित नहीं करता है। मुद्दों को न्यूनतम करने के लिए Intlayer आधारित कॉन्फ़िगरेशन पर बनाए रखना अनुशंसित है।
70
+ **पैकेज विवरण:**
60
71
 
61
- i18next शब्दकोष निर्यात करने के लिए, आपको Intlayer को उपयुक्त रूप से कॉन्फ़िगर करना होगा। नीचे दिए गए उदाहरण में दिखाया गया है कि Intlayer को कैसे सेटअप करें ताकि यह Intlayer और i18next दोनों शब्दकोषों को निर्यात करे।
72
+ - **intlayer**: अंतरराष्ट्रीयकरण प्रबंधन, सामग्री घोषणा, और निर्माण के लिए मुख्य लाइब्रेरी
73
+ - **@intlayer/sync-json-plugin**: Intlayer सामग्री घोषणाओं को i18next संगत JSON प्रारूप में निर्यात करने के लिए प्लगइन
62
74
 
63
- ```typescript fileName="intlayer.config.ts" codeFormat="typescript"
64
- import { Locales, type IntlayerConfig } from "intlayer";
75
+ ### चरण 2: JSON को लपेटने के लिए Intlayer प्लगइन लागू करें
65
76
 
66
- const config: IntlayerConfig = {
67
- content: {
68
- // Intlayer को यह बताना कि वह Intlayer और i18next दोनों शब्दकोषों को निर्यात करेगा
69
- dictionaryOutput: ["intlayer", "i18next"],
70
- // प्रोजेक्ट रूट से उस निर्देशिका के सापेक्ष पथ जहां i18n शब्दकोष निर्यात किए जाएंगे
71
- i18nextResourcesDir: "./i18next/dictionaries",
72
- },
73
- };
77
+ अपने समर्थित लोकल्स को परिभाषित करने के लिए एक Intlayer कॉन्फ़िगरेशन फ़ाइल बनाएं:
74
78
 
75
- export default config;
76
- ```
79
+ **यदि आप i18next के लिए JSON शब्दकोश भी निर्यात करना चाहते हैं**, तो `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
- // Intlayer को यह बताना कि वह Intlayer और i18next दोनों शब्दकोषों को निर्यात करेगा
85
- dictionaryOutput: ["intlayer", "i18next"],
86
- // प्रोजेक्ट रूट से उस निर्देशिका के सापेक्ष पथ जहां 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
- // Intlayer को यह बताना कि वह Intlayer और i18next दोनों शब्दकोषों को निर्यात करेगा
101
- dictionaryOutput: ["intlayer", "i18next"],
102
- // प्रोजेक्ट रूट से उस निर्देशिका के सापेक्ष पथ जहां i18n शब्दकोष निर्यात किए जाएंगे
103
- i18nextResourcesDir: "./i18next/dictionaries",
104
- },
105
- };
106
-
107
- module.exports = config;
108
- ```
100
+ `syncJSON` प्लगइन स्वचालित रूप से JSON को लपेटेगा। यह JSON फ़ाइलों को पढ़ेगा और लिखेगा बिना सामग्री संरचना को बदले।
109
101
 
110
- कॉन्फ़िगरेशन में 'i18next' को शामिल करके, Intlayer i18next शब्दकोषों के साथ-साथ Intlayer शब्दकोष भी उत्पन्न करता है। ध्यान दें कि कॉन्फ़िगरेशन से 'intlayer' को हटाने से React-Intlayer या Next-Intlayer के साथ संगतता टूट सकती है।
102
+ यदि आप JSON को intlayer सामग्री घोषणा फ़ाइलों (`.content` फ़ाइलें) के साथ सह-अस्तित्व में रखना चाहते हैं, तो Intlayer इस प्रकार आगे बढ़ेगा:
111
103
 
112
- ### अपने i18next कॉन्फ़िगरेशन में शब्दकोष आयात करना
104
+ 1. JSON और सामग्री घोषणा फ़ाइलों दोनों को लोड करें और उन्हें intlayer शब्दकोश में परिवर्तित करें।
105
+ 2. यदि JSON और सामग्री घोषणा फ़ाइलों के बीच संघर्ष होता है, तो Intlayer उन सभी शब्दकोशों को मर्ज करने की प्रक्रिया करेगा। यह प्लगइन्स की प्राथमिकता और सामग्री घोषणा फ़ाइल की प्राथमिकता पर निर्भर करता है (सभी कॉन्फ़िगर करने योग्य हैं)।
113
106
 
114
- आप अपने i18next कॉन्फ़िगरेशन में उत्पन्न शब्दकोष को आयात करने के लिए 'i18next-resources-to-backend' का उपयोग कर सकते हैं। यहां दिए गए उदाहरण में दिखाया गया है कि आप अपने i18next शब्दकोष को कैसे आयात कर सकते हैं:
107
+ यदि JSON का अनुवाद करने के लिए CLI का उपयोग करके या CMS का उपयोग करके परिवर्तन किए जाते हैं, तो Intlayer नई अनुवादों के साथ JSON फ़ाइल को अपडेट करेगा।
115
108
 
116
- ```typescript fileName="i18n/client.ts" codeFormat="typescript"
117
- // i18n/client.ts
109
+ ## Git कॉन्फ़िगरेशन
118
110
 
119
- import i18next from "i18next";
120
- import resourcesToBackend from "i18next-resources-to-backend";
111
+ स्वचालित रूप से उत्पन्न Intlayer फ़ाइलों को अनदेखा करने की सलाह दी जाती है:
121
112
 
122
- i18next
123
- // आपका i18next कॉन्फ़िगरेशन
124
- .use(
125
- resourcesToBackend(
126
- (language: string, namespace: string) =>
127
- import(`../i18next/dictionaries/${language}/${namespace}.json`)
128
- )
129
- );
113
+ ```plaintext fileName=".gitignore"
114
+ # Intlayer द्वारा उत्पन्न फ़ाइलों को अनदेखा करें
115
+ .intlayer
130
116
  ```
131
117
 
132
- ```javascript fileName="i18n/client.mjs" codeFormat="esm"
133
- // i18n/client.mjs
118
+ ये फ़ाइलें आपके बिल्ड प्रक्रिया के दौरान पुनः उत्पन्न की जा सकती हैं और इन्हें संस्करण नियंत्रण में कमिट करने की आवश्यकता नहीं है।
134
119
 
135
- import i18next from "i18next";
136
- import resourcesToBackend from "i18next-resources-to-backend";
120
+ ### VS कोड एक्सटेंशन
137
121
 
138
- i18next
139
- // आपका i18next कॉन्फ़िगरेशन
140
- .use(
141
- resourcesToBackend(
142
- (language, namespace) =>
143
- import(`../i18next/dictionaries/${language}/${namespace}.json`)
144
- )
145
- );
146
- ```
122
+ बेहतर डेवलपर अनुभव के लिए, आधिकारिक **Intlayer VS Code एक्सटेंशन** इंस्टॉल करें:
147
123
 
148
- ```javascript fileName="i18n/client.cjs" codeFormat="commonjs"
149
- // i18n/client.cjs
124
+ [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
- // आपका i18next कॉन्फ़िगरेशन
156
- .use(
157
- resourcesToBackend(
158
- (language, namespace) =>
159
- import(`../i18next/dictionaries/${language}/${namespace}.json`)
160
- )
161
- );
162
- ```
126
+ [VS कोड मार्केटप्लेस से इंस्टॉल करें](https://marketplace.visualstudio.com/items?itemName=intlayer.intlayer-vs-code-extension)