@intlayer/docs 8.1.5 → 8.1.7

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 (81) hide show
  1. package/README.md +18 -9
  2. package/dist/cjs/generated/docs.entry.cjs +1 -1
  3. package/dist/cjs/generated/docs.entry.cjs.map +1 -1
  4. package/dist/esm/generated/docs.entry.mjs +1 -1
  5. package/dist/esm/generated/docs.entry.mjs.map +1 -1
  6. package/dist/types/generated/docs.entry.d.ts +2 -0
  7. package/dist/types/generated/docs.entry.d.ts.map +1 -1
  8. package/docs/ar/compiler.md +26 -0
  9. package/docs/ar/intlayer_with_nextjs_compiler.md +481 -0
  10. package/docs/ar/intlayer_with_vite+react_compiler.md +369 -0
  11. package/docs/ar/readme.md +138 -110
  12. package/docs/de/compiler.md +26 -0
  13. package/docs/de/intlayer_with_nextjs_compiler.md +481 -0
  14. package/docs/de/intlayer_with_vite+react_compiler.md +369 -0
  15. package/docs/de/readme.md +152 -124
  16. package/docs/en/compiler.md +27 -0
  17. package/docs/en/intlayer_with_nextjs_compiler.md +481 -0
  18. package/docs/en/intlayer_with_vite+react_compiler.md +368 -0
  19. package/docs/en/readme.md +129 -105
  20. package/docs/en-GB/compiler.md +26 -0
  21. package/docs/en-GB/intlayer_with_nextjs_compiler.md +481 -0
  22. package/docs/en-GB/intlayer_with_vite+react_compiler.md +369 -0
  23. package/docs/en-GB/readme.md +134 -108
  24. package/docs/es/compiler.md +26 -0
  25. package/docs/es/intlayer_with_nextjs_compiler.md +481 -0
  26. package/docs/es/intlayer_with_vite+react_compiler.md +369 -0
  27. package/docs/es/readme.md +149 -121
  28. package/docs/fr/compiler.md +26 -0
  29. package/docs/fr/intlayer_with_nextjs_compiler.md +481 -0
  30. package/docs/fr/intlayer_with_vite+react_compiler.md +369 -0
  31. package/docs/fr/readme.md +150 -122
  32. package/docs/hi/compiler.md +26 -0
  33. package/docs/hi/intlayer_with_nextjs_compiler.md +481 -0
  34. package/docs/hi/intlayer_with_vite+react_compiler.md +370 -0
  35. package/docs/hi/readme.md +153 -125
  36. package/docs/id/compiler.md +26 -0
  37. package/docs/id/intlayer_with_nextjs_compiler.md +481 -0
  38. package/docs/id/intlayer_with_vite+react_compiler.md +369 -0
  39. package/docs/id/readme.md +133 -105
  40. package/docs/it/compiler.md +26 -0
  41. package/docs/it/intlayer_with_nextjs_compiler.md +481 -0
  42. package/docs/it/intlayer_with_vite+react_compiler.md +374 -0
  43. package/docs/it/readme.md +155 -127
  44. package/docs/ja/compiler.md +26 -0
  45. package/docs/ja/intlayer_with_nextjs_compiler.md +481 -0
  46. package/docs/ja/intlayer_with_vite+react_compiler.md +369 -0
  47. package/docs/ja/readme.md +152 -126
  48. package/docs/ko/compiler.md +26 -0
  49. package/docs/ko/intlayer_with_nextjs_compiler.md +481 -0
  50. package/docs/ko/intlayer_with_vite+react_compiler.md +369 -0
  51. package/docs/ko/readme.md +154 -126
  52. package/docs/pl/compiler.md +26 -0
  53. package/docs/pl/intlayer_with_nextjs_compiler.md +481 -0
  54. package/docs/pl/intlayer_with_vite+react_compiler.md +369 -0
  55. package/docs/pl/readme.md +134 -106
  56. package/docs/pt/compiler.md +27 -1
  57. package/docs/pt/intlayer_with_nextjs_compiler.md +481 -0
  58. package/docs/pt/intlayer_with_vite+react_compiler.md +374 -0
  59. package/docs/pt/readme.md +154 -126
  60. package/docs/ru/compiler.md +26 -0
  61. package/docs/ru/intlayer_with_nextjs_compiler.md +481 -0
  62. package/docs/ru/intlayer_with_vite+react_compiler.md +369 -0
  63. package/docs/ru/readme.md +137 -109
  64. package/docs/tr/compiler.md +26 -0
  65. package/docs/tr/intlayer_with_nextjs_compiler.md +481 -0
  66. package/docs/tr/intlayer_with_vite+react_compiler.md +375 -0
  67. package/docs/tr/readme.md +139 -111
  68. package/docs/uk/compiler.md +26 -0
  69. package/docs/uk/intlayer_with_nextjs_compiler.md +481 -0
  70. package/docs/uk/intlayer_with_vite+react_compiler.md +369 -0
  71. package/docs/uk/readme.md +133 -109
  72. package/docs/vi/compiler.md +27 -1
  73. package/docs/vi/intlayer_with_nextjs_compiler.md +481 -0
  74. package/docs/vi/intlayer_with_vite+react_compiler.md +369 -0
  75. package/docs/vi/readme.md +138 -110
  76. package/docs/zh/compiler.md +26 -0
  77. package/docs/zh/intlayer_with_nextjs_compiler.md +481 -0
  78. package/docs/zh/intlayer_with_vite+react_compiler.md +372 -0
  79. package/docs/zh/readme.md +148 -120
  80. package/package.json +7 -8
  81. package/src/generated/docs.entry.ts +40 -0
