@intlayer/docs 7.0.3 → 7.0.4
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/blog/ar/intlayer_with_i18next.md +68 -106
- package/blog/ar/intlayer_with_next-i18next.md +84 -288
- package/blog/ar/intlayer_with_next-intl.md +58 -337
- package/blog/ar/intlayer_with_react-i18next.md +68 -290
- package/blog/ar/intlayer_with_react-intl.md +63 -266
- package/blog/de/intlayer_with_i18next.md +77 -97
- package/blog/de/intlayer_with_next-i18next.md +69 -296
- package/blog/de/intlayer_with_next-intl.md +59 -340
- package/blog/de/intlayer_with_react-i18next.md +68 -290
- package/blog/de/intlayer_with_react-intl.md +62 -264
- package/blog/en/intlayer_with_i18next.md +67 -103
- package/blog/en/intlayer_with_next-i18next.md +69 -294
- package/blog/en/intlayer_with_next-intl.md +48 -300
- package/blog/en/intlayer_with_react-i18next.md +61 -289
- package/blog/en/intlayer_with_react-intl.md +61 -284
- package/blog/en/next-i18next_vs_next-intl_vs_intlayer.md +1 -1
- package/blog/en-GB/intlayer_with_i18next.md +67 -103
- package/blog/en-GB/intlayer_with_next-i18next.md +71 -292
- package/blog/en-GB/intlayer_with_next-intl.md +58 -337
- package/blog/en-GB/intlayer_with_react-i18next.md +67 -289
- package/blog/en-GB/intlayer_with_react-intl.md +61 -264
- package/blog/es/intlayer_with_i18next.md +67 -103
- package/blog/es/intlayer_with_next-i18next.md +71 -296
- package/blog/es/intlayer_with_next-intl.md +57 -338
- package/blog/es/intlayer_with_react-i18next.md +68 -290
- package/blog/es/intlayer_with_react-intl.md +62 -265
- package/blog/fr/intlayer_with_i18next.md +66 -104
- package/blog/fr/intlayer_with_next-i18next.md +82 -285
- package/blog/fr/intlayer_with_next-intl.md +57 -338
- package/blog/fr/intlayer_with_react-i18next.md +67 -289
- package/blog/fr/intlayer_with_react-intl.md +61 -264
- package/blog/hi/intlayer_with_i18next.md +68 -104
- package/blog/hi/intlayer_with_next-i18next.md +74 -299
- package/blog/hi/intlayer_with_next-intl.md +57 -239
- package/blog/hi/intlayer_with_react-i18next.md +69 -291
- package/blog/hi/intlayer_with_react-intl.md +65 -268
- package/blog/id/intlayer_with_i18next.md +126 -0
- package/blog/id/intlayer_with_next-i18next.md +142 -0
- package/blog/id/intlayer_with_next-intl.md +113 -0
- package/blog/id/intlayer_with_react-i18next.md +124 -0
- package/blog/id/intlayer_with_react-intl.md +122 -0
- package/blog/it/intlayer_with_i18next.md +67 -103
- package/blog/it/intlayer_with_next-i18next.md +71 -296
- package/blog/it/intlayer_with_next-intl.md +57 -338
- package/blog/it/intlayer_with_react-i18next.md +68 -290
- package/blog/it/intlayer_with_react-intl.md +62 -265
- package/blog/ja/intlayer_with_i18next.md +68 -103
- package/blog/ja/intlayer_with_next-i18next.md +85 -283
- package/blog/ja/intlayer_with_next-intl.md +58 -336
- package/blog/ja/intlayer_with_react-i18next.md +68 -290
- package/blog/ja/intlayer_with_react-intl.md +62 -264
- package/blog/ko/intlayer_with_i18next.md +80 -96
- package/blog/ko/intlayer_with_next-i18next.md +85 -287
- package/blog/ko/intlayer_with_next-intl.md +68 -327
- package/blog/ko/intlayer_with_react-i18next.md +68 -290
- package/blog/ko/intlayer_with_react-intl.md +64 -266
- package/blog/pl/intlayer_with_i18next.md +126 -0
- package/blog/pl/intlayer_with_next-i18next.md +142 -0
- package/blog/pl/intlayer_with_next-intl.md +111 -0
- package/blog/pl/intlayer_with_react-i18next.md +124 -0
- package/blog/pl/intlayer_with_react-intl.md +122 -0
- package/blog/pt/intlayer_with_i18next.md +67 -103
- package/blog/pt/intlayer_with_next-i18next.md +72 -293
- package/blog/pt/intlayer_with_next-intl.md +57 -256
- package/blog/pt/intlayer_with_react-i18next.md +104 -78
- package/blog/pt/intlayer_with_react-intl.md +62 -266
- package/blog/ru/intlayer_with_i18next.md +66 -104
- package/blog/ru/intlayer_with_next-i18next.md +71 -296
- package/blog/ru/intlayer_with_next-intl.md +58 -337
- package/blog/ru/intlayer_with_react-i18next.md +68 -290
- package/blog/ru/intlayer_with_react-intl.md +62 -265
- package/blog/tr/intlayer_with_i18next.md +71 -107
- package/blog/tr/intlayer_with_next-i18next.md +72 -297
- package/blog/tr/intlayer_with_next-intl.md +58 -339
- package/blog/tr/intlayer_with_react-i18next.md +69 -291
- package/blog/tr/intlayer_with_react-intl.md +63 -285
- package/blog/vi/intlayer_with_i18next.md +126 -0
- package/blog/vi/intlayer_with_next-i18next.md +142 -0
- package/blog/vi/intlayer_with_next-intl.md +111 -0
- package/blog/vi/intlayer_with_react-i18next.md +124 -0
- package/blog/vi/intlayer_with_react-intl.md +122 -0
- package/blog/zh/intlayer_with_i18next.md +67 -102
- package/blog/zh/intlayer_with_next-i18next.md +72 -296
- package/blog/zh/intlayer_with_next-intl.md +58 -336
- package/blog/zh/intlayer_with_react-i18next.md +68 -290
- package/blog/zh/intlayer_with_react-intl.md +63 -106
- package/dist/cjs/generated/blog.entry.cjs +13 -1
- package/dist/cjs/generated/blog.entry.cjs.map +1 -1
- package/dist/cjs/generated/docs.entry.cjs +13 -1
- package/dist/cjs/generated/docs.entry.cjs.map +1 -1
- package/dist/cjs/generated/frequentQuestions.entry.cjs +13 -1
- package/dist/cjs/generated/frequentQuestions.entry.cjs.map +1 -1
- package/dist/cjs/generated/legal.entry.cjs +13 -1
- package/dist/cjs/generated/legal.entry.cjs.map +1 -1
- package/dist/esm/generated/blog.entry.mjs +13 -2
- package/dist/esm/generated/blog.entry.mjs.map +1 -1
- package/dist/esm/generated/docs.entry.mjs +13 -2
- package/dist/esm/generated/docs.entry.mjs.map +1 -1
- package/dist/esm/generated/frequentQuestions.entry.mjs +13 -2
- package/dist/esm/generated/frequentQuestions.entry.mjs.map +1 -1
- package/dist/esm/generated/legal.entry.mjs +13 -2
- package/dist/esm/generated/legal.entry.mjs.map +1 -1
- package/dist/types/generated/blog.entry.d.ts.map +1 -1
- package/dist/types/generated/docs.entry.d.ts.map +1 -1
- package/dist/types/generated/frequentQuestions.entry.d.ts.map +1 -1
- package/dist/types/generated/legal.entry.d.ts.map +1 -1
- package/docs/ar/plugins/sync-json.md +244 -0
- package/docs/de/plugins/sync-json.md +244 -0
- package/docs/de/releases/v7.md +1 -18
- package/docs/en/CI_CD.md +1 -1
- package/docs/en/configuration.md +1 -1
- package/docs/en/formatters.md +1 -1
- package/docs/en/how_works_intlayer.md +1 -1
- package/docs/en/intlayer_CMS.md +1 -1
- package/docs/en/intlayer_cli.md +26 -1
- package/docs/en/intlayer_with_nextjs_14.md +3 -1
- package/docs/en/intlayer_with_nextjs_15.md +3 -1
- package/docs/en/intlayer_with_nextjs_16.md +3 -1
- package/docs/en/intlayer_with_nextjs_page_router.md +1 -1
- package/docs/en/intlayer_with_nuxt.md +1 -1
- package/docs/en/intlayer_with_react_native+expo.md +1 -1
- package/docs/en/intlayer_with_react_router_v7.md +1 -1
- package/docs/en/intlayer_with_tanstack.md +1 -1
- package/docs/en/intlayer_with_vite+preact.md +1 -1
- package/docs/en/intlayer_with_vite+react.md +1 -1
- package/docs/en/intlayer_with_vite+solid.md +1 -1
- package/docs/en/intlayer_with_vite+svelte.md +1 -1
- package/docs/en/intlayer_with_vite+vue.md +1 -1
- package/docs/en/plugins/sync-json.md +1 -1
- package/docs/en/roadmap.md +1 -1
- package/docs/en-GB/plugins/sync-json.md +244 -0
- package/docs/es/plugins/sync-json.md +244 -0
- package/docs/es/releases/v7.md +1 -18
- package/docs/fr/intlayer_with_nextjs_16.md +2 -51
- package/docs/fr/plugins/sync-json.md +244 -0
- package/docs/fr/releases/v7.md +1 -18
- package/docs/hi/intlayer_with_nextjs_16.md +3 -2
- package/docs/hi/plugins/sync-json.md +244 -0
- package/docs/id/plugins/sync-json.md +244 -0
- package/docs/id/releases/v7.md +1 -18
- package/docs/it/plugins/sync-json.md +244 -0
- package/docs/it/releases/v7.md +1 -18
- package/docs/ja/intlayer_with_nextjs_16.md +44 -205
- package/docs/ja/plugins/sync-json.md +244 -0
- package/docs/ja/releases/v7.md +1 -18
- package/docs/ko/plugins/sync-json.md +244 -0
- package/docs/ko/releases/v7.md +1 -18
- package/docs/pl/plugins/sync-json.md +244 -0
- package/docs/pt/intlayer_with_nextjs_16.md +1 -52
- package/docs/pt/plugins/sync-json.md +244 -0
- package/docs/ru/plugins/sync-json.md +244 -0
- package/docs/tr/plugins/sync-json.md +245 -0
- package/docs/vi/plugins/sync-json.md +244 -0
- package/docs/zh/plugins/sync-json.md +244 -0
- package/package.json +14 -14
- package/src/generated/blog.entry.ts +26 -3
- package/src/generated/docs.entry.ts +26 -3
- package/src/generated/frequentQuestions.entry.ts +26 -3
- package/src/generated/legal.entry.ts +26 -3
|
@@ -1,346 +1,124 @@
|
|
|
1
1
|
---
|
|
2
2
|
createdAt: 2025-01-02
|
|
3
|
-
updatedAt: 2025-
|
|
4
|
-
title:
|
|
5
|
-
description:
|
|
3
|
+
updatedAt: 2025-10-29
|
|
4
|
+
title: Cómo automatizar tus traducciones JSON de react-i18next usando Intlayer
|
|
5
|
+
description: Automatiza tus traducciones JSON con Intlayer y react-i18next para una internacionalización mejorada en aplicaciones React.
|
|
6
6
|
keywords:
|
|
7
7
|
- react-i18next
|
|
8
8
|
- i18next
|
|
9
9
|
- Intlayer
|
|
10
10
|
- Internacionalización
|
|
11
|
-
-
|
|
12
|
-
-
|
|
13
|
-
- JavaScript
|
|
11
|
+
- i18n
|
|
12
|
+
- Blog
|
|
14
13
|
- React
|
|
14
|
+
- JavaScript
|
|
15
|
+
- TypeScript
|
|
16
|
+
- Gestión de Contenido
|
|
15
17
|
slugs:
|
|
16
18
|
- blog
|
|
17
19
|
- intlayer-with-react-i18next
|
|
20
|
+
history:
|
|
21
|
+
- version: 7.0.0
|
|
22
|
+
date: 2025-10-29
|
|
23
|
+
changes: Cambio al plugin syncJSON
|
|
18
24
|
---
|
|
19
25
|
|
|
20
|
-
#
|
|
21
|
-
|
|
22
|
-
## Resumen
|
|
23
|
-
|
|
24
|
-
- **Intlayer** te ayuda a gestionar traducciones a través de archivos de declaración de contenido a **nivel de componente**.
|
|
25
|
-
- **react-i18next** es una integración popular de React para **i18next** que proporciona hooks como `useTranslation` para obtener cadenas localizadas en tus componentes.
|
|
26
|
-
|
|
27
|
-
Cuando se combinan, Intlayer puede **exportar** diccionarios en **JSON compatible con i18next**, de modo que react-i18next pueda **consumirlos** en tiempo de ejecución.
|
|
28
|
-
|
|
29
|
-
## ¿Por Qué Usar Intlayer con react-i18next?
|
|
30
|
-
|
|
31
|
-
Los archivos de declaración de contenido **Intlayer** ofrecen una mejor experiencia para desarrolladores porque son:
|
|
32
|
-
|
|
33
|
-
1. **Flexibles en la Ubicación de Archivos**
|
|
34
|
-
Coloca cada archivo de declaración de contenido justo al lado del componente que lo necesita. Esta estructura te permite mantener las traducciones co-localizadas, evitando traducciones huérfanas cuando los componentes se mueven o se eliminan.
|
|
35
|
-
|
|
36
|
-
```bash codeFormat="typescript"
|
|
37
|
-
.
|
|
38
|
-
└── src
|
|
39
|
-
└── components
|
|
40
|
-
└── MyComponent
|
|
41
|
-
├── index.content.ts # Archivo de declaración de contenido
|
|
42
|
-
└── index.tsx
|
|
43
|
-
```
|
|
44
|
-
|
|
45
|
-
```bash codeFormat="esm"
|
|
46
|
-
.
|
|
47
|
-
└── src
|
|
48
|
-
└── components
|
|
49
|
-
└── MyComponent
|
|
50
|
-
├── index.content.mjs # Archivo de declaración de contenido
|
|
51
|
-
└── index.mjx
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
```bash codeFormat="cjs"
|
|
55
|
-
.
|
|
56
|
-
└── src
|
|
57
|
-
└── components
|
|
58
|
-
└── MyComponent
|
|
59
|
-
├── index.content.cjs # Archivo de declaración de contenido
|
|
60
|
-
└── index.cjx
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
```bash codeFormat="json"
|
|
64
|
-
.
|
|
65
|
-
└── src
|
|
66
|
-
└── components
|
|
67
|
-
└── MyComponent
|
|
68
|
-
├── index.content.json # Archivo de declaración de contenido
|
|
69
|
-
└── index.jsx
|
|
70
|
-
```
|
|
71
|
-
|
|
72
|
-
2. **Traducciones Centralizadas**
|
|
73
|
-
Un solo archivo de declaración de contenido recopila todas las traducciones necesarias para un componente, haciendo que las traducciones faltantes sean más fáciles de detectar.
|
|
74
|
-
Con TypeScript, incluso obtienes errores en tiempo de compilación si faltan traducciones.
|
|
75
|
-
|
|
76
|
-
## Instalación
|
|
77
|
-
|
|
78
|
-
En un proyecto de Create React App, instala estas dependencias:
|
|
79
|
-
|
|
80
|
-
```bash
|
|
81
|
-
# Con npm
|
|
82
|
-
npm install intlayer react-i18next i18next i18next-resources-to-backend
|
|
83
|
-
```
|
|
84
|
-
|
|
85
|
-
```bash
|
|
86
|
-
# Con yarn
|
|
87
|
-
yarn add intlayer react-i18next i18next i18next-resources-to-backend
|
|
88
|
-
```
|
|
89
|
-
|
|
90
|
-
```bash
|
|
91
|
-
# Con pnpm
|
|
92
|
-
pnpm add intlayer react-i18next i18next i18next-resources-to-backend
|
|
93
|
-
```
|
|
26
|
+
# Cómo automatizar tus traducciones JSON de react-i18next usando Intlayer
|
|
94
27
|
|
|
95
|
-
|
|
28
|
+
## ¿Qué es Intlayer?
|
|
96
29
|
|
|
97
|
-
|
|
98
|
-
- **react-intlayer** – Integración específica de React para Intlayer, proporcionando notablemente algunos scripts para automatizar la construcción de diccionarios.
|
|
99
|
-
- **react-i18next** – Biblioteca de integración específica de React para i18next, incluyendo el hook `useTranslation`.
|
|
100
|
-
- **i18next** – El marco subyacente para el manejo de traducciones.
|
|
101
|
-
- **i18next-resources-to-backend** – Un backend de i18next que importa dinámicamente recursos JSON.
|
|
30
|
+
**Intlayer** es una biblioteca innovadora y de código abierto para la internacionalización, diseñada para abordar las limitaciones de las soluciones i18n tradicionales. Ofrece un enfoque moderno para la gestión de contenido en aplicaciones React.
|
|
102
31
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
Crea (o actualiza) tu `intlayer.config.ts` en la raíz de tu proyecto:
|
|
106
|
-
|
|
107
|
-
```typescript title="intlayer.config.ts"
|
|
108
|
-
import { Locales, type IntlayerConfig } from "intlayer";
|
|
109
|
-
|
|
110
|
-
const config: IntlayerConfig = {
|
|
111
|
-
internationalization: {
|
|
112
|
-
// Agrega tantos locales como desees
|
|
113
|
-
locales: [Locales.ENGLISH, Locales.FRENCH, Locales.SPANISH],
|
|
114
|
-
defaultLocale: Locales.ENGLISH,
|
|
115
|
-
},
|
|
116
|
-
content: {
|
|
117
|
-
// Indica a Intlayer que cree JSON compatible con i18next
|
|
118
|
-
dictionaryOutput: ["i18next"],
|
|
32
|
+
Consulta una comparación concreta con react-i18next en nuestro artículo del blog [react-i18next vs. react-intl vs. Intlayer](https://github.com/aymericzip/intlayer/blob/main/docs/blog/es/react-i18next_vs_react-intl_vs_intlayer.md).
|
|
119
33
|
|
|
120
|
-
|
|
121
|
-
// Esta carpeta se creará si no existe.
|
|
122
|
-
i18nextResourcesDir: "./i18next/resources",
|
|
123
|
-
},
|
|
124
|
-
};
|
|
34
|
+
## ¿Por qué combinar Intlayer con react-i18next?
|
|
125
35
|
|
|
126
|
-
|
|
127
|
-
```
|
|
36
|
+
Aunque Intlayer proporciona una excelente solución i18n independiente (consulta nuestra [guía de integración con React](https://github.com/aymericzip/intlayer/blob/main/docs/docs/es/intlayer_with_vite+react.md)), es posible que desees combinarlo con react-i18next por varias razones:
|
|
128
37
|
|
|
129
|
-
|
|
38
|
+
1. **Base de código existente**: Tienes una implementación establecida de react-i18next y quieres migrar gradualmente a la mejor experiencia de desarrollo que ofrece Intlayer.
|
|
39
|
+
2. **Requisitos heredados**: Tu proyecto requiere compatibilidad con plugins o flujos de trabajo existentes de react-i18next.
|
|
40
|
+
3. **Familiaridad del equipo**: Tu equipo está cómodo con react-i18next pero desea una mejor gestión del contenido.
|
|
130
41
|
|
|
131
|
-
|
|
42
|
+
**Para ello, Intlayer puede implementarse como un adaptador para react-i18next que ayude a automatizar tus traducciones JSON en la línea de comandos o en pipelines CI/CD, probar tus traducciones y más.**
|
|
132
43
|
|
|
133
|
-
|
|
44
|
+
Esta guía te muestra cómo aprovechar el sistema superior de declaración de contenido de Intlayer mientras mantienes la compatibilidad con react-i18next.
|
|
134
45
|
|
|
135
|
-
|
|
136
|
-
# Con npm
|
|
137
|
-
npx run intlayer build
|
|
138
|
-
```
|
|
46
|
+
## Tabla de Contenidos
|
|
139
47
|
|
|
140
|
-
|
|
141
|
-
# Con yarn
|
|
142
|
-
yarn intlayer build
|
|
143
|
-
```
|
|
48
|
+
<TOC/>
|
|
144
49
|
|
|
145
|
-
|
|
146
|
-
# Con pnpm
|
|
147
|
-
pnpm intlayer build
|
|
148
|
-
```
|
|
50
|
+
## Guía paso a paso para configurar Intlayer con react-i18next
|
|
149
51
|
|
|
150
|
-
|
|
52
|
+
### Paso 1: Instalar dependencias
|
|
151
53
|
|
|
152
|
-
|
|
54
|
+
Instala los paquetes necesarios:
|
|
153
55
|
|
|
154
|
-
```bash
|
|
155
|
-
|
|
156
|
-
└── i18next
|
|
157
|
-
└── resources
|
|
158
|
-
├── en
|
|
159
|
-
│ └── my-content.json
|
|
160
|
-
├── fr
|
|
161
|
-
│ └── my-content.json
|
|
162
|
-
└── es
|
|
163
|
-
└── my-content.json
|
|
56
|
+
```bash packageManager="npm"
|
|
57
|
+
npm install intlayer @intlayer/sync-json-plugin
|
|
164
58
|
```
|
|
165
59
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
## Importando Diccionarios en tu Configuración de react-i18next
|
|
169
|
-
|
|
170
|
-
Para cargar dinámicamente estos recursos en tiempo de ejecución, utiliza [`i18next-resources-to-backend`](https://www.npmjs.com/package/i18next-resources-to-backend). Por ejemplo, crea un archivo `i18n.ts` (o `.js`) en tu proyecto:
|
|
171
|
-
|
|
172
|
-
```typescript title="i18n.ts"
|
|
173
|
-
import i18next from "i18next";
|
|
174
|
-
import { initReactI18next } from "react-i18next";
|
|
175
|
-
import resourcesToBackend from "i18next-resources-to-backend";
|
|
176
|
-
|
|
177
|
-
i18next
|
|
178
|
-
// plugin react-i18next
|
|
179
|
-
.use(initReactI18next)
|
|
180
|
-
// carga dinámicamente los recursos
|
|
181
|
-
.use(
|
|
182
|
-
resourcesToBackend((language: string, namespace: string) => {
|
|
183
|
-
// Ajusta la ruta de importación a tu directorio de recursos
|
|
184
|
-
return import(`../i18next/resources/${language}/${namespace}.json`);
|
|
185
|
-
})
|
|
186
|
-
)
|
|
187
|
-
// Inicializa i18next
|
|
188
|
-
.init({
|
|
189
|
-
// Localidad de respaldo
|
|
190
|
-
fallbackLng: "en",
|
|
191
|
-
|
|
192
|
-
// Puedes agregar otras opciones de configuración de i18next aquí, consulta:
|
|
193
|
-
// https://www.i18next.com/overview/configuration-options
|
|
194
|
-
});
|
|
195
|
-
|
|
196
|
-
export default i18next;
|
|
60
|
+
```bash packageManager="pnpm"
|
|
61
|
+
pnpm add intlayer @intlayer/sync-json-plugin
|
|
197
62
|
```
|
|
198
63
|
|
|
199
|
-
```
|
|
200
|
-
|
|
201
|
-
import { initReactI18next } from "react-i18next";
|
|
202
|
-
import resourcesToBackend from "i18next-resources-to-backend";
|
|
203
|
-
|
|
204
|
-
i18next
|
|
205
|
-
.use(initReactI18next)
|
|
206
|
-
.use(
|
|
207
|
-
resourcesToBackend(
|
|
208
|
-
(language, namespace) =>
|
|
209
|
-
import(`../i18next/resources/${language}/${namespace}.json`)
|
|
210
|
-
)
|
|
211
|
-
)
|
|
212
|
-
.init({
|
|
213
|
-
fallbackLng: "en",
|
|
214
|
-
});
|
|
215
|
-
|
|
216
|
-
export default i18next;
|
|
64
|
+
```bash packageManager="yarn"
|
|
65
|
+
yarn add intlayer @intlayer/sync-json-plugin
|
|
217
66
|
```
|
|
218
67
|
|
|
219
|
-
|
|
68
|
+
**Descripción de los paquetes:**
|
|
220
69
|
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
import ReactDOM from "react-dom/client";
|
|
224
|
-
// Inicializa i18n antes de cualquier otra cosa
|
|
225
|
-
import "./i18n";
|
|
226
|
-
import App from "./App";
|
|
70
|
+
- **intlayer**: Biblioteca principal para la gestión de internacionalización, declaración de contenido y construcción
|
|
71
|
+
- **@intlayer/sync-json-plugin**: Plugin para exportar declaraciones de contenido de Intlayer a un formato JSON compatible con react-i18next
|
|
227
72
|
|
|
228
|
-
|
|
229
|
-
<React.StrictMode>
|
|
230
|
-
<App />
|
|
231
|
-
</React.StrictMode>
|
|
232
|
-
);
|
|
233
|
-
```
|
|
73
|
+
### Paso 2: Implementar el plugin de Intlayer para envolver el JSON
|
|
234
74
|
|
|
235
|
-
|
|
75
|
+
Crea un archivo de configuración de Intlayer para definir los locales que soportas:
|
|
236
76
|
|
|
237
|
-
|
|
238
|
-
Aquí hay un ejemplo mínimo en TypeScript:
|
|
77
|
+
**Si también quieres exportar diccionarios JSON para react-i18next**, añade el plugin `syncJSON`:
|
|
239
78
|
|
|
240
|
-
```typescript
|
|
241
|
-
import {
|
|
79
|
+
```typescript fileName="intlayer.config.ts"
|
|
80
|
+
import { Locales, type IntlayerConfig } from "intlayer";
|
|
81
|
+
import { syncJSON } from "@intlayer/sync-json-plugin";
|
|
242
82
|
|
|
243
|
-
const
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
// Cada llamada "t" es un nodo de traducción separado
|
|
248
|
-
heading: t({
|
|
249
|
-
en: "Hello World",
|
|
250
|
-
es: "Hola Mundo",
|
|
251
|
-
fr: "Bonjour le monde",
|
|
252
|
-
}),
|
|
253
|
-
description: t({
|
|
254
|
-
en: "My i18n description text...",
|
|
255
|
-
fr: "Ma description en i18n...",
|
|
256
|
-
es: "Mi descripción en i18n...",
|
|
257
|
-
}),
|
|
83
|
+
const config: IntlayerConfig = {
|
|
84
|
+
internationalization: {
|
|
85
|
+
locales: [Locales.ENGLISH, Locales.FRENCH, Locales.SPANISH],
|
|
86
|
+
defaultLocale: Locales.ENGLISH,
|
|
258
87
|
},
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
Si prefieres JSON, `.cjs` o `.mjs`, consulta la [documentación de Intlayer](https://intlayer.org/en/doc/concept/content).
|
|
265
|
-
|
|
266
|
-
> Por defecto, las declaraciones de contenido válidas coinciden con el patrón de extensión de archivo:
|
|
267
|
-
|
|
268
|
-
> `*.content.{ts,tsx,js,jsx,mjs,mjx,cjs,cjx,json}`
|
|
269
|
-
|
|
270
|
-
## Usando las Traducciones en Componentes de React
|
|
271
|
-
|
|
272
|
-
Después de que hayas **construido** tus recursos de Intlayer y configurado react-i18next, puedes usar directamente el hook `useTranslation` de **react-i18next**.
|
|
273
|
-
Por ejemplo:
|
|
274
|
-
|
|
275
|
-
```tsx title="src/components/MyComponent/MyComponent.tsx"
|
|
276
|
-
import type { FC } from "react";
|
|
277
|
-
import { useTranslation } from "react-i18next";
|
|
278
|
-
|
|
279
|
-
/**
|
|
280
|
-
* El "espacio de nombres" de i18next es la `clave` de Intlayer de "MyComponent.content.ts"
|
|
281
|
-
* así que pasaremos "my-component" a useTranslation().
|
|
282
|
-
*/
|
|
283
|
-
const MyComponent: FC = () => {
|
|
284
|
-
const { t } = useTranslation("my-component");
|
|
285
|
-
|
|
286
|
-
return (
|
|
287
|
-
<div>
|
|
288
|
-
<h1>{t("heading")}</h1>
|
|
289
|
-
<p>{t("description")}</p>
|
|
290
|
-
</div>
|
|
291
|
-
);
|
|
88
|
+
plugins: [
|
|
89
|
+
syncJSON({
|
|
90
|
+
source: ({ key, locale }) => `./messages/${locale}/${key}.json`,
|
|
91
|
+
}),
|
|
92
|
+
],
|
|
292
93
|
};
|
|
293
94
|
|
|
294
|
-
export default
|
|
95
|
+
export default config;
|
|
295
96
|
```
|
|
296
97
|
|
|
297
|
-
|
|
98
|
+
El plugin `syncJSON` envolverá automáticamente el JSON. Leerá y escribirá los archivos JSON sin cambiar la arquitectura del contenido.
|
|
298
99
|
|
|
299
|
-
|
|
100
|
+
Si deseas hacer coexistir ese JSON con los archivos de declaración de contenido de intlayer (`.content`), Intlayer procederá de la siguiente manera:
|
|
300
101
|
|
|
301
|
-
|
|
102
|
+
1. cargar tanto los archivos JSON como los archivos de declaración de contenido y transformarlos en un diccionario de intlayer.
|
|
103
|
+
2. si hay conflictos entre el JSON y los archivos de declaración de contenido, Intlayer procederá a fusionar todos esos diccionarios. Dependiendo de la prioridad de los plugins y la del archivo de declaración de contenido (todos son configurables).
|
|
302
104
|
|
|
303
|
-
|
|
304
|
-
```bash
|
|
305
|
-
npm install react-intlayer --save-dev
|
|
306
|
-
```
|
|
307
|
-
2. **Ajustar tus scripts de `package.json`** para usar los scripts de `react-intlayer`:
|
|
105
|
+
Si se realizan cambios usando la CLI para traducir el JSON, o usando el CMS, Intlayer actualizará el archivo JSON con las nuevas traducciones.
|
|
308
106
|
|
|
309
|
-
|
|
310
|
-
"scripts": {
|
|
311
|
-
"start": "react-intlayer start",
|
|
312
|
-
"build": "react-intlayer build",
|
|
313
|
-
"transpile": "intlayer build"
|
|
314
|
-
}
|
|
315
|
-
```
|
|
107
|
+
Para ver más detalles sobre el plugin `syncJSON`, por favor consulte la [documentación del plugin syncJSON](https://github.com/aymericzip/intlayer/blob/main/docs/docs/es/plugins/sync-json.md).
|
|
316
108
|
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
Ahora, al ejecutar `npm run build`, `yarn build`, o `pnpm build` se activan las construcciones de Intlayer y CRA.
|
|
320
|
-
|
|
321
|
-
## Configuración de TypeScript
|
|
109
|
+
## Configuración de Git
|
|
322
110
|
|
|
323
|
-
|
|
111
|
+
Se recomienda ignorar los archivos generados automáticamente por Intlayer:
|
|
324
112
|
|
|
325
|
-
```
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
// ...
|
|
329
|
-
},
|
|
330
|
-
"include": ["src", "types"],
|
|
331
|
-
}
|
|
113
|
+
```plaintext fileName=".gitignore"
|
|
114
|
+
# Ignorar archivos generados por Intlayer
|
|
115
|
+
.intlayer
|
|
332
116
|
```
|
|
333
117
|
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
## Configuración de Git
|
|
118
|
+
Estos archivos pueden ser regenerados durante su proceso de compilación y no necesitan ser comprometidos en el control de versiones.
|
|
337
119
|
|
|
338
|
-
|
|
120
|
+
### Extensión de VS Code
|
|
339
121
|
|
|
340
|
-
|
|
341
|
-
# Ignorar los archivos generados por Intlayer
|
|
342
|
-
.intlayer
|
|
343
|
-
i18next
|
|
344
|
-
```
|
|
122
|
+
Para mejorar la experiencia del desarrollador, instale la extensión oficial **Intlayer VS Code Extension**:
|
|
345
123
|
|
|
346
|
-
|
|
124
|
+
[Instalar desde el Marketplace de VS Code](https://marketplace.visualstudio.com/items?itemName=intlayer.intlayer-vs-code-extension)
|