@intlayer/docs 5.7.6 → 5.7.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 (73) hide show
  1. package/dist/cjs/generated/docs.entry.cjs +44 -238
  2. package/dist/cjs/generated/docs.entry.cjs.map +1 -1
  3. package/dist/esm/generated/docs.entry.mjs +44 -238
  4. package/dist/esm/generated/docs.entry.mjs.map +1 -1
  5. package/dist/types/generated/docs.entry.d.ts +1 -2
  6. package/dist/types/generated/docs.entry.d.ts.map +1 -1
  7. package/docs/ar/intlayer_with_tanstack.md +457 -0
  8. package/docs/ar/packages/next-intlayer/index.md +0 -1
  9. package/docs/ar/packages/react-intlayer/index.md +0 -1
  10. package/docs/de/intlayer_with_tanstack.md +458 -0
  11. package/docs/de/packages/next-intlayer/index.md +0 -1
  12. package/docs/de/packages/react-intlayer/index.md +0 -1
  13. package/docs/en/intlayer_with_tanstack.md +452 -0
  14. package/docs/en/packages/next-intlayer/index.md +0 -1
  15. package/docs/en/packages/react-intlayer/index.md +0 -1
  16. package/docs/en-GB/intlayer_with_tanstack.md +457 -0
  17. package/docs/en-GB/packages/next-intlayer/index.md +0 -1
  18. package/docs/en-GB/packages/react-intlayer/index.md +0 -1
  19. package/docs/es/intlayer_with_tanstack.md +435 -0
  20. package/docs/es/packages/next-intlayer/index.md +0 -1
  21. package/docs/es/packages/react-intlayer/index.md +0 -1
  22. package/docs/fr/intlayer_with_tanstack.md +435 -0
  23. package/docs/fr/packages/next-intlayer/index.md +0 -1
  24. package/docs/fr/packages/react-intlayer/index.md +0 -1
  25. package/docs/hi/intlayer_with_tanstack.md +438 -0
  26. package/docs/hi/packages/next-intlayer/index.md +0 -1
  27. package/docs/hi/packages/react-intlayer/index.md +0 -1
  28. package/docs/it/intlayer_with_tanstack.md +457 -0
  29. package/docs/it/packages/next-intlayer/index.md +0 -1
  30. package/docs/it/packages/react-intlayer/index.md +0 -1
  31. package/docs/ja/intlayer_with_tanstack.md +457 -0
  32. package/docs/ja/packages/next-intlayer/index.md +0 -1
  33. package/docs/ja/packages/react-intlayer/index.md +0 -1
  34. package/docs/ko/intlayer_with_tanstack.md +457 -0
  35. package/docs/ko/packages/next-intlayer/index.md +0 -1
  36. package/docs/ko/packages/react-intlayer/index.md +0 -1
  37. package/docs/pt/intlayer_with_tanstack.md +457 -0
  38. package/docs/pt/packages/next-intlayer/index.md +0 -1
  39. package/docs/pt/packages/react-intlayer/index.md +0 -1
  40. package/docs/ru/intlayer_with_tanstack.md +458 -0
  41. package/docs/ru/packages/next-intlayer/index.md +0 -1
  42. package/docs/ru/packages/react-intlayer/index.md +0 -1
  43. package/docs/zh/intlayer_with_tanstack.md +435 -0
  44. package/docs/zh/packages/next-intlayer/index.md +0 -1
  45. package/docs/zh/packages/react-intlayer/index.md +0 -1
  46. package/package.json +9 -9
  47. package/src/generated/docs.entry.ts +44 -238
  48. package/docs/ar/packages/next-intlayer/useIntlayerAsync.md +0 -237
  49. package/docs/ar/packages/react-intlayer/useIntlayerAsync.md +0 -252
  50. package/docs/de/packages/next-intlayer/useIntlayerAsync.md +0 -262
  51. package/docs/de/packages/react-intlayer/useIntlayerAsync.md +0 -256
  52. package/docs/en/packages/next-intlayer/useIntlayerAsync.md +0 -239
  53. package/docs/en/packages/react-intlayer/useIntlayerAsync.md +0 -254
  54. package/docs/en-GB/packages/next-intlayer/useIntlayerAsync.md +0 -237
  55. package/docs/en-GB/packages/react-intlayer/useIntlayerAsync.md +0 -257
  56. package/docs/es/packages/next-intlayer/useIntlayerAsync.md +0 -240
  57. package/docs/es/packages/react-intlayer/useIntlayerAsync.md +0 -276
  58. package/docs/fr/packages/next-intlayer/useIntlayerAsync.md +0 -238
  59. package/docs/fr/packages/react-intlayer/useIntlayerAsync.md +0 -252
  60. package/docs/hi/packages/next-intlayer/useIntlayerAsync.md +0 -237
  61. package/docs/hi/packages/react-intlayer/useIntlayerAsync.md +0 -252
  62. package/docs/it/packages/next-intlayer/useIntlayerAsync.md +0 -237
  63. package/docs/it/packages/react-intlayer/useIntlayerAsync.md +0 -252
  64. package/docs/ja/packages/next-intlayer/useIntlayerAsync.md +0 -237
  65. package/docs/ja/packages/react-intlayer/useIntlayerAsync.md +0 -268
  66. package/docs/ko/packages/next-intlayer/useIntlayerAsync.md +0 -260
  67. package/docs/ko/packages/react-intlayer/useIntlayerAsync.md +0 -271
  68. package/docs/pt/packages/next-intlayer/useIntlayerAsync.md +0 -238
  69. package/docs/pt/packages/react-intlayer/useIntlayerAsync.md +0 -252
  70. package/docs/ru/packages/next-intlayer/useIntlayerAsync.md +0 -237
  71. package/docs/ru/packages/react-intlayer/useIntlayerAsync.md +0 -252
  72. package/docs/zh/packages/next-intlayer/useIntlayerAsync.md +0 -239
  73. package/docs/zh/packages/react-intlayer/useIntlayerAsync.md +0 -257
