@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
@@ -15,10 +15,8 @@ keywords:
15
15
  slugs:
16
16
  - doc
17
17
  - environment
18
- - vite-and-react
19
18
  - tanstack-start
20
- applicationTemplate: https://github.com/AydinTheFirst/tanstack-start-intlayer
21
- author: AydinTheFirst
19
+ applicationTemplate: https://github.com/aymericzip/intlayer-tanstack-start-template
22
20
  ---
23
21
 
24
22
  # Getting Started Internationalizing (i18n) with Intlayer and Tanstack Start
@@ -61,7 +59,7 @@ pnpm add vite-intlayer --save-dev
61
59
 
62
60
  - **intlayer**
63
61
 
64
- 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).
62
+ 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).
65
63
 
66
64
  - **react-intlayer**
67
65
  The package that integrates Intlayer with React application. It provides context providers and hooks for React internationalization.
@@ -73,7 +71,7 @@ pnpm add vite-intlayer --save-dev
73
71
 
74
72
  Create a config file to configure the languages of your application:
75
73
 
76
- ```typescript fileName="intlayer.config.ts" codeFormat="typescript"
74
+ ```typescript fileName="intlayer.config.ts"
77
75
  import type { IntlayerConfig } from "intlayer";
78
76
 
79
77
  import { Locales } from "intlayer";
@@ -81,75 +79,27 @@ import { Locales } from "intlayer";
81
79
  const config: IntlayerConfig = {
82
80
  internationalization: {
83
81
  defaultLocale: Locales.ENGLISH,
84
- locales: [
85
- Locales.ENGLISH,
86
- Locales.FRENCH,
87
- Locales.SPANISH,
88
- // Your other locales
89
- ],
82
+ locales: [Locales.ENGLISH, Locales.FRENCH, Locales.SPANISH],
90
83
  },
91
84
  };
92
85
 
93
86
  export default config;
94
87
  ```
95
88
 
96
- ```javascript fileName="intlayer.config.mjs" codeFormat="esm"
97
- import { Locales } from "intlayer";
98
-
99
- /** @type {import('intlayer').IntlayerConfig} */
100
- const config = {
101
- internationalization: {
102
- defaultLocale: Locales.ENGLISH,
103
- locales: [
104
- Locales.ENGLISH,
105
- Locales.FRENCH,
106
- Locales.SPANISH,
107
- // Your other locales
108
- ],
109
- },
110
- };
111
-
112
- export default config;
113
- ```
114
-
115
- ```javascript fileName="intlayer.config.cjs" codeFormat="commonjs"
116
- const { Locales } = require("intlayer");
117
-
118
- /** @type {import('intlayer').IntlayerConfig} */
119
- const config = {
120
- internationalization: {
121
- defaultLocale: Locales.ENGLISH,
122
- locales: [
123
- Locales.ENGLISH,
124
- Locales.FRENCH,
125
- Locales.SPANISH,
126
- // Your other locales
127
- ],
128
- },
129
- };
130
-
131
- module.exports = config;
132
- ```
133
-
134
89
  > 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).
135
90
 
136
91
  ### Step 4: Integrate Intlayer in Your Vite Configuration
137
92
 
138
93
  Add the intlayer plugin into your configuration:
139
94
 
140
- ```typescript fileName="vite.config.ts" codeFormat="typescript"
95
+ ```typescript fileName="vite.config.ts"
141
96
  import { reactRouter } from "@react-router/dev/vite";
142
97
  import { defineConfig } from "vite";
143
- import { intlayerMiddlewarePlugin, intlayer } from "vite-intlayer";
98
+ import { intlayer } from "vite-intlayer";
144
99
  import tsconfigPaths from "vite-tsconfig-paths";
145
100
 
146
101
  export default defineConfig({
147
- plugins: [
148
- reactRouter(),
149
- tsconfigPaths(),
150
- intlayer(),
151
- intlayerMiddlewarePlugin(),
152
- ],
102
+ plugins: [reactRouter(), tsconfigPaths(), intlayer()],
153
103
  });
154
104
  ```
155
105
 
@@ -161,10 +111,8 @@ Set up your root layout and locale-specific layouts:
161
111
 
162
112
  #### Root Layout
163
113
 
