@intlayer/docs 6.1.6-canary.0 → 6.1.6

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 (242) hide show
  1. package/blog/en/next-i18next_vs_next-intl_vs_intlayer.md +71 -80
  2. package/dist/cjs/generated/docs.entry.cjs +16 -0
  3. package/dist/cjs/generated/docs.entry.cjs.map +1 -1
  4. package/dist/esm/generated/docs.entry.mjs +16 -0
  5. package/dist/esm/generated/docs.entry.mjs.map +1 -1
  6. package/dist/types/generated/docs.entry.d.ts +1 -0
  7. package/dist/types/generated/docs.entry.d.ts.map +1 -1
  8. package/docs/ar/intlayer_with_angular.md +2 -2
  9. package/docs/ar/intlayer_with_astro.md +246 -0
  10. package/docs/ar/intlayer_with_create_react_app.md +3 -2
  11. package/docs/ar/intlayer_with_express.md +2 -2
  12. package/docs/ar/intlayer_with_nestjs.md +2 -2
  13. package/docs/ar/intlayer_with_nextjs_14.md +2 -2
  14. package/docs/ar/intlayer_with_nextjs_15.md +2 -2
  15. package/docs/ar/intlayer_with_nextjs_page_router.md +2 -2
  16. package/docs/ar/intlayer_with_nuxt.md +2 -2
  17. package/docs/ar/intlayer_with_react_native+expo.md +11 -20
  18. package/docs/ar/intlayer_with_react_router_v7.md +195 -241
  19. package/docs/ar/intlayer_with_tanstack.md +198 -272
  20. package/docs/ar/intlayer_with_vite+preact.md +9 -9
  21. package/docs/ar/intlayer_with_vite+react.md +7 -7
  22. package/docs/ar/intlayer_with_vite+vue.md +9 -9
  23. package/docs/de/intlayer_with_angular.md +2 -2
  24. package/docs/de/intlayer_with_astro.md +246 -0
  25. package/docs/de/intlayer_with_create_react_app.md +2 -2
  26. package/docs/de/intlayer_with_express.md +2 -2
  27. package/docs/de/intlayer_with_nestjs.md +2 -2
  28. package/docs/de/intlayer_with_nextjs_14.md +2 -2
  29. package/docs/de/intlayer_with_nextjs_15.md +2 -2
  30. package/docs/de/intlayer_with_nextjs_page_router.md +2 -2
  31. package/docs/de/intlayer_with_nuxt.md +2 -2
  32. package/docs/de/intlayer_with_react_native+expo.md +11 -20
  33. package/docs/de/intlayer_with_react_router_v7.md +193 -242
  34. package/docs/de/intlayer_with_tanstack.md +194 -266
  35. package/docs/de/intlayer_with_vite+preact.md +9 -9
  36. package/docs/de/intlayer_with_vite+react.md +9 -9
  37. package/docs/de/intlayer_with_vite+vue.md +11 -11
  38. package/docs/de/packages/vite-intlayer/index.md +3 -3
  39. package/docs/en/how_works_intlayer.md +1 -1
  40. package/docs/en/index.md +1 -1
  41. package/docs/en/intlayer_cli.md +1 -1
  42. package/docs/en/intlayer_with_angular.md +4 -4
  43. package/docs/en/intlayer_with_astro.md +246 -0
  44. package/docs/en/intlayer_with_create_react_app.md +4 -4
  45. package/docs/en/intlayer_with_express.md +3 -3
  46. package/docs/en/intlayer_with_lynx+react.md +1 -1
  47. package/docs/en/intlayer_with_nestjs.md +2 -2
  48. package/docs/en/intlayer_with_nextjs_14.md +13 -4
  49. package/docs/en/intlayer_with_nextjs_15.md +13 -4
  50. package/docs/en/intlayer_with_nextjs_page_router.md +5 -5
  51. package/docs/en/intlayer_with_nuxt.md +4 -4
  52. package/docs/en/intlayer_with_react_native+expo.md +46 -24
  53. package/docs/en/intlayer_with_react_router_v7.md +164 -211
  54. package/docs/en/intlayer_with_tanstack.md +166 -241
  55. package/docs/en/intlayer_with_vite+preact.md +12 -12
  56. package/docs/en/intlayer_with_vite+react.md +12 -12
  57. package/docs/en/intlayer_with_vite+solid.md +2 -2
  58. package/docs/en/intlayer_with_vite+svelte.md +2 -2
  59. package/docs/en/intlayer_with_vite+vue.md +12 -12
  60. package/docs/en/introduction.md +1 -1
  61. package/docs/en/packages/next-intlayer/useDictionary.md +1 -1
  62. package/docs/en/packages/next-intlayer/useIntlayer.md +1 -1
  63. package/docs/en/packages/react-intlayer/useDictionary.md +1 -1
  64. package/docs/en/packages/react-intlayer/useI18n.md +1 -1
  65. package/docs/en/packages/react-intlayer/useIntlayer.md +1 -1
  66. package/docs/en/releases/v6.md +1 -0
  67. package/docs/en/roadmap.md +1 -1
  68. package/docs/en-GB/intlayer_with_angular.md +3 -3
  69. package/docs/en-GB/intlayer_with_astro.md +246 -0
  70. package/docs/en-GB/intlayer_with_create_react_app.md +5 -4
  71. package/docs/en-GB/intlayer_with_express.md +2 -2
  72. package/docs/en-GB/intlayer_with_nestjs.md +2 -2
  73. package/docs/en-GB/intlayer_with_nextjs_14.md +4 -4
  74. package/docs/en-GB/intlayer_with_nextjs_15.md +2 -2
  75. package/docs/en-GB/intlayer_with_nextjs_page_router.md +2 -2
  76. package/docs/en-GB/intlayer_with_nuxt.md +2 -2
  77. package/docs/en-GB/intlayer_with_react_native+expo.md +11 -20
  78. package/docs/en-GB/intlayer_with_react_router_v7.md +171 -220
  79. package/docs/en-GB/intlayer_with_tanstack.md +174 -248
  80. package/docs/en-GB/intlayer_with_vite+preact.md +9 -9
  81. package/docs/en-GB/intlayer_with_vite+react.md +9 -9
  82. package/docs/en-GB/intlayer_with_vite+vue.md +11 -11
  83. package/docs/en-GB/packages/next-intlayer/useIntlayer.md +1 -1
  84. package/docs/en-GB/packages/react-intlayer/useIntlayer.md +1 -1
  85. package/docs/es/intlayer_with_angular.md +2 -2
  86. package/docs/es/intlayer_with_astro.md +246 -0
  87. package/docs/es/intlayer_with_create_react_app.md +3 -2
  88. package/docs/es/intlayer_with_express.md +2 -2
  89. package/docs/es/intlayer_with_nextjs_14.md +2 -2
  90. package/docs/es/intlayer_with_nextjs_15.md +2 -2
  91. package/docs/es/intlayer_with_react_native+expo.md +11 -20
  92. package/docs/es/intlayer_with_react_router_v7.md +188 -232
  93. package/docs/es/intlayer_with_tanstack.md +203 -273
  94. package/docs/es/intlayer_with_vite+preact.md +7 -7
  95. package/docs/es/intlayer_with_vite+react.md +7 -7
  96. package/docs/es/intlayer_with_vite+vue.md +9 -9
  97. package/docs/fr/intlayer_with_angular.md +2 -2
  98. package/docs/fr/intlayer_with_astro.md +246 -0
  99. package/docs/fr/intlayer_with_create_react_app.md +3 -2
  100. package/docs/fr/intlayer_with_express.md +2 -2
  101. package/docs/fr/intlayer_with_nestjs.md +2 -2
  102. package/docs/fr/intlayer_with_nextjs_14.md +2 -2
  103. package/docs/fr/intlayer_with_react_native+expo.md +11 -20
  104. package/docs/fr/intlayer_with_react_router_v7.md +188 -248
  105. package/docs/fr/intlayer_with_tanstack.md +192 -265
  106. package/docs/fr/intlayer_with_vite+preact.md +7 -7
  107. package/docs/fr/intlayer_with_vite+react.md +7 -7
  108. package/docs/fr/intlayer_with_vite+vue.md +9 -9
  109. package/docs/hi/intlayer_cli.md +1 -4
  110. package/docs/hi/intlayer_with_angular.md +2 -2
  111. package/docs/hi/intlayer_with_astro.md +246 -0
  112. package/docs/hi/intlayer_with_create_react_app.md +2 -2
  113. package/docs/hi/intlayer_with_express.md +2 -2
  114. package/docs/hi/intlayer_with_nestjs.md +2 -2
  115. package/docs/hi/intlayer_with_nextjs_14.md +2 -2
  116. package/docs/hi/intlayer_with_nextjs_15.md +2 -2
  117. package/docs/hi/intlayer_with_nextjs_page_router.md +2 -2
  118. package/docs/hi/intlayer_with_nuxt.md +2 -2
  119. package/docs/hi/intlayer_with_react_native+expo.md +11 -20
  120. package/docs/hi/intlayer_with_react_router_v7.md +199 -243
  121. package/docs/hi/intlayer_with_tanstack.md +210 -285
  122. package/docs/hi/intlayer_with_vite+preact.md +9 -9
  123. package/docs/hi/intlayer_with_vite+react.md +9 -9
  124. package/docs/hi/intlayer_with_vite+solid.md +1 -1
  125. package/docs/hi/intlayer_with_vite+vue.md +11 -11
  126. package/docs/it/intlayer_with_angular.md +2 -2
  127. package/docs/it/intlayer_with_astro.md +246 -0
  128. package/docs/it/intlayer_with_create_react_app.md +3 -2
  129. package/docs/it/intlayer_with_express.md +2 -2
  130. package/docs/it/intlayer_with_nestjs.md +2 -2
  131. package/docs/it/intlayer_with_nextjs_14.md +2 -2
  132. package/docs/it/intlayer_with_nextjs_15.md +2 -2
  133. package/docs/it/intlayer_with_nextjs_page_router.md +2 -2
  134. package/docs/it/intlayer_with_nuxt.md +2 -2
  135. package/docs/it/intlayer_with_react_native+expo.md +11 -21
  136. package/docs/it/intlayer_with_react_router_v7.md +195 -242
  137. package/docs/it/intlayer_with_tanstack.md +203 -267
  138. package/docs/it/intlayer_with_vite+preact.md +9 -9
  139. package/docs/it/intlayer_with_vite+react.md +13 -11
  140. package/docs/it/intlayer_with_vite+vue.md +11 -11
  141. package/docs/ja/intlayer_with_angular.md +2 -2
  142. package/docs/ja/intlayer_with_astro.md +246 -0
  143. package/docs/ja/intlayer_with_create_react_app.md +3 -2
  144. package/docs/ja/intlayer_with_express.md +2 -2
  145. package/docs/ja/intlayer_with_nestjs.md +2 -2
  146. package/docs/ja/intlayer_with_nextjs_14.md +2 -2
  147. package/docs/ja/intlayer_with_nextjs_15.md +2 -2
  148. package/docs/ja/intlayer_with_nextjs_page_router.md +2 -2
  149. package/docs/ja/intlayer_with_nuxt.md +2 -2
  150. package/docs/ja/intlayer_with_react_native+expo.md +18 -29
  151. package/docs/ja/intlayer_with_react_router_v7.md +204 -250
  152. package/docs/ja/intlayer_with_tanstack.md +218 -286
  153. package/docs/ja/intlayer_with_vite+preact.md +9 -9
  154. package/docs/ja/intlayer_with_vite+react.md +11 -11
  155. package/docs/ja/intlayer_with_vite+vue.md +11 -11
  156. package/docs/ko/intlayer_with_angular.md +2 -2
  157. package/docs/ko/intlayer_with_astro.md +246 -0
  158. package/docs/ko/intlayer_with_create_react_app.md +3 -2
  159. package/docs/ko/intlayer_with_express.md +2 -2
  160. package/docs/ko/intlayer_with_nestjs.md +2 -2
  161. package/docs/ko/intlayer_with_nextjs_14.md +2 -2
  162. package/docs/ko/intlayer_with_nextjs_15.md +2 -2
  163. package/docs/ko/intlayer_with_nextjs_page_router.md +2 -2
  164. package/docs/ko/intlayer_with_nuxt.md +2 -2
  165. package/docs/ko/intlayer_with_react_native+expo.md +19 -28
  166. package/docs/ko/intlayer_with_react_router_v7.md +190 -244
  167. package/docs/ko/intlayer_with_tanstack.md +200 -270
  168. package/docs/ko/intlayer_with_vite+preact.md +9 -9
  169. package/docs/ko/intlayer_with_vite+react.md +9 -9
  170. package/docs/ko/intlayer_with_vite+vue.md +11 -11
  171. package/docs/pt/intlayer_with_angular.md +2 -2
  172. package/docs/pt/intlayer_with_astro.md +246 -0
  173. package/docs/pt/intlayer_with_create_react_app.md +3 -2
  174. package/docs/pt/intlayer_with_express.md +2 -2
  175. package/docs/pt/intlayer_with_nestjs.md +2 -2
  176. package/docs/pt/intlayer_with_nextjs_14.md +2 -2
  177. package/docs/pt/intlayer_with_nextjs_15.md +2 -2
  178. package/docs/pt/intlayer_with_nextjs_page_router.md +2 -2
  179. package/docs/pt/intlayer_with_nuxt.md +2 -2
  180. package/docs/pt/intlayer_with_react_native+expo.md +11 -20
  181. package/docs/pt/intlayer_with_react_router_v7.md +7 -13
  182. package/docs/pt/intlayer_with_tanstack.md +183 -258
  183. package/docs/pt/intlayer_with_vite+preact.md +9 -9
  184. package/docs/pt/intlayer_with_vite+react.md +9 -9
  185. package/docs/pt/intlayer_with_vite+vue.md +9 -9
  186. package/docs/ru/intlayer_with_angular.md +2 -2
  187. package/docs/ru/intlayer_with_astro.md +246 -0
  188. package/docs/ru/intlayer_with_create_react_app.md +3 -2
  189. package/docs/ru/intlayer_with_express.md +2 -2
  190. package/docs/ru/intlayer_with_nestjs.md +2 -2
  191. package/docs/ru/intlayer_with_nextjs_14.md +2 -2
  192. package/docs/ru/intlayer_with_nextjs_15.md +2 -2
  193. package/docs/ru/intlayer_with_nextjs_page_router.md +2 -2
  194. package/docs/ru/intlayer_with_nuxt.md +2 -2
  195. package/docs/ru/intlayer_with_react_native+expo.md +11 -20
  196. package/docs/ru/intlayer_with_react_router_v7.md +192 -238
  197. package/docs/ru/intlayer_with_tanstack.md +197 -269
  198. package/docs/ru/intlayer_with_vite+preact.md +9 -9
  199. package/docs/ru/intlayer_with_vite+react.md +9 -9
  200. package/docs/ru/intlayer_with_vite+vue.md +11 -11
  201. package/docs/tr/how_works_intlayer.md +1 -1
  202. package/docs/tr/index.md +1 -1
  203. package/docs/tr/intlayer_cli.md +1 -1
  204. package/docs/tr/intlayer_with_angular.md +4 -4
  205. package/docs/tr/intlayer_with_astro.md +246 -0
  206. package/docs/tr/intlayer_with_create_react_app.md +4 -4
  207. package/docs/tr/intlayer_with_express.md +3 -3
  208. package/docs/tr/intlayer_with_lynx+react.md +1 -1
  209. package/docs/tr/intlayer_with_nestjs.md +2 -2
  210. package/docs/tr/intlayer_with_nextjs_14.md +2 -2
  211. package/docs/tr/intlayer_with_nextjs_15.md +4 -4
  212. package/docs/tr/intlayer_with_nextjs_page_router.md +5 -5
  213. package/docs/tr/intlayer_with_nuxt.md +4 -4
  214. package/docs/tr/intlayer_with_react_native+expo.md +12 -21
  215. package/docs/tr/intlayer_with_react_router_v7.md +222 -267
  216. package/docs/tr/intlayer_with_tanstack.md +400 -303
  217. package/docs/tr/intlayer_with_vite+preact.md +12 -12
  218. package/docs/tr/intlayer_with_vite+react.md +12 -12
  219. package/docs/tr/intlayer_with_vite+solid.md +2 -2
  220. package/docs/tr/intlayer_with_vite+svelte.md +2 -2
  221. package/docs/tr/intlayer_with_vite+vue.md +12 -12
  222. package/docs/tr/introduction.md +1 -1
  223. package/docs/tr/packages/react-intlayer/useDictionary.md +1 -1
  224. package/docs/tr/packages/react-intlayer/useI18n.md +1 -1
  225. package/docs/tr/roadmap.md +1 -1
  226. package/docs/zh/intlayer_with_angular.md +2 -2
  227. package/docs/zh/intlayer_with_astro.md +246 -0
  228. package/docs/zh/intlayer_with_create_react_app.md +3 -2
  229. package/docs/zh/intlayer_with_express.md +2 -2
  230. package/docs/zh/intlayer_with_nestjs.md +2 -2
  231. package/docs/zh/intlayer_with_nextjs_14.md +2 -2
  232. package/docs/zh/intlayer_with_nextjs_15.md +2 -2
  233. package/docs/zh/intlayer_with_nextjs_page_router.md +2 -2
  234. package/docs/zh/intlayer_with_nuxt.md +2 -2
  235. package/docs/zh/intlayer_with_react_native+expo.md +19 -28
  236. package/docs/zh/intlayer_with_react_router_v7.md +200 -248
  237. package/docs/zh/intlayer_with_tanstack.md +208 -283
  238. package/docs/zh/intlayer_with_vite+preact.md +9 -9
  239. package/docs/zh/intlayer_with_vite+react.md +9 -9
  240. package/docs/zh/intlayer_with_vite+vue.md +9 -9
  241. package/package.json +11 -11
  242. package/src/generated/docs.entry.ts +16 -0
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  createdAt: 2025-09-04
3
- updatedAt: 2025-09-04
3
+ updatedAt: 2025-10-03
4
4
  title: Getting Started with Intlayer in React Router v7