@@ -0,0 +1,435 @@
1
+ ---
2
+ createdAt: 2025-08-11
3
+ updatedAt: 2025-08-11
4
+ title: Prise en main d'Intlayer avec TanStack Start (React)
5
+ description: Ajoutez l'internationalisation à votre application TanStack Start avec Intlayer — dictionnaires au niveau des composants, URLs localisées et métadonnées optimisées pour le SEO.
6
+ keywords:
7
+ - Internationalisation
8
+ - Documentation
9
+ - Intlayer
10
+ - TanStack Start
11
+ - TanStack Router
12
+ - React
13
+ - i18n
14
+ - JavaScript
15
+ slugs:
16
+ - doc
17
+ - environment
18
+ - tanstack-start
19
+ ---
20
+
21
+ # Prise en main de l'internationalisation (i18n) avec Intlayer et TanStack Start (React)
22
+
23
+ ## Qu'est-ce qu'Intlayer ?
24
+
25
+ **Intlayer** est une boîte à outils open-source d'internationalisation pour les applications React. Elle vous offre :
26
+
27
+ - **Dictionnaires locaux aux composants** avec la sécurité de TypeScript.
28
+ - **Métadonnées et routes dynamiques** (prêtes pour le SEO).
29
+ - **Changement de locale à l'exécution** (et helpers pour détecter/persister les locales).
30
+ - **Plugin Vite** pour les transformations au moment de la build + expérience développeur améliorée.
31
+
32
+ Ce guide montre comment intégrer Intlayer dans un projet **TanStack Start** (qui utilise Vite en interne et TanStack Router pour le routage/SSR).
33
+
34
+ ---
35
+
36
+ ## Étape 1 : Installer les dépendances
37
+
38
+ ```bash
39
+ # npm
40
+ npm i intlayer react-intlayer
41
+ npm i -D vite-intlayer
42
+
43
+ # pnpm
44
+ pnpm add intlayer react-intlayer
45
+ pnpm add -D vite-intlayer
46
+
47
+ # yarn
48
+ yarn add intlayer react-intlayer
49
+ yarn add -D vite-intlayer
50
+ ```
51
+
52
+ - **intlayer** : cœur (configuration, dictionnaires, CLI/transformations).
53
+ - **react-intlayer** : `<IntlayerProvider>` + hooks pour React.
54
+ - **vite-intlayer** : plugin Vite, plus middleware optionnel pour la détection/redirection de locale (fonctionne en dev & SSR/preview ; déplacer dans `dependencies` pour le SSR en production).
55
+
56
+ ---
57
+
58
+ ## Étape 2 : Configurer Intlayer
59
+
60
+ Créez `intlayer.config.ts` à la racine de votre projet :
61
+
62
+ ```ts fileName="intlayer.config.ts"
63
+ import { Locales, type IntlayerConfig } from "intlayer";
64
+
65
+ const config: IntlayerConfig = {
66
+ internationalization: {
67
+ locales: [Locales.ENGLISH, Locales.FRENCH, Locales.SPANISH],
68
+ defaultLocale: Locales.ENGLISH,
69
+ },
70
+ // Vous pouvez aussi ajuster : contentDir, contentFileExtensions, options du middleware, etc.
71
+ };
72
+
73
+ export default config;
74
+ ```
75
+
76
+ Les variantes CommonJS/ESM sont identiques à votre doc originale si vous préférez `cjs`/`mjs`.
77
+
78
+ > Référence complète de la configuration : voir la documentation de configuration d’Intlayer.
79
+
80
+ ---
81
+
82
+ ## Étape 3 : Ajouter le plugin Vite (et middleware optionnel)
83
+
84
+ **TanStack Start utilise Vite**, donc ajoutez le(s) plugin(s) d’Intlayer dans votre `vite.config.ts` :
85
+
86
+ ```ts fileName="vite.config.ts"
87
+ import { defineConfig } from "vite";
88
+ import react from "@vitejs/plugin-react-swc";
89
+ import { intlayerPlugin, intLayerMiddlewarePlugin } from "vite-intlayer";
90
+
91
+ export default defineConfig({
92
+ plugins: [
93
+ react(),
94
+ intlayerPlugin(),
95
+ // Optionnel mais recommandé pour la détection de la locale, les cookies et les redirections :
96
+ intLayerMiddlewarePlugin(),
97
+ ],
98
+ });
99
+ ```
100
+
101
+ > Si vous déployez en SSR, déplacez `vite-intlayer` dans les `dependencies` pour que le middleware fonctionne en production.
102
+
103
+ ---
104
+
105
+ ## Étape 4 : Déclarez Votre Contenu
106
+
107
+ Placez vos dictionnaires n'importe où sous `./src` (contentDir par défaut). Exemple :
108
+
109
+ ```tsx fileName="src/app.content.tsx"
110
+ import { t, type Dictionary } from "intlayer";
111
+ import type { ReactNode } from "react";
112
+
113
+ const appContent = {
114
+ key: "app",
115
+ content: {
116
+ viteLogo: t({ en: "Vite logo", fr: "Logo Vite", es: "Logo Vite" }),
117
+ reactLogo: t({ en: "React logo", fr: "Logo React", es: "Logo React" }),
118
+ title: t({
119
+ en: "TanStack Start + React",
120
+ fr: "TanStack Start + React",
121
+ es: "TanStack Start + React",
122
+ }),
123
+ count: t({ en: "count is ", fr: "le compte est ", es: "el recuento es " }),
124
+ edit: t<ReactNode>({
125
+ en: (
126
+ <>
127
+ Edit <code>src/routes/index.tsx</code> and save to test HMR
128
+ </>
129
+ ),
130
+ fr: (
131
+ <>
132
+ Éditez <code>src/routes/index.tsx</code> et enregistrez pour tester
133
+ HMR
134
+ </>
135
+ ),
136
+ es: (
137
+ <>
138
+ Edita <code>src/routes/index.tsx</code> y guarda para probar HMR
139
+ </>
140
+ ),
141
+ }),
142
+ readTheDocs: t({
143
+ en: "Cliquez sur les logos pour en savoir plus",
144
+ fr: "Cliquez sur les logos pour en savoir plus",
145
+ es: "Haz clic en los logotipos para saber más",
146
+ }),
147
+ },
148
+ } satisfies Dictionary;
149
+
150
+ export default appContent;
151
+ ```
152
+
153
+ Les variantes JSON/ESM/CJS fonctionnent de la même manière que dans votre document original.
154
+
155
+ > Contenu TSX ? N’oubliez pas `import React from "react"` si votre configuration en a besoin.
156
+
157
+ ---
158
+
159
+ ## Étape 5 : Envelopper TanStack Start avec Intlayer
160
+
161
+ Avec TanStack Start, votre **route racine** est l’endroit idéal pour définir les fournisseurs.
162
+
163
+ ```tsx fileName="src/routes/__root.tsx"
164
+ import {
165
+ Outlet,
166
+ createRootRoute,
167
+ Link as RouterLink,
168
+ } from "@tanstack/react-router";
169
+ import { IntlayerProvider, useIntlayer } from "react-intlayer";
170
+
171
+ function AppShell() {
172
+ // Exemple d’utilisation d’un dictionnaire au niveau supérieur :
173
+ const content = useIntlayer("app");
174
+
175
+ return (
176
+ <div>
177
+ <nav className="flex gap-3 p-3">
178
+ <RouterLink to="/">Accueil</RouterLink>
179
+ <RouterLink to="/about">À propos</RouterLink>
180
+ </nav>
181
+ <main className="p-6">
182
+ <h1>{content.title}</h1>
183
+ <Outlet />
184
+ </main>
185
+ </div>
186
+ );
187
+ }
188
+
189
+ export const Route = createRootRoute({
190
+ component: () => (
191
+ <IntlayerProvider>
192
+ <AppShell />
193
+ </IntlayerProvider>
194
+ ),
195
+ });
196
+ ```
197
+
198
+ Ensuite, utilisez votre contenu dans les pages :
199
+
200
+ ```tsx fileName="src/routes/index.tsx"
201
+ import { createFileRoute } from "@tanstack/react-router";
202
+ import { useIntlayer } from "react-intlayer";
203
+ import reactLogo from "../assets/react.svg";
204
+
205
+ export const Route = createFileRoute("/")({
206
+ component: () => {
207
+ const content = useIntlayer("app");
208
+ return (
209
+ <>
210
+ <button>{content.count}0</button>
211
+ <p>{content.edit}</p>
212
+ <img
213
+ src={reactLogo}
214
+ alt={content.reactLogo.value}
215
+ width={48}
216
+ height={48}
217
+ />
218
+ <p className="opacity-70">{content.readTheDocs}</p>
219
+ </>
220
+ );
221
+ },
222
+ });
223
+ ```
224
+
225
+ > Les attributs de type chaîne (`alt`, `title`, `aria-label`, …) nécessitent `.value` :
226
+ >
227
+ > ```jsx
228
+ > <img alt={c.reactLogo.value} />
229
+ > ```
230
+
231
+ ---
232
+
233
+ ## (Optionnel) Étape 6 : Changement de langue (Client)
234
+
235
+ ```tsx fileName="src/components/LocaleSwitcher.tsx"
236
+ import { Locales } from "intlayer";
237
+ import { useLocale } from "react-intlayer";
238
+
239
+ export function LocaleSwitcher() {
240
+ const { setLocale } = useLocale();
241
+ return (
242
+ <div className="flex gap-2">
243
+ <button onClick={() => setLocale(Locales.ENGLISH)}>English</button>
244
+ <button onClick={() => setLocale(Locales.FRENCH)}>Français</button>
245
+ <button onClick={() => setLocale(Locales.SPANISH)}>Español</button>
246
+ </div>
247
+ );
248
+ }
249
+ ```
250
+
251
+ ---
252
+
253
+ ## (Optionnel) Étape 7 : Routage localisé (URLs optimisées pour le SEO)
254
+
255
+ Vous avez **deux bons modèles** avec TanStack Start. Choisissez-en un.
256
+
257
+ Créez un dossier de segment dynamique `src/routes/$locale/` pour que vos URLs soient `/:locale/...`. Dans le layout `$locale`, validez le `params.locale`, définissez `<IntlayerProvider locale=...>`, et affichez un `<Outlet />`. Cette approche est simple, mais vous monterez le reste de vos routes sous `$locale`, et vous aurez besoin d’un arbre supplémentaire sans préfixe si vous ne souhaitez pas que la locale par défaut soit préfixée.
258
+
259
+ ---
260
+
261
+ ## (Optionnel) Étape 8 : Mettre à jour l’URL lors du changement de langue
262
+
263
+ Avec le Modèle A (basepath), changer de langue signifie **naviguer vers un basepath différent** :
264
+
265
+ ```tsx fileName="src/components/LocaleSwitcherNavigate.tsx"
266
+ import { useRouter } from "@tanstack/react-router";
267
+ import { Locales, getLocalizedUrl } from "intlayer";
268
+ import { useLocale } from "react-intlayer";
269
+
270
+ export function LocaleSwitcherNavigate() {
271
+ const router = useRouter();
272
+ const { locale, setLocale } = useLocale();
273
+
274
+ const change = async (next: Locales) => {
275
+ if (next === locale) return;
276
+ const nextPath = getLocalizedUrl(
277
+ window.location.pathname + window.location.search,
278
+ next
279
+ );
280
+ await router.navigate({ to: nextPath }); // préserve l’historique
281
+ setLocale(next);
282
+ };
283
+
284
+ return (
285
+ <div className="flex gap-2">
286
+ <button onClick={() => change(Locales.ENGLISH)}>English</button>
287
+ <button onClick={() => change(Locales.FRENCH)}>Français</button>
288
+ <button onClick={() => change(Locales.SPANISH)}>Español</button>
289
+ </div>
290
+ );
291
+ }
292
+ ```
293
+
294
+ ---
295
+
296
+ ## (Optionnel) Étape 9 : `<html lang>` et `dir` (Document TanStack Start)
297
+
298
+ TanStack Start expose un **Document** (coquille HTML racine) que vous pouvez personnaliser. Définissez `lang` et `dir` pour l’accessibilité/SEO :
299
+
300
+ ```tsx fileName="src/routes/__root.tsx" {4,15}
301
+ import { Outlet, createRootRoute } from "@tanstack/react-router";
302
+ import { IntlayerProvider } from "react.intlayer";
303
+ import { getHTMLTextDir } from "intlayer";
304
+
305
+ function Document({
306
+ locale,
307
+ children,
308
+ }: {
309
+ locale: string;
310
+ children: React.ReactNode;
311
+ }) {
312
+ return (
313
+ <html lang={locale} dir={getHTMLTextDir(locale)}>
314
+ <head>
315
+ <meta charSet="utf-8" />
316
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
317
+ {/* ... */}
318
+ </head>
319
+ <body>{children}</body>
320
+ </html>
321
+ );
322
+ }
323
+
324
+ export const Route = createRootRoute({
325
+ component: () => (
326
+ <IntlayerProvider>
327
+ {/* Si vous calculez la locale côté serveur, transmettez-la dans Document ; sinon le client corrigera après l'hydratation */}
328
+ <Document locale={document?.documentElement?.lang || "en"}>
329
+ <Outlet />
330
+ </Document>
331
+ </IntlayerProvider>
332
+ ),
333
+ });
334
+ ```
335
+
336
+ Pour la correction côté client, vous pouvez aussi conserver votre petit hook :
337
+
338
+ ```tsx fileName="src/hooks/useI18nHTMLAttributes.tsx"
339
+ import { useEffect } from "react";
340
+ import { useLocale } from "react-intlayer";
341
+ import { getHTMLTextDir } from "intlayer";
342
+
343
+ export const useI18nHTMLAttributes = () => {
344
+ const { locale } = useLocale();
345
+ useEffect(() => {
346
+ document.documentElement.lang = locale;
347
+ document.documentElement.dir = getHTMLTextDir(locale);
348
+ }, [locale]);
349
+ };
350
+ ```
351
+
352
+ ---
353
+
354
+ ## (Optionnel) Étape 10 : Composant Link localisé
355
+
356
+ TanStack Router fournit un `<Link/>`, mais si vous avez besoin d'un simple `<a>` qui préfixe automatiquement les URL internes :
357
+
358
+ ```tsx fileName="src/components/Link.tsx"
359
+ import { getLocalizedUrl } from "intlayer";
360
+ import {
361
+ forwardRef,
362
+ type AnchorHTMLAttributes,
363
+ type DetailedHTMLProps,
364
+ } from "react";
365
+ import { useLocale } from "react-intlayer";
366
+
367
+ export interface LinkProps
368
+ extends DetailedHTMLProps<
369
+ AnchorHTMLAttributes<HTMLAnchorElement>,
370
+ HTMLAnchorElement
371
+ > {}
372
+
373
+ const isExternal = (href?: string) => /^https?:\/\//.test(href ?? "");
374
+
375
+ export const Link = forwardRef<HTMLAnchorElement, LinkProps>(
376
+ ({ href, children, ...props }, ref) => {
377
+ const { locale } = useLocale();
378
+ const hrefI18n =
379
+ href && !isExternal(href) ? getLocalizedUrl(href, locale) : href;
380
+ return (
381
+ <a href={hrefI18n} ref={ref} {...props}>
382
+ {children}
383
+ </a>
384
+ );
385
+ }
386
+ );
387
+ Link.displayName = "Link";
388
+ ```
389
+
390
+ > Si vous utilisez le Modèle A (basepath), le `<Link to="/about" />` de TanStack résout déjà vers `/fr/about` via `basepath`, donc un lien personnalisé est optionnel.
391
+
392
+ ---
393
+
394
+ ## TypeScript
395
+
396
+ Inclure les types générés par Intlayer :
397
+
398
+ ```json5 fileName="tsconfig.json"
399
+ {
400
+ "include": ["src", ".intlayer/**/*.ts"],
401
+ }
402
+ ```
403
+
404
+ ---
405
+
406
+ ## Git
407
+
408
+ Ignorer les artefacts générés par Intlayer :
409
+
410
+ ```gitignore
411
+ .intlayer
412
+ ```
413
+
414
+ ---
415
+
416
+ ## Extension VS Code
417
+
418
+ - **Extension Intlayer pour VS Code** → autocomplétion, erreurs, aperçus en ligne, actions rapides.
419
+ Marketplace : `intlayer.intlayer-vs-code-extension`
420
+
421
+ ---
422
+
423
+ ## Aller Plus Loin
424
+
425
+ - Éditeur Visuel
426
+ - Mode CMS
427
+ - Détection de la locale à la périphérie / adaptateurs
428
+
429
+ ---
430
+
431
+ ## Historique de la Documentation
432
+
433
+ | Version | Date | Modifications |
434
+ | ------- | ---------- | --------------------------------- |
435
+ | 1.0.0 | 2025-08-11 | Adaptation TanStack Start ajoutée |
@@ -279,7 +279,6 @@ Le package `next-intlayer` fournit également quelques fonctions pour vous aider
279
279
  - [`useIntlayer()`](https://github.com/aymericzip/intlayer/blob/main/docs/docs/fr/packages/next-intlayer/useIntlayer.md)
280
280
  - [`useDictionary()`](https://github.com/aymericzip/intlayer/blob/main/docs/docs/fr/packages/next-intlayer/useDictionary.md)
281
281
  - [`useLocale()`](https://github.com/aymericzip/intlayer/blob/main/docs/docs/fr/packages/next-intlayer/useLocale.md)
282
- - [`useIntlayerAsync()`](https://github.com/aymericzip/intlayer/blob/main/docs/docs/fr/packages/next-intlayer/useIntlayerAsync.md)
283
282
 
284
283
  ## Historique de la documentation
285
284
 
@@ -273,7 +273,6 @@ Le package `react-intlayer` fournit également plusieurs fonctions pour vous aid
273
273
  - [`useIntlayer()`](https://github.com/aymericzip/intlayer/blob/main/docs/docs/fr/packages/react-intlayer/useIntlayer.md)
274
274
  - [`useDictionary()`](https://github.com/aymericzip/intlayer/blob/main/docs/docs/fr/packages/react-intlayer/useDictionary.md)
275
275
  - [`useLocale()`](https://github.com/aymericzip/intlayer/blob/main/docs/docs/fr/packages/react-intlayer/useLocale.md)
276
- - [`useIntlayerAsync()`](https://github.com/aymericzip/intlayer/blob/main/docs/docs/fr/packages/react-intlayer/useIntlayerAsync.md)
277
276
 
278
277
  ## Historique de la documentation
279
278