@intlayer/docs 9.0.0-canary.2 → 9.0.0-canary.3

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.
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  createdAt: 2025-03-13
3
- updatedAt: 2025-12-13
3
+ updatedAt: 2026-06-21
4
4
  title: सिंक JSON प्लगइन
5
5
  description: Intlayer शब्दकोशों को तृतीय-पक्ष i18n JSON फ़ाइलों (i18next, next-intl, react-intl, vue-i18n, और अन्य) के साथ सिंक्रनाइज़ करें। अपने मौजूदा i18n को बनाए रखें जबकि Intlayer का उपयोग करके अपने संदेशों का प्रबंधन, अनुवाद और परीक्षण करें।
6
6
  keywords:
@@ -24,6 +24,9 @@ slugs:
24
24
  - sync-json
25
25
  youtubeVideo: https://www.youtube.com/watch?v=MpGMxniDHNg
26
26
  history:
27
+ - version: 9.0.0
28
+ date: 2026-06-21
29
+ changes: "splitKeys विकल्प जोड़ा गया (next-intl / react-intl एकल-फ़ाइल लेआउट के लिए प्रति शीर्ष-स्तरीय नेमस्पेस कुंजी एक शब्दकोश)"
27
30
  - version: 7.5.0
28
31
  date: 2025-12-13
29
32
  changes: "ICU और i18next प्रारूप समर्थन जोड़ा गया"
@@ -54,7 +57,7 @@ author: aymericzip
54
57
  - आप पहले से ही एक i18n लाइब्रेरी का उपयोग करते हैं और संदेशों को JSON फ़ाइलों में संग्रहीत करते हैं।
55
58
  - आप AI-सहायता प्राप्त भराई, CI में परीक्षण, और कंटेंट ऑप्स चाहते हैं बिना अपने रेंडरिंग रनटाइम को बदले।
56
59
 
57
- ## स्थापना
60
+ ## Installation
58
61
 
59
62
  ```bash
60
63
  pnpm add -D @intlayer/sync-json-plugin
@@ -62,7 +65,63 @@ pnpm add -D @intlayer/sync-json-plugin
62
65
  npm i -D @intlayer/sync-json-plugin
63
66
  ```
64
67
 
65
- ## त्वरित शुरुआत
68
+ ## Plugins
69
+
70
+ This package provides two plugins:
71
+
72
+ - `loadJSON`: Load JSON files into Intlayer dictionaries.
73
+ - This plugin is used to load JSON files from a source and will be loaded into Intlayer dictionaries. It can scan all the codebase and search for specific JSON files.
74
+ This plugin can be used
75
+ - if you use an i18n library that impose a specific location for your JSON to be loaded (ex: `next-intl`, `i18next`, `react-intl`, `vue-i18n`, etc.), but you want to place your content declaration where you want in your code base.
76
+ - It can also be used if you want to fetch your messages from a remote source (ex: a CMS, a API, etc.) and store your messages in JSON files.
77
+
78
+ > Under the hood, this plugin will scan all the codebase and search for specific JSON files and load them into Intlayer dictionaries.
79
+ > Note that this plugin will not write the output and translations back to the JSON files.
80
+
81
+ - `syncJSON`: Synchronize JSON files with Intlayer dictionaries.
82
+ - This plugin is used to synchronize JSON files with Intlayer dictionaries. It can scan the given location and load the JSON that match the pattern for specific JSON files. This plugin is useful if you want to get the benefits of Intlayer while using another i18n library.
83
+
84
+ ## Using both plugins
85
+
86
+ ```ts fileName="intlayer.config.ts"
87
+ import { Locales, type IntlayerConfig } from "intlayer";
88
+ import { loadJSON, syncJSON } from "@intlayer/sync-json-plugin";
89
+
90
+ const config: IntlayerConfig = {
91
+ internationalization: {
92
+ locales: [Locales.ENGLISH, Locales.FRENCH, Locales.SPANISH],
93
+ defaultLocale: Locales.ENGLISH,
94
+ },
95
+
96
+ // Keep your current JSON files in sync with Intlayer dictionaries
97
+ plugins: [
98
+ /**
99
+ * Will load all the JSON files in the src that match the pattern {key}.i18n json
100
+ */
101
+ loadJSON({
102
+ source: ({ key }) => `./src/**/${key}.i18n.json`,
103
+ locale: Locales.ENGLISH,
104
+ priority: 1, // Ensures these JSON files take precedence over files at `./locales/en/${key}.json`
105
+ format: "intlayer", // Format of the JSON content
106
+ }),
107
+ /**
108
+ * Will load, and write the output and translations back to the JSON files in the locales directory
109
+ */
110
+ syncJSON({
111
+ format: "i18next",
112
+ source: ({ key, locale }) => `./locales/${locale}/${key}.json`,
113
+ priority: 0,
114
+ format: "i18next",
115
+ }),
116
+ ],
117
+ };
118
+
119
+ export default config;
120
+ ```
121
+
122
+ ## `syncJSON` plugin
123
+
124
+ ### Quick start
66
125
 