5
5
  description: Learn how to add internationalization (i18n) to your React Router v7 application using Intlayer. Follow this comprehensive guide to make your app multilingual with locale-aware routing.
6
6
  keywords:
@@ -17,8 +17,7 @@ slugs:
17
17
  - environment
18
18
  - vite-and-react
19
19
  - react-router-v7
20
- applicationTemplate: https://github.com/AydinTheFirst/react-router-intlayer
21
- author: AydinTheFirst
20
+ applicationTemplate: https://github.com/aymericzip/intlayer-react-router-v7-template
22
21
  ---
23
22
 
24
23
  # Getting Started Internationalizing (i18n) with Intlayer and React Router v7
@@ -57,7 +56,7 @@ pnpm add vite-intlayer --save-dev
57
56
 
58
57
  - **intlayer**
59
58
 
60
- The core package that provides internationalization tools for configuration management, translation, [content declaration](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/dictionary/get_started.md), transpilation, and [CLI commands](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/intlayer_cli.md).
59
+ The core package that provides internationalization tools for configuration management, translation, [content declaration](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/dictionary/content_file.md), transpilation, and [CLI commands](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/intlayer_cli.md).
61
60
 
62
61
  - **react-intlayer**
63
62
  The package that integrates Intlayer with React application. It provides context providers and hooks for React internationalization.
