@intlayer/docs 7.0.3 → 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 (159) 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 +67 -103
  12. package/blog/en/intlayer_with_next-i18next.md +69 -294
  13. package/blog/en/intlayer_with_next-intl.md +48 -300
  14. package/blog/en/intlayer_with_react-i18next.md +61 -289
  15. package/blog/en/intlayer_with_react-intl.md +61 -284
  16. package/blog/en/next-i18next_vs_next-intl_vs_intlayer.md +1 -1
  17. package/blog/en-GB/intlayer_with_i18next.md +67 -103
  18. package/blog/en-GB/intlayer_with_next-i18next.md +71 -292
  19. package/blog/en-GB/intlayer_with_next-intl.md +58 -337
  20. package/blog/en-GB/intlayer_with_react-i18next.md +67 -289
  21. package/blog/en-GB/intlayer_with_react-intl.md +61 -264
  22. package/blog/es/intlayer_with_i18next.md +67 -103
  23. package/blog/es/intlayer_with_next-i18next.md +71 -296
  24. package/blog/es/intlayer_with_next-intl.md +57 -338
  25. package/blog/es/intlayer_with_react-i18next.md +68 -290
  26. package/blog/es/intlayer_with_react-intl.md +62 -265
  27. package/blog/fr/intlayer_with_i18next.md +66 -104
  28. package/blog/fr/intlayer_with_next-i18next.md +82 -285
  29. package/blog/fr/intlayer_with_next-intl.md +57 -338
  30. package/blog/fr/intlayer_with_react-i18next.md +67 -289
  31. package/blog/fr/intlayer_with_react-intl.md +61 -264
  32. package/blog/hi/intlayer_with_i18next.md +68 -104
  33. package/blog/hi/intlayer_with_next-i18next.md +74 -299
  34. package/blog/hi/intlayer_with_next-intl.md +57 -239
  35. package/blog/hi/intlayer_with_react-i18next.md +69 -291
  36. package/blog/hi/intlayer_with_react-intl.md +65 -268
  37. package/blog/id/intlayer_with_i18next.md +126 -0
  38. package/blog/id/intlayer_with_next-i18next.md +142 -0
  39. package/blog/id/intlayer_with_next-intl.md +113 -0
  40. package/blog/id/intlayer_with_react-i18next.md +124 -0
  41. package/blog/id/intlayer_with_react-intl.md +122 -0
  42. package/blog/it/intlayer_with_i18next.md +67 -103
  43. package/blog/it/intlayer_with_next-i18next.md +71 -296
  44. package/blog/it/intlayer_with_next-intl.md +57 -338
  45. package/blog/it/intlayer_with_react-i18next.md +68 -290
  46. package/blog/it/intlayer_with_react-intl.md +62 -265
  47. package/blog/ja/intlayer_with_i18next.md +68 -103
  48. package/blog/ja/intlayer_with_next-i18next.md +85 -283
  49. package/blog/ja/intlayer_with_next-intl.md +58 -336
  50. package/blog/ja/intlayer_with_react-i18next.md +68 -290
  51. package/blog/ja/intlayer_with_react-intl.md +62 -264
  52. package/blog/ko/intlayer_with_i18next.md +80 -96
  53. package/blog/ko/intlayer_with_next-i18next.md +85 -287
  54. package/blog/ko/intlayer_with_next-intl.md +68 -327
  55. package/blog/ko/intlayer_with_react-i18next.md +68 -290
  56. package/blog/ko/intlayer_with_react-intl.md +64 -266
  57. package/blog/pl/intlayer_with_i18next.md +126 -0
  58. package/blog/pl/intlayer_with_next-i18next.md +142 -0
  59. package/blog/pl/intlayer_with_next-intl.md +111 -0
  60. package/blog/pl/intlayer_with_react-i18next.md +124 -0
  61. package/blog/pl/intlayer_with_react-intl.md +122 -0
  62. package/blog/pt/intlayer_with_i18next.md +67 -103
  63. package/blog/pt/intlayer_with_next-i18next.md +72 -293
  64. package/blog/pt/intlayer_with_next-intl.md +57 -256
  65. package/blog/pt/intlayer_with_react-i18next.md +104 -78
  66. package/blog/pt/intlayer_with_react-intl.md +62 -266
  67. package/blog/ru/intlayer_with_i18next.md +66 -104
  68. package/blog/ru/intlayer_with_next-i18next.md +71 -296
  69. package/blog/ru/intlayer_with_next-intl.md +58 -337
  70. package/blog/ru/intlayer_with_react-i18next.md +68 -290
  71. package/blog/ru/intlayer_with_react-intl.md +62 -265
  72. package/blog/tr/intlayer_with_i18next.md +71 -107
  73. package/blog/tr/intlayer_with_next-i18next.md +72 -297
  74. package/blog/tr/intlayer_with_next-intl.md +58 -339
  75. package/blog/tr/intlayer_with_react-i18next.md +69 -291
  76. package/blog/tr/intlayer_with_react-intl.md +63 -285
  77. package/blog/vi/intlayer_with_i18next.md +126 -0
  78. package/blog/vi/intlayer_with_next-i18next.md +142 -0
  79. package/blog/vi/intlayer_with_next-intl.md +111 -0
  80. package/blog/vi/intlayer_with_react-i18next.md +124 -0
  81. package/blog/vi/intlayer_with_react-intl.md +122 -0
  82. package/blog/zh/intlayer_with_i18next.md +67 -102
  83. package/blog/zh/intlayer_with_next-i18next.md +72 -296
  84. package/blog/zh/intlayer_with_next-intl.md +58 -336
  85. package/blog/zh/intlayer_with_react-i18next.md +68 -290
  86. package/blog/zh/intlayer_with_react-intl.md +63 -106
  87. package/dist/cjs/generated/blog.entry.cjs +13 -1
  88. package/dist/cjs/generated/blog.entry.cjs.map +1 -1
  89. package/dist/cjs/generated/docs.entry.cjs +13 -1
  90. package/dist/cjs/generated/docs.entry.cjs.map +1 -1
  91. package/dist/cjs/generated/frequentQuestions.entry.cjs +13 -1
  92. package/dist/cjs/generated/frequentQuestions.entry.cjs.map +1 -1
  93. package/dist/cjs/generated/legal.entry.cjs +13 -1
  94. package/dist/cjs/generated/legal.entry.cjs.map +1 -1
  95. package/dist/esm/generated/blog.entry.mjs +13 -2
  96. package/dist/esm/generated/blog.entry.mjs.map +1 -1
  97. package/dist/esm/generated/docs.entry.mjs +13 -2
  98. package/dist/esm/generated/docs.entry.mjs.map +1 -1
  99. package/dist/esm/generated/frequentQuestions.entry.mjs +13 -2
  100. package/dist/esm/generated/frequentQuestions.entry.mjs.map +1 -1
  101. package/dist/esm/generated/legal.entry.mjs +13 -2
  102. package/dist/esm/generated/legal.entry.mjs.map +1 -1
  103. package/dist/types/generated/blog.entry.d.ts.map +1 -1
  104. package/dist/types/generated/docs.entry.d.ts.map +1 -1
  105. package/dist/types/generated/frequentQuestions.entry.d.ts.map +1 -1
  106. package/dist/types/generated/legal.entry.d.ts.map +1 -1
  107. package/docs/ar/plugins/sync-json.md +244 -0
  108. package/docs/de/plugins/sync-json.md +244 -0
  109. package/docs/de/releases/v7.md +1 -18
  110. package/docs/en/CI_CD.md +1 -1
  111. package/docs/en/configuration.md +1 -1
  112. package/docs/en/formatters.md +1 -1
  113. package/docs/en/how_works_intlayer.md +1 -1
  114. package/docs/en/intlayer_CMS.md +1 -1
  115. package/docs/en/intlayer_cli.md +26 -1
  116. package/docs/en/intlayer_with_nextjs_14.md +3 -1
  117. package/docs/en/intlayer_with_nextjs_15.md +3 -1
  118. package/docs/en/intlayer_with_nextjs_16.md +3 -1
  119. package/docs/en/intlayer_with_nextjs_page_router.md +1 -1
  120. package/docs/en/intlayer_with_nuxt.md +1 -1
  121. package/docs/en/intlayer_with_react_native+expo.md +1 -1
  122. package/docs/en/intlayer_with_react_router_v7.md +1 -1
  123. package/docs/en/intlayer_with_tanstack.md +1 -1
  124. package/docs/en/intlayer_with_vite+preact.md +1 -1
  125. package/docs/en/intlayer_with_vite+react.md +1 -1
  126. package/docs/en/intlayer_with_vite+solid.md +1 -1
  127. package/docs/en/intlayer_with_vite+svelte.md +1 -1
  128. package/docs/en/intlayer_with_vite+vue.md +1 -1
  129. package/docs/en/plugins/sync-json.md +1 -1
  130. package/docs/en/roadmap.md +1 -1
  131. package/docs/en-GB/plugins/sync-json.md +244 -0
  132. package/docs/es/plugins/sync-json.md +244 -0
  133. package/docs/es/releases/v7.md +1 -18
  134. package/docs/fr/intlayer_with_nextjs_16.md +2 -51
  135. package/docs/fr/plugins/sync-json.md +244 -0
  136. package/docs/fr/releases/v7.md +1 -18
  137. package/docs/hi/intlayer_with_nextjs_16.md +3 -2
  138. package/docs/hi/plugins/sync-json.md +244 -0
  139. package/docs/id/plugins/sync-json.md +244 -0
  140. package/docs/id/releases/v7.md +1 -18
  141. package/docs/it/plugins/sync-json.md +244 -0
  142. package/docs/it/releases/v7.md +1 -18
  143. package/docs/ja/intlayer_with_nextjs_16.md +44 -205
  144. package/docs/ja/plugins/sync-json.md +244 -0
  145. package/docs/ja/releases/v7.md +1 -18
  146. package/docs/ko/plugins/sync-json.md +244 -0
  147. package/docs/ko/releases/v7.md +1 -18
  148. package/docs/pl/plugins/sync-json.md +244 -0
  149. package/docs/pt/intlayer_with_nextjs_16.md +1 -52
  150. package/docs/pt/plugins/sync-json.md +244 -0
  151. package/docs/ru/plugins/sync-json.md +244 -0
  152. package/docs/tr/plugins/sync-json.md +245 -0
  153. package/docs/vi/plugins/sync-json.md +244 -0
  154. package/docs/zh/plugins/sync-json.md +244 -0
  155. package/package.json +14 -14
  156. package/src/generated/blog.entry.ts +26 -3
  157. package/src/generated/docs.entry.ts +26 -3
  158. package/src/generated/frequentQuestions.entry.ts +26 -3
  159. package/src/generated/legal.entry.ts +26 -3