164
- ```tsx fileName="src/routes/{-$locale}/route.tsx" codeFormat="typescript"
165
- // src/routes/{-$locale}/route.tsx
114
+ ```tsx fileName="src/routes/{-$locale}/route.tsx"
166
115
  import { createFileRoute, Navigate, Outlet } from "@tanstack/react-router";
167
- import { configuration } from "intlayer";
168
116
  import { IntlayerProvider, useLocale } from "react-intlayer";
169
117
 
170
118
  import { useI18nHTMLAttributes } from "@/hooks/useI18nHTMLAttributes";
@@ -174,10 +122,11 @@ export const Route = createFileRoute("/{-$locale}")({
174
122
  });
175
123
 
176
124
  function LayoutComponent() {
125
+ const { defaultLocale } = useLocale();
177
126
  const { locale } = Route.useParams();
178
127
 
179
128
  return (
180
- <IntlayerProvider locale={locale}>
129
+ <IntlayerProvider locale={defaultLocale}>
181
130
  <Outlet />
182
131
  </IntlayerProvider>
183
132
  );
@@ -188,7 +137,7 @@ function LayoutComponent() {
188
137
 
189
138
  Create and manage your content declarations to store translations:
190
139
 
191
- ```tsx fileName="src/contents/page.content.ts" contentDeclarationFormat="typescript"
140
+ ```tsx fileName="src/contents/page.content.ts"
192
141
  import type { Dictionary } from "intlayer";
193
142
 
194
143
  import { t } from "intlayer";
@@ -228,65 +177,105 @@ export default appContent;
228
177
 
229
178
  > 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}`).
230
179
 
231
- > For more details, refer to the [content declaration documentation](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/dictionary/get_started.md).
180
+ > For more details, refer to the [content declaration documentation](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/dictionary/content_file.md).
232
181
 
233
182
  ### Step 7: Create Locale-Aware Components and Hooks
234
183
 
235
184
  Create a `LocalizedLink` component for locale-aware navigation:
236
185
 
237
- ```tsx fileName="src/components/localized-link.tsx" codeFormat="typescript"
238
- // src/components/localized-link.tsx
239
- // eslint-disable-next-line no-restricted-imports
240
- import { Link, type LinkProps } from "@tanstack/react-router";
241
- import { getLocalizedUrl } from "intlayer";
186
+ ```tsx fileName="src/components/localized-link.tsx"
187
+ import type { FC } from "react";
188
+
189
+ import { Link, type LinkComponentProps } from "@tanstack/react-router";
242
190
  import { useLocale } from "react-intlayer";
243
191
 
192
+ export const LOCALE_ROUTE = "{-$locale}" as const;
193
+
194
+ // Main utility
195
+ export type RemoveLocaleParam<T> = T extends string
196
+ ? RemoveLocaleFromString<T>
197
+ : T;
198
+
199
+ export type To = RemoveLocaleParam<LinkComponentProps["to"]>;
200
+
201
+ type CollapseDoubleSlashes<S extends string> =
202
+ S extends `${infer H}//${infer T}` ? CollapseDoubleSlashes<`${H}/${T}`> : S;
203
+
244
204
  type LocalizedLinkProps = {
245
- to: string;
246
- } & Omit<LinkProps, "to">;
205
+ to?: To;
206
+ } & Omit<LinkComponentProps, "to">;
247
207
 
248
- export function LocalizedLink(props: LocalizedLinkProps) {
249
- const { locale } = useLocale();
208
+ // Helpers
209
+ type RemoveAll<
210
+ S extends string,
211
+ Sub extends string,
212
+ > = S extends `${infer H}${Sub}${infer T}` ? RemoveAll<`${H}${T}`, Sub> : S;
250
213
 
251
- const isExternal = (to: string) => {
252
- return /^(https?:)?\/\//.test(to);
253
- };
214
+ type RemoveLocaleFromString<S extends string> = CollapseDoubleSlashes<
215
+ RemoveAll<S, typeof LOCALE_ROUTE>
216
+ >;
254
217
 
255
- const to = isExternal(props.to)
256
- ? props.to
257
- : getLocalizedUrl(props.to, locale);
218
+ export const LocalizedLink: FC<LocalizedLinkProps> = (props) => {
219
+ const { locale } = useLocale();
258
220
 
259
- return <Link {...props} to={to as LinkProps["to"]} />;
260
- }
221
+ return (
222
+ <Link
223
+ {...props}
224
+ params={{
225
+ locale,
226
+ ...(typeof props?.params === "object" ? props?.params : {}),
227
+ }}
228
+ to={`/${LOCALE_ROUTE}${props.to}` as LinkComponentProps["to"]}
229
+ />
230
+ );
231
+ };
261
232
  ```
262
233
 
263
- Create a `useLocalizedNavigate` hook for programmatic navigation:
234
+ This component has two objectives:
264
235
 
265
- ```tsx fileName="src/hooks/useLocalizedNavigate.tsx" codeFormat="typescript"
266
- // src/hooks/useLocalizedNavigate.tsx
267
- // eslint-disable-next-line no-restricted-imports
268
- import { NavigateOptions, useNavigate } from "@tanstack/react-router";
269
- import { getLocalizedUrl } from "intlayer";
270
- import { useLocale } from "react-intlayer";
236
+ - Remove the unnecessary `{-$locale}` prefix from the URL.
237
+ - Inject the locale parameter into the URL to ensure the user is directly redirected to the localized route.
271
238
 
