@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 internationalisation (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 Internationalising (i18n) with Intlayer and React Router v7
@@ -57,10 +56,10 @@ pnpm add vite-intlayer --save-dev
57
56
 
58
57
  - **intlayer**
59
58
 
60
- The core package that provides internationalisation tools for configuration management, translation, [content declaration](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en-GB/dictionary/get_started.md), transpilation, and [CLI commands](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en-GB/intlayer_cli.md).
59
+ The core package that provides internationalisation tools for configuration management, translation, [content declaration](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en-GB/dictionary/get_started.md), transpilation, and [CLI commands](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en-GB/intlayer_cli.md).
61
60
 
62
61
  - **react-intlayer**
63
- The package that integrates Intlayer with React applications. It provides context providers and hooks for React internationalisation.
62
+ The package that integrates Intlayer with a React application. It provides context providers and hooks for React internationalisation.
64
63
 
65
64
  - **vite-intlayer**
66
65
  Includes the Vite plugin for integrating Intlayer with the [Vite bundler](https://vite.dev/guide/why.html#why-bundle-for-production), as well as middleware for detecting the user's preferred locale, managing cookies, and handling URL redirection.
@@ -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 localised 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-GB/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"), // Localised home page
135
- route("/:lang/about", "routes/[lang]/about/page.tsx"), // Localised 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 optimise 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"), // Localised home page
141
+ route("/:lang?/about", "routes/about/page.tsx"), // Localised 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,21 +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
- "en-GB": "Learn About Us",
202
190
  en: "Learn About Us",
203
- tr: "Hakkımızda Öğrenin",
191
+ es: "Aprender Sobre Nosotros",
192
+ fr: "En savoir plus sur nous",
204
193
  }),
205
194
  homeLink: t({
206
- "en-GB": "Home",
207
195
  en: "Home",
208
- tr: "Ana Sayfa",
196
+ es: "Inicio",
197
+ fr: "Accueil",
209
198
  }),
210
199
  },
211
200
  } satisfies Dictionary;
@@ -213,7 +202,7 @@ const pageContent = {
213
202
  export default pageContent;
214
203
  ```
215
204
 
216
- > Your content declarations can be defined anywhere in your application as soon as 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}`).
205
+ > Your content declarations can be defined anywhere in your application as soon as they are included in 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}`).
217
206
 
218
207
  > For more details, refer to the [content declaration documentation](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en-GB/dictionary/get_started.md).
219
208
 
@@ -221,96 +210,82 @@ export default pageContent;
221
210
 
222
211
  Create a `LocalizedLink` component for locale-aware navigation:
223
212
 
224
- ```tsx fileName="app/components/localized-link.tsx" codeFormat="typescript"
225
- // app/components/localized-link.tsx
226
- import { getLocalizedUrl } from "intlayer";
227
- import { useLocale } from "react-intlayer";
228
- import React from "react";
229
- import { Link, useLocation } from "react-router";
230
-
231
- type RouterLinkProps = React.ComponentProps<typeof Link>;
213
+ ```tsx fileName="app/components/localized-link.tsx"
214
+ import type { FC } from "react";
232
215
 
233
- export default function LocalizedLink({ to, ...props }: RouterLinkProps) {
234
- const { locale } = useLocale();
235
- 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";
236
219
 
237
- const isExternal = (path: string) =>
238
- /^([a-z][a-z0-9+.-]*:)?\/\//i.test(path) || path.startsWith("mailto:");
220
+ const isExternalLink = (to: string) => /^(https?:)?\/\//.test(to);
239
221
 
222
+ export const locacalizeTo = (to: To, locale: LocalesValues): To => {
240
223
  if (typeof to === "string") {
241
- if (to.startsWith("/") && !isExternal(to)) {
242
- return <Link to={getLocalizedUrl(to, locale)} {...props} />;
224
+ if (isExternalLink(to)) {
225
+ return to;
243
226
  }
244
- return <Link to={to} {...props} />;
227
+
228
+ return getLocalizedUrl(to, locale);
245
229
  }
246
230
 
247
- if (to && typeof to === "object") {
248
- const pathname = (to as { pathname?: string }).pathname;
249
- if (pathname && pathname.startsWith("/") && !isExternal(pathname)) {
250
- return (
251
- <Link
252
- to={{ ...to, pathname: getLocalizedUrl(pathname, locale) }}
253
- {...props}
254
- />
255
- );
256
- }
257
- return <Link to={to} {...props} />;
231
+ if (isExternalLink(to.pathname ?? "")) {
232
+ return to;
258
233
  }
259
234
 
260
- return (
261
- <Link
262
- to={getLocalizedUrl(location.pathname + location.search, locale)}
263
- {...props}
264
- />
265
- );
266
- }
267
- ```
235
+ return {
236
+ ...to,
237
+ pathname: getLocalizedUrl(to.pathname ?? "", locale),
238
+ };
239
+ };
268
240
 
