@intlayer/docs 7.3.14 → 7.4.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.
Files changed (175) hide show
  1. package/blog/ar/intlayer_with_i18next.md +3 -0
  2. package/blog/ar/intlayer_with_next-i18next.md +3 -0
  3. package/blog/ar/intlayer_with_next-intl.md +3 -0
  4. package/blog/ar/intlayer_with_react-i18next.md +3 -0
  5. package/blog/ar/intlayer_with_react-intl.md +3 -0
  6. package/blog/ar/intlayer_with_vue-i18n.md +3 -0
  7. package/blog/de/intlayer_with_i18next.md +3 -0
  8. package/blog/de/intlayer_with_next-i18next.md +3 -0
  9. package/blog/de/intlayer_with_next-intl.md +3 -0
  10. package/blog/de/intlayer_with_react-i18next.md +3 -0
  11. package/blog/de/intlayer_with_react-intl.md +3 -0
  12. package/blog/de/intlayer_with_vue-i18n.md +3 -0
  13. package/blog/en/intlayer_with_i18next.md +7 -0
  14. package/blog/en/intlayer_with_next-i18next.md +3 -0
  15. package/blog/en/intlayer_with_next-intl.md +7 -0
  16. package/blog/en/intlayer_with_react-i18next.md +3 -0
  17. package/blog/en/intlayer_with_react-intl.md +3 -0
  18. package/blog/en/intlayer_with_vue-i18n.md +3 -0
  19. package/blog/en-GB/intlayer_with_i18next.md +3 -0
  20. package/blog/en-GB/intlayer_with_next-i18next.md +3 -0
  21. package/blog/en-GB/intlayer_with_next-intl.md +3 -0
  22. package/blog/en-GB/intlayer_with_react-i18next.md +3 -0
  23. package/blog/en-GB/intlayer_with_react-intl.md +3 -0
  24. package/blog/en-GB/intlayer_with_vue-i18n.md +3 -0
  25. package/blog/es/intlayer_with_i18next.md +3 -0
  26. package/blog/es/intlayer_with_next-i18next.md +3 -0
  27. package/blog/es/intlayer_with_next-intl.md +3 -0
  28. package/blog/es/intlayer_with_react-i18next.md +3 -0
  29. package/blog/es/intlayer_with_react-intl.md +3 -0
  30. package/blog/es/intlayer_with_vue-i18n.md +3 -0
  31. package/blog/fr/intlayer_with_i18next.md +3 -0
  32. package/blog/fr/intlayer_with_next-i18next.md +3 -0
  33. package/blog/fr/intlayer_with_next-intl.md +3 -0
  34. package/blog/fr/intlayer_with_react-i18next.md +3 -0
  35. package/blog/fr/intlayer_with_react-intl.md +3 -0
  36. package/blog/fr/intlayer_with_vue-i18n.md +3 -0
  37. package/blog/hi/intlayer_with_i18next.md +3 -0
  38. package/blog/hi/intlayer_with_next-i18next.md +3 -0
  39. package/blog/hi/intlayer_with_next-intl.md +3 -0
  40. package/blog/hi/intlayer_with_react-i18next.md +3 -0
  41. package/blog/hi/intlayer_with_react-intl.md +3 -0
  42. package/blog/hi/intlayer_with_vue-i18n.md +3 -0
  43. package/blog/id/intlayer_with_i18next.md +3 -0
  44. package/blog/id/intlayer_with_next-i18next.md +3 -0
  45. package/blog/id/intlayer_with_next-intl.md +3 -0
  46. package/blog/id/intlayer_with_react-i18next.md +3 -0
  47. package/blog/id/intlayer_with_react-intl.md +3 -0
  48. package/blog/id/intlayer_with_vue-i18n.md +3 -0
  49. package/blog/it/intlayer_with_i18next.md +3 -0
  50. package/blog/it/intlayer_with_next-i18next.md +3 -0
  51. package/blog/it/intlayer_with_next-intl.md +3 -0
  52. package/blog/it/intlayer_with_react-i18next.md +3 -0
  53. package/blog/it/intlayer_with_react-intl.md +3 -0
  54. package/blog/it/intlayer_with_vue-i18n.md +3 -0
  55. package/blog/ja/intlayer_with_i18next.md +3 -0
  56. package/blog/ja/intlayer_with_next-i18next.md +3 -0
  57. package/blog/ja/intlayer_with_next-intl.md +3 -0
  58. package/blog/ja/intlayer_with_react-i18next.md +3 -0
  59. package/blog/ja/intlayer_with_react-intl.md +3 -0
  60. package/blog/ja/intlayer_with_vue-i18n.md +3 -0
  61. package/blog/ko/intlayer_with_i18next.md +3 -0
  62. package/blog/ko/intlayer_with_next-i18next.md +3 -0
  63. package/blog/ko/intlayer_with_next-intl.md +3 -0
  64. package/blog/ko/intlayer_with_react-i18next.md +3 -0
  65. package/blog/ko/intlayer_with_react-intl.md +3 -0
  66. package/blog/ko/intlayer_with_vue-i18n.md +3 -0
  67. package/blog/pl/intlayer_with_i18next.md +3 -0
  68. package/blog/pl/intlayer_with_next-i18next.md +3 -0
  69. package/blog/pl/intlayer_with_next-intl.md +3 -0
  70. package/blog/pl/intlayer_with_react-i18next.md +3 -0
  71. package/blog/pl/intlayer_with_react-intl.md +3 -0
  72. package/blog/pl/intlayer_with_vue-i18n.md +3 -0
  73. package/blog/pt/intlayer_with_i18next.md +3 -0
  74. package/blog/pt/intlayer_with_next-i18next.md +3 -0
  75. package/blog/pt/intlayer_with_next-intl.md +3 -0
  76. package/blog/pt/intlayer_with_react-i18next.md +3 -0
  77. package/blog/pt/intlayer_with_react-intl.md +3 -0
  78. package/blog/pt/intlayer_with_vue-i18n.md +3 -0
  79. package/blog/ru/intlayer_with_i18next.md +3 -0
  80. package/blog/ru/intlayer_with_next-i18next.md +3 -0
  81. package/blog/ru/intlayer_with_next-intl.md +3 -0
  82. package/blog/ru/intlayer_with_react-i18next.md +3 -0
  83. package/blog/ru/intlayer_with_react-intl.md +3 -0
  84. package/blog/ru/intlayer_with_vue-i18n.md +3 -0
  85. package/blog/tr/intlayer_with_i18next.md +3 -0
  86. package/blog/tr/intlayer_with_next-i18next.md +3 -0
  87. package/blog/tr/intlayer_with_next-intl.md +3 -0
  88. package/blog/tr/intlayer_with_react-i18next.md +3 -0
  89. package/blog/tr/intlayer_with_vue-i18n.md +3 -0
  90. package/blog/vi/intlayer_with_i18next.md +3 -0
  91. package/blog/vi/intlayer_with_next-i18next.md +3 -0
  92. package/blog/vi/intlayer_with_next-intl.md +3 -0
  93. package/blog/vi/intlayer_with_react-i18next.md +3 -0
  94. package/blog/vi/intlayer_with_react-intl.md +3 -0
  95. package/blog/vi/intlayer_with_vue-i18n.md +3 -0
  96. package/blog/zh/intlayer_with_i18next.md +3 -0
  97. package/blog/zh/intlayer_with_next-i18next.md +3 -0
  98. package/blog/zh/intlayer_with_next-intl.md +3 -0
  99. package/blog/zh/intlayer_with_react-i18next.md +3 -0
  100. package/blog/zh/intlayer_with_react-intl.md +3 -0
  101. package/blog/zh/intlayer_with_vue-i18n.md +3 -0
  102. package/docs/ar/intlayer_with_lynx+react.md +1 -1
  103. package/docs/ar/intlayer_with_tanstack.md +132 -2
  104. package/docs/ar/intlayer_with_vite+react.md +99 -331
  105. package/docs/ar/plugins/sync-json.md +3 -0
  106. package/docs/de/intlayer_with_lynx+react.md +1 -1
  107. package/docs/de/intlayer_with_tanstack.md +132 -2
  108. package/docs/de/intlayer_with_vite+react.md +116 -380
  109. package/docs/de/plugins/sync-json.md +3 -0
  110. package/docs/en/intlayer_with_tanstack.md +131 -1
  111. package/docs/en/intlayer_with_vite+react.md +6 -10
  112. package/docs/en/plugins/sync-json.md +3 -0
  113. package/docs/en-GB/intlayer_with_tanstack.md +131 -1
  114. package/docs/en-GB/intlayer_with_vite+react.md +62 -74
  115. package/docs/en-GB/plugins/sync-json.md +3 -0
  116. package/docs/es/intlayer_with_tanstack.md +132 -2
  117. package/docs/es/intlayer_with_vite+react.md +101 -333
  118. package/docs/es/plugins/sync-json.md +3 -0
  119. package/docs/fr/intlayer_with_tanstack.md +132 -2
  120. package/docs/fr/intlayer_with_vite+react.md +101 -357
  121. package/docs/fr/plugins/sync-json.md +3 -0
  122. package/docs/hi/intlayer_with_tanstack.md +132 -2
  123. package/docs/hi/intlayer_with_vite+react.md +120 -333
  124. package/docs/hi/plugins/sync-json.md +3 -0
  125. package/docs/id/intlayer_with_tanstack.md +132 -2
  126. package/docs/id/intlayer_with_vite+react.md +7 -13
  127. package/docs/id/plugins/sync-json.md +3 -0
  128. package/docs/it/intlayer_with_lynx+react.md +1 -1
  129. package/docs/it/intlayer_with_tanstack.md +132 -2
  130. package/docs/it/intlayer_with_vite+react.md +121 -393
  131. package/docs/it/plugins/sync-json.md +3 -0
  132. package/docs/ja/intlayer_with_tanstack.md +132 -2
  133. package/docs/ja/intlayer_with_vite+react.md +106 -378
  134. package/docs/ja/plugins/sync-json.md +3 -0
  135. package/docs/ko/intlayer_with_lynx+react.md +1 -1
  136. package/docs/ko/intlayer_with_tanstack.md +132 -2
  137. package/docs/ko/intlayer_with_vite+react.md +90 -322
  138. package/docs/ko/plugins/sync-json.md +3 -0
  139. package/docs/pl/intlayer_with_tanstack.md +132 -2
  140. package/docs/pl/intlayer_with_vite+react.md +25 -21
  141. package/docs/pl/plugins/sync-json.md +3 -0
  142. package/docs/pt/intlayer_with_tanstack.md +132 -2
  143. package/docs/pt/intlayer_with_vite+react.md +96 -328
  144. package/docs/pt/plugins/sync-json.md +3 -0
  145. package/docs/ru/intlayer_with_lynx+react.md +1 -1
  146. package/docs/ru/intlayer_with_tanstack.md +132 -2
  147. package/docs/ru/intlayer_with_vite+react.md +109 -362
  148. package/docs/ru/plugins/sync-json.md +3 -0
  149. package/docs/tr/intlayer_with_tanstack.md +132 -2
  150. package/docs/tr/intlayer_with_vite+react.md +132 -366
  151. package/docs/tr/plugins/sync-json.md +3 -0
  152. package/docs/vi/intlayer_with_tanstack.md +132 -2
  153. package/docs/vi/intlayer_with_vite+react.md +16 -19
  154. package/docs/vi/plugins/sync-json.md +3 -0
  155. package/docs/zh/intlayer_with_tanstack.md +133 -3
  156. package/docs/zh/intlayer_with_vite+react.md +91 -374
  157. package/docs/zh/plugins/sync-json.md +3 -0
  158. package/frequent_questions/ar/customized_locale_list.md +1 -1
  159. package/frequent_questions/de/customized_locale_list.md +1 -1
  160. package/frequent_questions/en/customized_locale_list.md +1 -1
  161. package/frequent_questions/en-GB/customized_locale_list.md +1 -1
  162. package/frequent_questions/es/customized_locale_list.md +1 -1
  163. package/frequent_questions/fr/customized_locale_list.md +1 -1
  164. package/frequent_questions/hi/customized_locale_list.md +1 -1
  165. package/frequent_questions/id/customized_locale_list.md +1 -1
  166. package/frequent_questions/it/customized_locale_list.md +1 -1
  167. package/frequent_questions/ja/customized_locale_list.md +1 -1
  168. package/frequent_questions/ko/customized_locale_list.md +1 -1
  169. package/frequent_questions/pl/customized_locale_list.md +1 -1
  170. package/frequent_questions/pt/customized_locale_list.md +1 -1
  171. package/frequent_questions/ru/customized_locale_list.md +1 -1
  172. package/frequent_questions/tr/customized_locale_list.md +1 -1
  173. package/frequent_questions/vi/customized_locale_list.md +1 -1
  174. package/frequent_questions/zh/customized_locale_list.md +1 -1
  175. package/package.json +6 -6
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  createdAt: 2024-03-07
3
- updatedAt: 2024-03-07
4
- title: Cómo traducir tu Vite and React – guía i18n 2025
3
+ updatedAt: 2025-12-10
4
+ title: Cómo traducir tu aplicación Vite y React – guía i18n 2025
5
5
  description: Aprende cómo agregar internacionalización (i18n) a tu aplicación Vite y React usando Intlayer. Sigue esta guía para hacer tu aplicación multilingüe.
