@intlayer/docs 5.7.6 → 5.7.8
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 +44 -238
- package/dist/cjs/generated/docs.entry.cjs.map +1 -1
- package/dist/esm/generated/docs.entry.mjs +44 -238
- package/dist/esm/generated/docs.entry.mjs.map +1 -1
- package/dist/types/generated/docs.entry.d.ts +1 -2
- package/dist/types/generated/docs.entry.d.ts.map +1 -1
- package/docs/ar/CI_CD.md +67 -41
- package/docs/ar/intlayer_with_tanstack.md +457 -0
- package/docs/ar/packages/next-intlayer/index.md +0 -1
- package/docs/ar/packages/react-intlayer/index.md +0 -1
- package/docs/de/CI_CD.md +63 -37
- package/docs/de/intlayer_with_tanstack.md +458 -0
- package/docs/de/packages/next-intlayer/index.md +0 -1
- package/docs/de/packages/react-intlayer/index.md +0 -1
- package/docs/en/CI_CD.md +51 -27
- package/docs/en/intlayer_with_tanstack.md +452 -0
- package/docs/en/packages/next-intlayer/index.md +0 -1
- package/docs/en/packages/react-intlayer/index.md +0 -1
- package/docs/en-GB/CI_CD.md +58 -32
- package/docs/en-GB/intlayer_with_tanstack.md +457 -0
- package/docs/en-GB/packages/next-intlayer/index.md +0 -1
- package/docs/en-GB/packages/react-intlayer/index.md +0 -1
- package/docs/es/CI_CD.md +68 -42
- package/docs/es/intlayer_with_tanstack.md +435 -0
- package/docs/es/packages/next-intlayer/index.md +0 -1
- package/docs/es/packages/react-intlayer/index.md +0 -1
- package/docs/fr/intlayer_with_tanstack.md +435 -0
- package/docs/fr/packages/next-intlayer/index.md +0 -1
- package/docs/fr/packages/react-intlayer/index.md +0 -1
- package/docs/hi/CI_CD.md +69 -44
- package/docs/hi/intlayer_with_tanstack.md +438 -0
- package/docs/hi/packages/next-intlayer/index.md +0 -1
- package/docs/hi/packages/react-intlayer/index.md +0 -1
- package/docs/it/CI_CD.md +67 -41
- package/docs/it/intlayer_with_tanstack.md +457 -0
- package/docs/it/packages/next-intlayer/index.md +0 -1
- package/docs/it/packages/react-intlayer/index.md +0 -1
- package/docs/ja/CI_CD.md +67 -41
- package/docs/ja/intlayer_with_tanstack.md +457 -0
- package/docs/ja/packages/next-intlayer/index.md +0 -1
- package/docs/ja/packages/react-intlayer/index.md +0 -1
- package/docs/ko/CI_CD.md +63 -37
- package/docs/ko/intlayer_with_tanstack.md +457 -0
- package/docs/ko/packages/next-intlayer/index.md +0 -1
- package/docs/ko/packages/react-intlayer/index.md +0 -1
- package/docs/pt/CI_CD.md +67 -41
- package/docs/pt/intlayer_with_tanstack.md +457 -0
- package/docs/pt/packages/next-intlayer/index.md +0 -1
- package/docs/pt/packages/react-intlayer/index.md +0 -1
- package/docs/ru/CI_CD.md +70 -44
- package/docs/ru/intlayer_with_tanstack.md +458 -0
- package/docs/ru/packages/next-intlayer/index.md +0 -1
- package/docs/ru/packages/react-intlayer/index.md +0 -1
- package/docs/zh/CI_CD.md +62 -36
- package/docs/zh/intlayer_with_tanstack.md +435 -0
- package/docs/zh/packages/next-intlayer/index.md +0 -1
- package/docs/zh/packages/react-intlayer/index.md +0 -1
- package/package.json +9 -9
- package/src/generated/docs.entry.ts +44 -238
- package/docs/ar/packages/next-intlayer/useIntlayerAsync.md +0 -237
- package/docs/ar/packages/react-intlayer/useIntlayerAsync.md +0 -252
- package/docs/de/packages/next-intlayer/useIntlayerAsync.md +0 -262
- package/docs/de/packages/react-intlayer/useIntlayerAsync.md +0 -256
- package/docs/en/packages/next-intlayer/useIntlayerAsync.md +0 -239
- package/docs/en/packages/react-intlayer/useIntlayerAsync.md +0 -254
- package/docs/en-GB/packages/next-intlayer/useIntlayerAsync.md +0 -237
- package/docs/en-GB/packages/react-intlayer/useIntlayerAsync.md +0 -257
- package/docs/es/packages/next-intlayer/useIntlayerAsync.md +0 -240
- package/docs/es/packages/react-intlayer/useIntlayerAsync.md +0 -276
- package/docs/fr/packages/next-intlayer/useIntlayerAsync.md +0 -238
- package/docs/fr/packages/react-intlayer/useIntlayerAsync.md +0 -252
- package/docs/hi/packages/next-intlayer/useIntlayerAsync.md +0 -237
- package/docs/hi/packages/react-intlayer/useIntlayerAsync.md +0 -252
- package/docs/it/packages/next-intlayer/useIntlayerAsync.md +0 -237
- package/docs/it/packages/react-intlayer/useIntlayerAsync.md +0 -252
- package/docs/ja/packages/next-intlayer/useIntlayerAsync.md +0 -237
- package/docs/ja/packages/react-intlayer/useIntlayerAsync.md +0 -268
- package/docs/ko/packages/next-intlayer/useIntlayerAsync.md +0 -260
- package/docs/ko/packages/react-intlayer/useIntlayerAsync.md +0 -271
- package/docs/pt/packages/next-intlayer/useIntlayerAsync.md +0 -238
- package/docs/pt/packages/react-intlayer/useIntlayerAsync.md +0 -252
- package/docs/ru/packages/next-intlayer/useIntlayerAsync.md +0 -237
- package/docs/ru/packages/react-intlayer/useIntlayerAsync.md +0 -252
- package/docs/zh/packages/next-intlayer/useIntlayerAsync.md +0 -239
- 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: Comenzando con Intlayer en TanStack Start (React)
|
|
5
|
+
description: Añade i18n a tu aplicación TanStack Start usando Intlayer—diccionarios a nivel de componente, URLs localizadas y metadatos amigables para SEO.
|
|
6
|
+
keywords:
|
|
7
|
+
- Internacionalización
|
|
8
|
+
- Documentación
|
|
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
|
+
# Comenzando con la internacionalización (i18n) usando Intlayer y TanStack Start (React)
|
|
22
|
+
|
|
23
|
+
## ¿Qué es Intlayer?
|
|
24
|
+
|
|
25
|
+
**Intlayer** es un conjunto de herramientas i18n de código abierto para aplicaciones React. Te ofrece:
|
|
26
|
+
|
|
27
|
+
- **Diccionarios locales por componente** con seguridad de TypeScript.
|
|
28
|
+
- **Metadatos y rutas dinámicas** (preparadas para SEO).
|
|
29
|
+
- **Cambio de idioma en tiempo de ejecución** (y ayudas para detectar/persistir locales).
|
|
30
|
+
- **Plugin de Vite** para transformaciones en tiempo de compilación + experiencia de desarrollo (DX).
|
|
31
|
+
|
|
32
|
+
Esta guía muestra cómo integrar Intlayer en un proyecto **TanStack Start** (que usa Vite internamente y TanStack Router para enrutamiento/SSR).
|
|
33
|
+
|
|
34
|
+
---
|
|
35
|
+
|
|
36
|
+
## Paso 1: Instalar dependencias
|
|
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**: núcleo (configuración, diccionarios, CLI/transformaciones).
|
|
53
|
+
- **react-intlayer**: `<IntlayerProvider>` + hooks para React.
|
|
54
|
+
- **vite-intlayer**: plugin de Vite, además de middleware opcional para detección/redirección de locales (funciona en desarrollo y SSR/preview; mover a `dependencies` para SSR en producción).
|
|
55
|
+
|
|
56
|
+
---
|
|
57
|
+
|
|
58
|
+
## Paso 2: Configurar Intlayer
|
|
59
|
+
|
|
60
|
+
Crea `intlayer.config.ts` en la raíz de tu proyecto:
|
|
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
|
+
// También puedes ajustar: contentDir, contentFileExtensions, opciones de middleware, etc.
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
export default config;
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
Las variantes CommonJS/ESM son idénticas a tu documento original si prefieres `cjs`/`mjs`.
|
|
77
|
+
|
|
78
|
+
> Referencia completa de configuración: consulta la documentación de configuración de Intlayer.
|
|
79
|
+
|
|
80
|
+
---
|
|
81
|
+
|
|
82
|
+
## Paso 3: Añadir el plugin de Vite (y middleware opcional)
|
|
83
|
+
|
|
84
|
+
**TanStack Start usa Vite**, así que añade el/los plugin(s) de Intlayer a tu `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
|
+
// Opcional pero recomendado para la detección de idioma, cookies y redirecciones:
|
|
96
|
+
intLayerMiddlewarePlugin(),
|
|
97
|
+
],
|
|
98
|
+
});
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
> Si despliegas SSR, mueve `vite-intlayer` a `dependencies` para que el middleware se ejecute en producción.
|
|
102
|
+
|
|
103
|
+
---
|
|
104
|
+
|
|
105
|
+
## Paso 4: Declara tu contenido
|
|
106
|
+
|
|
107
|
+
Coloca tus diccionarios en cualquier lugar dentro de `./src` (contentDir por defecto). Ejemplo:
|
|
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
|
+
Edita <code>src/routes/index.tsx</code> y guarda para probar 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: "Haz clic en los logotipos para saber más",
|
|
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
|
+
Las variantes JSON/ESM/CJS funcionan igual que en tu documento original.
|
|
154
|
+
|
|
155
|
+
> ¿Contenido TSX? No olvides `import React from "react"` si tu configuración lo requiere.
|
|
156
|
+
|
|
157
|
+
---
|
|
158
|
+
|
|
159
|
+
## Paso 5: Envuelve TanStack Start con Intlayer
|
|
160
|
+
|
|
161
|
+
Con TanStack Start, tu **ruta raíz** es el lugar adecuado para establecer proveedores.
|
|
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
|
+
// Ejemplo de uso de un diccionario en el nivel superior:
|
|
173
|
+
const content = useIntlayer("app");
|
|
174
|
+
|
|
175
|
+
return (
|
|
176
|
+
<div>
|
|
177
|
+
<nav className="flex gap-3 p-3">
|
|
178
|
+
<RouterLink to="/">Inicio</RouterLink>
|
|
179
|
+
<RouterLink to="/about">Acerca de</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
|
+
Luego usa tu contenido en las páginas:
|
|
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
|
+
> Los atributos de cadena (`alt`, `title`, `aria-label`, …) necesitan `.value`:
|
|
226
|
+
>
|
|
227
|
+
> ```jsx
|
|
228
|
+
> <img alt={c.reactLogo.value} />
|
|
229
|
+
> ```
|
|
230
|
+
|
|
231
|
+
---
|
|
232
|
+
|
|
233
|
+
## (Opcional) Paso 6: Cambio de idioma (Cliente)
|
|
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)}>Inglés</button>
|
|
244
|
+
<button onClick={() => setLocale(Locales.FRENCH)}>Francés</button>
|
|
245
|
+
<button onClick={() => setLocale(Locales.SPANISH)}>Español</button>
|
|
246
|
+
</div>
|
|
247
|
+
);
|
|
248
|
+
}
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
---
|
|
252
|
+
|
|
253
|
+
## (Opcional) Paso 7: Enrutamiento localizado (URLs amigables para SEO)
|
|
254
|
+
|
|
255
|
+
Tienes **dos buenos patrones** con TanStack Start. Elige uno.
|
|
256
|
+
|
|
257
|
+
Crea una carpeta de segmento dinámico `src/routes/$locale/` para que tus URLs sean `/:locale/...`. En el layout `$locale`, valida el `params.locale`, configura `<IntlayerProvider locale=...>`, y renderiza un `<Outlet />`. Este enfoque es sencillo, pero montarás el resto de tus rutas debajo de `$locale`, y necesitarás un árbol adicional sin prefijo si _no_ quieres que la configuración regional predeterminada tenga prefijo.
|
|
258
|
+
|
|
259
|
+
---
|
|
260
|
+
|
|
261
|
+
## (Opcional) Paso 8: Actualizar la URL al cambiar de idioma
|
|
262
|
+
|
|
263
|
+
Con el Patrón A (basepath), cambiar de idioma significa **navegar a un basepath diferente**:
|
|
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 }); // preserva el historial
|
|
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
|
+
## (Opcional) Paso 9: `<html lang>` y `dir` (Documento TanStack Start)
|
|
297
|
+
|
|
298
|
+
TanStack Start expone un **Documento** (envoltorio raíz HTML) que puedes personalizar. Configura `lang` y `dir` para accesibilidad/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 calculas el locale en el servidor, pásalo al Document; de lo contrario, el cliente lo corregirá después de la hidratación */}
|
|
328
|
+
<Document locale={document?.documentElement?.lang || "en"}>
|
|
329
|
+
<Outlet />
|
|
330
|
+
</Document>
|
|
331
|
+
</IntlayerProvider>
|
|
332
|
+
),
|
|
333
|
+
});
|
|
334
|
+
```
|
|
335
|
+
|
|
336
|
+
Para la corrección del lado del cliente, también puedes mantener tu pequeño 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
|
+
## (Opcional) Paso 10: Componente Link localizado
|
|
355
|
+
|
|
356
|
+
TanStack Router proporciona un `<Link/>`, pero si alguna vez necesitas un `<a>` simple que añada automáticamente el prefijo a las URLs internas:
|
|
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 usas el Patrón A (basepath), el `<Link to="/about" />` de TanStack ya resuelve a `/fr/about` mediante `basepath`, por lo que un enlace personalizado es opcional.
|
|
391
|
+
|
|
392
|
+
---
|
|
393
|
+
|
|
394
|
+
## TypeScript
|
|
395
|
+
|
|
396
|
+
Incluye los tipos generados por Intlayer:
|
|
397
|
+
|
|
398
|
+
```json5 fileName="tsconfig.json"
|
|
399
|
+
{
|
|
400
|
+
"include": ["src", ".intlayer/**/*.ts"],
|
|
401
|
+
}
|
|
402
|
+
```
|
|
403
|
+
|
|
404
|
+
---
|
|
405
|
+
|
|
406
|
+
## Git
|
|
407
|
+
|
|
408
|
+
Ignora los artefactos generados por Intlayer:
|
|
409
|
+
|
|
410
|
+
```gitignore
|
|
411
|
+
.intlayer
|
|
412
|
+
```
|
|
413
|
+
|
|
414
|
+
---
|
|
415
|
+
|
|
416
|
+
## Extensión de VS Code
|
|
417
|
+
|
|
418
|
+
- **Extensión Intlayer para VS Code** → autocompletado, errores, vistas previas en línea, acciones rápidas.
|
|
419
|
+
Marketplace: `intlayer.intlayer-vs-code-extension`
|
|
420
|
+
|
|
421
|
+
---
|
|
422
|
+
|
|
423
|
+
## Ir Más Allá
|
|
424
|
+
|
|
425
|
+
- Editor Visual
|
|
426
|
+
- Modo CMS
|
|
427
|
+
- Detección de locale en el edge / adaptadores
|
|
428
|
+
|
|
429
|
+
---
|
|
430
|
+
|
|
431
|
+
## Historial de Documentación
|
|
432
|
+
|
|
433
|
+
| Versión | Fecha | Cambios |
|
|
434
|
+
| ------- | ---------- | -------------------------------------- |
|
|
435
|
+
| 1.0.0 | 2025-08-11 | Adaptación inicial de TanStack añadida |
|
|
@@ -279,7 +279,6 @@ El paquete `next-intlayer` también proporciona algunas funciones para ayudarte
|
|
|
279
279
|
- [`useIntlayer()`](https://github.com/aymericzip/intlayer/blob/main/docs/docs/es/packages/next-intlayer/useIntlayer.md)
|
|
280
280
|
- [`useDictionary()`](https://github.com/aymericzip/intlayer/blob/main/docs/docs/es/packages/next-intlayer/useDictionary.md)
|
|
281
281
|
- [`useLocale()`](https://github.com/aymericzip/intlayer/blob/main/docs/docs/es/packages/next-intlayer/useLocale.md)
|
|
282
|
-
- [`useIntlayerAsync()`](https://github.com/aymericzip/intlayer/blob/main/docs/docs/es/packages/next-intlayer/useIntlayerAsync.md)
|
|
283
282
|
|
|
284
283
|
## Historial de la documentación
|
|
285
284
|
|
|
@@ -273,7 +273,6 @@ El paquete `react-intlayer` también proporciona algunas funciones para ayudarte
|
|
|
273
273
|
- [`useIntlayer()`](https://github.com/aymericzip/intlayer/blob/main/docs/docs/es/packages/react-intlayer/useIntlayer.md)
|
|
274
274
|
- [`useDictionary()`](https://github.com/aymericzip/intlayer/blob/main/docs/docs/es/packages/react-intlayer/useDictionary.md)
|
|
275
275
|
- [`useLocale()`](https://github.com/aymericzip/intlayer/blob/main/docs/docs/es/packages/react-intlayer/useLocale.md)
|
|
276
|
-
- [`useIntlayerAsync()`](https://github.com/aymericzip/intlayer/blob/main/docs/docs/es/packages/react-intlayer/useIntlayerAsync.md)
|
|
277
276
|
|
|
278
277
|
## Historial de la documentación
|
|
279
278
|
|