269
- ### Step 8: Utilise Intlayer in Your Pages
241
+ export const LocalizedLink: FC<LinkProps> = (props) => {
242
+ const { locale } = useLocale();
270
243
 
271
- Access your content dictionaries throughout your application:
244
+ return <Link {...props} to={locacalizeTo(props.to, locale)} />;
245
+ };
246
+ ```
272
247
 
273
- #### Root Redirect Page
248
+ If you want to navigate to the localised routes, you can use the `useLocalizedNavigate` hook:
274
249
 
275
- ```tsx fileName="app/routes/page.tsx" codeFormat="typescript"
276
- // app/routes/page.tsx
277
- import { useLocale } from "react-intlayer";
278
- import { Navigate } from "react-router";
250
+ ```tsx fileName="app/hooks/useLocalizedNavigate.ts"
251
+ import { useLocale } from "intlayer";
252
+ import { type NavigateOptions, type To, useNavigate } from "react-router";
279
253
 
280
- export default function Page() {
254
+ import { locacalizeTo } from "~/components/localized-link";
255
+
256
+ export const useLocalizedNavigate = () => {
257
+ const navigate = useNavigate();
281
258
  const { locale } = useLocale();
282
259
 
283
- return <Navigate replace to={locale} />;
284
- }
260
+ const localisedNavigate = (to: To, options?: NavigateOptions) => {
261
+ const localedTo = locacalizeTo(to, locale);
262
+
263
+ navigate(localedTo, options);
264
+ };
265
+
266
+ return localisedNavigate;
267
+ };
285
268
  ```
286
269
 
270
+ ### Step 8: Utilise Intlayer in Your Pages
271
+
272
+ Access your content dictionaries throughout your application:
273
+
287
274
  #### Localised Home Page
288
275
 
289
- ```tsx fileName="app/routes/[lang]/page.tsx" codeFormat="typescript"
290
- import { useIntlayer } from "react-intlayer";
291
- import LocalizedLink from "~/components/localized-link";
276
+ ```tsx fileName="app/routes/[lang]/page.tsx"
277
+ import { useIntlayer } from "intlayer";
278
+ import { LocalizedLink } from "~/components/localized-link";
292
279
 