6
6
  keywords:
7
7
  - Internacionalización
@@ -16,23 +16,19 @@ slugs:
16
16
  - environment
17
17
  - vite-and-react
18
18
  applicationTemplate: https://github.com/aymericzip/intlayer-vite-react-template
19
- youtubeVideo: https://www.youtube.com/watch?v=dS9L7uJeak4---
19
+ youtubeVideo: https://www.youtube.com/watch?v=dS9L7uJeak4
20
20
  history:
21
21
  - version: 5.5.10
22
22
  date: 2025-06-29
23
23
  changes: Historial inicial
24
24
  ---
25
25
 
26
- # Comenzando con la internacionalización (i18n) usando Intlayer en Vite y React
26
+ # Traduce tu sitio web Vite y React usando Intlayer | Internacionalización (i18n)
27
27
 
28
28
  ## Tabla de contenido
29
29
 
30
30
  <TOC/>
31
31
 
32
- <iframe title="The best i18n solution for Vite and React? Discover 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?si=VaKmrYMmXjo3xpk2"/>
33
-
34
- Consulta la [Plantilla de Aplicación](https://github.com/aymericzip/intlayer-vite-react-template) en GitHub.
35
-
36
32
  ## ¿Qué es Intlayer?
37
33
 
38
34
  **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.
@@ -48,6 +44,27 @@ Con Intlayer, puedes:
48
44
 
49
45
  ## Guía paso a paso para configurar Intlayer en una aplicación Vite y React
50
46
 
47
+ <Tab defaultTab="video">
48
+ <TabItem label="Video" value="video">
49
+
50
+ <iframe title="The best i18n solution for Vite and React? Discover 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?si=VaKmrYMmXjo3xpk2"/>
51
+
52
+ </TabItem>
53
+ <TabItem label="Code" value="code">
54
+
55
+ <iframe
56
+ src="https://stackblitz.com/github/aymericzip/intlayer-vite-react-template?embed=1&ctl=1&file=intlayer.config.ts"
57
+ className="m-auto overflow-hidden rounded-lg border-0 max-md:size-full max-md:h-[700px] md:aspect-16/9 md:w-full"
58
+ title="Demo CodeSandbox - How to Internationalize your application using Intlayer"
59
+ sandbox="allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts"
60
+ loading="lazy"
61
+ />
62
+
63
+ </TabItem>
64
+ </Tab>
65
+
66
+ Consulta la [Plantilla de Aplicación](https://github.com/aymericzip/intlayer-vite-react-template) en GitHub.
67
+
51
68
  ### Paso 1: Instalar dependencias
52
69
 
53
70
  Instala los paquetes necesarios usando npm:
@@ -68,14 +85,13 @@ yarn add vite-intlayer --save-dev
68
85
  ```
69
86
 
70
87
  - **intlayer**
71
-
72
- 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).
88
+ 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/en/dictionary/content_file.md), transpile y [comandos CLI](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/cli/index.md).
73
89
 
74
90
  - **react-intlayer**
75
91
  El paquete que integra Intlayer con aplicaciones React. Proporciona proveedores de contexto y hooks para la internacionalización en React.
76
92
 
77
93
  - **vite-intlayer**
78
- 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 idioma preferido del usuario, gestionar cookies y manejar redirecciones de URL.
94
+ 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 la configuración regional preferida del usuario, gestionar cookies y manejar redirecciones de URL.
79
95
 
80
96
  ### Paso 2: Configuración de tu proyecto
81
97
 
@@ -137,7 +153,7 @@ const config = {
137
153
  module.exports = config;
138
154
  ```
139
155
 
140
- > 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, desactivar 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).
156
+ > 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, desactivar 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/en/configuration.md).
141
157
 