@@ -75,10 +74,7 @@ import { type IntlayerConfig, Locales } from "intlayer";
75
74
  const config: IntlayerConfig = {
76
75
  internationalization: {
77
76
  defaultLocale: Locales.ENGLISH,
78
- locales: [Locales.ENGLISH, Locales.TURKISH],
79
- },
80
- middleware: {
81
- prefixDefault: true, // Always prefix default locale in URLs
77
+ locales: [Locales.ENGLISH, Locales.FRENCH, Locales.SPANISH],
82
78
  },
83
79
  };
84
80
 
@@ -92,10 +88,7 @@ import { Locales } from "intlayer";
92
88
  const config = {
93
89
  internationalization: {
94
90
  defaultLocale: Locales.ENGLISH,
95
- locales: [Locales.ENGLISH, Locales.TURKISH],
96
- },
97
- middleware: {
98
- prefixDefault: true,
91
+ locales: [Locales.ENGLISH, Locales.FRENCH, Locales.SPANISH],
99
92
  },
100
93
  };
101
94
 
@@ -109,10 +102,7 @@ const { Locales } = require("intlayer");
109
102
  const config = {
110
103
  internationalization: {
111
104
  defaultLocale: Locales.ENGLISH,
112
- locales: [Locales.ENGLISH, Locales.TURKISH],
113
- },
114
- middleware: {
115
- prefixDefault: true,
105
+ locales: [Locales.ENGLISH, Locales.FRENCH, Locales.SPANISH],
116
106
  },
117
107
  };