67
126
  अपने `intlayer.config.ts` में प्लगइन जोड़ें और इसे अपनी मौजूदा JSON संरचना की ओर इंगित करें।
68
127
 
@@ -81,6 +140,7 @@ const config: IntlayerConfig = {
81
140
  syncJSON({
82
141
  // प्रति-लोकल, प्रति-नेमस्पेस लेआउट (जैसे, next-intl, i18next नेमस्पेस के साथ)
83
142
  source: ({ key, locale }) => `./locales/${locale}/${key}.json`,
143
+ format: "icu",
84
144
  }),
85
145
  ],
86
146
  };
@@ -91,14 +151,27 @@ export default config;
91
151
  वैकल्पिक: प्रति-लोकल एकल फ़ाइल (i18next/react-intl सेटअप में सामान्य):
92
152
 
93
153
  ```ts fileName="intlayer.config.ts"
94
- plugins: [
95
- syncJSON({
96
- source: ({ locale }) => `./locales/${locale}.json`,
97
- }),
98
- ];
154
+ import { Locales, type IntlayerConfig } from "intlayer";
155
+ import { syncJSON } from "@intlayer/sync-json-plugin";
156
+
157
+ const config: IntlayerConfig = {
158
+ internationalization: {
159
+ locales: [Locales.ENGLISH, Locales.FRENCH],
160
+ defaultLocale: Locales.ENGLISH,
161
+ },
162
+ plugins: [
163
+ syncJSON({
164
+ format: "i18next",
165
+ source: ({ locale }) => `./locales/${locale}.json`,
166
+ format: "i18next",
167
+ }),
168
+ ],
169
+ };
170
+
171
+ export default config;
99
172
  ```
100
173
 
101
- ### यह कैसे काम करता है
174
+ #### How it works
102
175
 
103
176
  - पढ़ें: प्लगइन आपके `source` बिल्डर से JSON फ़ाइलों को खोजता है और उन्हें Intlayer शब्दकोश के रूप में लोड करता है।
104
177
  - लिखें: बिल्ड और भराई के बाद, यह स्थानीयकृत JSON को उसी पथों पर वापस लिखता है (फॉर्मेटिंग समस्याओं से बचने के लिए अंतिम नई लाइन के साथ)।
@@ -112,6 +185,7 @@ syncJSON({
112
185
  location?: string, // वैकल्पिक लेबल, डिफ़ॉल्ट: "plugin"
113
186
  priority?: number, // संघर्ष समाधान के लिए वैकल्पिक प्राथमिकता, डिफ़ॉल्ट: 0
114
187
  format?: 'intlayer' | 'icu' | 'i18next', // वैकल्पिक फ़ॉर्मेटर, Intlayer रनटाइम संगतता के लिए उपयोग किया जाता है
188
+ splitKeys?: boolean, // वैकल्पिक, एक एकल फ़ाइल को प्रति शीर्ष-स्तरीय कुंजी एक शब्दकोश में विभाजित करें (स्वचालित रूप से पता लगाया गया)
115
189
  });
116
190
  ```
117
191
 
@@ -136,7 +210,39 @@ syncJSON({
136
210
  }),
137
211
  ```
138
212
 