142
158
  ### Paso 3: Integra Intlayer en tu configuración de Vite
143
159
 
@@ -414,7 +430,7 @@ module.exports = appContent;
414
430
 
415
431
  > Sus declaraciones de contenido pueden definirse en cualquier lugar de su 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}`).
416
432
 
417
- > Para más detalles, consulte la [documentación de declaración de contenido](https://github.com/aymericzip/intlayer/blob/main/docs/docs/es/dictionary/get_started.md).
433
+ > Para más detalles, consulte la [documentación de declaración de contenido](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/dictionary/content_file.md).
418
434
 
419
435
  > Si su archivo de contenido incluye código TSX, debería considerar importar `import React from "react";` en su archivo de contenido.
420
436
 
@@ -634,87 +650,15 @@ Ejemplo:
634
650
  - https://example.com/fr/about
635
651
  ```
636
652
 
637
- > Por defecto, las rutas no tienen prefijo para la configuración regional predeterminada. Si desea agregar un prefijo para la configuración regional predeterminada, puede establecer la opción `middleware.prefixDefault` en `true` en su configuración. Consulte la [documentación de configuración](https://github.com/aymericzip/intlayer/blob/main/docs/docs/es/configuration.md) para obtener más información.
653
+ > Por defecto, las rutas no tienen prefijo para la configuración regional predeterminada. Si desea agregar un prefijo para la configuración regional predeterminada, puede establecer la opción `middleware.prefixDefault` en `true` en su configuración. Consulte la [documentación de configuración](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/configuration.md) para obtener más información.
638
654
 
639
655
  Para agregar enrutamiento localizado a su aplicación, puede crear un componente `LocaleRouter` que envuelva las rutas de su aplicación y gestione el enrutamiento basado en la configuración regional. Aquí hay un ejemplo usando [React Router](https://reactrouter.com/home):
640
656
 
641
657
  ```tsx fileName="src/components/LocaleRouter.tsx" codeFormat="typescript"
642
- // Importando las dependencias y funciones necesarias
643
- import { type Locales, configuration, getPathWithoutLocale } from "intlayer"; // Funciones y tipos utilitarios de 'intlayer'
658
+ import { localeMap } from "intlayer"; // Funciones y tipos utilitarios de 'intlayer'
644
659
  import type { FC, PropsWithChildren } from "react"; // Tipos de React para componentes funcionales y props
645
660
  import { IntlayerProvider } from "react-intlayer"; // Proveedor para el contexto de internacionalización
646
- import {
647
- BrowserRouter,
648
- Routes,
649
- Route,
650
- Navigate,
651
- useLocation,
652
- } from "react-router-dom"; // Componentes del router para gestionar la navegación
653
-
654
- // Desestructurando la configuración de Intlayer
655
- const { internationalization, middleware } = configuration;
656
- const { locales, defaultLocale } = internationalization;
657
-
658
- /**
659
- * Un componente que maneja la localización y envuelve a los hijos con el contexto de locale apropiado.
660
- * Gestiona la detección y validación del locale basado en la URL.
661
- */
662
- const AppLocalized: FC<PropsWithChildren<{ locale: Locales }>> = ({
663
- children,
664
- locale,
665
- }) => {
666
- const { pathname, search } = useLocation(); // Obtener la ruta URL actual
667
-
668
- // Determinar la configuración regional actual, usando la predeterminada si no se proporciona
669
- const currentLocale = locale ?? defaultLocale;
670
-
671
- // Eliminar el prefijo de la configuración regional de la ruta para construir una ruta base
672
- const pathWithoutLocale = getPathWithoutLocale(
673
- pathname // Ruta URL actual
674
- );
675
-
676
- /**
677
- * Si middleware.prefixDefault es true, la configuración regional predeterminada siempre debe tener prefijo.
678
- */
679
- if (middleware.prefixDefault) {
680
- // Validar la configuración regional
681
- if (!locale || !locales.includes(locale)) {
682
- // Redirigir a la configuración regional predeterminada con la ruta actualizada
683
- return (
684
- <Navigate
685
- to={`/${defaultLocale}/${pathWithoutLocale}${search}`}
686
- replace // Reemplaza la entrada actual del historial con la nueva
687
- />
688
- );
689
- }
690
-
691
- // Envuelve los hijos con IntlayerProvider y establece la configuración regional actual
692
- return (
693
- <IntlayerProvider locale={currentLocale}>{children}</IntlayerProvider>
694
- );
695
- } else {
696
- /**
697
- * Cuando middleware.prefixDefault es falso, la configuración regional predeterminada no tiene prefijo.
698
- * Asegúrate de que la configuración regional actual sea válida y no sea la predeterminada.
699
- */
700
- if (
701
- currentLocale.toString() !== defaultLocale.toString() &&
702
- !locales
703
- .filter(
704
- (locale) => locale.toString() !== defaultLocale.toString() // Excluir la configuración regional predeterminada
705
- )
706
- .includes(currentLocale) // Verifica si la configuración regional actual está en la lista de configuraciones regionales válidas
707
- ) {
708
- // Redirige a la ruta sin el prefijo de configuración regional
709
- return <Navigate to={`${pathWithoutLocale}${search}`} replace />;
710
- }
711
-
712
- // Envuelve los hijos con IntlayerProvider y establece la configuración regional actual
713
- return (
714
- <IntlayerProvider locale={currentLocale}>{children}</IntlayerProvider>
715
- );
716
- }
717
- };
661
+ import { BrowserRouter, Route, Routes } from "react-router-dom"; // Componentes del router para gestionar la navegación
718
662
 
719
663
  /**
720
664
  * Un componente de enrutador que configura rutas específicas por configuración regional.
@@ -723,256 +667,81 @@ const AppLocalized: FC<PropsWithChildren<{ locale: Locales }>> = ({
723
667
  export const LocaleRouter: FC<PropsWithChildren> = ({ children }) => (
724
668
  <BrowserRouter>
725
669
  <Routes>
726
- {locales
727
- .filter(
728
- (locale) => middleware.prefixDefault || locale !== defaultLocale
729
- )
730
- .map((locale) => (
731
- <Route
732
- // Patrón de ruta para capturar la localidad (por ejemplo, /en/, /fr/) y coincidir con todas las rutas subsecuentes
733
- path={`/${locale}/*`}
734
- key={locale}
735
- element={<AppLocalized locale={locale}>{children}</AppLocalized>} // Envuelve los hijos con la gestión de la localidad
736
- />
737
- ))}
738
-
739
- {
740
- // Si el prefijo para la localidad por defecto está deshabilitado, renderiza los hijos directamente en la ruta raíz
741
- !middleware.prefixDefault && (
742
- <Route
743
- path="*"
744
- element={
745
- <AppLocalized locale={defaultLocale}>{children}</AppLocalized>
746
- } // Envuelve los hijos con la gestión de la localidad
747
- />
748
- )
749
- }
670
+ {localeMap(({ locale, urlPrefix }) => (
671
+ <Route
672
+ // Patrón de ruta para capturar la localidad (por ejemplo, /en/, /fr/) y coincidir con todas las rutas subsecuentes
673
+ path={`${urlPrefix}/*`}
674
+ key={locale}
675
+ element={
676
+ <IntlayerProvider locale={locale}>{children}</IntlayerProvider>
677
+ } // Envuelve los hijos con la gestión de la localidad
678
+ />
679
+ ))}
750
680
  </Routes>
751
681
  </BrowserRouter>
752
682
  );
753
683
  ```
754
684
 
755
685
  ```jsx fileName="src/components/LocaleRouter.mjx" codeFormat="esm"
756
- // Importación de dependencias y funciones necesarias
757
- import { configuration, getPathWithoutLocale } from "intlayer"; // Funciones utilitarias y tipos de 'intlayer'
758
- // Funciones utilitarias y tipos de 'intlayer'
759
- import { IntlayerProvider } from "react-intlayer"; // Proveedor para el contexto de internacionalización
760
- import {
761
- BrowserRouter,
762
- Routes,
763
- Route,
764
- Navigate,
765
- useLocation,
766
- } from "react-router-dom"; // Componentes del enrutador para gestionar la navegación
767
-
768
- // Desestructuración de la configuración desde Intlayer
769
- const { internationalization, middleware } = configuration;
770
- const { locales, defaultLocale } = internationalization;
771
-
772
- /**
773
- * Un componente que maneja la localización y envuelve a los hijos con el contexto de idioma apropiado.
774
- * Gestiona la detección y validación de la localización basada en la URL.
775
- */
776
- const AppLocalized = ({ children, locale }) => {
777
- const { pathname, search } = useLocation(); // Obtener la ruta URL actual
778
-
779
- // Determinar la localización actual, usando la predeterminada si no se proporciona
780
- const currentLocale = locale ?? defaultLocale;
781
-
782
- // Eliminar el prefijo de localización de la ruta para construir una ruta base
783
- const pathWithoutLocale = getPathWithoutLocale(
784
- pathname // Ruta URL actual
785
- );
786
-
787
- /**
788
- * Si middleware.prefixDefault es true, la localización predeterminada siempre debe tener prefijo.
789
- */
790
- if (middleware.prefixDefault) {
791
- // Validar la localización
792
- if (!locale || !locales.includes(locale)) {
793
- // Redirigir a la localización predeterminada con la ruta actualizada
794
- return (
795
- <Navigate
796
- to={`/${defaultLocale}/${pathWithoutLocale}${search}`}
797
- replace // Reemplaza la entrada actual del historial con la nueva
798
- />
799
- );
800
- }
801
-
802
- // Envuelve los hijos con IntlayerProvider y establece la localidad actual
803
- return (
804
- <IntlayerProvider locale={currentLocale}>{children}</IntlayerProvider>
805
- );
806
- } else {
807
- /**
808
- * Cuando middleware.prefixDefault es falso, la localidad por defecto no tiene prefijo.
809
- * Asegura que la localidad actual sea válida y no la localidad por defecto.
810
- */
811
- if (
812
- currentLocale.toString() !== defaultLocale.toString() &&
813
- !locales
814
- .filter(
815
- (locale) => locale.toString() !== defaultLocale.toString() // Excluir la localidad por defecto
816
- )
817
- .includes(currentLocale) // Verifica si la configuración regional actual está en la lista de configuraciones regionales válidas
818
- ) {
819
- // Redirige a la ruta sin el prefijo de configuración regional
820
- return <Navigate to={`${pathWithoutLocale}${search}`} replace />;
821
- }
822
-
823
- // Envuelve los hijos con IntlayerProvider y establece la configuración regional actual
824
- return (
825
- <IntlayerProvider locale={currentLocale}>{children}</IntlayerProvider>
826
- );
827
- }
828
- };
686
+ import { localeMap } from 'intlayer'; // Funciones utilitarias y tipos de 'intlayer'
687
+ import type { FC, PropsWithChildren } from 'react'; // Tipos de React para componentes funcionales y props
688
+ import { IntlayerProvider } from 'react-intlayer'; // Proveedor para el contexto de internacionalización
689
+ import { BrowserRouter, Route, Routes } from 'react-router-dom'; // Componentes del enrutador para gestionar la navegación
829
690
 
830
691
  /**
831
692
  * Un componente de enrutador que configura rutas específicas por configuración regional.
832
693
  * Utiliza React Router para gestionar la navegación y renderizar componentes localizados.
833
694
  */
834
- export const LocaleRouter = ({ children }) => (
695
+ export const LocaleRouter: FC<PropsWithChildren> = ({ children }) => (
835
696
  <BrowserRouter>
836
697
  <Routes>
837
- {locales
838
- .filter(
839
- (locale) => middleware.prefixDefault || locale !== defaultLocale
840
- )
841
- .map((locale) => (
842
- <Route
843
- // Patrón de ruta para capturar la localidad (por ejemplo, /en/, /fr/) y coincidir con todas las rutas subsecuentes
844
- path={`/${locale}/*`}
845
- key={locale}
846
- element={<AppLocalized locale={locale}>{children}</AppLocalized>} // Envuelve los hijos con la gestión de la localidad
847
- />
848
- ))}
849
-
850
- {
851
- // Si la prefijación de la localidad por defecto está deshabilitada, renderiza los hijos directamente en la ruta raíz
852
- !middleware.prefixDefault && (
853
- <Route
854
- path="*"
855
- element={
856
- <AppLocalized locale={defaultLocale}>{children}</AppLocalized>
857
- } // Envuelve los hijos con la gestión de la localidad
858
- />
859
- )
860
- }
698
+ {localeMap(({ locale, urlPrefix }) => (
699
+ <Route
700
+ // Patrón de ruta para capturar la localidad (por ejemplo, /en/, /fr/) y coincidir con todas las rutas subsecuentes
701
+ path={`${urlPrefix}/*`}
702
+ key={locale}
703
+ element={
704
+ <IntlayerProvider locale={locale}>{children}</IntlayerProvider>
705
+ } // Envuelve los hijos con la gestión de la localidad
706
+ />
707
+ ))}
861
708
  </Routes>
862
709
  </BrowserRouter>
863
710
  );
864
711
  ```
865
712
 
866
713
  ```jsx fileName="src/components/LocaleRouter.cjx" codeFormat="commonjs"
867
- // Importando las dependencias y funciones necesarias
868
- const { configuration, getPathWithoutLocale } = require("intlayer"); // Funciones utilitarias y tipos de 'intlayer'
869
- const { IntlayerProvider, useLocale } = require("react-intlayer"); // Proveedor para el contexto de internacionalización
870
- const {
871
- BrowserRouter,
872
- Routes,
873
- Route,
874
- Navigate,
875
- useLocation,
876
- } = require("react-router-dom"); // Componentes del enrutador para gestionar la navegación
877
-
878
- // Desestructurando la configuración de Intlayer
879
- const { internationalization, middleware } = configuration;
880
- const { locales, defaultLocale } = internationalization;
714
+ const { localeMap } = require("intlayer"); // Funciones utilitarias y tipos de 'intlayer'
715
+ const React = require("react"); // Importar React
716
+ const { IntlayerProvider } = require("react-intlayer"); // Proveedor para el contexto de internacionalización
717
+ const { BrowserRouter, Route, Routes } = require("react-router-dom"); // Componentes del enrutador para gestionar la navegación
881
718
 
882
719
  /**
883
- * Un componente que maneja la localización y envuelve a los hijos con el contexto de locale apropiado.
884
- * Gestiona la detección y validación del locale basado en la URL.
885
- */
886
- const AppLocalized = ({ children, locale }) => {
887
- const { pathname, search } = useLocation(); // Obtener la ruta URL actual
888
-
889
- // Determinar la configuración regional actual, usando la predeterminada si no se proporciona
890
- const currentLocale = locale ?? defaultLocale;
891
-
892
- // Eliminar el prefijo de la configuración regional de la ruta para construir una ruta base
893
- const pathWithoutLocale = getPathWithoutLocale(
894
- pathname // Ruta URL actual
895
- );
896
-
897
- /**
898
- * Si middleware.prefixDefault es verdadero, la configuración regional predeterminada siempre debe tener prefijo.
899
- */
900
- if (middleware.prefixDefault) {
901
- // Validar la configuración regional
902
- if (!locale || !locales.includes(locale)) {
903
- // Redirigir a la configuración regional predeterminada con la ruta actualizada
904
- return (
905
- <Navigate
906
- to={`/${defaultLocale}/${pathWithoutLocale}${search}`}
907
- replace // Reemplaza la entrada actual del historial con la nueva
908
- />
909
- );
910
- }
911
-
912
- // Envuelve los hijos con IntlayerProvider y establece la localidad actual
913
- return (
914
- <IntlayerProvider locale={currentLocale}>{children}</IntlayerProvider>
915
- );
916
- } else {
917
- /**
918
- * Cuando middleware.prefixDefault es falso, la localidad por defecto no se antepone.
919
- * Asegura que la localidad actual sea válida y no la localidad por defecto.
920
- */
921
- if (
922
- currentLocale.toString() !== defaultLocale.toString() &&
923
- !locales
924
- .filter(
925
- (locale) => locale.toString() !== defaultLocale.toString() // Excluir la localidad por defecto
926
- )
927
- .includes(currentLocale) // Verifica si la localidad actual está en la lista de localidades válidas
928
- ) {
929
- // Redirigir a la ruta sin el prefijo de la localidad
930
- return <Navigate to={`${pathWithoutLocale}${search}`} replace />;
931
- }
932
-
933
- // Envolver los hijos con IntlayerProvider y establecer la localidad actual
934
- return (
935
- <IntlayerProvider locale={currentLocale}>{children}</IntlayerProvider>
936
- );
937
- }
938
- };
939
-
940
- /**
941
- * Un componente de enrutador que configura rutas específicas por localidad.
720
+ * Un componente de enrutador que configura rutas específicas por configuración regional.
942
721
  * Utiliza React Router para gestionar la navegación y renderizar componentes localizados.
943
722
  */
944
- const LocaleRouter = ({ children }) => (
945
- <BrowserRouter>
946
- <Routes>
947
- {locales
948
- .filter(
949
- (locale) => middleware.prefixDefault || locale !== defaultLocale
950
- )
951
- .map((locale) => (
952
- <Route
953
- // Patrón de ruta para capturar la localidad (por ejemplo, /en/, /fr/) y coincidir con todas las rutas subsecuentes
954
- path={`/${locale}/*`}
955
- key={locale}
956
- element={<AppLocalized locale={locale}>{children}</AppLocalized>} // Envuelve los hijos con la gestión de la configuración regional
957
- />
958
- ))}
723
+ const LocaleRouter = ({ children }) =>
724
+ React.createElement(
725
+ BrowserRouter,
726
+ {},
727
+ React.createElement(
728
+ Routes,
729
+ {},
730
+ localeMap(({ locale, urlPrefix }) =>
731
+ React.createElement(Route, {
732
+ path: `${urlPrefix}/*`,
733
+ key: locale,
734
+ element: React.createElement(IntlayerProvider, { locale }, children),
735
+ })
736
+ )
737
+ )
738
+ );
959
739
 
960
- {
961
- // Si la prefijación de la configuración regional predeterminada está deshabilitada, renderiza los hijos directamente en la ruta raíz
962
- !middleware.prefixDefault && (
963
- <Route
964
- path="*"
965
- element={
966
- <AppLocalized locale={defaultLocale}>{children}</AppLocalized>
967
- } // Envuelve los hijos con la gestión de la configuración regional
968
- />
969
- )
970
- }
971
- </Routes>
972
- </BrowserRouter>
973
- );
740
+ exports.LocaleRouter = LocaleRouter;
974
741
  ```
975
742
 
743
+ > Nota: Si usas `routing.mode: 'no-prefix' | 'search-params'`, probablemente no necesites usar la función `localeMap`.
744
+
976
745
  Luego, puedes usar el componente `LocaleRouter` en tu aplicación:
977
746
 
978
747
  ```tsx fileName="src/App.tsx" codeFormat="typescript"
@@ -1014,6 +783,8 @@ const App = () => (
1014
783
 
1015
784
  Paralelamente, 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 correspondiente. Si no se especifica ninguna configuración regional, el plugin determinará la configuración regional más adecuada basándose en las preferencias de idioma del navegador del usuario. Si no se detecta ninguna configuración regional, redirigirá a la configuración regional predeterminada.
1016
785
 
786
+ > Ten en cuenta que para usar el `intlayerProxy` en producción, debes mover el paquete `vite-intlayer` de `devDependencies` a `dependencies`.
787
+
1017
788
  ```typescript {3,7} fileName="vite.config.ts" codeFormat="typescript"
1018
789
  import { defineConfig } from "vite";
1019
790
  import react from "@vitejs/plugin-react-swc";
@@ -1246,14 +1017,14 @@ const LocaleSwitcher = () => {
1246
1017
 
1247
1018
  > Referencias de la documentación:
1248
1019
  >
1249
- > - [`useLocale` hook](https://github.com/aymericzip/intlayer/blob/main/docs/docs/es/packages/react-intlayer/useLocale.md)
1250
- > - [`getLocaleName` hook](https://github.com/aymericzip/intlayer/blob/main/docs/docs/es/packages/intlayer/getLocaleName.md)
1251
- > - [`getLocalizedUrl` hook](https://github.com/aymericzip/intlayer/blob/main/docs/docs/es/packages/intlayer/getLocalizedUrl.md)
1252
- > - [`getHTMLTextDir` hook](https://github.com/aymericzip/intlayer/blob/main/docs/docs/es/packages/intlayer/getHTMLTextDir.md)
1020
+ > - [`useLocale` hook](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/packages/react-intlayer/useLocale.md)
1021
+ > - [`getLocaleName` hook](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/packages/intlayer/getLocaleName.md)
1022
+ > - [`getLocalizedUrl` hook](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/packages/intlayer/getLocalizedUrl.md)
1023
+ > - [`getHTMLTextDir` hook](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/packages/intlayer/getHTMLTextDir.md)
1253
1024
  > - [`hrefLang` attribute](https://developers.google.com/search/docs/specialty/international/localized-versions?hl=fr)
1254
- > - [`lang` attribute](https://developer.mozilla.org/es/docs/Web/HTML/Atributos_globales/lang)
1255
- > - [`dir` attribute](https://developer.mozilla.org/es/docs/Web/HTML/Atributos_globales/dir)
1256
- > - [`aria-current` attribute](https://developer.mozilla.org/es/docs/Web/Accessibility/ARIA/Atributos/aria-current)
1025
+ > - [`lang` attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/lang)
1026
+ > - [`dir` attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/dir)
1027
+ > - [`aria-current` attribute](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-current)
1257
1028
 
1258
1029
  A continuación se muestra el **Paso 9** actualizado con explicaciones añadidas y ejemplos de código refinados:
1259
1030
 
@@ -1421,9 +1192,9 @@ module.exports = App;
1421
1192
 
1422
1193
  Al aplicar estos cambios, tu aplicación:
1423
1194
 
1424
- - Asegurará que el atributo **language** (`lang`) refleje correctamente la configuración regional actual, lo cual es importante para SEO y el comportamiento del navegador.
1425
- - Ajustará la **dirección del texto** (`dir`) según la configuración regional, mejorando la legibilidad y usabilidad para idiomas con diferentes órdenes de lectura.
1426
- - Proporcionará una experiencia más **accesible**, ya que las tecnologías de asistencia dependen de estos atributos para funcionar de manera óptima.
1195
+ - Asegurar que el atributo **language** (`lang`) refleje correctamente la configuración regional actual, lo cual es importante para SEO y el comportamiento del navegador.
1196
+ - Ajustar la **dirección del texto** (`dir`) según la configuración regional, mejorando la legibilidad y usabilidad para idiomas con diferentes órdenes de lectura.
1197
+ - Proporcionar una experiencia más **accesible**, ya que las tecnologías de asistencia dependen de estos atributos para funcionar de manera óptima.
1427
1198
 
1428
1199
  ### (Opcional) Paso 10: Crear un Componente de Enlace Localizado
1429
1200
 
@@ -1446,11 +1217,10 @@ import {
1446
1217
  } from "react";
1447
1218
  import { useLocale } from "react-intlayer";
1448
1219
 
1449
- export interface LinkProps
1450
- extends DetailedHTMLProps<
1451
- AnchorHTMLAttributes<HTMLAnchorElement>,
1452
- HTMLAnchorElement
1453
- > {}
1220
+ export interface LinkProps extends DetailedHTMLProps<
1221
+ AnchorHTMLAttributes<HTMLAnchorElement>,
1222
+ HTMLAnchorElement
1223
+ > {}
1454
1224
 
1455
1225
  /**
1456
1226
  * Función utilitaria para verificar si una URL dada es externa.
@@ -1577,9 +1347,9 @@ Al integrar este componente `Link` en toda su aplicación, mantiene una experien
1577
1347
 
1578
1348
  Intlayer utiliza la ampliación de módulos para aprovechar las ventajas de TypeScript y fortalecer su base de código.
1579
1349
 
1580
- ![texto alternativo](https://github.com/aymericzip/intlayer/blob/main/docs/assets/autocompletion.png)
1350
+ ![Autocompletado](https://github.com/aymericzip/intlayer/blob/main/docs/assets/autocompletion.png?raw=true)
1581
1351
 
1582
- ![texto alternativo](https://github.com/aymericzip/intlayer/blob/main/docs/assets/translation_error.png)
1352
+ ![Error de traducción](https://github.com/aymericzip/intlayer/blob/main/docs/assets/translation_error.png?raw=true)
1583
1353
 
1584
1354
  Asegúrese de que su configuración de TypeScript incluya los tipos generados automáticamente.
1585
1355
 
@@ -1599,8 +1369,8 @@ Se recomienda ignorar los archivos generados por Intlayer. Esto te permite evita
1599
1369
 
1600
1370
  Para hacerlo, puedes agregar las siguientes instrucciones a tu archivo `.gitignore`:
1601
1371
 
1602
- ```plaintext
1603
- # Traduce tu Vite and React con Intlayer | Internacionalización (i18n)
1372
+ ```plaintext fileName=".gitignore"
1373
+ # Ignore the files generated by Intlayer
1604
1374
  .intlayer
1605
1375
  ```
1606
1376
 
@@ -1624,5 +1394,3 @@ Para más detalles sobre cómo usar la extensión, consulta la [documentación d
1624
1394
  ### Ir más allá
1625
1395
 
1626
1396
  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).
1627
-
1628
- ---
@@ -22,6 +22,7 @@ slugs:
22
22
  - doc
23
23
  - plugin
24
24
  - sync-json
25
+ youtubeVideo: https://www.youtube.com/watch?v=MpGMxniDHNg
25
26
  history:
26
27
  - version: 6.1.6
27
28
  date: 2025-10-05
@@ -30,6 +31,8 @@ history:
30
31
 
31
32
  ## Sincronización JSON (puentes i18n)
32
33
 
34
+ <iframe title="Cómo mantener tus traducciones JSON sincronizadas con 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/MpGMxniDHNg?autoplay=0&amp;origin=http://intlayer.org&amp;controls=0&amp;rel=1"/>
35
+
33
36
  Usa Intlayer como un complemento para tu stack i18n existente. Este plugin mantiene tus mensajes JSON sincronizados con los diccionarios de Intlayer para que puedas:
34
37
 
35
38
  - Mantener i18next, next-intl, react-intl, vue-i18n, next-translate, nuxt-i18n, Solid-i18next, svelte-i18n, etc.