118
108
 
@@ -121,58 +111,55 @@ module.exports = config;
121
111
 
122
112
  > Through this configuration file, you can set up localized URLs, middleware redirection, cookie names, the location and extension of your content declarations, disable Intlayer logs in the console, and more. For a complete list of available parameters, refer to the [configuration documentation](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/configuration.md).
123
113
 
124
- ### Step 3: Configure React Router v7 Routes
125
-
126
- Set up your routing configuration with locale-aware routes:
127
-
128
- ```typescript fileName="app/routes.ts" codeFormat="typescript"
129
- import { layout, route, type RouteConfig } from "@react-router/dev/routes";
130
-
131
- export default [
132
- layout("routes/layout.tsx", [
133
- route("/", "routes/page.tsx"), // Root page - redirects to locale
134
- route("/:lang", "routes/[lang]/page.tsx"), // Localized home page
135
- route("/:lang/about", "routes/[lang]/about/page.tsx"), // Localized about page
136
- ]),
137
- ] satisfies RouteConfig;
138
- ```
139
-
140
- ### Step 4: Integrate Intlayer in Your Vite Configuration
114
+ ### Step 3: Integrate Intlayer in Your Vite Configuration
141
115
 
142
116
  Add the intlayer plugin into your configuration:
143
117
 