139
- ## कई JSON स्रोत और प्राथमिकता
213
+ #### `splitKeys` (बूलियन)
214
+
215
+ यह नियंत्रित करता है कि एक एकल JSON फ़ाइल जिसके **पहले-स्तर की कुंजियाँ नेमस्पेस हैं** उसे पूरी फ़ाइल को रखने वाले एक एकल शब्दकोश के बजाय, प्रति शीर्ष-स्तरीय कुंजी एक शब्दकोश बनना चाहिए या नहीं।
216
+
217
+ यह `next-intl` और `react-intl` जैसी लाइब्रेरी के नेमस्पेस मॉडल से मेल खाता है, जहाँ एक `messages/{locale}.json` फ़ाइल अपने पहले-स्तर की कुंजियों द्वारा कई नेमस्पेस को समूहित करती है, प्रत्येक को स्वतंत्र रूप से संबोधित किया जाता है (उदाहरण के लिए `useTranslations('Hero')` `Hero` शब्दकोश में हल होता है)।
218
+
219
+ - `undefined` (डिफ़ॉल्ट): **स्वचालित रूप से पता लगाया गया** — फ़ाइल तब विभाजित होती है जब `source` पैटर्न में कोई `{key}` खंड नहीं होता है (एक फ़ाइल हर नेमस्पेस को रखती है), और अन्यथा एक एकल शब्दकोश के रूप में रखा जाता है (प्रति कुंजी एक फ़ाइल)।
220
+ - `true`: हमेशा प्रत्येक शीर्ष-स्तरीय कुंजी को उसके अपने शब्दकोश में विभाजित करें।
221
+ - `false`: कभी विभाजित न करें; पूरी फ़ाइल एक एकल शब्दकोश बन जाती है।
222
+
223
+ एकल `messages/{locale}.json` फ़ाइल को देखते हुए:
224
+
225
+ ```json fileName="messages/en.json"
226
+ {
227
+ "Hero": { "title": "Full-stack developer" },
228
+ "Nav": { "work": "Work", "about": "About" },
229
+ "About": { "lead": "I build apps end to end." }
230
+ }
231
+ ```
232
+
233
+ ```ts fileName="intlayer.config.ts"
234
+ syncJSON({
235
+ format: "icu",
236
+ source: ({ locale }) => `./messages/${locale}.json`,
237
+ // splitKeys: true, // implied because the pattern has no `{key}` segment
238
+ }),
239
+ ```
240
+
241
+ यह तीन शब्दकोश — `Hero`, `Nav`, और `About` — उत्पन्न करता है, ताकि `useTranslations('Hero')` (next-intl) सही ढंग से हल हो सके। वापस लिखने पर, सभी नेमस्पेस को उसी प्रति-लोकल फ़ाइल में फिर से इकट्ठा किया जाता है।
242
+
243
+ > जब आप अपने `source` में स्पष्ट `{key}` खंड रखते हैं (उदाहरण के लिए `./locales/${locale}/${key}.json`), तो प्रत्येक फ़ाइल पहले से ही एक नेमस्पेस होती है, इसलिए विभाजन डिफ़ॉल्ट रूप से अक्षम होता है।
244
+
245
+ ### Multiple JSON sources and priority
140
246
 
141
247
  आप विभिन्न JSON स्रोतों को सिंक्रनाइज़ करने के लिए कई `syncJSON` प्लगइन्स जोड़ सकते हैं। यह तब उपयोगी होता है जब आपके प्रोजेक्ट में कई i18n लाइब्रेरीज़ या विभिन्न JSON संरचनाएँ हों।
142
248
 
