@intlayer/docs 7.3.11 → 7.3.13
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.
- package/dist/cjs/generated/docs.entry.cjs +19 -0
- package/dist/cjs/generated/docs.entry.cjs.map +1 -1
- package/dist/esm/generated/docs.entry.mjs +19 -0
- package/dist/esm/generated/docs.entry.mjs.map +1 -1
- package/dist/types/generated/docs.entry.d.ts +1 -0
- package/dist/types/generated/docs.entry.d.ts.map +1 -1
- package/docs/ar/intlayer_with_nuxt.md +294 -438
- package/docs/ar/intlayer_with_react_router_v7.md +33 -4
- package/docs/ar/intlayer_with_react_router_v7_fs_routes.md +516 -0
- package/docs/ar/intlayer_with_tanstack.md +2 -12
- package/docs/ar/intlayer_with_vite+vue.md +1 -0
- package/docs/de/intlayer_with_nuxt.md +284 -410
- package/docs/de/intlayer_with_react_router_v7.md +33 -4
- package/docs/de/intlayer_with_react_router_v7_fs_routes.md +573 -0
- package/docs/de/intlayer_with_tanstack.md +1 -0
- package/docs/de/intlayer_with_vite+vue.md +1 -0
- package/docs/en/intlayer_with_nuxt.md +237 -341
- package/docs/en/intlayer_with_react_router_v7.md +24 -0
- package/docs/en/intlayer_with_react_router_v7_fs_routes.md +570 -0
- package/docs/en/intlayer_with_tanstack.md +2 -12
- package/docs/en/intlayer_with_vite+vue.md +49 -48
- package/docs/en-GB/intlayer_with_nuxt.md +254 -378
- package/docs/en-GB/intlayer_with_react_router_v7.md +33 -4
- package/docs/en-GB/intlayer_with_react_router_v7_fs_routes.md +513 -0
- package/docs/en-GB/intlayer_with_tanstack.md +2 -12
- package/docs/en-GB/intlayer_with_vite+vue.md +1 -0
- package/docs/es/intlayer_with_nuxt.md +271 -390
- package/docs/es/intlayer_with_react_router_v7.md +33 -4
- package/docs/es/intlayer_with_react_router_v7_fs_routes.md +575 -0
- package/docs/es/intlayer_with_tanstack.md +1 -0
- package/docs/es/intlayer_with_vite+vue.md +1 -2
- package/docs/fr/intlayer_with_nuxt.md +278 -405
- package/docs/fr/intlayer_with_react_router_v7.md +34 -5
- package/docs/fr/intlayer_with_react_router_v7_fs_routes.md +574 -0
- package/docs/fr/intlayer_with_tanstack.md +1 -0
- package/docs/fr/intlayer_with_vite+vue.md +1 -0
- package/docs/hi/intlayer_with_nuxt.md +303 -447
- package/docs/hi/intlayer_with_react_router_v7.md +33 -4
- package/docs/hi/intlayer_with_react_router_v7_fs_routes.md +518 -0
- package/docs/hi/intlayer_with_tanstack.md +2 -12
- package/docs/hi/intlayer_with_vite+vue.md +1 -0
- package/docs/id/intlayer_with_nuxt.md +266 -395
- package/docs/id/intlayer_with_react_router_v7.md +29 -4
- package/docs/id/intlayer_with_react_router_v7_fs_routes.md +521 -0
- package/docs/id/intlayer_with_tanstack.md +2 -12
- package/docs/id/intlayer_with_vite+vue.md +1 -0
- package/docs/it/intlayer_with_nuxt.md +299 -423
- package/docs/it/intlayer_with_react_router_v7.md +33 -4
- package/docs/it/intlayer_with_react_router_v7_fs_routes.md +574 -0
- package/docs/it/intlayer_with_tanstack.md +1 -0
- package/docs/ja/intlayer_with_nuxt.md +309 -432
- package/docs/ja/intlayer_with_react_router_v7.md +33 -4
- package/docs/ja/intlayer_with_react_router_v7_fs_routes.md +574 -0
- package/docs/ja/intlayer_with_tanstack.md +2 -12
- package/docs/ja/intlayer_with_vite+vue.md +1 -0
- package/docs/ko/intlayer_with_nuxt.md +295 -422
- package/docs/ko/intlayer_with_react_router_v7.md +33 -4
- package/docs/ko/intlayer_with_react_router_v7_fs_routes.md +515 -0
- package/docs/ko/intlayer_with_tanstack.md +2 -12
- package/docs/ko/intlayer_with_vite+vue.md +1 -0
- package/docs/pl/intlayer_with_nuxt.md +273 -476
- package/docs/pl/intlayer_with_react_router_v7.md +32 -5
- package/docs/pl/intlayer_with_react_router_v7_fs_routes.md +615 -0
- package/docs/pl/intlayer_with_tanstack.md +2 -12
- package/docs/pl/intlayer_with_vite+vue.md +1 -0
- package/docs/pt/intlayer_with_nuxt.md +277 -420
- package/docs/pt/intlayer_with_react_router_v7.md +28 -0
- package/docs/pt/intlayer_with_tanstack.md +1 -0
- package/docs/ru/intlayer_with_nuxt.md +287 -425
- package/docs/ru/intlayer_with_react_router_v7.md +33 -4
- package/docs/ru/intlayer_with_react_router_v7_fs_routes.md +574 -0
- package/docs/ru/intlayer_with_tanstack.md +1 -0
- package/docs/ru/intlayer_with_vite+vue.md +1 -0
- package/docs/tr/intlayer_with_nuxt.md +313 -406
- package/docs/tr/intlayer_with_react_router_v7.md +33 -4
- package/docs/tr/intlayer_with_react_router_v7_fs_routes.md +572 -0
- package/docs/tr/intlayer_with_tanstack.md +2 -12
- package/docs/tr/intlayer_with_vite+vue.md +1 -0
- package/docs/vi/intlayer_with_nuxt.md +273 -418
- package/docs/vi/intlayer_with_react_router_v7.md +29 -4
- package/docs/vi/intlayer_with_react_router_v7_fs_routes.md +523 -0
- package/docs/vi/intlayer_with_tanstack.md +2 -12
- package/docs/vi/intlayer_with_vite+vue.md +1 -0
- package/docs/zh/intlayer_with_nuxt.md +300 -461
- package/docs/zh/intlayer_with_react_router_v7.md +33 -4
- package/docs/zh/intlayer_with_react_router_v7_fs_routes.md +516 -0
- package/docs/zh/intlayer_with_tanstack.md +2 -12
- package/docs/zh/intlayer_with_vite+vue.md +1 -0
- package/package.json +10 -11
- package/src/generated/docs.entry.ts +19 -0
|
@@ -18,6 +18,7 @@ slugs:
|
|
|
18
18
|
- vite-and-react
|
|
19
19
|
- react-router-v7
|
|
20
20
|
applicationTemplate: https://github.com/aymericzip/intlayer-react-router-v7-template
|
|
21
|
+
youtubeVideo: https://www.youtube.com/watch?v=dS9L7uJeak4
|
|
21
22
|
history:
|
|
22
23
|
- version: 6.1.5
|
|
23
24
|
date: 2025-10-03
|
|
@@ -31,6 +32,10 @@ history:
|
|
|
31
32
|
|
|
32
33
|
Questa guida dimostra come integrare **Intlayer** per un'internazionalizzazione senza soluzione di continuità nei progetti React Router v7 con routing consapevole della localizzazione, supporto TypeScript e pratiche di sviluppo moderne.
|
|
33
34
|
|
|
35
|
+
## Table of Contents
|
|
36
|
+
|
|
37
|
+
<TOC/>
|
|
38
|
+
|
|
34
39
|
## Cos'è Intlayer?
|
|
35
40
|
|
|
36
41
|
**Intlayer** è una libreria innovativa e open-source per l'internazionalizzazione (i18n) progettata per semplificare il supporto multilingue nelle applicazioni web moderne.
|
|
@@ -73,6 +78,29 @@ pnpm add vite-intlayer --save-dev
|
|
|
73
78
|
|
|
74
79
|
### Passo 2: Configurazione del tuo progetto
|
|
75
80
|
|
|
81
|
+
## Guida passo-passo per configurare Intlayer in un'applicazione React Router v7 con route basate sul file system
|
|
82
|
+
|
|
83
|
+
<Tab defaultTab="video">
|
|
84
|
+
<TabItem label="Video" value="video">
|
|
85
|
+
|
|
86
|
+
<iframe title="How to translate your React Router v7 app using 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?autoplay=0&origin=http://intlayer.org&controls=0&rel=1"/>
|
|
87
|
+
|
|
88
|
+
</TabItem>
|
|
89
|
+
<TabItem label="Code" value="code">
|
|
90
|
+
|
|
91
|
+
<iframe
|
|
92
|
+
src="https://stackblitz.com/github/aymericzip/intlayer-react-router-v7-template?embed=1&ctl=1&file=intlayer.config.ts"
|
|
93
|
+
className="m-auto overflow-hidden rounded-lg border-0 max-md:size-full max-md:h-[700px] md:aspect-16/9 md:w-full"
|
|
94
|
+
title="Demo CodeSandbox - How to Internationalize your application using Intlayer"
|
|
95
|
+
sandbox="allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts"
|
|
96
|
+
loading="lazy"
|
|
97
|
+
/>
|
|
98
|
+
|
|
99
|
+
</TabItem>
|
|
100
|
+
</Tab>
|
|
101
|
+
|
|
102
|
+
See [Application Template](https://github.com/aymericzip/intlayer-react-router-v7-template) on GitHub.
|
|
103
|
+
|
|
76
104
|
Crea un file di configurazione per impostare le lingue della tua applicazione:
|
|
77
105
|
|
|
78
106
|
```typescript fileName="intlayer.config.ts" codeFormat="typescript"
|
|
@@ -259,7 +287,7 @@ export const LocalizedLink: FC<LinkProps> = (props) => {
|
|
|
259
287
|
Nel caso in cui desideri navigare verso le rotte localizzate, puoi utilizzare l'hook `useLocalizedNavigate`:
|
|
260
288
|
|
|
261
289
|
```tsx fileName="app/hooks/useLocalizedNavigate.ts"
|
|
262
|
-
import { useLocale } from "intlayer";
|
|
290
|
+
import { useLocale } from "react-intlayer";
|
|
263
291
|
import { type NavigateOptions, type To, useNavigate } from "react-router";
|
|
264
292
|
|
|
265
293
|
import { locacalizeTo } from "~/components/localized-link";
|
|
@@ -317,6 +345,7 @@ import {
|
|
|
317
345
|
getLocaleName,
|
|
318
346
|
getLocalizedUrl,
|
|
319
347
|
getPathWithoutLocale,
|
|
348
|
+
Locales,
|
|
320
349
|
} from "intlayer";
|
|
321
350
|
import { setLocaleInStorage, useIntlayer, useLocale } from "react-intlayer";
|
|
322
351
|
import { Link, useLocation } from "react-router";
|
|
@@ -410,13 +439,13 @@ Puoi anche utilizzare `intlayerProxy` per aggiungere il routing lato server alla
|
|
|
410
439
|
> Nota che per utilizzare `intlayerProxy` in produzione, è necessario spostare il pacchetto `vite-intlayer` da `devDependencies` a `dependencies`.
|
|
411
440
|
|
|
412
441
|
```typescript {3,7} fileName="vite.config.ts"
|
|
442
|
+
import { reactRouter } from "@react-router/dev/vite";
|
|
413
443
|
import { defineConfig } from "vite";
|
|
414
|
-
import react from "@vitejs/plugin-react-swc";
|
|
415
444
|
import { intlayer, intlayerProxy } from "vite-intlayer";
|
|
445
|
+
import tsconfigPaths from "vite-tsconfig-paths";
|
|
416
446
|
|
|
417
|
-
// https://vitejs.dev/config/
|
|
418
447
|
export default defineConfig({
|
|
419
|
-
plugins: [
|
|
448
|
+
plugins: [reactRouter(), tsconfigPaths(), intlayer(), intlayerProxy()],
|
|
420
449
|
});
|
|
421
450
|
```
|
|
422
451
|
|
|
@@ -0,0 +1,574 @@
|
|
|
1
|
+
---
|
|
2
|
+
createdAt: 2025-12-07
|
|
3
|
+
updatedAt: 2025-12-07
|
|
4
|
+
title: Come tradurre la tua React Router v7 (File-System Routes) – guida i18n 2025
|
|
5
|
+
description: Scopri come aggiungere l'internazionalizzazione (i18n) alla tua applicazione React Router v7 utilizzando Intlayer con routing basato sul file system. Segui questa guida completa per rendere la tua app multilingue con il routing consapevole della localizzazione.
|
|
6
|
+
keywords:
|
|
7
|
+
- Internazionalizzazione
|
|
8
|
+
- Documentazione
|
|
9
|
+
- Intlayer
|
|
10
|
+
- React Router v7
|
|
11
|
+
- fs-routes
|
|
12
|
+
- Route basate sul file system
|
|
13
|
+
- React
|
|
14
|
+
- i18n
|
|
15
|
+
- TypeScript
|
|
16
|
+
- Routing Locale
|
|
17
|
+
slugs:
|
|
18
|
+
- doc
|
|
19
|
+
- environment
|
|
20
|
+
- vite-and-react
|
|
21
|
+
- react-router-v7-fs-routes
|
|
22
|
+
applicationTemplate: https://github.com/aymericzip/intlayer-react-router-v7-fs-routes-template
|
|
23
|
+
youtubeVideo: https://www.youtube.com/watch?v=dS9L7uJeak4
|
|
24
|
+
history:
|
|
25
|
+
- version: 7.3.4
|
|
26
|
+
date: 2025-12-08
|
|
27
|
+
changes: Init history
|
|
28
|
+
---
|
|
29
|
+
|
|
30
|
+
# Traduci la tua React Router v7 (File-System Routes) con Intlayer | Internazionalizzazione (i18n)
|
|
31
|
+
|
|
32
|
+
Questa guida dimostra come integrare **Intlayer** per un'internazionalizzazione senza soluzione di continuità nei progetti React Router v7 usando **routing basato sul file system** (`@react-router/fs-routes`) con routing consapevole della localizzazione, supporto TypeScript e pratiche di sviluppo moderne.
|
|
33
|
+
|
|
34
|
+
## Table of Contents
|
|
35
|
+
|
|
36
|
+
<TOC/>
|
|
37
|
+
|
|
38
|
+
## Cos'è Intlayer?
|
|
39
|
+
|
|
40
|
+
**Intlayer** è una libreria innovativa e open-source per l'internazionalizzazione (i18n) progettata per semplificare il supporto multilingue nelle applicazioni web moderne.
|
|
41
|
+
|
|
42
|
+
Con Intlayer, puoi:
|
|
43
|
+
|
|
44
|
+
- **Gestire facilmente le traduzioni** utilizzando dizionari dichiarativi a livello di componente.
|
|
45
|
+
- **Localizzare dinamicamente i metadata**, le rotte e i contenuti.
|
|
46
|
+
- **Garantire il supporto TypeScript** con tipi generati automaticamente, migliorando l'autocompletamento e il rilevamento degli errori.
|
|
47
|
+
- **Beneficiare di funzionalità avanzate**, come il rilevamento e il cambio dinamico della localizzazione.
|
|
48
|
+
- **Abilitare il routing consapevole della localizzazione** con il sistema di routing basato sul file system di React Router v7.
|
|
49
|
+
|
|
50
|
+
---
|
|
51
|
+
|
|
52
|
+
## Guida passo-passo per configurare Intlayer in un'applicazione React Router v7 con route basate sul file system
|
|
53
|
+
|
|
54
|
+
<Tab defaultTab="video">
|
|
55
|
+
<TabItem label="Video" value="video">
|
|
56
|
+
|
|
57
|
+
<iframe title="How to translate your React Router v7 (File-System Routes) app using 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?autoplay=0&origin=http://intlayer.org&controls=0&rel=1"/>
|
|
58
|
+
|
|
59
|
+
</TabItem>
|
|
60
|
+
<TabItem label="Code" value="code">
|
|
61
|
+
|
|
62
|
+
<iframe
|
|
63
|
+
src="https://stackblitz.com/github/aymericzip/intlayer-react-router-v7-fs-routes-template?embed=1&ctl=1&file=intlayer.config.ts"
|
|
64
|
+
className="m-auto overflow-hidden rounded-lg border-0 max-md:size-full max-md:h-[700px] md:aspect-16/9 md:w-full"
|
|
65
|
+
title="Demo CodeSandbox - How to Internationalize your application using Intlayer"
|
|
66
|
+
sandbox="allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts"
|
|
67
|
+
loading="lazy"
|
|
68
|
+
/>
|
|
69
|
+
|
|
70
|
+
</TabItem>
|
|
71
|
+
</Tab>
|
|
72
|
+
|
|
73
|
+
See [Application Template](https://github.com/aymericzip/intlayer-react-router-v7-fs-routes-template) on GitHub.
|
|
74
|
+
|
|
75
|
+
### Passo 1: Installare le dipendenze
|
|
76
|
+
|
|
77
|
+
Installa i pacchetti necessari usando il tuo gestore di pacchetti preferito:
|
|
78
|
+
|
|
79
|
+
```bash packageManager="npm"
|
|
80
|
+
npm install intlayer react-intlayer
|
|
81
|
+
npm install vite-intlayer --save-dev
|
|
82
|
+
npm install @react-router/fs-routes --save-dev
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
```bash packageManager="pnpm"
|
|
86
|
+
pnpm add intlayer react-intlayer
|
|
87
|
+
pnpm add vite-intlayer --save-dev
|
|
88
|
+
pnpm add @react-router/fs-routes --save-dev
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
- **intlayer**
|
|
92
|
+
|
|
93
|
+
- **Il pacchetto core** che fornisce strumenti di internazionalizzazione per la gestione della configurazione, la traduzione, la [dichiarazione dei contenuti](https://github.com/aymericzip/intlayer/blob/main/docs/docs/it/dictionary/get_started.md), la traspilazione e i [comandi CLI](https://github.com/aymericzip/intlayer/blob/main/docs/docs/it/intlayer_cli.md).
|
|
94
|
+
|
|
95
|
+
- **react-intlayer**
|
|
96
|
+
Il pacchetto che integra Intlayer con l'applicazione React. Fornisce provider di contesto e hook per l'internazionalizzazione in React.
|
|
97
|
+
|
|
98
|
+
- **vite-intlayer**
|
|
99
|
+
Include il plugin Vite per integrare Intlayer con il [bundler Vite](https://vite.dev/guide/why.html#why-bundle-for-production), oltre a middleware per rilevare la locale preferita dall'utente, gestire i cookie e gestire il reindirizzamento degli URL.
|
|
100
|
+
|
|
101
|
+
- **@react-router/fs-routes**
|
|
102
|
+
Il pacchetto che abilita il routing basato sul file system per React Router v7.
|
|
103
|
+
|
|
104
|
+
### Passo 2: Configurazione del tuo progetto
|
|
105
|
+
|
|
106
|
+
Crea un file di configurazione per impostare le lingue della tua applicazione:
|
|
107
|
+
|
|
108
|
+
```typescript fileName="intlayer.config.ts" codeFormat="typescript"
|
|
109
|
+
import { type IntlayerConfig, Locales } from "intlayer";
|
|
110
|
+
|
|
111
|
+
const config: IntlayerConfig = {
|
|
112
|
+
internationalization: {
|
|
113
|
+
defaultLocale: Locales.ENGLISH,
|
|
114
|
+
locales: [Locales.ENGLISH, Locales.FRENCH, Locales.SPANISH],
|
|
115
|
+
},
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
export default config;
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
```javascript fileName="intlayer.config.mjs" codeFormat="esm"
|
|
122
|
+
import { Locales } from "intlayer";
|
|
123
|
+
|
|
124
|
+
/** @type {import('intlayer').IntlayerConfig} */
|
|
125
|
+
// Configurazione per l'internazionalizzazione
|
|
126
|
+
const config = {
|
|
127
|
+
internationalization: {
|
|
128
|
+
defaultLocale: Locales.ENGLISH,
|
|
129
|
+
locales: [Locales.ENGLISH, Locales.FRENCH, Locales.SPANISH],
|
|
130
|
+
},
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
export default config;
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
```javascript fileName="intlayer.config.cjs" codeFormat="commonjs"
|
|
137
|
+
const { Locales } = require("intlayer");
|
|
138
|
+
|
|
139
|
+
/** @type {import('intlayer').IntlayerConfig} */
|
|
140
|
+
// Configurazione per Intlayer
|
|
141
|
+
const config = {
|
|
142
|
+
internationalization: {
|
|
143
|
+
defaultLocale: Locales.ENGLISH, // Lingua predefinita
|
|
144
|
+
locales: [Locales.ENGLISH, Locales.FRENCH, Locales.SPANISH], // Lingue supportate
|
|
145
|
+
},
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
module.exports = config;
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
> Attraverso questo file di configurazione, puoi impostare URL localizzati, reindirizzamenti middleware, nomi dei cookie, la posizione e l'estensione delle dichiarazioni di contenuto, disabilitare i log di Intlayer nella console e altro ancora. Per un elenco completo dei parametri disponibili, consulta la [documentazione di configurazione](https://github.com/aymericzip/intlayer/blob/main/docs/docs/it/configuration.md).
|
|
152
|
+
|
|
153
|
+
### Passo 3: Integra Intlayer nella tua configurazione Vite
|
|
154
|
+
|
|
155
|
+
Aggiungi il plugin intlayer nella tua configurazione:
|
|
156
|
+
|
|
157
|
+
```typescript fileName="vite.config.ts"
|
|
158
|
+
import { reactRouter } from "@react-router/dev/vite";
|
|
159
|
+
import { defineConfig } from "vite";
|
|
160
|
+
import { intlayer } from "vite-intlayer";
|
|
161
|
+
import tsconfigPaths from "vite-tsconfig-paths";
|
|
162
|
+
|
|
163
|
+
export default defineConfig({
|
|
164
|
+
plugins: [reactRouter(), tsconfigPaths(), intlayer()],
|
|
165
|
+
});
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
> Il plugin Vite `intlayer()` viene utilizzato per integrare Intlayer con Vite. Garantisce la creazione dei file di dichiarazione dei contenuti e li monitora in modalità sviluppo. Definisce le variabili d'ambiente di Intlayer all'interno dell'applicazione Vite. Inoltre, fornisce alias per ottimizzare le prestazioni.
|
|
169
|
+
|
|
170
|
+
### Passo 4: Configurare le rotte basate sul file system di React Router v7
|
|
171
|
+
|
|
172
|
+
Configura la tua configurazione di routing per utilizzare rotte basate sul file system con `flatRoutes`:
|
|
173
|
+
|
|
174
|
+
```typescript fileName="app/routes.ts"
|
|
175
|
+
import type { RouteConfig } from "@react-router/dev/routes";
|
|
176
|
+
import { flatRoutes } from "@react-router/fs-routes";
|
|
177
|
+
import { configuration } from "intlayer";
|
|
178
|
+
|
|
179
|
+
const routes: RouteConfig = flatRoutes({
|
|
180
|
+
// Ignorare i file di dichiarazione del contenuto per evitare che vengano trattati come rotte
|
|
181
|
+
ignoredRouteFiles: configuration.content.fileExtensions.map(
|
|
182
|
+
(fileExtension) => `**/*${fileExtension}`
|
|
183
|
+
),
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
export default routes;
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
> La funzione `flatRoutes` di `@react-router/fs-routes` abilita il routing basato sul file system, dove la struttura dei file nella directory `routes/` determina le rotte della tua applicazione. L'opzione `ignoredRouteFiles` garantisce che i file di dichiarazione del contenuto Intlayer (`.content.ts`, ecc.) non vengano trattati come file di rotta.
|
|
190
|
+
|
|
191
|
+
### Passo 5: Creare file di rotta con convenzioni del file system
|
|
192
|
+
|
|
193
|
+
Con il routing basato sul file system, usi una convenzione di denominazione piatta dove i punti (`.`) rappresentano segmenti di percorso e le parentesi `()` denotano segmenti opzionali.
|
|
194
|
+
|
|
195
|
+
Crea i seguenti file nella directory `app/routes/`:
|
|
196
|
+
|
|
197
|
+
#### Struttura dei file
|
|
198
|
+
|
|
199
|
+
```bash
|
|
200
|
+
app/routes/
|
|
201
|
+
├── ($locale)._layout.tsx # Wrapper di layout per le rotte di locale
|
|
202
|
+
├── ($locale)._index.tsx # Pagina iniziale (/:locale?)
|
|
203
|
+
├── ($locale)._index.content.ts # Contenuto della pagina iniziale
|
|
204
|
+
├── ($locale).about.tsx # Pagina About (/:locale?/about)
|
|
205
|
+
└── ($locale).about.content.ts # Contenuto della pagina About
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
Le convenzioni di denominazione:
|
|
209
|
+
|
|
210
|
+
- `($locale)` - Segmento dinamico opzionale per il parametro locale
|
|
211
|
+
- `_layout` - Rotta di layout che avvolge le rotte figlie
|
|
212
|
+
- `_index` - Rotta di indice (viene renderizzata al percorso padre)
|
|
213
|
+
- `.` (punto) - Separa i segmenti di percorso (ad esempio, `($locale).about` → `/:locale?/about`)
|
|
214
|
+
|
|
215
|
+
#### Componente Layout
|
|
216
|
+
|
|
217
|
+
```tsx fileName="app/routes/($locale)._layout.tsx"
|
|
218
|
+
import { IntlayerProvider } from "react-intlayer";
|
|
219
|
+
import { Outlet } from "react-router";
|
|
220
|
+
|
|
221
|
+
import { useI18nHTMLAttributes } from "~/hooks/useI18nHTMLAttributes";
|
|
222
|
+
|
|
223
|
+
import type { Route } from "./+types/($locale)._layout";
|
|
224
|
+
|
|
225
|
+
export default function RootLayout({ params }: Route.ComponentProps) {
|
|
226
|
+
useI18nHTMLAttributes();
|
|
227
|
+
|
|
228
|
+
const { locale } = params;
|
|
229
|
+
|
|
230
|
+
return (
|
|
231
|
+
<IntlayerProvider locale={locale}>
|
|
232
|
+
<Outlet />
|
|
233
|
+
</IntlayerProvider>
|
|
234
|
+
);
|
|
235
|
+
}
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
#### Pagina Indice
|
|
239
|
+
|
|
240
|
+
```tsx fileName="app/routes/($locale)._index.tsx"
|
|
241
|
+
import { useIntlayer } from "react-intlayer";
|
|
242
|
+
import { LocalizedLink } from "~/components/localized-link";
|
|
243
|
+
|
|
244
|
+
import type { Route } from "./+types/($locale)._index";
|
|
245
|
+
|
|
246
|
+
export default function Page() {
|
|
247
|
+
const { title, description, aboutLink } = useIntlayer("page");
|
|
248
|
+
|
|
249
|
+
return (
|
|
250
|
+
<div>
|
|
251
|
+
<h1>{title}</h1>
|
|
252
|
+
<p>{description}</p>
|
|
253
|
+
<nav>
|
|
254
|
+
<LocalizedLink to="/about">{aboutLink}</LocalizedLink>
|
|
255
|
+
</nav>
|
|
256
|
+
</div>
|
|
257
|
+
);
|
|
258
|
+
}
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
#### Pagina About
|
|
262
|
+
|
|
263
|
+
```tsx fileName="app/routes/($locale).about.tsx"
|
|
264
|
+
import { useIntlayer } from "react-intlayer";
|
|
265
|
+
import { LocalizedLink } from "~/components/localized-link";
|
|
266
|
+
|
|
267
|
+
import type { Route } from "./+types/($locale).about";
|
|
268
|
+
|
|
269
|
+
export default function AboutPage() {
|
|
270
|
+
const { title, content, homeLink } = useIntlayer("about");
|
|
271
|
+
|
|
272
|
+
return (
|
|
273
|
+
<div>
|
|
274
|
+
<h1>{title}</h1>
|
|
275
|
+
<p>{content}</p>
|
|
276
|
+
<nav>
|
|
277
|
+
<LocalizedLink to="/">{homeLink}</LocalizedLink>
|
|
278
|
+
</nav>
|
|
279
|
+
</div>
|
|
280
|
+
);
|
|
281
|
+
}
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
### Passo 6: Dichiarare il Tuo Contenuto
|
|
285
|
+
|
|
286
|
+
Crea e gestisci le tue dichiarazioni di contenuto per memorizzare le traduzioni. Posiziona i file di contenuto accanto ai file di rotta:
|
|
287
|
+
|
|
288
|
+
```tsx fileName="app/routes/($locale)._index.content.ts"
|
|
289
|
+
import { t, type Dictionary } from "intlayer";
|
|
290
|
+
|
|
291
|
+
const pageContent = {
|
|
292
|
+
key: "page",
|
|
293
|
+
content: {
|
|
294
|
+
title: t({
|
|
295
|
+
en: "Welcome to React Router v7 + Intlayer",
|
|
296
|
+
es: "Bienvenido a React Router v7 + Intlayer",
|
|
297
|
+
fr: "Bienvenue sur React Router v7 + Intlayer",
|
|
298
|
+
}),
|
|
299
|
+
description: t({
|
|
300
|
+
en: "Build multilingual applications with ease using React Router v7 and Intlayer.",
|
|
301
|
+
es: "Cree aplicaciones multilingües fácilmente usando React Router v7 y Intlayer.",
|
|
302
|
+
fr: "Créez des applications multilingues facilement avec React Router v7 et Intlayer.",
|
|
303
|
+
}),
|
|
304
|
+
aboutLink: t({
|
|
305
|
+
en: "Learn About Us",
|
|
306
|
+
es: "Aprender Sobre Nosotros",
|
|
307
|
+
fr: "En savoir plus sur nous",
|
|
308
|
+
}),
|
|
309
|
+
},
|
|
310
|
+
} satisfies Dictionary;
|
|
311
|
+
|
|
312
|
+
export default pageContent;
|
|
313
|
+
```
|
|
314
|
+
|
|
315
|
+
```tsx fileName="app/routes/($locale).about.content.ts"
|
|
316
|
+
import { t, type Dictionary } from "intlayer";
|
|
317
|
+
|
|
318
|
+
const aboutContent = {
|
|
319
|
+
key: "about",
|
|
320
|
+
content: {
|
|
321
|
+
title: t({
|
|
322
|
+
en: "About Us",
|
|
323
|
+
es: "Sobre Nosotros",
|
|
324
|
+
fr: "À propos de nous",
|
|
325
|
+
}),
|
|
326
|
+
content: t({
|
|
327
|
+
en: "This is the about page content.",
|
|
328
|
+
es: "Este es el contenido de la página de información.",
|
|
329
|
+
fr: "Ceci est le contenu de la page à propos.",
|
|
330
|
+
}),
|
|
331
|
+
homeLink: t({
|
|
332
|
+
en: "Home",
|
|
333
|
+
es: "Inicio",
|
|
334
|
+
fr: "Accueil",
|
|
335
|
+
}),
|
|
336
|
+
},
|
|
337
|
+
} satisfies Dictionary;
|
|
338
|
+
|
|
339
|
+
export default aboutContent;
|
|
340
|
+
```
|
|
341
|
+
|
|
342
|
+
> Le tue dichiarazioni di contenuto possono essere definite ovunque nella tua applicazione non appena vengono incluse nella directory `contentDir` (per default, `./app`). E devono corrispondere all'estensione del file di dichiarazione del contenuto (per default, `.content.{json,ts,tsx,js,jsx,mjs,mjx,cjs,cjx}`).
|
|
343
|
+
|
|
344
|
+
> Per maggiori dettagli, consulta la [documentazione sulla dichiarazione del contenuto](https://github.com/aymericzip/intlayer/blob/main/docs/docs/it/dictionary/get_started.md).
|
|
345
|
+
|
|
346
|
+
### Passo 7: Crea Componenti Consapevoli della Locale
|
|
347
|
+
|
|
348
|
+
Crea un componente `LocalizedLink` per una navigazione consapevole della locale:
|
|
349
|
+
|
|
350
|
+
```tsx fileName="app/components/localized-link.tsx"
|
|
351
|
+
import type { FC } from "react";
|
|
352
|
+
|
|
353
|
+
import { getLocalizedUrl, type LocalesValues } from "intlayer";
|
|
354
|
+
import { useLocale } from "react-intlayer";
|
|
355
|
+
import { Link, type LinkProps, type To } from "react-router";
|
|
356
|
+
|
|
357
|
+
const isExternalLink = (to: string) => /^(https?:)?\/\//.test(to);
|
|
358
|
+
|
|
359
|
+
// Funzione per localizzare l'URL in base alla lingua
|
|
360
|
+
export const locacalizeTo = (to: To, locale: LocalesValues): To => {
|
|
361
|
+
if (typeof to === "string") {
|
|
362
|
+
if (isExternalLink(to)) {
|
|
363
|
+
return to;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
return getLocalizedUrl(to, locale);
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
if (isExternalLink(to.pathname ?? "")) {
|
|
370
|
+
return to;
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
return {
|
|
374
|
+
...to,
|
|
375
|
+
pathname: getLocalizedUrl(to.pathname ?? "", locale),
|
|
376
|
+
};
|
|
377
|
+
};
|
|
378
|
+
|
|
379
|
+
// Componente per link localizzati
|
|
380
|
+
export const LocalizedLink: FC<LinkProps> = (props) => {
|
|
381
|
+
const { locale } = useLocale();
|
|
382
|
+
|
|
383
|
+
return <Link {...props} to={locacalizeTo(props.to, locale)} />;
|
|
384
|
+
};
|
|
385
|
+
```
|
|
386
|
+
|
|
387
|
+
Nel caso in cui desideri navigare verso le rotte localizzate, puoi utilizzare l'hook `useLocalizedNavigate`:
|
|
388
|
+
|
|
389
|
+
```tsx fileName="app/hooks/useLocalizedNavigate.ts"
|
|
390
|
+
import { useLocale } from "react-intlayer";
|
|
391
|
+
import { type NavigateOptions, type To, useNavigate } from "react-router";
|
|
392
|
+
|
|
393
|
+
import { locacalizeTo } from "~/components/localized-link";
|
|
394
|
+
|
|
395
|
+
export const useLocalizedNavigate = () => {
|
|
396
|
+
const navigate = useNavigate();
|
|
397
|
+
const { locale } = useLocale();
|
|
398
|
+
|
|
399
|
+
const localizedNavigate = (to: To, options?: NavigateOptions) => {
|
|
400
|
+
const localedTo = locacalizeTo(to, locale);
|
|
401
|
+
|
|
402
|
+
navigate(localedTo, options);
|
|
403
|
+
};
|
|
404
|
+
|
|
405
|
+
return localizedNavigate;
|
|
406
|
+
};
|
|
407
|
+
```
|
|
408
|
+
|
|
409
|
+
### Passo 8: Crea un Componente per il Selettore di Lingua
|
|
410
|
+
|
|
411
|
+
Crea un componente per permettere agli utenti di cambiare lingua:
|
|
412
|
+
|
|
413
|
+
```tsx fileName="app/components/locale-switcher.tsx"
|
|
414
|
+
import type { FC } from "react";
|
|
415
|
+
|
|
416
|
+
import {
|
|
417
|
+
getHTMLTextDir,
|
|
418
|
+
getLocaleName,
|
|
419
|
+
getLocalizedUrl,
|
|
420
|
+
getPathWithoutLocale,
|
|
421
|
+
Locales,
|
|
422
|
+
} from "intlayer";
|
|
423
|
+
import { useIntlayer, useLocale } from "react-intlayer";
|
|
424
|
+
import { Link, useLocation } from "react-router";
|
|
425
|
+
|
|
426
|
+
export const LocaleSwitcher: FC = () => {
|
|
427
|
+
const { localeSwitcherLabel } = useIntlayer("locale-switcher");
|
|
428
|
+
const { pathname } = useLocation();
|
|
429
|
+
|
|
430
|
+
const { availableLocales, locale } = useLocale();
|
|
431
|
+
|
|
432
|
+
const pathWithoutLocale = getPathWithoutLocale(pathname);
|
|
433
|
+
|
|
434
|
+
return (
|
|
435
|
+
<ol>
|
|
436
|
+
{availableLocales.map((localeItem) => (
|
|
437
|
+
<li key={localeItem}>
|
|
438
|
+
<Link
|
|
439
|
+
aria-current={localeItem === locale ? "page" : undefined}
|
|
440
|
+
aria-label={`${localeSwitcherLabel.value} ${getLocaleName(localeItem)}`}
|
|
441
|
+
reloadDocument // Ricaricare la pagina per applicare la nuova locale
|
|
442
|
+
to={getLocalizedUrl(pathWithoutLocale, localeItem)}
|
|
443
|
+
>
|
|
444
|
+
<span>
|
|
445
|
+
{/* Locale - es. FR */}
|
|
446
|
+
{localeItem}
|
|
447
|
+
</span>
|
|
448
|
+
<span>
|
|
449
|
+
{/* Lingua nella propria Locale - es. Français */}
|
|
450
|
+
{getLocaleName(localeItem, locale)}
|
|
451
|
+
</span>
|
|
452
|
+
<span dir={getHTMLTextDir(localeItem)} lang={localeItem}>
|
|
453
|
+
{/* Lingua nella Locale corrente - es. Francés con la locale corrente impostata su Locales.SPANISH */}
|
|
454
|
+
{getLocaleName(localeItem)}
|
|
455
|
+
</span>
|
|
456
|
+
<span dir="ltr" lang={Locales.ENGLISH}>
|
|
457
|
+
{/* Lingua in inglese - es. French */}
|
|
458
|
+
{getLocaleName(localeItem, Locales.ENGLISH)}
|
|
459
|
+
</span>
|
|
460
|
+
</Link>
|
|
461
|
+
</li>
|
|
462
|
+
))}
|
|
463
|
+
</ol>
|
|
464
|
+
);
|
|
465
|
+
};
|
|
466
|
+
```
|
|
467
|
+
|
|
468
|
+
> Per saperne di più sull'hook `useLocale`, consulta la [documentazione](https://github.com/aymericzip/intlayer/blob/main/docs/docs/it/packages/react-intlayer/useLocale.md).
|
|
469
|
+
|
|
470
|
+
### Passo 10: Aggiungere la gestione degli attributi HTML (Opzionale)
|
|
471
|
+
|
|
472
|
+
Crea un hook per gestire gli attributi lang e dir dell'HTML:
|
|
473
|
+
|
|
474
|
+
```tsx fileName="app/hooks/useI18nHTMLAttributes.tsx"
|
|
475
|
+
import { getHTMLTextDir } from "intlayer";
|
|
476
|
+
import { useEffect } from "react";
|
|
477
|
+
import { useLocale } from "react-intlayer";
|
|
478
|
+
|
|
479
|
+
export const useI18nHTMLAttributes = () => {
|
|
480
|
+
const { locale } = useLocale();
|
|
481
|
+
|
|
482
|
+
useEffect(() => {
|
|
483
|
+
document.documentElement.lang = locale;
|
|
484
|
+
document.documentElement.dir = getHTMLTextDir(locale);
|
|
485
|
+
}, [locale]);
|
|
486
|
+
};
|
|
487
|
+
```
|
|
488
|
+
|
|
489
|
+
Questo hook è già utilizzato nel componente di layout (`($locale)._layout.tsx`) mostrato nel Passo 5.
|
|
490
|
+
|
|
491
|
+
### Passo 10: Aggiungere il middleware (Opzionale)
|
|
492
|
+
|
|
493
|
+
Puoi anche utilizzare `intlayerProxy` per aggiungere il routing lato server alla tua applicazione. Questo plugin rileverà automaticamente la lingua corrente basandosi sull'URL e imposterà il cookie della lingua appropriata. Se non viene specificata alcuna lingua, il plugin determinerà la lingua più adatta in base alle preferenze linguistiche del browser dell'utente. Se non viene rilevata alcuna lingua, verrà effettuato un reindirizzamento alla lingua predefinita.
|
|
494
|
+
|
|
495
|
+
> Nota che per utilizzare `intlayerProxy` in produzione, è necessario spostare il pacchetto `vite-intlayer` da `devDependencies` a `dependencies`.
|
|
496
|
+
|
|
497
|
+
```typescript {3,7} fileName="vite.config.ts"
|
|
498
|
+
import { reactRouter } from "@react-router/dev/vite";
|
|
499
|
+
import { defineConfig } from "vite";
|
|
500
|
+
import { intlayer, intlayerProxy } from "vite-intlayer";
|
|
501
|
+
import tsconfigPaths from "vite-tsconfig-paths";
|
|
502
|
+
|
|
503
|
+
export default defineConfig({
|
|
504
|
+
plugins: [reactRouter(), tsconfigPaths(), intlayer(), intlayerProxy()],
|
|
505
|
+
});
|
|
506
|
+
```
|
|
507
|
+
|
|
508
|
+
---
|
|
509
|
+
|
|
510
|
+
## Configurare TypeScript
|
|
511
|
+
|
|
512
|
+
Intlayer utilizza l'augmentation dei moduli per sfruttare i vantaggi di TypeScript e rendere il tuo codice più robusto.
|
|
513
|
+
|
|
514
|
+
Assicurati che la tua configurazione di TypeScript includa i tipi generati automaticamente:
|
|
515
|
+
|
|
516
|
+
```json5 fileName="tsconfig.json"
|
|
517
|
+
{
|
|
518
|
+
// ... le tue configurazioni esistenti
|
|
519
|
+
include: [
|
|
520
|
+
// ... i tuoi include esistenti
|
|
521
|
+
".intlayer/**/*.ts", // Includi i tipi generati automaticamente
|
|
522
|
+
],
|
|
523
|
+
}
|
|
524
|
+
```
|
|
525
|
+
|
|
526
|
+
---
|
|
527
|
+
|
|
528
|
+
## Configurazione Git
|
|
529
|
+
|
|
530
|
+
È consigliato ignorare i file generati da Intlayer. Questo ti permette di evitare di committarli nel tuo repository Git.
|
|
531
|
+
|
|
532
|
+
Per farlo, puoi aggiungere le seguenti istruzioni nel tuo file `.gitignore`:
|
|
533
|
+
|
|
534
|
+
```plaintext fileName=".gitignore"
|
|
535
|
+
# Ignora i file generati da Intlayer
|
|
536
|
+
.intlayer
|
|
537
|
+
```
|
|
538
|
+
|
|
539
|
+
---
|
|
540
|
+
|
|
541
|
+
## Estensione VS Code
|
|
542
|
+
|
|
543
|
+
Per migliorare la tua esperienza di sviluppo con Intlayer, puoi installare l'**Estensione ufficiale Intlayer per VS Code**.
|
|
544
|
+
|
|
545
|
+
[Installa dal Marketplace di VS Code](https://marketplace.visualstudio.com/items?itemName=intlayer.intlayer-vs-code-extension)
|
|
546
|
+
|
|
547
|
+
Questa estensione offre:
|
|
548
|
+
|
|
549
|
+
- **Completamento automatico** per le chiavi di traduzione.
|
|
550
|
+
- **Rilevamento errori in tempo reale** per traduzioni mancanti.
|
|
551
|
+
- **Anteprime inline** del contenuto tradotto.
|
|
552
|
+
- **Azioni rapide** per creare e aggiornare facilmente le traduzioni.
|
|
553
|
+
|
|
554
|
+
Per maggiori dettagli su come utilizzare l'estensione, consulta la [documentazione dell'Estensione Intlayer per VS Code](https://intlayer.org/doc/vs-code-extension).
|
|
555
|
+
|
|
556
|
+
---
|
|
557
|
+
|
|
558
|
+
## Andare Oltre
|
|
559
|
+
|
|
560
|
+
Per andare oltre, puoi implementare l’[editor visuale](https://github.com/aymericzip/intlayer/blob/main/docs/docs/it/intlayer_visual_editor.md) oppure esternalizzare i tuoi contenuti utilizzando il [CMS](https://github.com/aymericzip/intlayer/blob/main/docs/docs/it/intlayer_CMS.md).
|
|
561
|
+
|
|
562
|
+
---
|
|
563
|
+
|
|
564
|
+
## Riferimenti alla Documentazione
|
|
565
|
+
|
|
566
|
+
- [Documentazione Intlayer](https://intlayer.org)
|
|
567
|
+
- [Documentazione React Router v7](https://reactrouter.com/)
|
|
568
|
+
- [Documentazione React Router fs-routes](https://reactrouter.com/how-to/file-route-conventions)
|
|
569
|
+
- [Hook useIntlayer](https://github.com/aymericzip/intlayer/blob/main/docs/docs/it/packages/react-intlayer/useIntlayer.md)
|
|
570
|
+
- [Hook useLocale](https://github.com/aymericzip/intlayer/blob/main/docs/docs/it/packages/react-intlayer/useLocale.md)
|
|
571
|
+
- [Dichiarazione dei Contenuti](https://github.com/aymericzip/intlayer/blob/main/docs/docs/it/dictionary/get_started.md)
|
|
572
|
+
- [Configurazione](https://github.com/aymericzip/intlayer/blob/main/docs/docs/it/configuration.md)
|
|
573
|
+
|
|
574
|
+
Questa guida completa fornisce tutto il necessario per integrare Intlayer con React Router v7 usando routing basato sul file system per un'applicazione completamente internazionalizzata con routing consapevole della localizzazione e supporto TypeScript.
|