144
- ```typescript fileName="vite.config.ts" codeFormat="typescript"
118
+ ```typescript fileName="vite.config.ts"
145
119
  import { reactRouter } from "@react-router/dev/vite";
146
120
  import { defineConfig } from "vite";
147
- import { intlayerMiddlewarePlugin, intlayer } from "vite-intlayer";
121
+ import { intlayer } from "vite-intlayer";
148
122
  import tsconfigPaths from "vite-tsconfig-paths";
149
123
 
150
124
  export default defineConfig({
151
- plugins: [
152
- reactRouter(),
153
- tsconfigPaths(),
154
- intlayer(),
155
- intlayerMiddlewarePlugin(),
156
- ],
125
+ plugins: [reactRouter(), tsconfigPaths(), intlayer()],
157
126
  });
158
127
  ```
159
128
 
160
129
  > The `intlayer()` Vite plugin is used to integrate Intlayer with Vite. It ensures the building of content declaration files and monitors them in development mode. It defines Intlayer environment variables within the Vite application. Additionally, it provides aliases to optimize performance.
161
130
 
131
+ ### Step 4: Configure React Router v7 Routes
132
+
133
+ Set up your routing configuration with locale-aware routes:
134
+
135
+ ```typescript fileName="app/routes.ts"
136
+ import { layout, route, type RouteConfig } from "@react-router/dev/routes";
137
+
138
+ export default [
139
+ layout("routes/layout.tsx", [
140
+ route("/:lang?", "routes/page.tsx"), // Localized home page
141
+ route("/:lang?/about", "routes/about/page.tsx"), // Localized about page
142
+ ]),
143
+ ] satisfies RouteConfig;
144
+ ```
145
+
162
146
  ### Step 5: Create Layout Components
163
147
 
164
148
  Set up your root layout and locale-specific layouts:
165
149
 
166
150
  #### Root Layout
167
151
 
168
- ```tsx fileName="app/routes/layout.tsx" codeFormat="typescript"
169
- // app/routes/layout.tsx
170
- import { Outlet } from "react-router";
152
+ ```tsx fileName="app/routes/layout.tsx"
171
153
  import { IntlayerProvider } from "react-intlayer";
154
+ import { Outlet } from "react-router";
155
+
156
+ import type { Route } from "./+types/layout";
157
+
158
+ export default function RootLayout({ params }: Route.ComponentProps) {
159
+ const { locale } = params;
172
160
 
173
- export default function RootLayout() {
174
161
  return (
175
- <IntlayerProvider>
162
+ <IntlayerProvider locale={locale}>
176
163
  <Outlet />
177
164
  </IntlayerProvider>
178
165
  );
@@ -183,7 +170,7 @@ export default function RootLayout() {
183
170
 
184
171
  Create and manage your content declarations to store translations:
185
172
 
186
- ```tsx fileName="app/routes/[lang]/page.content.ts" contentDeclarationFormat="typescript"
173
+ ```tsx fileName="app/routes/[lang]/page.content.ts"
187
174
  import { t, type Dictionary } from "intlayer";
188
175
 
189
176
  const pageContent = {
@@ -191,19 +178,23 @@ const pageContent = {
191
178
  content: {
192
179
  title: t({
193
180
  en: "Welcome to React Router v7 + Intlayer",
194
- tr: "React Router v7 + Intlayer'a Hoş Geldiniz",
181
+ es: "Bienvenido a React Router v7 + Intlayer",
182
+ fr: "Bienvenue sur React Router v7 + Intlayer",
195
183
  }),
196
184
  description: t({
197
185
  en: "Build multilingual applications with ease using React Router v7 and Intlayer.",
198
- tr: "React Router v7 ve Intlayer kullanarak kolayca çok dilli uygulamalar geliştirin.",
186
+ es: "Cree aplicaciones multilingües fácilmente usando React Router v7 y Intlayer.",
187
+ fr: "Créez des applications multilingues facilement avec React Router v7 et Intlayer.",
199
188
  }),
200
189
  aboutLink: t({
201
190
  en: "Learn About Us",
202
- tr: "Hakkımızda Öğrenin",
191
+ es: "Aprender Sobre Nosotros",
192
+ fr: "En savoir plus sur nous",
203
193
  }),
204
194
  homeLink: t({
205
195
  en: "Home",
206
- tr: "Ana Sayfa",
196
+ es: "Inicio",
197
+ fr: "Accueil",
207
198
  }),
208
199
  },
209
200
  } satisfies Dictionary;
@@ -213,102 +204,88 @@ export default pageContent;
213
204
 
214
205
  > Your content declarations can be defined anywhere in your application as soon they are included into the `contentDir` directory (by default, `./app`). And match the content declaration file extension (by default, `.content.{json,ts,tsx,js,jsx,mjs,mjx,cjs,cjx}`).
215
206
 
216
- > For more details, refer to the [content declaration documentation](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/dictionary/get_started.md).
207
+ > For more details, refer to the [content declaration documentation](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/dictionary/content_file.md).
217
208
 
218
209
  ### Step 7: Create Locale-Aware Components
219
210
 
220
211
  Create a `LocalizedLink` component for locale-aware navigation:
221
212
 
222
- ```tsx fileName="app/components/localized-link.tsx" codeFormat="typescript"
223
- // app/components/localized-link.tsx
224
- import { getLocalizedUrl } from "intlayer";
225
- import { useLocale } from "react-intlayer";
226
- import React from "react";
227
- import { Link, useLocation } from "react-router";
228
-
229
- type RouterLinkProps = React.ComponentProps<typeof Link>;
213
+ ```tsx fileName="app/components/localized-link.tsx"
214
+ import type { FC } from "react";
230
215
 
231
- export default function LocalizedLink({ to, ...props }: RouterLinkProps) {
232
- const { locale } = useLocale();
233
- const location = useLocation();
216
+ import { getLocalizedUrl, type LocalesValues } from "intlayer";
217
+ import { useLocale } from "react-intlayer";
218
+ import { Link, type LinkProps, type To } from "react-router";
234
219
 
235
- const isExternal = (path: string) =>
236
- /^([a-z][a-z0-9+.-]*:)?\/\//i.test(path) || path.startsWith("mailto:");
220
+ const isExternalLink = (to: string) => /^(https?:)?\/\//.test(to);
237
221
 
222
+ export const locacalizeTo = (to: To, locale: LocalesValues): To => {
238
223
  if (typeof to === "string") {
239
- if (to.startsWith("/") && !isExternal(to)) {
240
- return <Link to={getLocalizedUrl(to, locale)} {...props} />;
224
+ if (isExternalLink(to)) {
225
+ return to;
241
226
  }
242
- return <Link to={to} {...props} />;
227
+
228
+ return getLocalizedUrl(to, locale);
243
229
  }
244
230
 
245
- if (to && typeof to === "object") {
246
- const pathname = (to as { pathname?: string }).pathname;
247
- if (pathname && pathname.startsWith("/") && !isExternal(pathname)) {
248
- return (
249
- <Link
250
- to={{ ...to, pathname: getLocalizedUrl(pathname, locale) }}
251
- {...props}
252
- />
253
- );
254
- }
255
- return <Link to={to} {...props} />;
231
+ if (isExternalLink(to.pathname ?? "")) {
232
+ return to;
256
233
  }
257
234
 
258
- return (
259
- <Link
260
- to={getLocalizedUrl(location.pathname + location.search, locale)}
261
- {...props}
262
- />
263
- );
264
- }
265
- ```
235
+ return {
236
+ ...to,
237
+ pathname: getLocalizedUrl(to.pathname ?? "", locale),
238
+ };
239
+ };
266
240
 