@@ -189,73 +295,140 @@ const config: IntlayerConfig = {
189
295
  export default config;
190
296
  ```
191
297
 
192
- ### संघर्ष समाधान
298
+ ## Load JSON plugin
193
299
 
194
- जब एक ही अनुवाद कुंजी कई JSON स्रोतों में मौजूद होती है:
300
+ ### Quick start
195
301
 
196
- 1. सबसे उच्च प्राथमिकता वाला प्लगइन अंतिम मान निर्धारित करता है
197
- 2. कम प्राथमिकता वाले स्रोत गायब कुंजी के लिए फॉलबैक के रूप में उपयोग किए जाते हैं
198
- 3. यह आपको लेगेसी अनुवाद बनाए रखने की अनुमति देता है जबकि आप धीरे-धीरे नए संरचनाओं में माइग्रेट कर रहे होते हैं
302
+ Add the plugin to your `intlayer.config.ts` to ingest existing JSON files as Intlayer dictionaries. This plugin is read‑only (no writes to disk):
199
303
 
200
- ## एकीकरण
304
+ ```ts fileName="intlayer.config.ts"
305
+ import { Locales, type IntlayerConfig } from "intlayer";
306
+ import { loadJSON } from "@intlayer/sync-json-plugin";
201
307
 
202
- नीचे सामान्य मैपिंग दी गई हैं। अपने रनटाइम को बिना छुए रखें; केवल प्लगइन जोड़ें।
308
+ const config: IntlayerConfig = {
309
+ internationalization: {
310
+ locales: [Locales.ENGLISH, Locales.FRENCH, Locales.SPANISH],
311
+ defaultLocale: Locales.ENGLISH,
312
+ },
203
313
 
204
- ### i18next
314
+ plugins: [
315
+ // Ingest JSON messages located anywhere in your source tree
316
+ loadJSON({
317
+ source: ({ key }) => `./src/**/${key}.i18n.json`,
318
+ // Load a single locale per plugin instance (defaults to the config defaultLocale)
319
+ locale: Locales.ENGLISH,
320
+ priority: 0,
321
+ }),
322
+ ],
323
+ };
205
324
 
206
- सामान्य फ़ाइल लेआउट: `./public/locales/{locale}/{namespace}.json` या `./locales/{locale}/{namespace}.json`।
325
+ export default config;
326
+ ```
327
+
328
+ Alternative: per‑locale layout, still read‑only (only the selected locale is loaded):
207
329
 
208
330
  ```ts fileName="intlayer.config.ts"
209
- import { syncJSON } from "@intlayer/sync-json-plugin";
331
+ import { Locales, type IntlayerConfig } from "intlayer";
332
+ import { loadJSON } from "@intlayer/sync-json-plugin";
210
333
 
211
- export default {
334
+ const config: IntlayerConfig = {
335
+ internationalization: {
336
+ locales: [Locales.ENGLISH, Locales.FRENCH],
337
+ defaultLocale: Locales.ENGLISH,
338
+ },
212
339
  plugins: [
213
- syncJSON({
214
- format: "i18next",
340
+ loadJSON({
341
+ // Only files for Locales.FRENCH will be loaded from this pattern
215
342
  source: ({ key, locale }) => `./locales/${locale}/${key}.json`,
343
+ locale: Locales.FRENCH,
216
344
  }),
217
345
  ],
218
346
  };
347
+
348
+ export default config;
219
349
  ```
220
350
 
221
- ### next-intl
351
+ ### How it works
222
352
 
223
- प्रति-लोकल JSON संदेश (अक्सर `./messages/{locale}.json`) या प्रति-नेमस्पेस।
353
+ - Discover: builds a glob from your `source` builder and collects matching JSON files.
354
+ - Ingest: loads each JSON file as an Intlayer dictionary with the provided `locale`.
355
+ - Read‑only: does not write or format output files; use `syncJSON` if you need round‑trip sync.
356
+ - Auto‑fill ready: defines a `fill` pattern so `intlayer content fill` can populate missing keys.
224
357
 
225
- ```ts fileName="intlayer.config.ts"
226
- plugins: [
227
- syncJSON({
228
- source: ({ locale, key }) => `./messages/${locale}/${key}.json`,
229
- }),
230
- ];
358
+ ### API
359
+
360
+ ```ts
361
+ loadJSON({
362
+ // Build paths to your JSON. `locale` is optional if your structure has no locale segment
363
+ source: ({ key, locale }) => string,
364
+
365
+ // Target locale for the dictionaries loaded by this plugin instance
366
+ // Defaults to configuration.internationalization.defaultLocale
367
+ locale?: Locale,
368
+
369
+ // Optional label to identify the source
370
+ location?: string, // default: "plugin"
371
+
372
+ // Priority used for conflict resolution against other sources
373
+ priority?: number, // default: 0
374
+
375
+ // Optional formatter for the JSON content
376
+ format?: 'intlayer' | 'icu' | 'i18next', // default: 'intlayer'
377
+
378
+ // एक एकल फ़ाइल को प्रति शीर्ष-स्तरीय कुंजी एक शब्दकोश में विभाजित करें (स्वचालित रूप से पता लगाया गया)
379
+ splitKeys?: boolean,
380
+ });
231
381
  ```
232
382
 
233
- देखें: `docs/hi/intlayer_with_next-intl.md`।
383
+ #### `format` ('intlayer' | 'icu' | 'i18next')
234
384
 
235
- ### react-intl
385
+ Specifies the formatter to use for the dictionary content when loading JSON files. This allows using different message formatting syntaxes compatible with various i18n libraries.
236
386
 
237
- प्रति लोकल एकल JSON सामान्य है:
387
+ - `'intlayer'`: The default Intlayer formatter (default).
388
+ - `'icu'`: Uses ICU message formatting (compatible with libraries like react-intl, vue-i18n).
389
+ - `'i18next'`: Uses i18next message formatting (compatible with i18next, next-i18next, Solid-i18next).
238
390
 
239
- ```ts fileName="intlayer.config.ts"
240
- plugins: [
241
- syncJSON({
242
- source: ({ locale }) => `./locales/${locale}.json`,
243
- }),
244
- ];
391
+ **Example:**
392
+
393
+ ```ts
394
+ loadJSON({
395
+ source: ({ key }) => `./src/**/${key}.i18n.json`,
396
+ locale: Locales.ENGLISH,
397
+ format: "icu", // Use ICU formatting for compatibility
398
+ }),
245
399
  ```
246
400
 
247
- ### vue-i18n
401
+ #### `splitKeys` (बूलियन)
248
402
 
249
- प्रति-लोकल या प्रति-नेमस्पेस एकल फ़ाइल हो सकती है:
403
+ [`syncJSON`](#splitkeys-boolean) के समान व्यवहार: जब एक एकल JSON फ़ाइल अपने पहले-स्तर की कुंजियों द्वारा कई नेमस्पेस को समूहित करती है, तो प्रत्येक शीर्ष-स्तरीय कुंजी अपना स्वयं का शब्दकोश बन जाती है।
250
404
 
251
- ```ts fileName="intlayer.config.ts"
252
- plugins: [
253
- syncJSON({
254
- source: ({ key, locale }) => `./src/locales/${locale}/${key}.json`,
255
- }),
256
- ];
405
+ - `undefined` (डिफ़ॉल्ट): **स्वचालित रूप से पता लगाया गया** — जब `source` पैटर्न में कोई `{key}` खंड नहीं होता है तो विभाजित करें, अन्यथा एकल शब्दकोश।
406
+ - `true` / `false`: विभाजन को लागू करें या अक्षम करें।
407
+
408
+ ```ts
409
+ loadJSON({
410
+ source: ({ locale }) => `./messages/${locale}.json`,
411
+ format: "icu",
412
+ // splitKeys auto-enabled: `Hero`, `Nav`, `About`, … each become a dictionary
413
+ }),
257
414
  ```
258
415
 
416
+ ### Behavior and conventions
417
+
418
+ - If your `source` mask includes a locale placeholder, only files for the selected `locale` are ingested.
419
+ - यदि आपके मास्क में कोई `{key}` खंड नहीं है, तो फ़ाइल की प्रत्येक शीर्ष-स्तरीय कुंजी डिफ़ॉल्ट रूप से अपना स्वयं का शब्दकोश बन जाती है (देखें [`splitKeys`](#splitkeys-boolean))। पूरी फ़ाइल को एक एकल `index` शब्दकोश के रूप में लोड करने के लिए `splitKeys: false` सेट करें।
420
+ - Keys are derived from file paths by substituting the `{key}` placeholder in your `source` builder.
421
+ - The plugin only uses discovered files and does not fabricate missing locales or keys.
422
+ - The `fill` path is inferred from your `source` and used to update missing values via CLI when you opt‑in.
423
+
424
+ ## Conflict resolution
425
+
426
+ जब एक ही अनुवाद कुंजी कई JSON स्रोतों में मौजूद होती है:
427
+
428
+ 1. सबसे उच्च प्राथमिकता वाला प्लगइन अंतिम मान निर्धारित करता है
429
+ 2. कम प्राथमिकता वाले स्रोत गायब कुंजी के लिए फॉलबैक के रूप में उपयोग किए जाते हैं
430
+ 3. यह आपको लेगेसी अनुवाद बनाए रखने की अनुमति देता है जबकि आप धीरे-धीरे नए संरचनाओं में माइग्रेट कर रहे होते हैं
431
+
259
432
  ## CLI
260
433
 
261
434
  सिंक किए गए JSON फ़ाइलों को अन्य `.content` फ़ाइलों के रूप में माना जाएगा। इसका मतलब है कि सभी intlayer कमांड सिंक किए गए JSON फ़ाइलों के लिए उपलब्ध होंगे। जिनमें शामिल हैं: