@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.
Files changed (90) hide show
  1. package/dist/cjs/generated/docs.entry.cjs +19 -0
  2. package/dist/cjs/generated/docs.entry.cjs.map +1 -1
  3. package/dist/esm/generated/docs.entry.mjs +19 -0
  4. package/dist/esm/generated/docs.entry.mjs.map +1 -1
  5. package/dist/types/generated/docs.entry.d.ts +1 -0
  6. package/dist/types/generated/docs.entry.d.ts.map +1 -1
  7. package/docs/ar/intlayer_with_nuxt.md +294 -438
  8. package/docs/ar/intlayer_with_react_router_v7.md +33 -4
  9. package/docs/ar/intlayer_with_react_router_v7_fs_routes.md +516 -0
  10. package/docs/ar/intlayer_with_tanstack.md +2 -12
  11. package/docs/ar/intlayer_with_vite+vue.md +1 -0
  12. package/docs/de/intlayer_with_nuxt.md +284 -410
  13. package/docs/de/intlayer_with_react_router_v7.md +33 -4
  14. package/docs/de/intlayer_with_react_router_v7_fs_routes.md +573 -0
  15. package/docs/de/intlayer_with_tanstack.md +1 -0
  16. package/docs/de/intlayer_with_vite+vue.md +1 -0
  17. package/docs/en/intlayer_with_nuxt.md +237 -341
  18. package/docs/en/intlayer_with_react_router_v7.md +24 -0
  19. package/docs/en/intlayer_with_react_router_v7_fs_routes.md +570 -0
  20. package/docs/en/intlayer_with_tanstack.md +2 -12
  21. package/docs/en/intlayer_with_vite+vue.md +49 -48
  22. package/docs/en-GB/intlayer_with_nuxt.md +254 -378
  23. package/docs/en-GB/intlayer_with_react_router_v7.md +33 -4
  24. package/docs/en-GB/intlayer_with_react_router_v7_fs_routes.md +513 -0
  25. package/docs/en-GB/intlayer_with_tanstack.md +2 -12
  26. package/docs/en-GB/intlayer_with_vite+vue.md +1 -0
  27. package/docs/es/intlayer_with_nuxt.md +271 -390
  28. package/docs/es/intlayer_with_react_router_v7.md +33 -4
  29. package/docs/es/intlayer_with_react_router_v7_fs_routes.md +575 -0
  30. package/docs/es/intlayer_with_tanstack.md +1 -0
  31. package/docs/es/intlayer_with_vite+vue.md +1 -2
  32. package/docs/fr/intlayer_with_nuxt.md +278 -405
  33. package/docs/fr/intlayer_with_react_router_v7.md +34 -5
  34. package/docs/fr/intlayer_with_react_router_v7_fs_routes.md +574 -0
  35. package/docs/fr/intlayer_with_tanstack.md +1 -0
  36. package/docs/fr/intlayer_with_vite+vue.md +1 -0
  37. package/docs/hi/intlayer_with_nuxt.md +303 -447
  38. package/docs/hi/intlayer_with_react_router_v7.md +33 -4
  39. package/docs/hi/intlayer_with_react_router_v7_fs_routes.md +518 -0
  40. package/docs/hi/intlayer_with_tanstack.md +2 -12
  41. package/docs/hi/intlayer_with_vite+vue.md +1 -0
  42. package/docs/id/intlayer_with_nuxt.md +266 -395
  43. package/docs/id/intlayer_with_react_router_v7.md +29 -4
  44. package/docs/id/intlayer_with_react_router_v7_fs_routes.md +521 -0
  45. package/docs/id/intlayer_with_tanstack.md +2 -12
  46. package/docs/id/intlayer_with_vite+vue.md +1 -0
  47. package/docs/it/intlayer_with_nuxt.md +299 -423
  48. package/docs/it/intlayer_with_react_router_v7.md +33 -4
  49. package/docs/it/intlayer_with_react_router_v7_fs_routes.md +574 -0
  50. package/docs/it/intlayer_with_tanstack.md +1 -0
  51. package/docs/ja/intlayer_with_nuxt.md +309 -432
  52. package/docs/ja/intlayer_with_react_router_v7.md +33 -4
  53. package/docs/ja/intlayer_with_react_router_v7_fs_routes.md +574 -0
  54. package/docs/ja/intlayer_with_tanstack.md +2 -12
  55. package/docs/ja/intlayer_with_vite+vue.md +1 -0
  56. package/docs/ko/intlayer_with_nuxt.md +295 -422
  57. package/docs/ko/intlayer_with_react_router_v7.md +33 -4
  58. package/docs/ko/intlayer_with_react_router_v7_fs_routes.md +515 -0
  59. package/docs/ko/intlayer_with_tanstack.md +2 -12
  60. package/docs/ko/intlayer_with_vite+vue.md +1 -0
  61. package/docs/pl/intlayer_with_nuxt.md +273 -476
  62. package/docs/pl/intlayer_with_react_router_v7.md +32 -5
  63. package/docs/pl/intlayer_with_react_router_v7_fs_routes.md +615 -0
  64. package/docs/pl/intlayer_with_tanstack.md +2 -12
  65. package/docs/pl/intlayer_with_vite+vue.md +1 -0
  66. package/docs/pt/intlayer_with_nuxt.md +277 -420
  67. package/docs/pt/intlayer_with_react_router_v7.md +28 -0
  68. package/docs/pt/intlayer_with_tanstack.md +1 -0
  69. package/docs/ru/intlayer_with_nuxt.md +287 -425
  70. package/docs/ru/intlayer_with_react_router_v7.md +33 -4
  71. package/docs/ru/intlayer_with_react_router_v7_fs_routes.md +574 -0
  72. package/docs/ru/intlayer_with_tanstack.md +1 -0
  73. package/docs/ru/intlayer_with_vite+vue.md +1 -0
  74. package/docs/tr/intlayer_with_nuxt.md +313 -406
  75. package/docs/tr/intlayer_with_react_router_v7.md +33 -4
  76. package/docs/tr/intlayer_with_react_router_v7_fs_routes.md +572 -0
  77. package/docs/tr/intlayer_with_tanstack.md +2 -12
  78. package/docs/tr/intlayer_with_vite+vue.md +1 -0
  79. package/docs/vi/intlayer_with_nuxt.md +273 -418
  80. package/docs/vi/intlayer_with_react_router_v7.md +29 -4
  81. package/docs/vi/intlayer_with_react_router_v7_fs_routes.md +523 -0
  82. package/docs/vi/intlayer_with_tanstack.md +2 -12
  83. package/docs/vi/intlayer_with_vite+vue.md +1 -0
  84. package/docs/zh/intlayer_with_nuxt.md +300 -461
  85. package/docs/zh/intlayer_with_react_router_v7.md +33 -4
  86. package/docs/zh/intlayer_with_react_router_v7_fs_routes.md +516 -0
  87. package/docs/zh/intlayer_with_tanstack.md +2 -12
  88. package/docs/zh/intlayer_with_vite+vue.md +1 -0
  89. package/package.json +10 -11
  90. 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
  Esta guía demuestra cómo integrar **Intlayer** para una internacionalización fluida en proyectos con React Router v7, con enrutamiento consciente del locale, soporte para TypeScript y prácticas modernas de desarrollo.