@@ -0,0 +1,368 @@
1
+ ---
2
+ createdAt: 2024-03-07
3
+ updatedAt: 2025-12-30
4
+ title: Vite and React i18n - Transform an existing app into a multilingual app (i18n guide 2026)
5
+ description: Discover how to make your existing Vite and React application multilingual using Intlayer Compiler. Follow the documentation to internationalize (i18n) and translate it with AI.
6
+ keywords:
7
+ - Internationalization
8
+ - Documentation
9
+ - Intlayer
10
+ - Vite
11
+ - React
12
+ - Compiler
13
+ - AI
14
+ slugs:
15
+ - doc
16
+ - environment
17
+ - vite-and-react
18
+ - compiler
19
+ applicationTemplate: https://github.com/aymericzip/intlayer-vite-react-template
20
+ youtubeVideo: https://www.youtube.com/watch?v=dS9L7uJeak4
21
+ history:
22
+ - version: 8.1.6
23
+ date: 2026-02-23
24
+ changes: Initial release
25
+ ---
26
+
27
+ # How to make multilingual (i18n) an existing Vite and React application afterward (i18n guide 2026)
28
+
29
+ <Tabs defaultTab="video">
30
+ <Tab label="Video" value="video">
31
+
32
+ <iframe title="The best i18n solution for Vite and React? Discover Intlayer" class="m-auto aspect-16/9 w-full overflow-hidden rounded-lg border-0" allow="autoplay; gyroscope;" loading="lazy" width="1080" height="auto" src="https://www.youtube.com/embed/dS9L7uJeak4?si=VaKmrYMmXjo3xpk2"/>
33
+
34
+ </Tab>
35
+ <Tab label="Code" value="code">
36
+
37
+ <iframe
38
+ src="https://stackblitz.com/github/aymericzip/intlayer-vite-react-template?embed=1&ctl=1&file=intlayer.config.ts"
39
+ className="m-auto overflow-hidden rounded-lg border-0 max-md:size-full max-md:h-[700px] md:aspect-16/9 md:w-full"
40
+ title="Demo CodeSandbox - How to Internationalize your application using Intlayer"
41
+ sandbox="allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts"
42
+ loading="lazy"
43
+ />
44
+
45
+ </Tab>
46
+ </Tabs>
47
+
48
+ See [Application Template](https://github.com/aymericzip/intlayer-vite-react-template) on GitHub.
49
+
50
+ ## Table of Contents
51
+
52
+ <TOC/>
53
+
54
+ ## Why is it hard to internationalize an existing application?
55
+
56
+ If you've ever tried to add multiple languages to an app that was built for just one, you know the pain. It's not just "hard"—it's tedious. You have to comb through every single file, hunt down every string of text, and move them into separate dictionary files.
57
+
58
+ Then comes the risky part: replacing all that text with code hooks without breaking your layout or logic. It's the kind of work that halts new feature development for weeks and feels like endless refactoring.
59
+
60
+ ## What is the Intlayer Compiler?
61
+
62
+ The **Intlayer Compiler** was built to skip that manual grunt work. Instead of you manually extracting strings, the compiler does it for you. It scans your code, finds the text, and uses AI to generate the dictionaries behind the scenes.
63
+ Then, it modifies your code during the build to inject the necessary i18n hooks. Basically, you keep writing your app as if it's single-language, and the compiler handles the multilingual transformation automatically.
64
+
65
+ > Doc Compiler: [https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/compiler.md](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/compiler.md)
66
+
67
+ ### Limitations
68
+
69
+ Because the compiler performs code analysis and transformation (inserting hooks and generating dictionaries) at **compile time**, it can **slow down the build process** of your application.
70
+
71
+ To mitigate this impact during development, you can configure the compiler to run in [`'build-only'`](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/configuration.md) mode or disable it when not needed.
72
+
73
+ ---
74
+
75
+ ## Step-by-Step Guide to Set Up Intlayer in a Vite and React Application
76
+
77
+ ### Step 1: Install Dependencies
78
+
79
+ Install the necessary packages using npm:
80
+
81
+ ```bash packageManager="npm"
82
+ npm install intlayer react-intlayer
83
+ npm install vite-intlayer --save-dev
84
+ npx intlayer init
85
+ ```
86
+
87
+ ```bash packageManager="pnpm"
88
+ pnpm add intlayer react-intlayer
89
+ pnpm add vite-intlayer --save-dev
90
+ pnpm intlayer init
91
+ ```
92
+
93
+ ```bash packageManager="yarn"
94
+ yarn add intlayer react-intlayer
95
+ yarn add vite-intlayer --save-dev
96
+ yarn intlayer init
97
+ ```
98
+
99
+ ```bash packageManager="bun"
100
+ bun add intlayer react-intlayer
101
+ bun add vite-intlayer --dev
102
+ bunx intlayer init
103
+ ```
104
+
105
+ - **intlayer**
106
+ The core package that provides internationalization tools for configuration management, translation, [content declaration](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/dictionary/content_file.md), transpilation, and [CLI commands](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/cli/index.md).
107
+
108
+ - **react-intlayer**
109
+ The package that integrates Intlayer with React application. It provides context providers and hooks for React internationalization.
110
+
111
+ - **vite-intlayer**
112
+ Includes the Vite plugin for integrating Intlayer with the [Vite bundler](https://vite.dev/guide/why.html#why-bundle-for-production), as well as middleware for detecting the user's preferred locale, managing cookies, and handling URL redirection.
113
+
114
+ ### Step 2: Configure Your Project
115
+
116
+ Create a config file to configure the languages of your application:
117
+
118
+ ```typescript fileName="intlayer.config.ts"
119
+ import { Locales, type IntlayerConfig } from "intlayer";
120
+
121
+ const config: IntlayerConfig = {
122
+ internationalization: {
123
+ locales: [Locales.ENGLISH, Locales.FRENCH, Locales.SPANISH],
124
+ defaultLocale: Locales.ENGLISH,
125
+ },
126
+ compiler: {
127
+ enabled: true, // Can be set to 'build-only' to limit impact on dev mode
128
+ outputDir: "i18n",
129
+ dictionaryKeyPrefix: "", // No prefix comp-
130
+ },
131
+ ai: {
132
+ provider: "openai",
133
+ model: "gpt-5-mini",
134
+ apiKey: process.env.OPEN_AI_API_KEY,
135
+ applicationContext: "This app is an map app", // Note: you can customize this app description
136
+ },
137
+ };
138
+
139
+ export default config;
140
+ ```
141
+
142
+ > **Note**: Ensure you have your `OPEN_AI_API_KEY` set in your environment variables.
143
+
144
+ > Through this configuration file, you can set up localized URLs, middleware redirection, cookie names, the location and extension of your content declarations, disable Intlayer logs in the console, and more. For a complete list of available parameters, refer to the [configuration documentation](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/configuration.md).
145
+
146
+ ### Step 3: Integrate Intlayer in Your Vite Configuration
147
+
148
+ Add the intlayer plugin into your configuration.
149
+
150
+ ```typescript fileName="vite.config.ts"
151
+ import { defineConfig } from "vite";
152
+ import react from "@vitejs/plugin-react-swc";
153
+ import { intlayer, intlayerCompiler } from "vite-intlayer";
154
+
155
+ // https://vitejs.dev/config/
156
+ export default defineConfig({
157
+ plugins: [react(), intlayer(), intlayerCompiler()],
158
+ });
159
+ ```
160
+
161
+ > The `intlayer()` Vite plugin is used to integrate Intlayer with Vite. It ensures the building of content declaration files and monitors them in development mode. It defines Intlayer environment variables within the Vite application. Additionally, it provides aliases to optimize performance.
162
+
163
+ > The `intlayerCompiler()` Vite plugin is used to extract content from component and write `.content` files.
164
+
165
+ ### Step 4: Compile your code
166
+
167
+ Just write your components with hardcoded strings in your default locale. The compiler handles the rest.
168
+
169
+ Example of how your page might look:
170
+
171
+ <Tabs>
172
+ <Tab value="Code">
173
+
174
+ ```tsx fileName="src/App.tsx"
175
+ import { useState, type FC } from "react";
176
+ import reactLogo from "./assets/react.svg";
177
+ import viteLogo from "/vite.svg";
178
+ import "./App.css";
179
+ import { IntlayerProvider } from "react-intlayer";
180
+
181
+ const AppContent: FC = () => {
182
+ const [count, setCount] = useState(0);
183
+
184
+ return (
185
+ <>
186
+ <div>
187
+ <a href="https://vitejs.dev" target="_blank">
188
+ <img src={viteLogo} className="logo" alt="Vite logo" />
189
+ </a>
190
+ <a href="https://react.dev" target="_blank">
191
+ <img src={reactLogo} className="logo react" alt="React logo" />
192
+ </a>
193
+ </div>
194
+ <h1>Vite + React</h1>
195
+ <div className="card">
196
+ <button onClick={() => setCount((count) => count + 1)}>
197
+ count is {count}
198
+ </button>
199
+ <p>
200
+ Edit <code>src/App.tsx</code> and save to test HMR
201
+ </p>
202
+ </div>
203
+ <p className="read-the-docs">
204
+ Click on the Vite and React logos to learn more
205
+ </p>
206
+ </>
207
+ );
208
+ };
209
+
210
+ const App: FC = () => (
211
+ <IntlayerProvider>
212
+ <AppContent />
213
+ </IntlayerProvider>
214
+ );
215
+
216
+ export default App;
217
+ ```
218
+
219
+ </Tab>
220
+ <Tab value="Output">
221
+
222
+ ```ts fileName="i18n/app-content.content.json"
223
+ {
224
+ key: "app-content",
225
+ content: {
226
+ nodeType: "translation",
227
+ translation: {
228
+ en: {
229
+ viteLogo: "Vite logo",
230
+ reactLogo: "React logo",
231
+ title: "Vite + React",
232
+ countButton: "count is",
233
+ editMessage: "Edit",
234
+ hmrMessage: "and save to test HMR",
235
+ readTheDocs: "Click on the Vite and React logos to learn more",
236
+ },
237
+ fr: {
238
+ viteLogo: "Logo Vite",
239
+ reactLogo: "Logo React",
240
+ title: "Vite + React",
241
+ countButton: "compte est",
242
+ editMessage: "Modifier",
243
+ hmrMessage: "et enregistrer pour tester HMR",
244
+ readTheDocs: "Cliquez sur les logos Vite et React pour en savoir plus",
245
+ },
246
+ }
247
+ }
248
+ }
249
+ ```
250
+
251
+ ```tsx fileName="src/App.tsx"
252
+ import { useState, type FC } from "react";
253
+ import reactLogo from "./assets/react.svg";
254
+ import viteLogo from "/vite.svg";
255
+ import "./App.css";
256
+ import { IntlayerProvider, useIntlayer } from "react-intlayer";
257
+
258
+ const AppContent: FC = () => {
259
+ const [count, setCount] = useState(0);
260
+ const content = useIntlayer("app-content");
261
+
262
+ return (
263
+ <>
264
+ <div>
265
+ <a href="https://vitejs.dev" target="_blank">
266
+ <img src={viteLogo} className="logo" alt={content.viteLogo.value} />
267
+ </a>
268
+ <a href="https://react.dev" target="_blank">
269
+ <img
270
+ src={reactLogo}
271
+ className="logo react"
272
+ alt={content.reactLogo.value}
273
+ />
274
+ </a>
275
+ </div>
276
+ <h1>{content.title}</h1>
277
+ <div className="card">
278
+ <button onClick={() => setCount((count) => count + 1)}>
279
+ {content.countButton} {count}
280
+ </button>
281
+ <p>
282
+ {content.editMessage} <code>src/App.tsx</code> {content.hmrMessage}
283
+ </p>
284
+ </div>
285
+ <p className="read-the-docs">{content.readTheDocs}</p>
286
+ </>
287
+ );
288
+ };
289
+
290
+ const App: FC = () => (
291
+ <IntlayerProvider>
292
+ <AppContent />
293
+ </IntlayerProvider>
294
+ );
295
+
296
+ export default App;
297
+ ```
298
+
299
+ </Tab>
300
+ </Tabs>
301
+
302
+ - **`IntlayerProvider`** is used to provide the locale to nested components.
303
+
304
+ ### (Optional) Step 6: Change the language of your content
305
+
306
+ To change the language of your content, you can use the `setLocale` function provided by the `useLocale` hook. This function allows you to set the locale of the application and update the content accordingly.
307
+
308
+ ```tsx fileName="src/components/LocaleSwitcher.tsx"
309
+ import type { FC } from "react";
310
+ import { Locales } from "intlayer";
311
+ import { useLocale } from "react-intlayer";
312
+
313
+ const LocaleSwitcher: FC = () => {
314
+ const { setLocale } = useLocale();
315
+
316
+ return (
317
+ <button onClick={() => setLocale(Locales.English)}>
318
+ Change Language to English
319
+ </button>
320
+ );
321
+ };
322
+ ```
323
+
324
+ > To Learn more about the `useLocale` hook, refer to the [documentation](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/packages/react-intlayer/useLocale.md).
325
+
326
+ ### (Optional) Step 7: Fill missing translation
327
+
328
+ Intlayer provide a CLI tool to help you fill missing translations. You can use the `intlayer` command to test and fill missing translations from your code.
329
+
330
+ ```bash
331
+ npx intlayer test # Test if there is missing translations
332
+ ```
333
+
334
+ ```bash
335
+ npx intlayer fill # Fill missing translations
336
+ ```
337
+
338
+ > For more details, refer to the [CLI documentation](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/cli/ci.md)
339
+
340
+ ### Git Configuration
341
+
342
+ It is recommended to ignore the files generated by Intlayer. This allows you to avoid committing them to your Git repository.
343
+
344
+ To do this, you can add the following instructions to your `.gitignore` file:
345
+
346
+ ```plaintext fileName=".gitignore"
347
+ # Ignore the files generated by Intlayer
348
+ .intlayer
349
+ ```
350
+
351
+ ### VS Code Extension
352
+
353
+ To improve your development experience with Intlayer, you can install the official **Intlayer VS Code Extension**.
354
+
355
+ [Install from the VS Code Marketplace](https://marketplace.visualstudio.com/items?itemName=intlayer.intlayer-vs-code-extension)
356
+
357
+ This extension provides:
358
+
359
+ - **Autocompletion** for translation keys.
360
+ - **Real-time error detection** for missing translations.
361
+ - **Inline previews** of translated content.
362
+ - **Quick actions** to easily create and update translations.
363
+
364
+ For more details on how to use the extension, refer to the [Intlayer VS Code Extension documentation](https://intlayer.org/doc/vs-code-extension).
365
+
366
+ ### Go Further
367
+
368
+ To go further, you can implement the [visual editor](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/intlayer_visual_editor.md) or externalize your content using the [CMS](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/intlayer_CMS.md).