293
280
  export default function Page() {
294
- const content = useIntlayer("page");
281
+ const { title, description, aboutLink } = useIntlayer("page");
295
282
 
296
283
  return (
297
- <div style={{ padding: "2rem", textAlign: "center" }}>
298
- <h1>{content.title}</h1>
299
- <p>{content.description}</p>
300
- <nav style={{ marginTop: "2rem" }}>
301
- <LocalizedLink
302
- to="/about"
303
- style={{
304
- display: "inline-block",
305
- padding: "0.5rem 1rem",
306
- backgroundColor: "#007bff",
307
- colour: "white",
308
- textDecoration: "none",
309
- borderRadius: "4px",
310
- }}
311
- >
312
- {content.aboutLink}
313
- </LocalizedLink>
284
+ <div>
285
+ <h1>{title}</h1>
286
+ <p>{description}</p>
287
+ <nav>
288
+ <LocalizedLink to="/about">{aboutLink}</LocalizedLink>
314
289
  </nav>
315
290
  </div>
316
291
  );
@@ -323,43 +298,58 @@ export default function Page() {
323
298
 
324
299
  Create a component to allow users to change languages:
325
300
 
326
- ```tsx fileName="app/components/locale-switcher.tsx" codeFormat="typescript"
327
- import { getLocalizedUrl, getLocaleName } from "intlayer";
328
- import { useLocale } from "react-intlayer";
329
- import { useLocation, useNavigate } from "react-router";
301
+ ```tsx fileName="app/components/locale-switcher.tsx"
302
+ import type { FC } from "react";
330
303
 
331
- export default function LocaleSwitcher() {
332
- const { locale, availableLocales, setLocale } = useLocale();
333
- const location = useLocation();
334
- 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";
335
312
 
336
- const handleLocaleChange = (newLocale: string) => {
337
- const localizedUrl = getLocalizedUrl(
338
- location.pathname + location.search,
339
- newLocale
340
- );
341
- setLocale(newLocale);
342
- navigate(localizedUrl);
343
- };
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);
344
320
 
345
321
  return (
346
- <div style={{ margin: "1rem 0" }}>
347
- <label htmlFor="locale-select">Choose Language: </label>
348
- <select
349
- id="locale-select"
350
- value={locale}
351
- onChange={(e) => handleLocaleChange(e.target.value)}
352
- style={{ padding: "0.25rem", marginLeft: "0.5rem" }}
353
- >
354
- {availableLocales.map((availableLocale) => (
355
- <option key={availableLocale} value={availableLocale}>
356
- {getLocaleName(availableLocale)}
357
- </option>
358
- ))}
359
- </select>
360
- </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>
361
351
  );
362
- }
352
+ };
363
353
  ```
364
354
 
365
355
  > To learn more about the `useLocale` hook, refer to the [documentation](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en-GB/packages/react-intlayer/useLocale.md).
@@ -368,8 +358,7 @@ export default function LocaleSwitcher() {
368
358
 
369
359
  Create a hook to manage HTML lang and dir attributes:
370
360
 
371
- ```tsx fileName="app/hooks/useI18nHTMLAttributes.tsx" codeFormat="typescript"
372
- // app/hooks/useI18nHTMLAttributes.tsx
361
+ ```tsx fileName="app/hooks/useI18nHTMLAttributes.tsx"
373
362
  import { getHTMLTextDir } from "intlayer";
374
363
  import { useEffect } from "react";
375
364
  import { useLocale } from "react-intlayer";
@@ -386,8 +375,7 @@ export const useI18nHTMLAttributes = () => {
386
375
 
387
376
  Then use it in your root component:
388
377
 
389
- ```tsx fileName="app/root.tsx" codeFormat="typescript"
390
- // app/routes/layout.tsx
378
+ ```tsx fileName="app/routes/layout.tsx"
391
379
  import { Outlet } from "react-router";
392
380
  import { IntlayerProvider } from "react-intlayer";
393
381
 
@@ -404,35 +392,26 @@ export default function RootLayout() {
404
392
  }
405
393
  ```
406
394
 
407
- ### Step 11: Build and Run Your Application
408
-
409
- Build the content dictionaries and run your application:
395
+ ### Step 11: Add middleware (Optional)
410
396
 
411
- ```bash packageManager="npm"
412
- # Build Intlayer dictionaries
413
- 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.
414
398
 
415
- # Start development server
416
- npm run dev
417
- ```
399
+ > Note that to use the `intlayerMiddleware` in production, you need to switch the `vite-intlayer` package from `devDependencies` to `dependencies`.
418
400
 
419
- ```bash packageManager="pnpm"
420
- # Build Intlayer dictionaries
421
- 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";
422
405
 
423
- # Start development server
424
- pnpm dev
406
+ // https://vitejs.dev/config/
407
+ export default defineConfig({
408
+ plugins: [react(), intlayer(), intlayerMiddleware()],
409
+ });
425
410
  ```
426
411
 
427
- ```bash packageManager="yarn"
428
- # Build Intlayer dictionaries
429
- yarn intlayer:build
430
-
431
- # Start development server
432
- yarn dev
433
- ```
412
+ ---
434
413
 
435
- ### Step 12: Configure TypeScript (Optional)
414
+ ## Configure TypeScript
436
415
 
437
416
  Intlayer uses module augmentation to benefit from TypeScript and strengthen your codebase.
438
417
 
@@ -440,9 +419,7 @@ Ensure your TypeScript configuration includes the autogenerated types:
440
419
 