33
34
 
35
+ ## Table of Contents
36
+
37
+ <TOC/>
38
+
34
39
  ## ¿Qué es Intlayer?
35
40
 
36
41
  **Intlayer** es una biblioteca innovadora y de código abierto para internacionalización (i18n) diseñada para simplificar el soporte multilingüe en aplicaciones web modernas.
@@ -75,6 +80,29 @@ pnpm add vite-intlayer --save-dev
75
80
 
76
81
  ### Paso 2: Configuración de tu proyecto
77
82
 
83
+ ## Guía paso a paso para configurar Intlayer en una aplicación React Router v7 con rutas basadas en el sistema de archivos
84
+
85
+ <Tab defaultTab="video">
86
+ <TabItem label="Video" value="video">
87
+
88
+ <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&amp;origin=http://intlayer.org&amp;controls=0&amp;rel=1"/>
89
+
90
+ </TabItem>
91
+ <TabItem label="Code" value="code">
92
+
93
+ <iframe
94
+ src="https://stackblitz.com/github/aymericzip/intlayer-react-router-v7-template?embed=1&ctl=1&file=intlayer.config.ts"
95
+ className="m-auto overflow-hidden rounded-lg border-0 max-md:size-full max-md:h-[700px] md:aspect-16/9 md:w-full"
96
+ title="Demo CodeSandbox - How to Internationalize your application using Intlayer"
97
+ sandbox="allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts"
98
+ loading="lazy"
99
+ />
100
+
101
+ </TabItem>
102
+ </Tab>
103
+
104
+ See [Application Template](https://github.com/aymericzip/intlayer-react-router-v7-template) on GitHub.
105
+
78
106
  Crea un archivo de configuración para configurar los idiomas de tu aplicación:
79
107
 
80
108
  ```typescript fileName="intlayer.config.ts" codeFormat="typescript"
@@ -260,7 +288,7 @@ export const LocalizedLink: FC<LinkProps> = (props) => {
260
288
  En caso de que desees navegar a las rutas localizadas, puedes usar el hook `useLocalizedNavigate`:
261
289
 
262
290
  ```tsx fileName="app/hooks/useLocalizedNavigate.ts"
263
- import { useLocale } from "intlayer";
291
+ import { useLocale } from "react-intlayer";
264
292
  import { type NavigateOptions, type To, useNavigate } from "react-router";
265
293
 
266
294
  import { locacalizeTo } from "~/components/localized-link";
@@ -318,6 +346,7 @@ import {
318
346
  getLocaleName,
319
347
  getLocalizedUrl,
320
348
  getPathWithoutLocale,
349
+ Locales,
321
350
  } from "intlayer";
322
351
  import { setLocaleInStorage, useIntlayer, useLocale } from "react-intlayer";
323
352
  import { Link, useLocation } from "react-router";
@@ -411,13 +440,13 @@ También puedes usar el `intlayerProxy` para agregar enrutamiento del lado del s
411
440
  > Ten en cuenta que para usar el `intlayerProxy` en producción, necesitas cambiar el paquete `vite-intlayer` de `devDependencies` a `dependencies`.
412
441
 
413
442
  ```typescript {3,7} fileName="vite.config.ts"
443
+ import { reactRouter } from "@react-router/dev/vite";
414
444
  import { defineConfig } from "vite";
415
- import react from "@vitejs/plugin-react-swc";
416
445
  import { intlayer, intlayerProxy } from "vite-intlayer";
446
+ import tsconfigPaths from "vite-tsconfig-paths";
417
447
 
418
- // https://vitejs.dev/config/
419
448
  export default defineConfig({
420
- plugins: [react(), intlayer(), intlayerProxy()],
449
+ plugins: [reactRouter(), tsconfigPaths(), intlayer(), intlayerProxy()],
421
450
  });
422
451
  ```
423
452
 
@@ -0,0 +1,575 @@
1
+ ---
2
+ createdAt: 2025-12-07
3
+ updatedAt: 2025-12-07
4
+ title: Cómo traducir tu React Router v7 (File-System Routes) – guía i18n 2025
5
+ description: Aprende cómo agregar internacionalización (i18n) a tu aplicación React Router v7 usando Intlayer con enrutamiento basado en el sistema de archivos. Sigue esta guía completa para hacer tu aplicación multilingüe con enrutamiento consciente del locale.
6
+ keywords:
7
+ - Internacionalización
8
+ - Documentación
9
+ - Intlayer
10
+ - React Router v7
11
+ - fs-routes
12
+ - Rutas basadas en el sistema de archivos
13
+ - React
14
+ - i18n
15
+ - TypeScript
16
+ - Enrutamiento por 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
+ # Traduce tu React Router v7 (File-System Routes) con Intlayer | Internacionalización (i18n)
31
+
32
+ Esta guía demuestra cómo integrar **Intlayer** para una internacionalización fluida en proyectos con React Router v7 usando **enrutamiento basado en el sistema de archivos** (`@react-router/fs-routes`) con enrutamiento consciente del locale, soporte para TypeScript y prácticas modernas de desarrollo.
33
+
34
+ ## Table of Contents
35
+
36
+ <TOC/>
37
+
38
+ ## ¿Qué es Intlayer?
39
+
40
+ **Intlayer** es una biblioteca innovadora y de código abierto para internacionalización (i18n) diseñada para simplificar el soporte multilingüe en aplicaciones web modernas.
41
+
42
+ Con Intlayer, puedes:
43
+
44
+ - **Gestionar traducciones fácilmente** usando diccionarios declarativos a nivel de componente.
45
+ - **Localizar dinámicamente metadatos**, rutas y contenido.
46
+ - **Garantizar soporte para TypeScript** con tipos autogenerados, mejorando la autocompletación y la detección de errores.
47
+ - **Beneficiarte de características avanzadas**, como la detección y cambio dinámico de locale.
48
+ - **Habilitar enrutamiento consciente del locale** con el sistema de enrutamiento basado en el sistema de archivos de React Router v7.
49
+
50
+ ---
51
+
52
+ ## Guía paso a paso para configurar Intlayer en una aplicación React Router v7 con rutas basadas en el sistema de archivos
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&amp;origin=http://intlayer.org&amp;controls=0&amp;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
+ ### Paso 1: Instalar dependencias
76
+
77
+ Instala los paquetes necesarios usando tu gestor de paquetes preferido:
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
+ - **intlayer**
94
+
95
+ El paquete principal que proporciona herramientas de internacionalización para la gestión de configuración, traducción, [declaración de contenido](https://github.com/aymericzip/intlayer/blob/main/docs/docs/es/dictionary/get_started.md), transpile y [comandos CLI](https://github.com/aymericzip/intlayer/blob/main/docs/docs/es/intlayer_cli.md).
96
+
97
+ - **react-intlayer**
98
+ El paquete que integra Intlayer con la aplicación React. Proporciona proveedores de contexto y hooks para la internacionalización en React.
99
+
100
+ - **vite-intlayer**
101
+ Incluye el plugin de Vite para integrar Intlayer con el [empaquetador Vite](https://vite.dev/guide/why.html#why-bundle-for-production), así como middleware para detectar el locale preferido del usuario, gestionar cookies y manejar la redirección de URLs.
102
+
103
+ - **@react-router/fs-routes**
104
+ El paquete que habilita el enrutamiento basado en el sistema de archivos para React Router v7.
105
+
106
+ ### Paso 2: Configuración de tu proyecto
107
+
108
+ Crea un archivo de configuración para configurar los idiomas de tu aplicación:
109
+
110
+ ```typescript fileName="intlayer.config.ts" codeFormat="typescript"
111
+ import { type IntlayerConfig, Locales } from "intlayer";
112
+
113
+ const config: IntlayerConfig = {
114
+ internationalization: {
115
+ defaultLocale: Locales.ENGLISH,
116
+ locales: [Locales.ENGLISH, Locales.FRENCH, Locales.SPANISH],
117
+ },
118
+ };
119
+
120
+ export default config;
121
+ ```
122
+
123
+ ```javascript fileName="intlayer.config.mjs" codeFormat="esm"
124
+ import { Locales } from "intlayer";
125
+
126
+ /** @type {import('intlayer').IntlayerConfig} */
127
+ // Configuración de internacionalización
128
+ const config = {
129
+ internationalization: {
130
+ defaultLocale: Locales.ENGLISH, // Idioma predeterminado
131
+ locales: [Locales.ENGLISH, Locales.FRENCH, Locales.SPANISH], // Idiomas soportados
132
+ },
133
+ };
134
+
135
+ export default config;
136
+ ```
137
+
138
+ ```javascript fileName="intlayer.config.cjs" codeFormat="commonjs"
139
+ const { Locales } = require("intlayer");
140
+
141
+ /** @type {import('intlayer').IntlayerConfig} */
142
+ const config = {
143
+ internationalization: {
144
+ defaultLocale: Locales.ENGLISH,
145
+ locales: [Locales.ENGLISH, Locales.FRENCH, Locales.SPANISH],
146
+ },
147
+ };
148
+
149
+ module.exports = config;
150
+ ```
151
+
152
+ > A través de este archivo de configuración, puedes configurar URLs localizadas, redirección mediante middleware, nombres de cookies, la ubicación y extensión de tus declaraciones de contenido, deshabilitar los registros de Intlayer en la consola, y más. Para una lista completa de los parámetros disponibles, consulta la [documentación de configuración](https://github.com/aymericzip/intlayer/blob/main/docs/docs/es/configuration.md).
153
+
154
+ ### Paso 3: Integra Intlayer en tu configuración de Vite
155
+
156
+ Agrega el plugin intlayer en tu configuración:
157
+
158
+ ```typescript fileName="vite.config.ts"
159
+ import { reactRouter } from "@react-router/dev/vite";
160
+ import { defineConfig } from "vite";
161
+ import { intlayer } from "vite-intlayer";
162
+ import tsconfigPaths from "vite-tsconfig-paths";
163
+
164
+ export default defineConfig({
165
+ plugins: [reactRouter(), tsconfigPaths(), intlayer()],
166
+ });
167
+ ```
168
+
169
+ > El plugin `intlayer()` para Vite se utiliza para integrar Intlayer con Vite. Asegura la construcción de archivos de declaración de contenido y los supervisa en modo desarrollo. Define variables de entorno de Intlayer dentro de la aplicación Vite. Además, proporciona alias para optimizar el rendimiento.
170
+
171
+ ### Paso 4: Configurar las rutas basadas en el sistema de archivos de React Router v7
172
+
173
+ Configura tu enrutamiento para usar rutas basadas en el sistema de archivos con `flatRoutes`:
174
+
175
+ ```typescript fileName="app/routes.ts"
176
+ import type { RouteConfig } from "@react-router/dev/routes";
177
+ import { flatRoutes } from "@react-router/fs-routes";
178
+ import { configuration } from "intlayer";
179
+
180
+ const routes: RouteConfig = flatRoutes({
181
+ // Ignorar los archivos de declaración de contenido para que no se traten como rutas
182
+ ignoredRouteFiles: configuration.content.fileExtensions.map(
183
+ (fileExtension) => `**/*${fileExtension}`
184
+ ),
185
+ });
186
+
187
+ export default routes;
188
+ ```
189
+
190
+ > La función `flatRoutes` de `@react-router/fs-routes` habilita el enrutamiento basado en el sistema de archivos, donde la estructura de archivos en el directorio `routes/` determina las rutas de tu aplicación. La opción `ignoredRouteFiles` garantiza que los archivos de declaración de contenido de Intlayer (`.content.ts`, etc.) no se traten como archivos de ruta.
191
+
192
+ ### Paso 5: Crear archivos de ruta con convenciones del sistema de archivos
193
+
194
+ Con el enrutamiento basado en el sistema de archivos, usas una convención de nomenclatura plana donde los puntos (`.`) representan segmentos de ruta y los paréntesis `()` denotan segmentos opcionales.
195
+
196
+ Crea los siguientes archivos en tu directorio `app/routes/`:
197
+
198
+ #### Estructura de archivos
199
+
200
+ ```bash
201
+ app/routes/
202
+ ├── ($locale)._layout.tsx # Wrapper de layout para rutas de locale
203
+ ├── ($locale)._index.tsx # Página de inicio (/:locale?)
204
+ ├── ($locale)._index.content.ts # Contenido de la página de inicio
205
+ ├── ($locale).about.tsx # Página Acerca de (/:locale?/about)
206
+ └── ($locale).about.content.ts # Contenido de la página Acerca de
207
+ ```
208
+
209
+ Las convenciones de nomenclatura:
210
+
211
+ - `($locale)` - Segmento dinámico opcional para el parámetro de locale
212
+ - `_layout` - Ruta de layout que envuelve las rutas hijas
213
+ - `_index` - Ruta de índice (se renderiza en la ruta padre)
214
+ - `.` (punto) - Separa segmentos de ruta (por ejemplo, `($locale).about` → `/:locale?/about`)
215
+
216
+ #### Componente de Layout
217
+
218
+ ```tsx fileName="app/routes/($locale)._layout.tsx"
219
+ import { IntlayerProvider } from "react-intlayer";
220
+ import { Outlet } from "react-router";
221
+
222
+ import { useI18nHTMLAttributes } from "~/hooks/useI18nHTMLAttributes";
223
+
224
+ import type { Route } from "./+types/($locale)._layout";
225
+
226
+ export default function RootLayout({ params }: Route.ComponentProps) {
227
+ useI18nHTMLAttributes();
228
+
229
+ const { locale } = params;
230
+
231
+ return (
232
+ <IntlayerProvider locale={locale}>
233
+ <Outlet />
234
+ </IntlayerProvider>
235
+ );
236
+ }
237
+ ```
238
+
239
+ #### Página de índice
240
+
241
+ ```tsx fileName="app/routes/($locale)._index.tsx"
242
+ import { useIntlayer } from "react-intlayer";
243
+ import { LocalizedLink } from "~/components/localized-link";
244
+
245
+ import type { Route } from "./+types/($locale)._index";
246
+
247
+ export default function Page() {
248
+ const { title, description, aboutLink } = useIntlayer("page");
249
+
250
+ return (
251
+ <div>
252
+ <h1>{title}</h1>
253
+ <p>{description}</p>
254
+ <nav>
255
+ <LocalizedLink to="/about">{aboutLink}</LocalizedLink>
256
+ </nav>
257
+ </div>
258
+ );
259
+ }
260
+ ```
261
+
262
+ #### Página Acerca de
263
+
264
+ ```tsx fileName="app/routes/($locale).about.tsx"
265
+ import { useIntlayer } from "react-intlayer";
266
+ import { LocalizedLink } from "~/components/localized-link";
267
+
268
+ import type { Route } from "./+types/($locale).about";
269
+
270
+ export default function AboutPage() {
271
+ const { title, content, homeLink } = useIntlayer("about");
272
+
273
+ return (
274
+ <div>
275
+ <h1>{title}</h1>
276
+ <p>{content}</p>
277
+ <nav>
278
+ <LocalizedLink to="/">{homeLink}</LocalizedLink>
279
+ </nav>
280
+ </div>
281
+ );
282
+ }
283
+ ```
284
+
285
+ ### Paso 6: Declara Tu Contenido
286
+
287
+ Crea y gestiona tus declaraciones de contenido para almacenar traducciones. Coloca los archivos de contenido junto a tus archivos de ruta:
288
+
289
+ ```tsx fileName="app/routes/($locale)._index.content.ts"
290
+ import { t, type Dictionary } from "intlayer";
291
+
292
+ const pageContent = {
293
+ key: "page",
294
+ content: {
295
+ title: t({
296
+ en: "Welcome to React Router v7 + Intlayer",
297
+ es: "Bienvenido a React Router v7 + Intlayer",
298
+ fr: "Bienvenue sur React Router v7 + Intlayer",
299
+ }),
300
+ description: t({
301
+ en: "Build multilingual applications with ease using React Router v7 and Intlayer.",
302
+ es: "Cree aplicaciones multilingües fácilmente usando React Router v7 y Intlayer.",
303
+ fr: "Créez des applications multilingues facilement avec React Router v7 et Intlayer.",
304
+ }),
305
+ aboutLink: t({
306
+ en: "Learn About Us",
307
+ es: "Aprender Sobre Nosotros",
308
+ fr: "En savoir plus sur nous",
309
+ }),
310
+ },
311
+ } satisfies Dictionary;
312
+
313
+ export default pageContent;
314
+ ```
315
+
316
+ ```tsx fileName="app/routes/($locale).about.content.ts"
317
+ import { t, type Dictionary } from "intlayer";
318
+
319
+ const aboutContent = {
320
+ key: "about",
321
+ content: {
322
+ title: t({
323
+ en: "About Us",
324
+ es: "Sobre Nosotros",
325
+ fr: "À propos de nous",
326
+ }),
327
+ content: t({
328
+ en: "This is the about page content.",
329
+ es: "Este es el contenido de la página de información.",
330
+ fr: "Ceci est le contenu de la page à propos.",
331
+ }),
332
+ homeLink: t({
333
+ en: "Home",
334
+ es: "Inicio",
335
+ fr: "Accueil",
336
+ }),
337
+ },
338
+ } satisfies Dictionary;
339
+
340
+ export default aboutContent;
341
+ ```
342
+
343
+ > Tus declaraciones de contenido pueden definirse en cualquier parte de tu aplicación tan pronto como se incluyan en el directorio `contentDir` (por defecto, `./app`). Y deben coincidir con la extensión del archivo de declaración de contenido (por defecto, `.content.{json,ts,tsx,js,jsx,mjs,mjx,cjs,cjx}`).
344
+
345
+ > Para más detalles, consulta la [documentación de declaración de contenido](https://github.com/aymericzip/intlayer/blob/main/docs/docs/es/dictionary/get_started.md).
346
+
347
+ ### Paso 7: Crear Componentes Sensibles al Idioma
348
+
349
+ Crea un componente `LocalizedLink` para la navegación sensible al idioma:
350
+
351
+ ```tsx fileName="app/components/localized-link.tsx"
352
+ import type { FC } from "react";
353
+
354
+ import { getLocalizedUrl, type LocalesValues } from "intlayer";
355
+ import { useLocale } from "react-intlayer";
356
+ import { Link, type LinkProps, type To } from "react-router";
357
+
358
+ const isExternalLink = (to: string) => /^(https?:)?\/\//.test(to);
359
+
360
+ // Función para localizar la URL según el locale
361
+ export const locacalizeTo = (to: To, locale: LocalesValues): To => {
362
+ if (typeof to === "string") {
363
+ if (isExternalLink(to)) {
364
+ return to;
365
+ }
366
+
367
+ return getLocalizedUrl(to, locale);
368
+ }
369
+
370
+ if (isExternalLink(to.pathname ?? "")) {
371
+ return to;
372
+ }
373
+
374
+ return {
375
+ ...to,
376
+ pathname: getLocalizedUrl(to.pathname ?? "", locale),
377
+ };
378
+ };
379
+
380
+ // Componente para enlaces localizados
381
+ export const LocalizedLink: FC<LinkProps> = (props) => {
382
+ const { locale } = useLocale();
383
+
384
+ return <Link {...props} to={locacalizeTo(props.to, locale)} />;
385
+ };
386
+ ```
387
+
388
+ En caso de que desees navegar a las rutas localizadas, puedes usar el hook `useLocalizedNavigate`:
389
+
390
+ ```tsx fileName="app/hooks/useLocalizedNavigate.ts"
391
+ import { useLocale } from "react-intlayer";
392
+ import { type NavigateOptions, type To, useNavigate } from "react-router";
393
+
394
+ import { locacalizeTo } from "~/components/localized-link";
395
+
396
+ export const useLocalizedNavigate = () => {
397
+ const navigate = useNavigate();
398
+ const { locale } = useLocale();
399
+
400
+ const localizedNavigate = (to: To, options?: NavigateOptions) => {
401
+ const localedTo = locacalizeTo(to, locale);
402
+
403
+ navigate(localedTo, options);
404
+ };
405
+
406
+ return localizedNavigate;
407
+ };
408
+ ```
409
+
410
+ ### Paso 8: Crear un componente para cambiar de idioma
411
+
412
+ Crea un componente para permitir a los usuarios cambiar de idioma:
413
+
414
+ ```tsx fileName="app/components/locale-switcher.tsx"
415
+ import type { FC } from "react";
416
+
417
+ import {
418
+ getHTMLTextDir,
419
+ getLocaleName,
420
+ getLocalizedUrl,
421
+ getPathWithoutLocale,
422
+ Locales,
423
+ } from "intlayer";
424
+ import { useIntlayer, useLocale } from "react-intlayer";
425
+ import { Link, useLocation } from "react-router";
426
+
427
+ export const LocaleSwitcher: FC = () => {
428
+ const { localeSwitcherLabel } = useIntlayer("locale-switcher");
429
+ const { pathname } = useLocation();
430
+
431
+ const { availableLocales, locale } = useLocale();
432
+
433
+ const pathWithoutLocale = getPathWithoutLocale(pathname);
434
+
435
+ return (
436
+ <ol>
437
+ {availableLocales.map((localeItem) => (
438
+ <li key={localeItem}>
439
+ <Link
440
+ aria-current={localeItem === locale ? "page" : undefined}
441
+ aria-label={`${localeSwitcherLabel.value} ${getLocaleName(localeItem)}`}
442
+ reloadDocument // Recargar la página para aplicar la nueva locale
443
+ to={getLocalizedUrl(pathWithoutLocale, localeItem)}
444
+ >
445
+ <span>
446
+ {/* Localización - p.ej. FR */}
447
+ {localeItem}
448
+ </span>
449
+ <span>
450
+ {/* Idioma en su propia localización - p.ej. Français */}
451
+ {getLocaleName(localeItem, locale)}
452
+ </span>
453
+ <span dir={getHTMLTextDir(localeItem)} lang={localeItem}>
454
+ {/* Idioma en la localización actual - p.ej. Francés con la localización actual configurada a Locales.SPANISH */}
455
+ {getLocaleName(localeItem)}
456
+ </span>
457
+ <span dir="ltr" lang={Locales.ENGLISH}>
458
+ {/* Idioma en inglés - por ejemplo, French */}
459
+ {getLocaleName(localeItem, Locales.ENGLISH)}
460
+ </span>
461
+ </Link>
462
+ </li>
463
+ ))}
464
+ </ol>
465
+ );
466
+ };
467
+ ```
468
+
469
+ > Para aprender más sobre el hook `useLocale`, consulta la [documentación](https://github.com/aymericzip/intlayer/blob/main/docs/docs/es/packages/react-intlayer/useLocale.md).
470
+
471
+ ### Paso 9: Añadir gestión de atributos HTML (Opcional)
472
+
473
+ Crea un hook para gestionar los atributos lang y dir del HTML:
474
+
475
+ ```tsx fileName="app/hooks/useI18nHTMLAttributes.tsx"
476
+ import { getHTMLTextDir } from "intlayer";
477
+ import { useEffect } from "react";
478
+ import { useLocale } from "react-intlayer";
479
+
480
+ export const useI18nHTMLAttributes = () => {
481
+ const { locale } = useLocale();
482
+
483
+ useEffect(() => {
484
+ document.documentElement.lang = locale;
485
+ document.documentElement.dir = getHTMLTextDir(locale);
486
+ }, [locale]);
487
+ };
488
+ ```
489
+
490
+ Este hook ya se usa en el componente de layout (`($locale)._layout.tsx`) mostrado en el Paso 5.
491
+
492
+ ### Paso 10: Añadir middleware (Opcional)
493
+
494
+ También puedes usar el `intlayerProxy` para agregar enrutamiento del lado del servidor a tu aplicación. Este plugin detectará automáticamente la configuración regional actual basada en la URL y establecerá la cookie de configuración regional apropiada. Si no se especifica ninguna configuración regional, el plugin determinará la configuración regional más adecuada según las preferencias de idioma del navegador del usuario. Si no se detecta ninguna configuración regional, redirigirá a la configuración regional predeterminada.
495
+
496
+ > Ten en cuenta que para usar el `intlayerProxy` en producción, necesitas cambiar el paquete `vite-intlayer` de `devDependencies` a `dependencies`.
497
+
498
+ ```typescript {3,7} fileName="vite.config.ts"
499
+ import { reactRouter } from "@react-router/dev/vite";
500
+ import { defineConfig } from "vite";
501
+ import { intlayer, intlayerProxy } from "vite-intlayer";
502
+ import tsconfigPaths from "vite-tsconfig-paths";
503
+
504
+ export default defineConfig({
505
+ plugins: [reactRouter(), tsconfigPaths(), intlayer(), intlayerProxy()],
506
+ });
507
+ ```
508
+
509
+ ---
510
+
511
+ ## Configurar TypeScript
512
+
513
+ Intlayer utiliza la ampliación de módulos para aprovechar las ventajas de TypeScript y fortalecer tu base de código.
514
+
515
+ Asegúrate de que tu configuración de TypeScript incluya los tipos autogenerados:
516
+
517
+ ```json5 fileName="tsconfig.json"
518
+ {
519
+ // ... tus configuraciones existentes
520
+ include: [
521
+ // ... tus inclusiones existentes
522
+ ".intlayer/**/*.ts", // Incluir los tipos autogenerados
523
+ ],
524
+ }
525
+ ```
526
+
527
+ ---
528
+
529
+ ## Configuración de Git
530
+
531
+ Se recomienda ignorar los archivos generados por Intlayer. Esto te permite evitar comprometerlos en tu repositorio Git.
532
+
533
+ Para hacer esto, puedes agregar las siguientes instrucciones a tu archivo `.gitignore`:
534
+
535
+ ```plaintext fileName=".gitignore"
536
+ # Ignorar los archivos generados por Intlayer
537
+ .intlayer
538
+ ```
539
+
540
+ ---
541
+
542
+ ## Extensión de VS Code
543
+
544
+ Para mejorar tu experiencia de desarrollo con Intlayer, puedes instalar la **Extensión oficial de Intlayer para VS Code**.
545
+
546
+ [Instalar desde el Marketplace de VS Code](https://marketplace.visualstudio.com/items?itemName=intlayer.intlayer-vs-code-extension)
547
+
548
+ Esta extensión ofrece:
549
+
550
+ - **Autocompletado** para las claves de traducción.
551
+ - **Detección de errores en tiempo real** para traducciones faltantes.
552
+ - **Previsualizaciones en línea** del contenido traducido.
553
+ - **Acciones rápidas** para crear y actualizar traducciones fácilmente.
554
+
555
+ Para más detalles sobre cómo usar la extensión, consulta la [documentación de la Extensión de Intlayer para VS Code](https://intlayer.org/doc/vs-code-extension).
556
+
557
+ ---
558
+
559
+ ## Ir Más Allá
560
+
561
+ Para profundizar, puedes implementar el [editor visual](https://github.com/aymericzip/intlayer/blob/main/docs/docs/es/intlayer_visual_editor.md) o externalizar tu contenido usando el [CMS](https://github.com/aymericzip/intlayer/blob/main/docs/docs/es/intlayer_CMS.md).
562
+
563
+ ---
564
+
565
+ ## Referencias de la Documentación
566
+
567
+ - [Documentación de Intlayer](https://intlayer.org)
568
+ - [Documentación de React Router v7](https://reactrouter.com/)
569
+ - [Documentación React Router fs-routes](https://reactrouter.com/how-to/file-route-conventions)
570
+ - [Hook useIntlayer](https://github.com/aymericzip/intlayer/blob/main/docs/docs/es/packages/react-intlayer/useIntlayer.md)
571
+ - [Hook useLocale](https://github.com/aymericzip/intlayer/blob/main/docs/docs/es/packages/react-intlayer/useLocale.md)
572
+ - [Declaración de Contenido](https://github.com/aymericzip/intlayer/blob/main/docs/docs/es/dictionary/get_started.md)
573
+ - [Configuración](https://github.com/aymericzip/intlayer/blob/main/docs/docs/es/configuration.md)
574
+
575
+ Esta guía completa proporciona todo lo que necesitas para integrar Intlayer con React Router v7 usando enrutamiento basado en el sistema de archivos para una aplicación completamente internacionalizada con enrutamiento consciente del idioma y soporte para TypeScript.
@@ -17,6 +17,7 @@ slugs:
17
17
  - environment
18
18
  - tanstack-start
19
19
  applicationTemplate: https://github.com/aymericzip/intlayer-tanstack-start-template
20
+ youtubeVideo: https://www.youtube.com/watch?v=_XTdKVWaeqg
20
21
  history:
21
22
  - version: 7.3.9
22
23
  date: 2025-12-05
@@ -15,6 +15,7 @@ slugs:
15
15
  - environment
16
16
  - vite-and-vue
17
17
  applicationTemplate: https://github.com/aymericzip/intlayer-vite-vue-template
18
+ youtubeVideo: https://www.youtube.com/watch?v=IE3XWkZ6a5U
18
19
  history:
19
20
  - version: 5.5.10
20
21
  date: 2025-06-29
@@ -1119,5 +1120,3 @@ Para más detalles sobre cómo usar la extensión, consulta la [documentación d
1119
1120
  ### Ir Más Allá
1120
1121
 
1121
1122
  Para ir más allá, puedes implementar el [editor visual](https://github.com/aymericzip/intlayer/blob/main/docs/docs/es/intlayer_visual_editor.md) o externalizar tu contenido usando el [CMS](https://github.com/aymericzip/intlayer/blob/main/docs/docs/es/intlayer_CMS.md).
1122
-
1123
- ---