@@ -1,325 +1,122 @@
1
1
  ---
2
2
  createdAt: 2025-01-02
3
- updatedAt: 2025-06-29
4
- title: Intlayer e react-intl
5
- description: Integra Intlayer con react-intl per un'app React
3
+ updatedAt: 2025-10-29
4
+ title: Come automatizzare le traduzioni JSON di react-intl usando Intlayer
5
+ description: Automatizza le tue traduzioni JSON con Intlayer e react-intl per una migliore internazionalizzazione nelle applicazioni React.
6
6
  keywords:
7
7
  - react-intl
8
8
  - Intlayer
9
9
  - Internazionalizzazione
10
- - Blogumentazione
11
- - Next.js
10
+ - Blog
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: Cambio al plugin syncJSON
17
22
  ---
18
23
 
19
- # React Internationalization (i18n) con **react-intl** e Intlayer
24
+ # Come automatizzare le traduzioni JSON di react-intl usando Intlayer
20
25
 
21
- Questa guida mostra come integrare **Intlayer** con **react-intl** per gestire le traduzioni in un'applicazione React. Dichiari i tuoi contenuti traducibili con Intlayer e poi consuma quei messaggi con **react-intl**, una popolare libreria dell'ecosistema [FormatJS](https://formatjs.io/docs/react-intl).
26
+ ## Cos'è Intlayer?
22
27
 
23
- ## Panoramica
28
+ **Intlayer** è una libreria di internazionalizzazione innovativa e open-source progettata per superare le limitazioni delle soluzioni i18n tradizionali. Offre un approccio moderno alla gestione dei contenuti nelle applicazioni React.
24
29
 
25
- - **Intlayer** ti consente di memorizzare le traduzioni nei file di dichiarazione dei contenuti a **livello di componente** (JSON, JS, TS, ecc.) all'interno del tuo progetto.
26
- - **react-intl** fornisce componenti React e hook (come `<FormattedMessage>` e `useIntl()`) per visualizzare stringhe localizzate.
30
+ Consulta un confronto concreto con react-intl nel nostro post del blog [react-i18next vs. react-intl vs. Intlayer](https://github.com/aymericzip/intlayer/blob/main/docs/blog/it/react-i18next_vs_react-intl_vs_intlayer.md).
27
31
 
28
- Configurando Intlayer per **esportare** le traduzioni in un formato **compatibile con react-intl**, puoi automaticamente **generare** e **aggiornare** i file di messaggi di cui `<IntlProvider>` (da react-intl) ha bisogno.
32
+ ## Perché combinare Intlayer con react-intl?
29
33
 
30
- ---
34
+ Sebbene Intlayer fornisca una soluzione i18n autonoma eccellente (vedi la nostra [guida all'integrazione con React](https://github.com/aymericzip/intlayer/blob/main/docs/docs/it/intlayer_with_vite+react.md)), potresti volerlo combinare con react-intl per diversi motivi:
31
35
 
32
- ## Perché usare Intlayer con react-intl?
36
+ 1. **Codice esistente**: Hai un'implementazione consolidata di react-intl e vuoi migrare gradualmente alla migliore esperienza sviluppatore offerta da Intlayer.
37
+ 2. **Requisiti legacy**: Il tuo progetto richiede compatibilità con plugin o flussi di lavoro esistenti di react-intl.
38
+ 3. **Familiarità del team**: Il tuo team è abituato a react-intl ma desidera una migliore gestione dei contenuti.
33
39
 
34
- 1. **Dichiarazioni di contenuto per componente**
35
- I file di dichiarazione dei contenuti di Intlayer possono vivere accanto ai tuoi componenti React, evitando traduzioni “orfane” se i componenti vengono spostati o rimossi. Ad esempio:
40
+ **Per questo, Intlayer può essere implementato come un adattatore per react-intl per aiutarti ad automatizzare le traduzioni JSON nella CLI o nelle pipeline CI/CD, testare le traduzioni e altro ancora.**
36
41
 
37
- ```bash
38
- .
39
- └── src
40
- └── components
41
- └── MyComponent
42
- ├── index.content.ts # Dichiarazione contenuti Intlayer
43
- └── index.tsx # Componente React
44
- ```
42
+ Questa guida ti mostra come sfruttare il sistema superiore di dichiarazione dei contenuti di Intlayer mantenendo la compatibilità con react-intl.
45
43
 
46
- 2. **Traduzioni centralizzate**
47
- Ogni file di dichiarazione dei contenuti raccoglie tutte le traduzioni necessarie a un componente. Questo è particolarmente utile nei progetti TypeScript: le traduzioni mancanti possono essere catturate al **momento della compilazione**.
44
+ ## Indice
48
45
 
49
- 3. **Build e rigenerazione automatiche**
50
- Ogni volta che aggiungi o aggiorni le traduzioni, Intlayer rigenera file JSON di messaggio. Puoi quindi passarli a `<IntlProvider>` di react-intl.
46
+ <TOC/>
51
47
 
52
- ---
48
+ ## Guida passo-passo per configurare Intlayer con react-intl
53
49
 
54
- ## Installazione
50
+ ### Passo 1: Installa le dipendenze
55
51
 
56
- In un tipico progetto React, installa i seguenti:
52
+ Installa i pacchetti necessari:
57
53
 
58
- ```bash
59
- # con npm
60
- npm install intlayer react-intl
54
+ ```bash packageManager="npm"
55
+ npm install intlayer @intlayer/sync-json-plugin
56
+ ```
61
57
 
62
- # con yarn
63
- yarn add intlayer react-intl
58
+ ```bash packageManager="pnpm"
59
+ pnpm add intlayer @intlayer/sync-json-plugin
60
+ ```
64
61
 
65
- # con pnpm
66
- pnpm add intlayer react-intl
62
+ ```bash packageManager="yarn"
63
+ yarn add intlayer @intlayer/sync-json-plugin
67
64
  ```
68
65
 
69
- ### Perché questi pacchetti?
66
+ **Descrizione dei pacchetti:**
70
67
 
71
- - **intlayer**: CLI core e libreria che scansiona le dichiarazioni di contenuto, le unisce e genera output di dizionario.
72
- - **react-intl**: La libreria principale di FormatJS che fornisce `<IntlProvider>`, `<FormattedMessage>`, `useIntl()` e altre primitives di internazionalizzazione.
68
+ - **intlayer**: Libreria core per la gestione dell'internazionalizzazione, dichiarazione dei contenuti e build
69
+ - **@intlayer/sync-json-plugin**: Plugin per esportare le dichiarazioni di contenuto di Intlayer in formato JSON compatibile con react-intl
73
70
 
74
- > Se non hai già installato React, avrai bisogno anche di esso (`react` e `react-dom`).
71
+ ### Passo 2: Implementa il plugin Intlayer per incapsulare il JSON
75
72
 
76
- ## Configurare Intlayer per esportare i messaggi react-intl
73
+ Crea un file di configurazione Intlayer per definire le tue localizzazioni supportate:
77
74
 
78
- Nella radice del tuo progetto, crea **`intlayer.config.ts`** (o `.js`, `.mjs`, `.cjs`) in questo modo:
75
+ **Se vuoi anche esportare dizionari JSON per react-intl**, aggiungi il 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
- // Aggiungi quanti più locali desideri
86
83
  locales: [Locales.ENGLISH, Locales.FRENCH, Locales.SPANISH],
87
84
  defaultLocale: Locales.ENGLISH,
88
85
  },
89
- content: {
90
- // Indica a Intlayer di generare file di messaggi per react-intl
91
- dictionaryOutput: ["react-intl"],
92
-
93
- // La directory in cui Intlayer scriverà i tuoi file JSON di messaggi
94
- reactIntlMessagesDir: "./react-intl/messages",
95
- },
96
- };
97
-
98
- export default config;
99
- ```
100
-
101
- > **Nota**: Per altri tipi di file (`.mjs`, `.cjs`, `.js`), consulta la [documentazione di Intlayer](https://intlayer.org/it/doc/concept/configuration) per i dettagli sull'uso.
102
-
103
- ---
104
-
105
- ## Creazione delle dichiarazioni di contenuto di Intlayer
106
-
107
- Intlayer scansiona il tuo codice sorgente (per impostazione predefinita, sotto `./src`) per file che corrispondono a `*.content.{ts,tsx,js,jsx,mjs,mjx,cjs,cjx,json}`.
108
- Ecco un esempio in **TypeScript**:
109
-
110
- ```typescript title="src/components/MyComponent/index.content.ts"
111
- import { t, type Dictionary } from "intlayer";
112
-
113
- const content = {
114
- // "chiave" diventa la chiave di messaggio di primo livello nel tuo file JSON react-intl
115
- key: "my-component",
116
-
117
- content: {
118
- // Ogni chiamata a t() dichiara un campo traducibile
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
- Se preferisci JSON o diversi tipi di JS (`.cjs`, `.mjs`), la struttura è essenzialmente la stessa, vedi [documentazione di Intlayer sulla dichiarazione dei contenuti](https://intlayer.org/it/doc/concept/content).
136
-
137
- ---
138
-
139
- ## Costruzione dei messaggi react-intl
140
-
141
- Per generare i file JSON di messaggi effettivi per **react-intl**, esegui:
142
-
143
- ```bash
144
- # con npm
145
- npx intlayer dictionaries build
146
-
147
- # con yarn
148
- yarn intlayer build
149
-
150
- # con pnpm
151
- pnpm intlayer build
152
- ```
153
-
154
- Questo scansiona tutti i file `*.content.*`, li compila e scrive i risultati nella directory specificata nel tuo **`intlayer.config.ts`** , in questo esempio, `./react-intl/messages`.
155
- Un output tipico potrebbe apparire così:
156
-
157
- ```bash
158
- .
159
- └── react-intl
160
- └── messages
161
- ├── en.json
162
- ├── fr.json
163
- └── es.json
164
- ```
165
-
166
- Ogni file è un oggetto JSON i cui **chiavi di primo livello** corrispondono a ciascuna **`content.key`** dalle tue dichiarazioni. Le **sotto-chiavi** (come `helloWorld`) riflettono le traduzioni dichiarate all'interno di quell'elemento di contenuto.
167
-
168
- Ad esempio, il **en.json** potrebbe apparire così:
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
- ## Inizializzare react-intl nella tua app React
180
-
181
- ### 1. Carica i messaggi generati
182
-
183
- Dove configuri il componente radice della tua app (ad esempio, `src/main.tsx` o `src/index.tsx`), dovrai:
184
-
185
- 1. **Importare** i file di messaggi generati (staticamente o dinamicamente).
186
- 2. **Fornirli** a `<IntlProvider>` da `react-intl`.
187
-
188
- Un approccio semplice è importare staticamente:
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
- // Importa i file JSON dall'output della build.
197
- // In alternativa, puoi importare dinamicamente in base alla lingua scelta dall'utente.
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
- // Se hai un meccanismo per rilevare la lingua dell'utente, impostalo qui.
203
- // Per semplicità, scegliamo l'inglese.
204
- const locale = "en";
205
-
206
- // Raccogli i messaggi in un oggetto (o scegli in modo dinamico)
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
- > **Suggerimento**: Per progetti reali, potresti:
223
- >
224
- > - Caricare dinamicamente i messaggi JSON a runtime.
225
- > - Utilizzare rilevamenti di locale basati su ambiente, browser o account utente.
226
-
227
- ### 2. Usa `<FormattedMessage>` o `useIntl()`
228
-
229
- Una volta che i tuoi messaggi sono stati caricati in `<IntlProvider>`, qualsiasi componente figlio può utilizzare react-intl per accedere a stringhe localizzate. Ci sono due approcci principali:
230
-
231
- - **Componente `<FormattedMessage>`**
232
- - **Hook `useIntl()`**
233
-
234
- ---
235
-
236
- ## Utilizzo delle traduzioni nei componenti React
237
-
238
- ### Approccio A: `<FormattedMessage>`
239
-
240
- Per un utilizzo rapido in linea:
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” fa riferimento alla chiave da en.json, fr.json, ecc. */}
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`** in `<FormattedMessage>` deve corrispondere alla **chiave di primo livello** (`my-component`) più eventuali sotto-chiavi (`helloWorld`).
263
-
264
- ### Approccio B: `useIntl()`
265
-
266
- Per un utilizzo più dinamico:
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
- Entrambi gli approcci sono validi: scegli quello che meglio si adatta alla tua app.
285
-
286
- ---
96
+ Il plugin `syncJSON` incapsulerà automaticamente il JSON. Leggerà e scriverà i file JSON senza modificare l'architettura del contenuto.
287
97
 
288
- ## Aggiornamento o aggiunta di nuove traduzioni
98
+ Se vuoi far coesistere quel JSON con i file di dichiarazione dei contenuti di Intlayer (file `.content`), Intlayer procederà in questo modo:
289
99
 
290
- 1. **Aggiungi o modifica** contenuti in qualsiasi file `*.content.*`.
291
- 2. Riesegui `intlayer build` per rigenerare i file JSON sotto `./react-intl/messages`.
292
- 3. React (e react-intl) rileveranno gli aggiornamenti la prossima volta che ricompili o ricarichi la tua applicazione.
100
+ 1. caricherà sia i file JSON che quelli di dichiarazione dei contenuti e li trasformerà in un dizionario Intlayer.
101
+ 2. se ci sono conflitti tra i file JSON e i file di dichiarazione del contenuto, Intlayer procederà alla fusione di tutti questi dizionari. A seconda della priorità dei plugin e di quella del file di dichiarazione del contenuto (tutti configurabili).
293
102
 
294
- ---
103
+ Se vengono apportate modifiche utilizzando la CLI per tradurre il JSON, o utilizzando il CMS, Intlayer aggiornerà il file JSON con le nuove traduzioni.
295
104
 
296
- ## Integrazione TypeScript (Opzionale)
105
+ Per maggiori dettagli sul plugin `syncJSON`, si prega di fare riferimento alla [documentazione del plugin syncJSON](https://github.com/aymericzip/intlayer/blob/main/docs/docs/it/plugins/sync-json.md).
297
106
 
298
- Se stai usando TypeScript, Intlayer può **generare definizioni di tipo** per le tue traduzioni.
107
+ ## Configurazione Git
299
108
 
300
- - Assicurati che `tsconfig.json` includa la tua cartella `types` (o qualsiasi altra cartella di output generata da Intlayer) nell'array `"include"`.
109
+ Si consiglia di ignorare i file Intlayer generati automaticamente:
301
110
 
302
- ```json5
303
- {
304
- "compilerOptions": {
305
- // ...
306
- },
307
- "include": ["src", "types"],
308
- }
111
+ ```plaintext fileName=".gitignore"
112
+ # Ignora i file generati da Intlayer
113
+ .intlayer
309
114
  ```
310
115
 
311
- I tipi generati possono aiutare a rilevare traduzioni mancanti o chiavi non valide nei tuoi componenti React al momento della compilazione.
312
-
313
- ---
314
-
315
- ## Configurazione Git
116
+ Questi file possono essere rigenerati durante il processo di build e non è necessario che vengano inseriti nel controllo di versione.
316
117
 
317
- È comune **escludere** gli artefatti di build interni di Intlayer dal controllo versione. Nel tuo `.gitignore`, aggiungi:
118
+ ### Estensione VS Code
318
119
 
319
- ```plaintext
320
- # Ignora gli artefatti di build di intlayer
321
- .intlayer
322
- react-intl
323
- ```
120
+ Per migliorare l'esperienza dello sviluppatore, installa l'**Estensione ufficiale Intlayer per VS Code**:
324
121
 
325
- A seconda del tuo flusso di lavoro, potresti anche voler ignorare o impegnare i dizionari finali in `./react-intl/messages`. Se la tua pipeline CI/CD li rigenera, puoi ignorarli in sicurezza; altrimenti, impegnali se hai bisogno di loro per le distribuzioni in produzione.
122
+ [Installa dal Marketplace di VS Code](https://marketplace.visualstudio.com/items?itemName=intlayer.intlayer-vs-code-extension)
@@ -1,162 +1,127 @@
1
1
  ---
2
2
  createdAt: 2024-12-24
3
- updatedAt: 2025-06-29
4
- title: IntlayerとI18next
5
- description: 最適な国際化のためにIntlayeri18nextと統合します。両フレームワークを比較し、それらを一緒に設定する方法を学びます。
3
+ updatedAt: 2025-10-29
4
+ title: Intlayerを使ってi18nextのJSON翻訳を自動化する方法
5
+ description: Intlayeri18nextを使ってJavaScriptアプリケーションの国際化を強化するためにJSON翻訳を自動化する方法。
6
6
  keywords:
7
7
  - Intlayer
8
8
  - i18next
9
9
  - 国際化
10
10
  - i18n
11
- - ローカライゼーション
11
+ - ローカリゼーション
12
12
  - 翻訳
13
13
  - React
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
- # Internationalization with Intlayer and i18next
28
+ # Intlayerを使ってi18nextのJSON翻訳を自動化する方法
23
29
 
24
- i18nextは、JavaScriptアプリケーション向けに設計されたオープンソースの国際化(i18n)フレームワークです。これは、ソフトウェアプロジェクトにおける翻訳、ローカライズ、および言語切り替えの管理に広く使用されています。ただし、スケーラビリティや開発を複雑にするいくつかの制限があります。
30
+ ## Intlayerとは何ですか?
25
31
 
26
- Intlayerは、これらの制限に対処する別の国際化フレームワークであり、コンテンツの宣言と管理により柔軟なアプローチを提供します。i18nextとIntlayerの間のいくつかの主要な違いと、両方を最適な国際化のために設定する方法について探ってみましょう。
32
+ **Intlayer**は、従来のi18nソリューションの欠点を解決するために設計された革新的なオープンソースの国際化ライブラリです。JavaScriptアプリケーションにおけるコンテンツ管理に対して、モダンなアプローチを提供します。
27
33
 
28
- ## Intlayer vs. i18next: 主な違い
34
+ 具体的な比較については、当社のブログ記事[Next-i18next vs. next-intl vs. Intlayer](https://github.com/aymericzip/intlayer/blob/main/docs/blog/ja/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/ja/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
+ このガイドでは、i18nextとの互換性を維持しつつ、Intlayerの優れたコンテンツ宣言システムを活用する方法を示します。
40
47
 
41
- ### 3. 翻訳辞書の一貫性
48
+ ## 目次
42
49
 
43
- 異なる言語間で翻訳辞書の一貫性を確保することは、i18nextでは困難です。この不一致により、適切に処理されない場合にはアプリケーションがクラッシュする可能性があります。Intlayerは、翻訳されたコンテンツに制約を課すことでこれに対応し、翻訳が漏れず、翻訳コンテンツが正確であることを保証します。
50
+ <TOC/>
44
51
 
45
- ### 4. TypeScriptとの統合
52
+ ## Intlayerとi18nextをセットアップするステップバイステップガイド
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
- ### i18next辞書をエクスポートするためのIntlayerの設定
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");
100
+ `syncJSON`プラグインはJSONを自動的にラップします。コンテンツの構造を変更することなく、JSONファイルの読み書きを行います。
96
101
 
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
- };
102
+ JSONとintlayerのコンテンツ宣言ファイル(`.content`ファイル)を共存させたい場合、Intlayerは以下の手順で処理します:
106
103
 
107
- module.exports = config;
108
- ```
104
+ 1. JSONファイルとコンテンツ宣言ファイルの両方を読み込み、intlayerの辞書に変換します。
109
105
 
110
- 設定に'i18next'を含めることで、IntlayerはIntlayer辞書に加えて専用のi18next辞書を生成します。設定から'intlayer'を削除すると、React-IntlayerやNext-Intlayerとの互換性に問題が生じる場合があります。
106
+ 2. JSONとコンテンツ宣言ファイル間に競合がある場合、Intlayerはすべての辞書をマージします。プラグインの優先度およびコンテンツ宣言ファイルの優先度に応じて処理されます(すべて設定可能です)。
111
107
 
112
- ### i18next設定に辞書をインポートする
108
+ CLIを使用してJSONの翻訳を行った場合やCMSを使用した場合、Intlayerは新しい翻訳でJSONファイルを更新します。
113
109
 
114
- 生成された辞書をi18nextの設定にインポートするには、'i18next-resources-to-backend'を使用できます。以下は、i18next辞書をインポートする方法の例です。
110
+ ## Git設定
115
111
 
116
- ```typescript fileName="i18n/client.ts" codeFormat="typescript"
117
- // i18n/client.ts
112
+ 自動生成されたIntlayerファイルは無視することを推奨します:
118
113
 
119
- import i18next from "i18next";
120
- import resourcesToBackend from "i18next-resources-to-backend";
121
-
122
- i18next
123
- // あなたのi18next設定
124
- .use(
125
- resourcesToBackend(
126
- (language: string, namespace: string) =>
127
- import(`../i18next/dictionaries/${language}/${namespace}.json`)
128
- )
129
- );
114
+ ```plaintext fileName=".gitignore"
115
+ # Intlayerによって生成されたファイルを無視
116
+ .intlayer
130
117
  ```
131
118
 
132
- ```javascript fileName="i18n/client.mjs" codeFormat="esm"
133
- // i18n/client.mjs
134
-
135
- import i18next from "i18next";
136
- import resourcesToBackend from "i18next-resources-to-backend";
119
+ これらのファイルはビルドプロセス中に再生成可能であり、バージョン管理にコミットする必要はありません。
137
120
 
138
- i18next
139
- // あなたのi18next設定
140
- .use(
141
- resourcesToBackend(
142
- (language, namespace) =>
143
- import(`../i18next/dictionaries/${language}/${namespace}.json`)
144
- )
145
- );
146
- ```
121
+ ### VS Code拡張機能
147
122
 
148
- ```javascript fileName="i18n/client.cjs" codeFormat="commonjs"
149
- // i18n/client.cjs
123
+ 開発者体験を向上させるために、公式の**Intlayer VS Code拡張機能**をインストールしてください:
150
124
 
151
- const i18next = require("i18next");
152
- const resourcesToBackend = require("i18next-resources-to-backend");
125
+ [VS Codeマーケットプレイスからインストール](https://marketplace.visualstudio.com/items?itemName=intlayer.intlayer-vs-code-extension)
153
126
 
154
- i18next
155
- // あなたのi18next設定
156
- .use(
157
- resourcesToBackend(
158
- (language, namespace) =>
159
- import(`../i18next/dictionaries/${language}/${namespace}.json`)
160
- )
161
- );
162
- ```
127
+ [VS Codeマーケットプレイスからインストール](https://marketplace.visualstudio.com/items?itemName=intlayer.intlayer-vs-code-extension)