267
- ### Step 8: Utilize Intlayer in Your Pages
241
+ export const LocalizedLink: FC<LinkProps> = (props) => {
242
+ const { locale } = useLocale();
268
243
 
269
- Access your content dictionaries throughout your application:
244
+ return <Link {...props} to={locacalizeTo(props.to, locale)} />;
245
+ };
246
+ ```
270
247
 
271
- #### Root Redirect Page
248
+ In the case you want to navigate to the localized routes, you can use the `useLocalizedNavigate` hook:
272
249
 
273
- ```tsx fileName="app/routes/page.tsx" codeFormat="typescript"
274
- // app/routes/page.tsx
250
+ ```tsx fileName="app/hooks/useLocalizedNavigate.ts"
275
251
  import { useLocale } from "react-intlayer";
276
- import { Navigate } from "react-router";
252
+ import { type NavigateOptions, type To, useNavigate } from "react-router";
277
253
 
278
- export default function Page() {
254
+ import { locacalizeTo } from "~/components/localized-link";
255
+
256
+ export const useLocalizedNavigate = () => {
257
+ const navigate = useNavigate();
279
258
  const { locale } = useLocale();
280
259
 
281
- return <Navigate replace to={locale} />;
282
- }
260
+ const localizedNavigate = (to: To, options?: NavigateOptions) => {
261
+ const localedTo = locacalizeTo(to, locale);
262
+
263
+ navigate(localedTo, options);
264
+ };
265
+
266
+ return localizedNavigate;
267
+ };
283
268
  ```
284
269
 
270
+ ### Step 8: Utilize Intlayer in Your Pages
271
+
272
+ Access your content dictionaries throughout your application:
273
+
285
274
  #### Localized Home Page
286
275
 
287
- ```tsx fileName="app/routes/[lang]/page.tsx" codeFormat="typescript"
276
+ ```tsx fileName="app/routes/[lang]/page.tsx"
288
277
  import { useIntlayer } from "react-intlayer";
289
- import LocalizedLink from "~/components/localized-link";
278
+ import { LocalizedLink } from "~/components/localized-link";
290
279
 