441
420
  ```json5 fileName="tsconfig.json"
442
421
  {
443
- compilerOptions: {
444
- // ... your existing TypeScript configurations
445
- },
422
+ // ... your existing configurations
446
423
  include: [
447
424
  // ... your existing includes
448
425
  ".intlayer/**/*.ts", // Include the auto-generated types
@@ -450,7 +427,9 @@ Ensure your TypeScript configuration includes the autogenerated types:
450
427
  }
451
428
  ```
452
429
 
453
- ### Git Configuration
430
+ ---
431
+
432
+ ## Git Configuration
454
433
 
455
434
  It is recommended to ignore the files generated by Intlayer. This prevents you from committing them to your Git repository.
456
435
 
@@ -463,35 +442,6 @@ To do this, you can add the following instructions to your `.gitignore` file:
463
442
 
464
443
  ---
465
444
 
466
- ## Production Deployment
467
-
468
- When deploying your application:
469
-
470
- 1. **Build your application:**
471
-
472
- ```bash
473
- npm run build
474
- ```
475
-
476
- 2. **Build Intlayer dictionaries:**
477
-
478
- ```bash
479
- npm run intlayer:build
480
- ```
481
-
482
- 3. **Move `vite-intlayer` to dependencies** if using middleware in production:
483
- ```bash
484
- npm install vite-intlayer --save
485
- ```
486
-
487
- Your application will now support:
488
-
489
- - **URL Structure**: `/en`, `/en/about`, `/tr`, `/tr/about`
490
- - **Automatic locale detection** based on browser preferences
491
- - **Locale-aware routing** with React Router v7
492
- - **TypeScript support** with auto-generated types
493
- - **Server-side rendering** with proper locale handling
494
-
495
445
  ## VS Code Extension
496
446
 
497
447
  To enhance your development experience with Intlayer, you can install the official **Intlayer VS Code Extension**.
@@ -511,7 +461,7 @@ For more details on how to use the extension, refer to the [Intlayer VS Code Ext
511
461
 
512
462
  ## Go Further
513
463
 
514
- To go further, you can implement the [visual editor](https://github.com/aymericzip/intlayer/blob/main/docs/docs/{{locale}}/intlayer_visual_editor.md) or externalise your content using the [CMS](https://github.com/aymericzip/intlayer/blob/main/docs/docs/{{locale}}/intlayer_CMS.md).
464
+ To go further, you can implement the [visual editor](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en-GB/intlayer_visual_editor.md) or externalise your content using the [CMS](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en-GB/intlayer_CMS.md).
515
465
 
516
466
  ---
517
467
 
@@ -519,15 +469,16 @@ To go further, you can implement the [visual editor](https://github.com/aymericz
519
469
 
520
470
  - [Intlayer Documentation](https://intlayer.org)
521
471
  - [React Router v7 Documentation](https://reactrouter.com/)
522
- - [useIntlayer hook](https://github.com/aymericzip/intlayer/blob/main/docs/docs/{{locale}}/packages/react-intlayer/useIntlayer.md)
523
- - [useLocale hook](https://github.com/aymericzip/intlayer/blob/main/docs/docs/{{locale}}/packages/react-intlayer/useLocale.md)
524
- - [Content Declaration](https://github.com/aymericzip/intlayer/blob/main/docs/docs/{{locale}}/dictionary/get_started.md)
525
- - [Configuration](https://github.com/aymericzip/intlayer/blob/main/docs/docs/{{locale}}/configuration.md)
472
+ - [useIntlayer hook](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en-GB/packages/react-intlayer/useIntlayer.md)
473
+ - [useLocale hook](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en-GB/packages/react-intlayer/useLocale.md)
474
+ - [Content Declaration](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en-GB/dictionary/get_started.md)
475
+ - [Configuration](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en-GB/configuration.md)
526
476
 
527
477
  This comprehensive guide provides everything you need to integrate Intlayer with React Router v7 for a fully internationalised application with locale-aware routing and TypeScript support.
528
478
 
529
479
  ## Doc History
530
480
 
531
- | Version | Date | Changes |
532
- | ------- | --------- | ------------------------- |
533
- | 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 |