272
- type LocalizedNavigateOptions = {
273
- to: string;
274
- } & Omit<NavigateOptions, "to">;
239
+ Then we can create a `useLocalizedNavigate` hook for programmatic navigation:
240
+
241
+ ```tsx fileName="src/hooks/useLocalizedNavigate.tsx"
242
+ import { useLocale } from "react-intlayer";
243
+ import { useNavigate } from "@tanstack/react-router";
244
+ import { LOCALE_ROUTE } from "@/components/localized-link";
245
+ import type { FileRouteTypes } from "@/routeTree.gen";
275
246
 
276
247
  export const useLocalizedNavigate = () => {
277
248
  const navigate = useNavigate();
249
+
278
250
  const { locale } = useLocale();
279
251
 
280
- const isExternal = (to: string) => {
281
- return /^(https?:)?\/\//.test(to);
282
- };
252
+ type StripLocalePrefix<T extends string> = T extends
253
+ | `/${typeof LOCALE_ROUTE}`
254
+ | `/${typeof LOCALE_ROUTE}/`
255
+ ? "/"
256
+ : T extends `/${typeof LOCALE_ROUTE}/${infer Rest}`
257
+ ? `/${Rest}`
258
+ : never;
259
+
260
+ type LocalizedTo = StripLocalePrefix<FileRouteTypes["to"]>;
261
+
262
+ interface LocalizedNavigate {
263
+ (to: LocalizedTo): ReturnType<typeof navigate>;
264
+ (
265
+ opts: { to: LocalizedTo } & Record<string, unknown>
266
+ ): ReturnType<typeof navigate>;
267
+ }
268
+
269
+ const localizedNavigate: LocalizedNavigate = (args: any) => {
270
+ if (typeof args === "string") {
271
+ return navigate({ to: `/${LOCALE_ROUTE}${args}`, params: { locale } });
272
+ }
273
+
274
+ const { to, ...rest } = args;
283
275
 
284
- const localizedNavigate = (options: LocalizedNavigateOptions) => {
285
- const to = isExternal(options.to)
286
- ? options.to
287
- : getLocalizedUrl(options.to, locale);
276
+ const localedTo = `/${LOCALE_ROUTE}${to}` as any;
288
277
 
289
- navigate({ ...options, to: to as NavigateOptions["to"] });
278
+ return navigate({ to: localedTo, params: { locale, ...rest } as any });
290
279
  };
291
280
 
292
281
  return localizedNavigate;
@@ -297,23 +286,9 @@ export const useLocalizedNavigate = () => {
297
286
 
298
287
  Access your content dictionaries throughout your application:
299
288
 
300
- #### Root Redirect Page
301
-
302
- ```tsx fileName="src/routes/page.tsx" codeFormat="typescript"
303
- // src/routes/page.tsx
304
- import { useLocale } from "react-intlayer";
305
- import { Navigate } from "react-router";
306
-
307
- export default function Page() {
308
- const { locale } = useLocale();
309
-
310
- return <Navigate replace to={locale} />;
311
- }
312
- ```
313
-
314
289
  #### Localized Home Page
315
290
 
316
- ```tsx fileName="src/routes/{-$locale}/index.tsx" codeFormat="typescript"
291
+ ```tsx fileName="src/routes/{-$locale}/index.tsx"
317
292
  import { createFileRoute } from "@tanstack/react-router";
318
293
  import { getIntlayer } from "intlayer";
319
294
  import { useIntlayer } from "react-intlayer";
@@ -342,16 +317,15 @@ function RouteComponent() {
342
317
  const navigate = useLocalizedNavigate();
343
318
 
344
319
  return (
345
- <div className="grid place-items-center h-screen">
346
- <div className="flex flex-col gap-4 items-center text-center">
320
+ <div>
321
+ <div>
347
322
  {content.title}
348
323
  <LocaleSwitcher />
349
- <div className="flex gap-4">
350
- <a href="/">Index</a>
324
+ <div>
351
325
  <LocalizedLink to="/">{content.links.home}</LocalizedLink>
352
326
  <LocalizedLink to="/about">{content.links.about}</LocalizedLink>
353
327
  </div>
354
- <div className="flex gap-4">
328
+ <div>
355
329
  <button onClick={() => navigate({ to: "/" })}>
356
330
  {content.links.home}
357
331
  </button>
@@ -371,48 +345,56 @@ function RouteComponent() {
371
345
 
372
346
  Create a component to allow users to change languages:
373
347
 
374
- ```tsx fileName="src/components/locale-switcher.tsx" codeFormat="typescript"
348
+ ```tsx fileName="src/components/locale-switcher.tsx"
349
+ import type { FC } from "react";
350
+
375
351
  import { useLocation } from "@tanstack/react-router";
376
- import {
377
- getHTMLTextDir,
378
- getLocaleName,
379
- getLocalizedUrl,
380
- Locales,
381
- } from "intlayer";
382
- import { useIntlayer, useLocale } from "react-intlayer";
383
-
384
- export default function LocaleSwitcher() {
385
- const { pathname, searchStr } = useLocation();
386
- const content = useIntlayer("locale-switcher");
387
-
388
- const { availableLocales, locale, setLocale } = useLocale({
389
- onLocaleChange: (newLocale) => {
390
- const pathWithLocale = getLocalizedUrl(pathname + searchStr, newLocale);
391
- location.replace(pathWithLocale);
392
- },
393
- });
352
+ import { getHTMLTextDir, getLocaleName, getPathWithoutLocale } from "intlayer";
353
+ import { setLocaleCookie, useIntlayer, useLocale } from "react-intlayer";
354
+
355
+ import { LocalizedLink, To } from "./localized-link";
356
+
357
+ export const LocaleSwitcher: FC = () => {
358
+ const { localeSwitcherLabel } = useIntlayer("locale-switcher");
359
+ const { pathname } = useLocation();
360
+
361
+ const { availableLocales, locale } = useLocale();
362
+
363
+ const pathWithoutLocale = getPathWithoutLocale(pathname);
394
364
 
395
365
  return (
396
- <select
397
- aria-label={content.label.toString()}
398
- onChange={(e) => setLocale(e.target.value)}
399
- value={locale}
400
- >
401
- {availableLocales.map((localeItem) => (
402
- <option
403
- dir={getHTMLTextDir(localeItem)}
404
- key={localeItem}
405
- lang={localeItem}
406
- value={localeItem}
407
- >
408
- {/* Example: Français (French) */}
409
- {getLocaleName(localeItem, locale)} (
410
- {getLocaleName(localeItem, Locales.ENGLISH)})
411
- </option>
366
+ <ol>
367
+ {availableLocales.map((localeEl) => (
368
+ <li key={localeEl}>
369
+ <LocalizedLink
370
+ aria-current={localeEl === locale ? "page" : undefined}
371
+ aria-label={`${localeSwitcherLabel.value} ${getLocaleName(localeEl)}`}
372
+ onClick={() => setLocaleCookie(localeEl)}
373
+ params={{ locale: localeEl }}
374
+ to={pathWithoutLocale as To}
375
+ >
376
+ <span>
377
+ {/* Locale - e.g. FR */}
378
+ {localeItem}
379
+ </span>
380
+ <span>
381
+ {/* Language in its own Locale - e.g. Français */}
382
+ {getLocaleName(localeItem, locale)}
383
+ </span>
384
+ <span dir={getHTMLTextDir(localeItem)} lang={localeItem}>
385
+ {/* Language in current Locale - e.g. Francés with current locale set to Locales.SPANISH */}
386
+ {getLocaleName(localeItem)}
387
+ </span>
388
+ <span dir="ltr" lang={Locales.ENGLISH}>
389
+ {/* Language in English - e.g. French */}
390
+ {getLocaleName(localeItem, Locales.ENGLISH)}
391
+ </span>
392
+ </LocalizedLink>
393
+ </li>
412
394
  ))}
413
- </select>
395
+ </ol>
414
396
  );
415
- }
397
+ };
416
398
  ```