291
280
  export default function Page() {
292
- const content = useIntlayer("page");
281
+ const { title, description, aboutLink } = useIntlayer("page");
293
282
 
294
283
  return (
295
- <div style={{ padding: "2rem", textAlign: "center" }}>
296
- <h1>{content.title}</h1>
297
- <p>{content.description}</p>
298
- <nav style={{ marginTop: "2rem" }}>
299
- <LocalizedLink
300
- to="/about"
301
- style={{
302
- display: "inline-block",
303
- padding: "0.5rem 1rem",
304
- backgroundColor: "#007bff",
305
- color: "white",
306
- textDecoration: "none",
307
- borderRadius: "4px",
308
- }}
309
- >
310
- {content.aboutLink}
311
- </LocalizedLink>
284
+ <div>
285
+ <h1>{title}</h1>
286
+ <p>{description}</p>
287
+ <nav>
288
+ <LocalizedLink to="/about">{aboutLink}</LocalizedLink>
312
289
  </nav>
313
290
  </div>
314
291
  );
@@ -321,43 +298,58 @@ export default function Page() {
321
298
 
322
299
  Create a component to allow users to change languages:
323
300
 
324
- ```tsx fileName="app/components/locale-switcher.tsx" codeFormat="typescript"
325
- import { getLocalizedUrl, getLocaleName } from "intlayer";
326
- import { useLocale } from "react-intlayer";
327
- import { useLocation, useNavigate } from "react-router";
301
+ ```tsx fileName="app/components/locale-switcher.tsx"
302
+ import type { FC } from "react";
328
303
 
329
- export default function LocaleSwitcher() {
330
- const { locale, availableLocales, setLocale } = useLocale();
331
- const location = useLocation();
332
- const navigate = useNavigate();
304
+ import {
305
+ getHTMLTextDir,
306
+ getLocaleName,
307
+ getLocalizedUrl,
308
+ getPathWithoutLocale,
309
+ } from "intlayer";
310
+ import { setLocaleCookie, useIntlayer, useLocale } from "react-intlayer";
311
+ import { Link, useLocation } from "react-router";
333
312
 
334
- const handleLocaleChange = (newLocale: string) => {
335
- const localizedUrl = getLocalizedUrl(
336
- location.pathname + location.search,
337
- newLocale
338
- );
339
- setLocale(newLocale);
340
- navigate(localizedUrl);
341
- };
313
+ export const LocaleSwitcher: FC = () => {
314
+ const { localeSwitcherLabel } = useIntlayer("locale-switcher");
315
+ const { pathname } = useLocation();
316
+
317
+ const { availableLocales, locale } = useLocale();
318
+
319
+ const pathWithoutLocale = getPathWithoutLocale(pathname);
342
320
 
343
321
  return (
344
- <div style={{ margin: "1rem 0" }}>
345
- <label htmlFor="locale-select">Choose Language: </label>
346
- <select
347
- id="locale-select"
348
- value={locale}
349
- onChange={(e) => handleLocaleChange(e.target.value)}
350
- style={{ padding: "0.25rem", marginLeft: "0.5rem" }}
351
- >
352
- {availableLocales.map((availableLocale) => (
353
- <option key={availableLocale} value={availableLocale}>
354
- {getLocaleName(availableLocale)}
355
- </option>
356
- ))}
357
- </select>
358
- </div>
322
+ <ol>
323
+ {availableLocales.map((localeItem) => (
324
+ <li key={localeItem}>
325
+ <Link
326
+ aria-current={localeItem === locale ? "page" : undefined}
327
+ aria-label={`${localeSwitcherLabel.value} ${getLocaleName(localeItem)}`}
328
+ onClick={() => setLocaleCookie(localeItem)}
329
+ to={getLocalizedUrl(pathWithoutLocale, localeItem)}
330
+ >
331
+ <span>
332
+ {/* Locale - e.g. FR */}
333
+ {localeItem}
334
+ </span>
335
+ <span>
336
+ {/* Language in its own Locale - e.g. Français */}
337
+ {getLocaleName(localeItem, locale)}
338
+ </span>
339
+ <span dir={getHTMLTextDir(localeItem)} lang={localeItem}>
340
+ {/* Language in current Locale - e.g. Francés with current locale set to Locales.SPANISH */}
341
+ {getLocaleName(localeItem)}
342
+ </span>
343
+ <span dir="ltr" lang={Locales.ENGLISH}>
344
+ {/* Language in English - e.g. French */}
345
+ {getLocaleName(localeItem, Locales.ENGLISH)}
346
+ </span>
347
+ </Link>
348
+ </li>
349
+ ))}
350
+ </ol>
359
351
  );
360
- }
352
+ };
361
353
  ```
362
354
 
363
355
  > To Learn more about the `useLocale` hook, refer to the [documentation](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/packages/react-intlayer/useLocale.md).
@@ -366,8 +358,7 @@ export default function LocaleSwitcher() {
366
358
 
367
359
  Create a hook to manage HTML lang and dir attributes:
368
360
 
369
- ```tsx fileName="app/hooks/useI18nHTMLAttributes.tsx" codeFormat="typescript"
370
- // app/hooks/useI18nHTMLAttributes.tsx
361
+ ```tsx fileName="app/hooks/useI18nHTMLAttributes.tsx"
371
362
  import { getHTMLTextDir } from "intlayer";
372
363
  import { useEffect } from "react";
373
364
  import { useLocale } from "react-intlayer";
@@ -384,8 +375,7 @@ export const useI18nHTMLAttributes = () => {
384
375
 
385
376
  Then use it in your root component:
386
377
 
387
- ```tsx fileName="app/root.tsx" codeFormat="typescript"
388
- // app/routes/layout.tsx
378
+ ```tsx fileName="app/routes/layout.tsx"
389
379
  import { Outlet } from "react-router";
390
380
  import { IntlayerProvider } from "react-intlayer";
391
381
 
@@ -402,35 +392,26 @@ export default function RootLayout() {
402
392
  }
403
393
  ```
404
394
 
405
- ### Step 11: Build and Run Your Application
406
-
407
- Build the content dictionaries and run your application:
395
+ ### Step 11: Add middleware (Optional)
408
396
 
409
- ```bash packageManager="npm"
410
- # Build Intlayer dictionaries
411
- npm run intlayer:build
397
+ You can also use the `intlayerMiddleware` to add server-side routing to your application. This plugin will automatically detect the current locale based on the URL and set the appropriate locale cookie. If no locale is specified, the plugin will determine the most appropriate locale based on the user's browser language preferences. If no locale is detected, it will redirect to the default locale.
412
398
 
413
- # Start development server
414
- npm run dev
415
- ```
399
+ > Note that to use the `intlayerMiddleware` in production, you need to switch the `vite-intlayer` package from `devDependencies` to `dependencies`.
416
400
 
417
- ```bash packageManager="pnpm"
418
- # Build Intlayer dictionaries
419
- pnpm intlayer:build
401
+ ```typescript {3,7} fileName="vite.config.ts"
402
+ import { defineConfig } from "vite";
403
+ import react from "@vitejs/plugin-react-swc";
404
+ import { intlayer, intlayerMiddleware } from "vite-intlayer";
420
405
 
421
- # Start development server
422
- pnpm dev
406
+ // https://vitejs.dev/config/
407
+ export default defineConfig({
408
+ plugins: [react(), intlayer(), intlayerMiddleware()],
409
+ });
423
410
  ```
424
411
 
425
- ```bash packageManager="yarn"
426
- # Build Intlayer dictionaries
427
- yarn intlayer:build
428
-
429
- # Start development server
430
- yarn dev
431
- ```
412
+ ---
432
413
 
433
- ### Step 12: Configure TypeScript (Optional)
414
+ ## Configure TypeScript
434
415
 
435
416
  Intlayer uses module augmentation to get benefits of TypeScript and make your codebase stronger.
436
417
 
@@ -438,9 +419,7 @@ Ensure your TypeScript configuration includes the autogenerated types:
438
419
 
439
420
  ```json5 fileName="tsconfig.json"
440
421
  {
441
- compilerOptions: {
442
- // ... your existing TypeScript configurations
443
- },
422
+ // ... your existing configurations
444
423
  include: [
445
424
  // ... your existing includes
446
425
  ".intlayer/**/*.ts", // Include the auto-generated types
@@ -448,7 +427,9 @@ Ensure your TypeScript configuration includes the autogenerated types:
448
427
  }
449
428
  ```
450
429
 
451
- ### Git Configuration
430
+ ---
431
+
432
+ ## Git Configuration
452
433
 
453
434
  It is recommended to ignore the files generated by Intlayer. This allows you to avoid committing them to your Git repository.
454
435
 
@@ -461,35 +442,6 @@ To do this, you can add the following instructions to your `.gitignore` file:
461
442
 
462
443
  ---
463
444
 
464
- ## Production Deployment
465
-
466
- When deploying your application:
467
-
468
- 1. **Build your application:**
469
-
470
- ```bash
471
- npm run build
472
- ```
473
-
474
- 2. **Build Intlayer dictionaries:**
475
-
476
- ```bash
477
- npm run intlayer:build
478
- ```
479
-
480
- 3. **Move `vite-intlayer` to dependencies** if using middleware in production:
481
- ```bash
482
- npm install vite-intlayer --save
483
- ```
484
-
485
- Your application will now support:
486
-
487
- - **URL Structure**: `/en`, `/en/about`, `/tr`, `/tr/about`
488
- - **Automatic locale detection** based on browser preferences
489
- - **Locale-aware routing** with React Router v7
490
- - **TypeScript support** with auto-generated types
491
- - **Server-side rendering** with proper locale handling
492
-
493
445
  ## VS Code Extension
494
446
 
495
447
  To improve your development experience with Intlayer, you can install the official **Intlayer VS Code Extension**.
@@ -519,13 +471,14 @@ To go further, you can implement the [visual editor](https://github.com/aymericz
519
471
  - [React Router v7 Documentation](https://reactrouter.com/)
520
472
  - [useIntlayer hook](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/packages/react-intlayer/useIntlayer.md)
521
473
  - [useLocale hook](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/packages/react-intlayer/useLocale.md)
522
- - [Content Declaration](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/dictionary/get_started.md)
474
+ - [Content Declaration](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/dictionary/content_file.md)
523
475
  - [Configuration](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/configuration.md)
524
476
 
525
477
  This comprehensive guide provides everything you need to integrate Intlayer with React Router v7 for a fully internationalized application with locale-aware routing and TypeScript support.
526
478
 
527
479
  ## Doc History
528
480
 
529
- | Version | Date | Changes |
530
- | ------- | --------- | ------------------------- |
531
- | 5.8.2 | 2025-09-4 | Added for React Router v7 |
481
+ | Version | Date | Changes |
482
+ | ------- | ---------- | ------------------------- |
483
+ | 6.1.5 | 2025-10-03 | Updated doc |
484
+ | 5.8.2 | 2025-09-04 | Added for React Router v7 |