@intlayer/docs 7.1.9 → 7.2.0
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/README.md +1 -0
- 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_svelte_kit.md +730 -0
- package/docs/ar/intlayer_with_vite+svelte.md +288 -104
- package/docs/de/intlayer_with_svelte_kit.md +730 -0
- package/docs/de/intlayer_with_vite+svelte.md +302 -101
- package/docs/en/intlayer_with_svelte_kit.md +560 -0
- package/docs/en/intlayer_with_vite+svelte.md +22 -6
- package/docs/en/introduction.md +2 -0
- package/docs/en-GB/intlayer_with_svelte_kit.md +730 -0
- package/docs/en-GB/intlayer_with_vite+svelte.md +262 -84
- package/docs/es/intlayer_with_svelte_kit.md +730 -0
- package/docs/es/intlayer_with_vite+svelte.md +300 -107
- package/docs/fr/intlayer_with_svelte_kit.md +762 -0
- package/docs/fr/intlayer_with_vite+svelte.md +297 -101
- package/docs/hi/intlayer_with_svelte_kit.md +730 -0
- package/docs/hi/intlayer_with_vite+svelte.md +298 -108
- package/docs/id/intlayer_with_svelte_kit.md +730 -0
- package/docs/id/intlayer_with_vite+svelte.md +277 -99
- package/docs/it/intlayer_with_svelte_kit.md +762 -0
- package/docs/it/intlayer_with_vite+svelte.md +275 -99
- package/docs/ja/intlayer_with_svelte_kit.md +730 -0
- package/docs/ja/intlayer_with_vite+svelte.md +295 -110
- package/docs/ko/intlayer_with_svelte_kit.md +730 -0
- package/docs/ko/intlayer_with_vite+svelte.md +286 -199
- package/docs/pl/intlayer_with_svelte_kit.md +732 -0
- package/docs/pl/intlayer_with_vite+svelte.md +273 -101
- package/docs/pt/intlayer_with_svelte_kit.md +764 -0
- package/docs/pt/intlayer_with_vite+svelte.md +290 -96
- package/docs/ru/intlayer_with_svelte_kit.md +730 -0
- package/docs/ru/intlayer_with_vite+svelte.md +275 -99
- package/docs/tr/intlayer_with_svelte_kit.md +730 -0
- package/docs/tr/intlayer_with_vite+svelte.md +297 -119
- package/docs/vi/intlayer_with_svelte_kit.md +730 -0
- package/docs/vi/intlayer_with_vite+svelte.md +275 -102
- package/docs/zh/intlayer_with_svelte_kit.md +730 -0
- package/docs/zh/intlayer_with_vite+svelte.md +309 -107
- package/package.json +6 -6
- package/src/generated/docs.entry.ts +19 -0
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
---
|
|
2
2
|
createdAt: 2025-04-18
|
|
3
|
-
updatedAt: 2025-
|
|
4
|
-
title: Cómo traducir tu Vite
|
|
5
|
-
description: Descubre cómo hacer tu sitio web
|
|
3
|
+
updatedAt: 2025-11-19
|
|
4
|
+
title: Cómo traducir tu aplicación Vite y Svelte – Guía i18n 2025
|
|
5
|
+
description: Descubre cómo hacer tu sitio web Vite y Svelte multilingüe. Sigue la documentación para internacionalizar (i18n) y traducirlo.
|
|
6
6
|
keywords:
|
|
7
7
|
- Internacionalización
|
|
8
8
|
- Documentación
|
|
@@ -14,35 +14,48 @@ slugs:
|
|
|
14
14
|
- doc
|
|
15
15
|
- environment
|
|
16
16
|
- vite-and-svelte
|
|
17
|
-
|
|
17
|
+
applicationTemplate: https://github.com/aymericzip/intlayer-vite-svelte-template
|
|
18
18
|
history:
|
|
19
|
+
- version: 5.5.11
|
|
20
|
+
date: 2025-11-19
|
|
21
|
+
changes: Actualización de la documentación
|
|
19
22
|
- version: 5.5.10
|
|
20
23
|
date: 2025-06-29
|
|
21
|
-
changes:
|
|
24
|
+
changes: Inicio del historial
|
|
22
25
|
---
|
|
23
26
|
|
|
24
|
-
# Traduce tu Vite
|
|
27
|
+
# Traduce tu sitio web Vite y Svelte usando Intlayer | Internacionalización (i18n)
|
|
25
28
|
|
|
26
|
-
|
|
29
|
+
## Tabla de Contenidos
|
|
27
30
|
|
|
28
|
-
|
|
31
|
+
<TOC/>
|
|
29
32
|
|
|
30
33
|
## ¿Qué es Intlayer?
|
|
31
34
|
|
|
32
|
-
**Intlayer** es una biblioteca innovadora y de código abierto para
|
|
35
|
+
**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.
|
|
33
36
|
|
|
34
37
|
Con Intlayer, puedes:
|
|
35
38
|
|
|
36
|
-
- **Gestionar traducciones
|
|
39
|
+
- **Gestionar fácilmente las traducciones** usando diccionarios declarativos a nivel de componente.
|
|
37
40
|
- **Localizar dinámicamente metadatos**, rutas y contenido.
|
|
38
|
-
- **
|
|
39
|
-
- **
|
|
41
|
+
- **Asegurar soporte para TypeScript** con tipos autogenerados, mejorando el autocompletado y la detección de errores.
|
|
42
|
+
- **Beneficiarte de funciones avanzadas**, como la detección y cambio dinámico de locales.
|
|
40
43
|
|
|
41
44
|
---
|
|
42
45
|
|
|
43
|
-
## Guía
|
|
46
|
+
## Guía Paso a Paso para Configurar Intlayer en una Aplicación Vite y Svelte
|
|
44
47
|
|
|
45
|
-
|
|
48
|
+
<iframe
|
|
49
|
+
src="https://stackblitz.com/github/aymericzip/intlayer-vite-react-template?embed=1&ctl=1&file=intlayer.config.ts"
|
|
50
|
+
className="m-auto overflow-hidden rounded-lg border-0 max-md:size-full max-md:h-[700px] md:aspect-16/9 md:w-full"
|
|
51
|
+
title="Demo CodeSandbox - Cómo internacionalizar tu aplicación usando Intlayer"
|
|
52
|
+
sandbox="allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts"
|
|
53
|
+
loading="lazy"
|
|
54
|
+
/>
|
|
55
|
+
|
|
56
|
+
Consulta la [Plantilla de Aplicación](https://github.com/aymericzip/intlayer-vite-svelte-template) en GitHub.
|
|
57
|
+
|
|
58
|
+
### Paso 1: Instalar Dependencias
|
|
46
59
|
|
|
47
60
|
Instala los paquetes necesarios usando npm:
|
|
48
61
|
|
|
@@ -61,23 +74,26 @@ yarn add intlayer svelte-intlayer
|
|
|
61
74
|
yarn add vite-intlayer --save-dev
|
|
62
75
|
```
|
|
63
76
|
|
|
64
|
-
|
|
77
|
+
```bash packageManager="bun"
|
|
78
|
+
bun add intlayer svelte-intlayer
|
|
79
|
+
bun add vite-intlayer --save-dev
|
|
80
|
+
```
|
|
65
81
|
|
|
66
82
|
- **intlayer**
|
|
67
83
|
|
|
68
|
-
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/
|
|
84
|
+
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/content_file.md), transpileación y [comandos CLI](https://github.com/aymericzip/intlayer/blob/main/docs/docs/es/intlayer_cli.md).
|
|
69
85
|
|
|
70
86
|
- **svelte-intlayer**
|
|
71
87
|
El paquete que integra Intlayer con la aplicación Svelte. Proporciona proveedores de contexto y hooks para la internacionalización en Svelte.
|
|
72
88
|
|
|
73
89
|
- **vite-intlayer**
|
|
74
|
-
Incluye el plugin de Vite para integrar Intlayer con el [
|
|
90
|
+
Incluye el plugin de Vite para integrar Intlayer con el [bundler Vite](https://vite.dev/guide/why.html#why-bundle-for-production), así como middleware para detectar la configuración regional preferida del usuario, gestionar cookies y manejar redirecciones de URL.
|
|
75
91
|
|
|
76
92
|
### Paso 2: Configuración de tu proyecto
|
|
77
93
|
|
|
78
94
|
Crea un archivo de configuración para configurar los idiomas de tu aplicación:
|
|
79
95
|
|
|
80
|
-
```typescript fileName="intlayer.config.ts"
|
|
96
|
+
```typescript fileName="intlayer.config.ts"
|
|
81
97
|
import { Locales, type IntlayerConfig } from "intlayer";
|
|
82
98
|
|
|
83
99
|
const config: IntlayerConfig = {
|
|
@@ -86,26 +102,7 @@ const config: IntlayerConfig = {
|
|
|
86
102
|
Locales.ENGLISH,
|
|
87
103
|
Locales.FRENCH,
|
|
88
104
|
Locales.SPANISH,
|
|
89
|
-
// Tus otros
|
|
90
|
-
],
|
|
91
|
-
defaultLocale: Locales.ENGLISH,
|
|
92
|
-
},
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
export default config;
|
|
96
|
-
```
|
|
97
|
-
|
|
98
|
-
```javascript fileName="intlayer.config.mjs" codeFormat="esm"
|
|
99
|
-
import { Locales } from "intlayer";
|
|
100
|
-
|
|
101
|
-
/** @type {import('intlayer').IntlayerConfig} */
|
|
102
|
-
const config = {
|
|
103
|
-
internationalization: {
|
|
104
|
-
locales: [
|
|
105
|
-
Locales.ENGLISH,
|
|
106
|
-
Locales.FRENCH,
|
|
107
|
-
Locales.SPANISH,
|
|
108
|
-
// Tus otros idiomas
|
|
105
|
+
// Tus otros locales
|
|
109
106
|
],
|
|
110
107
|
defaultLocale: Locales.ENGLISH,
|
|
111
108
|
},
|
|
@@ -114,33 +111,13 @@ const config = {
|
|
|
114
111
|
export default config;
|
|
115
112
|
```
|
|
116
113
|
|
|
117
|
-
|
|
118
|
-
const { Locales } = require("intlayer");
|
|
119
|
-
|
|
120
|
-
/** @type {import('intlayer').IntlayerConfig} */
|
|
121
|
-
// Configuración de Intlayer para internacionalización
|
|
122
|
-
const config = {
|
|
123
|
-
internationalization: {
|
|
124
|
-
locales: [
|
|
125
|
-
Locales.ENGLISH,
|
|
126
|
-
Locales.FRENCH,
|
|
127
|
-
Locales.SPANISH,
|
|
128
|
-
// Tus otros idiomas
|
|
129
|
-
],
|
|
130
|
-
defaultLocale: Locales.ENGLISH,
|
|
131
|
-
},
|
|
132
|
-
};
|
|
133
|
-
|
|
134
|
-
module.exports = config;
|
|
135
|
-
```
|
|
136
|
-
|
|
137
|
-
> A través de este archivo de configuración, puedes configurar URLs localizadas, redirección de 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).
|
|
114
|
+
> 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, desactivar los logs 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).
|
|
138
115
|
|
|
139
116
|
### Paso 3: Integra Intlayer en tu configuración de Vite
|
|
140
117
|
|
|
141
118
|
Agrega el plugin intlayer en tu configuración.
|
|
142
119
|
|
|
143
|
-
```typescript fileName="vite.config.ts"
|
|
120
|
+
```typescript fileName="vite.config.ts"
|
|
144
121
|
import { defineConfig } from "vite";
|
|
145
122
|
import { svelte } from "@sveltejs/vite-plugin-svelte";
|
|
146
123
|
import { intlayer } from "vite-intlayer";
|
|
@@ -151,31 +128,9 @@ export default defineConfig({
|
|
|
151
128
|
});
|
|
152
129
|
```
|
|
153
130
|
|
|
154
|
-
|
|
155
|
-
import { defineConfig } from "vite";
|
|
156
|
-
import { svelte } from "@sveltejs/vite-plugin-svelte";
|
|
157
|
-
import { intlayer } from "vite-intlayer";
|
|
131
|
+
> El plugin `intlayer()` para Vite se utiliza para integrar Intlayer con Vite. Asegura la construcción de los archivos de declaración de contenido y los supervisa en modo desarrollo. Define las variables de entorno de Intlayer dentro de la aplicación Vite. Además, proporciona alias para optimizar el rendimiento.
|
|
158
132
|
|
|
159
|
-
|
|
160
|
-
export default defineConfig({
|
|
161
|
-
plugins: [svelte(), intlayer()],
|
|
162
|
-
});
|
|
163
|
-
```
|
|
164
|
-
|
|
165
|
-
```javascript fileName="vite.config.cjs" codeFormat="commonjs"
|
|
166
|
-
const { defineConfig } = require("vite");
|
|
167
|
-
const react = require("@vitejs/plugin-react-swc");
|
|
168
|
-
const { intlayer } = require("vite-intlayer");
|
|
169
|
-
|
|
170
|
-
// https://vitejs.dev/config/
|
|
171
|
-
module.exports = defineConfig({
|
|
172
|
-
plugins: [react(), intlayer()],
|
|
173
|
-
});
|
|
174
|
-
```
|
|
175
|
-
|
|
176
|
-
> 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 de desarrollo. Define variables de entorno de Intlayer dentro de la aplicación Vite. Además, proporciona alias para optimizar el rendimiento.
|
|
177
|
-
|
|
178
|
-
### Paso 4: Declara Tu Contenido
|
|
133
|
+
### Paso 4: Declara tu contenido
|
|
179
134
|
|
|
180
135
|
Crea y administra tus declaraciones de contenido para almacenar traducciones:
|
|
181
136
|
|
|
@@ -200,6 +155,7 @@ export default appContent;
|
|
|
200
155
|
import { t } from "intlayer";
|
|
201
156
|
|
|
202
157
|
/** @type {import('intlayer').Dictionary} */
|
|
158
|
+
// Declaración del contenido de la aplicación
|
|
203
159
|
const appContent = {
|
|
204
160
|
key: "app",
|
|
205
161
|
content: {
|
|
@@ -250,39 +206,278 @@ module.exports = appContent;
|
|
|
250
206
|
}
|
|
251
207
|
```
|
|
252
208
|
|
|
253
|
-
> Tus declaraciones de contenido pueden definirse en cualquier parte de tu aplicación
|
|
209
|
+
> Tus declaraciones de contenido pueden definirse en cualquier parte de tu aplicación tan pronto como se incluyan en el directorio `contentDir` (por defecto, `./src`). Y coincidan con la extensión del archivo de declaración de contenido (por defecto, `.content.{json,ts,tsx,js,jsx,mjs,mjx,cjs,cjx}`).
|
|
210
|
+
|
|
211
|
+
> Para más detalles, consulta la [documentación de declaración de contenido](https://github.com/aymericzip/intlayer/blob/main/docs/docs/es/dictionary/content_file.md).
|
|
212
|
+
|
|
213
|
+
### Paso 5: Utiliza Intlayer en tu código
|
|
214
|
+
|
|
215
|
+
```svelte fileName="src/App.svelte"
|
|
216
|
+
<script>
|
|
217
|
+
import { useIntlayer } from "svelte-intlayer";
|
|
218
|
+
|
|
219
|
+
const content = useIntlayer("app");
|
|
220
|
+
</script>
|
|
221
|
+
|
|
222
|
+
<div>
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
<!-- Renderizar contenido como contenido simple -->
|
|
226
|
+
<h1>{$content.title}</h1>
|
|
227
|
+
<!-- Para renderizar el contenido editable usando el editor -->
|
|
228
|
+
<h1><svelte:component this={$content.title} /></h1>
|
|
229
|
+
<!-- Para renderizar el contenido como una cadena -->
|
|
230
|
+
<div aria-label={$content.title.value}></div>
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
### (Opcional) Paso 6: Cambiar el idioma de tu contenido
|
|
234
|
+
|
|
235
|
+
```svelte fileName="src/App.svelte"
|
|
236
|
+
<script lang="ts">
|
|
237
|
+
import { getLocaleName } from 'intlayer';
|
|
238
|
+
import { useLocale } from 'svelte-intlayer';
|
|
239
|
+
|
|
240
|
+
// Obtener información del locale y la función setLocale
|
|
241
|
+
const { locale, availableLocales, setLocale } = useLocale();
|
|
242
|
+
|
|
243
|
+
// Manejar el cambio de locale
|
|
244
|
+
const changeLocale = (event: Event) => {
|
|
245
|
+
const target = event.target as HTMLSelectElement;
|
|
246
|
+
const newLocale = target.value;
|
|
247
|
+
setLocale(newLocale);
|
|
248
|
+
};
|
|
249
|
+
</script>
|
|
250
|
+
|
|
251
|
+
<div>
|
|
252
|
+
<select value={$locale} on:change={changeLocale}>
|
|
253
|
+
{#each availableLocales ?? [] as loc}
|
|
254
|
+
<option value={loc}>
|
|
255
|
+
{getLocaleName(loc)}
|
|
256
|
+
</option>
|
|
257
|
+
{/each}
|
|
258
|
+
</select>
|
|
259
|
+
</div>
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
### (Opcional) Paso 7: Renderizar Markdown
|
|
263
|
+
|
|
264
|
+
Intlayer soporta renderizar contenido Markdown directamente en tu aplicación Svelte. Por defecto, Markdown se trata como texto plano. Para convertir Markdown en HTML enriquecido, puedes integrar `@humanspeak/svelte-markdown` u otro parser de markdown.
|
|
265
|
+
|
|
266
|
+
> Para ver cómo declarar contenido markdown usando el paquete `intlayer`, consulta la [documentación de markdown](https://github.com/aymericzip/intlayer/tree/main/docs/docs/es/dictionary/markdown.md).
|
|
267
|
+
|
|
268
|
+
```svelte fileName="src/App.svelte"
|
|
269
|
+
<script>
|
|
270
|
+
import { setIntlayerMarkdown } from "svelte-intlayer";
|
|
271
|
+
|
|
272
|
+
setIntlayerMarkdown((markdown) =>
|
|
273
|
+
// renderizar el contenido markdown como una cadena
|
|
274
|
+
return markdown;
|
|
275
|
+
);
|
|
276
|
+
</script>
|
|
277
|
+
|
|
278
|
+
<h1>{$content.markdownContent}</h1>
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
> También puedes acceder a los datos del front-matter de tu markdown usando la propiedad `content.markdownContent.metadata.xxx`.
|
|
282
|
+
|
|
283
|
+
### (Opcional) Paso 8: Configurar el editor / CMS de intlayer
|
|
284
|
+
|
|
285
|
+
Para configurar el editor de intlayer, debes seguir la [documentación del editor de intlayer](https://github.com/aymericzip/intlayer/blob/main/docs/docs/es/intlayer_visual_editor.md).
|
|
286
|
+
|
|
287
|
+
Para configurar el CMS de intlayer, debes seguir la [documentación del CMS de intlayer](https://github.com/aymericzip/intlayer/blob/main/docs/docs/es/intlayer_CMS.md).
|
|
288
|
+
|
|
289
|
+
En paralelo, en tu aplicación Svelte, debes agregar la siguiente línea en un layout, o en la raíz de tu aplicación:
|
|
290
|
+
|
|
291
|
+
```svelte fileName="src/layout.svelte"
|
|
292
|
+
import { useIntlayerEditor } from "svelte-intlayer";
|
|
293
|
+
|
|
294
|
+
useIntlayerEditor();
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
### (Opcional) Paso 7: Añadir enrutamiento localizado a tu aplicación
|
|
254
298
|
|
|
255
|
-
|
|
299
|
+
Para manejar el enrutamiento localizado en tu aplicación Svelte, puedes usar `svelte-spa-router` junto con `localeFlatMap` de Intlayer para generar rutas para cada locale.
|
|
256
300
|
|
|
257
|
-
|
|
301
|
+
Primero, instala `svelte-spa-router`:
|
|
258
302
|
|
|
259
|
-
|
|
303
|
+
```bash packageManager="npm"
|
|
304
|
+
npm install svelte-spa-router
|
|
305
|
+
```
|
|
260
306
|
|
|
261
|
-
|
|
307
|
+
```bash packageManager="pnpm"
|
|
308
|
+
pnpm add svelte-spa-router
|
|
309
|
+
```
|
|
262
310
|
|
|
263
|
-
|
|
311
|
+
```bash packageManager="yarn"
|
|
312
|
+
yarn add svelte-spa-router
|
|
313
|
+
```
|
|
314
|
+
|
|
315
|
+
```bash packageManager="bun"
|
|
316
|
+
bun add svelte-spa-router
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
Luego, crea un archivo `Router.svelte` para definir tus rutas:
|
|
320
|
+
|
|
321
|
+
```svelte fileName="src/Router.svelte"
|
|
322
|
+
<script lang="ts">
|
|
323
|
+
import { localeFlatMap } from "intlayer";
|
|
324
|
+
import Router from "svelte-spa-router";
|
|
325
|
+
import { wrap } from "svelte-spa-router/wrap";
|
|
326
|
+
import App from "./App.svelte";
|
|
327
|
+
|
|
328
|
+
const routes = Object.fromEntries(
|
|
329
|
+
localeFlatMap(({locale, urlPrefix}) => [
|
|
330
|
+
[
|
|
331
|
+
urlPrefix || '/',
|
|
332
|
+
wrap({
|
|
333
|
+
component: App as any,
|
|
334
|
+
props: {
|
|
335
|
+
locale,
|
|
336
|
+
},
|
|
337
|
+
}),
|
|
338
|
+
],
|
|
339
|
+
])
|
|
340
|
+
);
|
|
341
|
+
</script>
|
|
342
|
+
|
|
343
|
+
<Router {routes} />
|
|
344
|
+
```
|
|
345
|
+
|
|
346
|
+
Actualiza tu `main.ts` para montar el componente `Router` en lugar de `App`:
|
|
347
|
+
|
|
348
|
+
```typescript fileName="src/main.ts"
|
|
349
|
+
import { mount } from "svelte";
|
|
350
|
+
import Router from "./Router.svelte";
|
|
351
|
+
|
|
352
|
+
const app = mount(Router, {
|
|
353
|
+
target: document.getElementById("app")!,
|
|
354
|
+
});
|
|
355
|
+
|
|
356
|
+
export default app;
|
|
357
|
+
```
|
|
358
|
+
|
|
359
|
+
Finalmente, actualiza tu `App.svelte` para recibir la propiedad `locale` y usarla con `useIntlayer`:
|
|
360
|
+
|
|
361
|
+
```svelte fileName="src/App.svelte"
|
|
362
|
+
<script lang="ts">
|
|
363
|
+
import type { Locale } from 'intlayer';
|
|
364
|
+
import { useIntlayer } from 'svelte-intlayer';
|
|
365
|
+
import Counter from './lib/Counter.svelte';
|
|
366
|
+
import LocaleSwitcher from './lib/LocaleSwitcher.svelte';
|
|
367
|
+
|
|
368
|
+
export let locale: Locale;
|
|
369
|
+
|
|
370
|
+
$: content = useIntlayer('app', locale);
|
|
371
|
+
</script>
|
|
372
|
+
|
|
373
|
+
<main>
|
|
374
|
+
<div class="locale-switcher-container">
|
|
375
|
+
<LocaleSwitcher currentLocale={locale} />
|
|
376
|
+
</div>
|
|
377
|
+
|
|
378
|
+
<!-- ... resto de tu aplicación ... -->
|
|
379
|
+
</main>
|
|
380
|
+
```
|
|
264
381
|
|
|
265
|
-
|
|
382
|
+
#### Configurar el enrutamiento del lado del servidor (Opcional)
|
|
266
383
|
|
|
267
|
-
|
|
384
|
+
Paralelamente, también puedes usar `intlayerProxy` para añadir enrutamiento del lado del servidor a tu aplicación. Este plugin detectará automáticamente la locale actual basada en la URL y establecerá la cookie de locale correspondiente. Si no se especifica ninguna locale, el plugin determinará la locale más adecuada según las preferencias de idioma del navegador del usuario. Si no se detecta ninguna locale, redirigirá a la locale por defecto.
|
|
385
|
+
|
|
386
|
+
> Ten en cuenta que para usar `intlayerProxy` en producción, necesitas mover el paquete `vite-intlayer` de `devDependencies` a `dependencies`.
|
|
387
|
+
|
|
388
|
+
```typescript {3,7} fileName="vite.config.ts" codeFormat="typescript"
|
|
389
|
+
import { defineConfig } from "vite";
|
|
390
|
+
import { svelte } from "@sveltejs/vite-plugin-svelte";
|
|
391
|
+
import { intlayer, intlayerProxy } from "vite-intlayer";
|
|
392
|
+
|
|
393
|
+
plugins: [svelte(), intlayer(), intlayerProxy()],
|
|
394
|
+
});
|
|
395
|
+
```
|
|
396
|
+
|
|
397
|
+
```javascript {3,7} fileName="vite.config.mjs" codeFormat="esm"
|
|
398
|
+
import { defineConfig } from "vite";
|
|
399
|
+
import { svelte } from "@sveltejs/vite-plugin-svelte";
|
|
400
|
+
import { intlayer, intlayerProxy } from "vite-intlayer";
|
|
401
|
+
|
|
402
|
+
// https://vitejs.dev/config/
|
|
403
|
+
export default defineConfig({
|
|
404
|
+
plugins: [svelte(), intlayer(), intlayerProxy()],
|
|
405
|
+
});
|
|
406
|
+
```
|
|
407
|
+
|
|
408
|
+
```javascript {3,7} fileName="vite.config.cjs" codeFormat="commonjs"
|
|
409
|
+
const { defineConfig } = require("vite");
|
|
410
|
+
const { svelte } = require("@sveltejs/vite-plugin-svelte");
|
|
411
|
+
const { intlayer, intlayerProxy } = require("vite-intlayer");
|
|
412
|
+
|
|
413
|
+
// https://vitejs.dev/config/
|
|
414
|
+
module.exports = defineConfig({
|
|
415
|
+
plugins: [svelte(), intlayer(), intlayerProxy()],
|
|
416
|
+
});
|
|
417
|
+
```
|
|
418
|
+
|
|
419
|
+
### (Opcional) Paso 8: Cambiar la URL cuando cambia la locale
|
|
420
|
+
|
|
421
|
+
Para permitir que los usuarios cambien de idioma y actualicen la URL en consecuencia, puedes crear un componente `LocaleSwitcher`. Este componente usará `getLocalizedUrl` de `intlayer` y `push` de `svelte-spa-router`.
|
|
422
|
+
|
|
423
|
+
```svelte fileName="src/lib/LocaleSwitcher.svelte"
|
|
424
|
+
<script lang="ts">
|
|
425
|
+
import { getLocaleName, getLocalizedUrl } from "intlayer";
|
|
426
|
+
import { useLocale } from "svelte-intlayer";
|
|
427
|
+
import { push } from "svelte-spa-router";
|
|
428
|
+
|
|
429
|
+
export let currentLocale: string | undefined = undefined;
|
|
430
|
+
|
|
431
|
+
// Obtener información de la locale
|
|
432
|
+
const { locale, availableLocales } = useLocale();
|
|
433
|
+
|
|
434
|
+
// Manejar el cambio de locale
|
|
435
|
+
const changeLocale = (event: Event) => {
|
|
436
|
+
plugins: [svelte(), intlayer(), intlayerProxy()],
|
|
437
|
+
});
|
|
438
|
+
```
|
|
268
439
|
|
|
269
440
|
### (Opcional) Paso 8: Cambiar la URL cuando cambia la configuración regional
|
|
270
441
|
|
|
271
|
-
|
|
442
|
+
Para permitir que los usuarios cambien de idioma y actualicen la URL en consecuencia, puedes crear un componente `LocaleSwitcher`. Este componente utilizará `getLocalizedUrl` de `intlayer` y `push` de `svelte-spa-router`.
|
|
272
443
|
|
|
273
|
-
|
|
444
|
+
```svelte fileName="src/lib/LocaleSwitcher.svelte"
|
|
445
|
+
<script lang="ts">
|
|
446
|
+
import { getLocaleName, getLocalizedUrl } from "intlayer";
|
|
447
|
+
import { useLocale } from "svelte-intlayer";
|
|
448
|
+
import { push } from "svelte-spa-router";
|
|
274
449
|
|
|
275
|
-
|
|
450
|
+
export let currentLocale: string | undefined = undefined;
|
|
276
451
|
|
|
277
|
-
|
|
452
|
+
// Obtener información de la configuración regional
|
|
453
|
+
const { locale, availableLocales } = useLocale();
|
|
278
454
|
|
|
279
|
-
|
|
455
|
+
// Manejar el cambio de configuración regional
|
|
456
|
+
const changeLocale = (event: Event) => {
|
|
457
|
+
const target = event.target as HTMLSelectElement;
|
|
458
|
+
const newLocale = target.value;
|
|
459
|
+
const currentUrl = window.location.pathname;
|
|
460
|
+
const url = getLocalizedUrl( currentUrl, newLocale);
|
|
461
|
+
push(url);
|
|
462
|
+
};
|
|
463
|
+
</script>
|
|
464
|
+
|
|
465
|
+
<div class="locale-switcher">
|
|
466
|
+
<select value={currentLocale ?? $locale} onchange={changeLocale}>
|
|
467
|
+
{#each availableLocales ?? [] as loc}
|
|
468
|
+
<option value={loc}>
|
|
469
|
+
{getLocaleName(loc)}
|
|
470
|
+
</option>
|
|
471
|
+
{/each}
|
|
472
|
+
</select>
|
|
473
|
+
</div>
|
|
474
|
+
```
|
|
280
475
|
|
|
281
476
|
### Configuración de Git
|
|
282
477
|
|
|
283
|
-
Se recomienda ignorar los archivos generados por Intlayer. Esto
|
|
478
|
+
Se recomienda ignorar los archivos generados por Intlayer. Esto te permite evitar comprometerlos en tu repositorio Git.
|
|
284
479
|
|
|
285
|
-
Para
|
|
480
|
+
Para hacerlo, puedes agregar las siguientes instrucciones a tu archivo `.gitignore`:
|
|
286
481
|
|
|
287
482
|
```plaintext
|
|
288
483
|
# Ignorar los archivos generados por Intlayer
|
|
@@ -291,23 +486,21 @@ Para hacer esto, puede agregar las siguientes instrucciones a su archivo `.gitig
|
|
|
291
486
|
|
|
292
487
|
### Extensión para VS Code
|
|
293
488
|
|
|
294
|
-
Para mejorar
|
|
489
|
+
Para mejorar tu experiencia de desarrollo con Intlayer, puedes instalar la extensión oficial **Intlayer VS Code Extension**.
|
|
295
490
|
|
|
296
|
-
[Instalar desde el
|
|
491
|
+
[Instalar desde el VS Code Marketplace](https://marketplace.visualstudio.com/items?itemName=intlayer.intlayer-vs-code-extension)
|
|
297
492
|
|
|
298
|
-
Esta extensión
|
|
493
|
+
Esta extensión ofrece:
|
|
299
494
|
|
|
300
495
|
- **Autocompletado** para las claves de traducción.
|
|
301
496
|
- **Detección de errores en tiempo real** para traducciones faltantes.
|
|
302
|
-
- **
|
|
497
|
+
- **Vistas previas en línea** del contenido traducido.
|
|
303
498
|
- **Acciones rápidas** para crear y actualizar traducciones fácilmente.
|
|
304
499
|
|
|
305
|
-
Para más detalles sobre cómo usar la extensión,
|
|
500
|
+
Para más detalles sobre cómo usar la extensión, consulta la [documentación de la extensión Intlayer para VS Code](https://intlayer.org/doc/vs-code-extension).
|
|
306
501
|
|
|
307
502
|
---
|
|
308
503
|
|
|
309
504
|
### Ir Más Allá
|
|
310
505
|
|
|
311
|
-
Para ir más allá,
|
|
312
|
-
|
|
313
|
-
---
|
|
506
|
+
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).
|