417
399
 
418
400
  > 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).
@@ -421,7 +403,7 @@ export default function LocaleSwitcher() {
421
403
 
422
404
  Create a hook to manage HTML lang and dir attributes:
423
405
 
424
- ```tsx fileName="src/hooks/useI18nHTMLAttributes.tsx" codeFormat="typescript"
406
+ ```tsx fileName="src/hooks/useI18nHTMLAttributes.tsx"
425
407
  // src/hooks/useI18nHTMLAttributes.tsx
426
408
  import { getHTMLTextDir } from "intlayer";
427
409
  import { useEffect } from "react";
@@ -439,9 +421,8 @@ export const useI18nHTMLAttributes = () => {
439
421
 
440
422
  Then use it in your root component:
441
423
 
442
- ```tsx fileName="src/routes/{-$locale}/index.tsx" codeFormat="typescript"
424
+ ```tsx fileName="src/routes/{-$locale}/index.tsx"
443
425
  import { createFileRoute, Navigate, Outlet } from "@tanstack/react-router";
444
- import { configuration } from "intlayer";
445
426
  import { IntlayerProvider, useLocale } from "react-intlayer";
446
427
 
447
428
  import { useI18nHTMLAttributes } from "@/hooks/useI18nHTMLAttributes"; // import the hook
@@ -453,43 +434,44 @@ export const Route = createFileRoute("/{-$locale}")({
453
434
  function LayoutComponent() {
454
435
  useI18nHTMLAttributes(); // add this line
455
436
 
437
+ const { defaultLocale } = useLocale();
456
438
  const { locale } = Route.useParams();
457
439
 
458
440
  return (
459
- <IntlayerProvider locale={locale}>
441
+ <IntlayerProvider locale={locale ?? defaultLocale}>
460
442
  <Outlet />
461
443
  </IntlayerProvider>
462
444
  );
463
445
  }
464
446
  ```
465
447
 
466
- ### Step 11: Build and Run Your Application
448
+ ---
467
449
 
468
- Build the content dictionaries and run your application:
450
+ ### Step 11: Add middleware (Optional)
469
451
 
470
- ```bash packageManager="npm"
471
- # Build Intlayer dictionaries
472
- npm run intlayer:build
452
+ 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.
473
453
 
474
- # Start development server
475
- npm run dev
476
- ```
454
+ > Note that to use the `intlayerMiddleware` in production, you need to switch the `vite-intlayer` package from `devDependencies` to `dependencies`.
477
455
 
478
- ```bash packageManager="pnpm"
479
- # Build Intlayer dictionaries
480
- pnpm intlayer:build
456
+ ```typescript {3,7} fileName="vite.config.ts"
457
+ import { reactRouter } from "@react-router/dev/vite";
458
+ import tailwindcss from "@tailwindcss/vite";
459
+ import { defineConfig } from "vite";
460
+ import { intlayer, intlayerMiddleware } from "vite-intlayer";
461
+ import tsconfigPaths from "vite-tsconfig-paths";
481
462
 
482
- # Start development server
483
- pnpm dev
463
+ export default defineConfig({
464
+ plugins: [
465
+ tailwindcss(),
466
+ reactRouter(),
467
+ tsconfigPaths(),
468
+ intlayer(),
469
+ intlayerMiddleware(),
470
+ ],
471
+ });
484
472
  ```
485
473
 
486
- ```bash packageManager="yarn"
487
- # Build Intlayer dictionaries
488
- yarn intlayer:build
489
-
490
- # Start development server
491
- yarn dev
492
- ```
474
+ ---
493
475
 
494
476
  ### Step 12: Configure TypeScript (Optional)
495
477
 
@@ -499,9 +481,7 @@ Ensure your TypeScript configuration includes the autogenerated types:
499
481
 
500
482
  ```json5 fileName="tsconfig.json"
501
483
  {
502
- compilerOptions: {
503
- // ... your existing TypeScript configurations
504
- },
484
+ // ... your existing configurations
505
485
  include: [
506
486
  // ... your existing includes
507
487
  ".intlayer/**/*.ts", // Include the auto-generated types
@@ -509,6 +489,8 @@ Ensure your TypeScript configuration includes the autogenerated types:
509
489
  }
510
490
  ```
511
491
 
492
+ ---
493
+
512
494
  ### Git Configuration
513
495
 
514
496
  It is recommended to ignore the files generated by Intlayer. This allows you to avoid committing them to your Git repository.
@@ -522,64 +504,6 @@ To do this, you can add the following instructions to your `.gitignore` file:
522
504
 
523
505
  ---
524
506
 
525
- ### Step 13: Create Redirection (Optional)
526
-
527
- ```typescript fileName="src/routes/{-$locale}/rotue.tsx" codeFormat="typescript"
528
- function LayoutComponent() {
529
- useI18nHTMLAttributes();
530
-
531
- const { locale } = Route.useParams();
532
- const { locale: selectedLocale } = useLocale();
533
- const { defaultLocale } = configuration.internationalization;
534
- const { prefixDefault } = configuration.middleware;
535
-
536
- // Redirect to the default locale if no locale is present in the URL when prefixDefault is true
537
- if (selectedLocale === defaultLocale && !locale && prefixDefault) {
538
- return <Navigate replace to={defaultLocale} />;
539
- }
540
-
541
- // Redirect to the selected locale if the locale in the URL does not match the selected locale
542
- if (selectedLocale !== defaultLocale && !locale) {
543
- return <Navigate replace to={selectedLocale} />;
544
- }
545
-
546
- return (
547
- <IntlayerProvider locale={locale}>
548
- <Outlet />
549
- </IntlayerProvider>
550
- );
551
- }
552
- ```
553
-
554
- ## Production Deployment
555
-
556
- When deploying your application:
557
-
558
- 1. **Build your application:**
559
-
560
- ```bash
561
- npm run build
562
- ```
563
-
564
- 2. **Build Intlayer dictionaries:**
565
-
566
- ```bash
567
- npm run intlayer:build
568
- ```
569
-
570
- 3. **Move `vite-intlayer` to dependencies** if using middleware in production:
571
- ```bash
572
- npm install vite-intlayer --save
573
- ```
574
-
575
- Your application will now support:
576
-
577
- - **URL Structure**: `/en`, `/en/about`, `/tr`, `/tr/about`
578
- - **Automatic locale detection** based on browser preferences
579
- - **Locale-aware routing** with Tanstack Start
580
- - **TypeScript support** with auto-generated types
581
- - **Server-side rendering** with proper locale handling
582
-
583
507
  ## VS Code Extension
584
508
 
585
509
  To improve your development experience with Intlayer, you can install the official **Intlayer VS Code Extension**.
@@ -609,7 +533,7 @@ To go further, you can implement the [visual editor](https://github.com/aymericz
609
533
  - [Tanstack Start Documentation](https://reactrouter.com/)
610
534
  - [useIntlayer hook](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/packages/react-intlayer/useIntlayer.md)
611
535
  - [useLocale hook](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/packages/react-intlayer/useLocale.md)
612
- - [Content Declaration](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/dictionary/get_started.md)
536
+ - [Content Declaration](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/dictionary/content_file.md)
613
537
  - [Configuration](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/configuration.md)
614
538
 
615
539
  This comprehensive guide provides everything you need to integrate Intlayer with Tanstack Start for a fully internationalized application with locale-aware routing and TypeScript support.
@@ -618,4 +542,5 @@ This comprehensive guide provides everything you need to integrate Intlayer with
618
542
 
619
543
  | Version | Date | Changes |
620
544
  | ------- | ---------- | ------------------------ |
545
+ | 6.5.2 | 2025-10-03 | Update doc |
621
546
  | 5.8.1 | 2025-09-09 | Added for Tanstack Start |