@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.
- package/blog/en/next-i18next_vs_next-intl_vs_intlayer.md +71 -80
- package/dist/cjs/generated/docs.entry.cjs +16 -0
- package/dist/cjs/generated/docs.entry.cjs.map +1 -1
- package/dist/esm/generated/docs.entry.mjs +16 -0
- package/dist/esm/generated/docs.entry.mjs.map +1 -1
- package/dist/types/generated/docs.entry.d.ts +1 -0
- package/dist/types/generated/docs.entry.d.ts.map +1 -1
- package/docs/ar/intlayer_with_angular.md +2 -2
- package/docs/ar/intlayer_with_astro.md +246 -0
- package/docs/ar/intlayer_with_create_react_app.md +3 -2
- package/docs/ar/intlayer_with_express.md +2 -2
- package/docs/ar/intlayer_with_nestjs.md +2 -2
- package/docs/ar/intlayer_with_nextjs_14.md +2 -2
- package/docs/ar/intlayer_with_nextjs_15.md +2 -2
- package/docs/ar/intlayer_with_nextjs_page_router.md +2 -2
- package/docs/ar/intlayer_with_nuxt.md +2 -2
- package/docs/ar/intlayer_with_react_native+expo.md +11 -20
- package/docs/ar/intlayer_with_react_router_v7.md +195 -241
- package/docs/ar/intlayer_with_tanstack.md +198 -272
- package/docs/ar/intlayer_with_vite+preact.md +9 -9
- package/docs/ar/intlayer_with_vite+react.md +7 -7
- package/docs/ar/intlayer_with_vite+vue.md +9 -9
- package/docs/de/intlayer_with_angular.md +2 -2
- package/docs/de/intlayer_with_astro.md +246 -0
- package/docs/de/intlayer_with_create_react_app.md +2 -2
- package/docs/de/intlayer_with_express.md +2 -2
- package/docs/de/intlayer_with_nestjs.md +2 -2
- package/docs/de/intlayer_with_nextjs_14.md +2 -2
- package/docs/de/intlayer_with_nextjs_15.md +2 -2
- package/docs/de/intlayer_with_nextjs_page_router.md +2 -2
- package/docs/de/intlayer_with_nuxt.md +2 -2
- package/docs/de/intlayer_with_react_native+expo.md +11 -20
- package/docs/de/intlayer_with_react_router_v7.md +193 -242
- package/docs/de/intlayer_with_tanstack.md +194 -266
- package/docs/de/intlayer_with_vite+preact.md +9 -9
- package/docs/de/intlayer_with_vite+react.md +9 -9
- package/docs/de/intlayer_with_vite+vue.md +11 -11
- package/docs/de/packages/vite-intlayer/index.md +3 -3
- package/docs/en/how_works_intlayer.md +1 -1
- package/docs/en/index.md +1 -1
- package/docs/en/intlayer_cli.md +1 -1
- package/docs/en/intlayer_with_angular.md +4 -4
- package/docs/en/intlayer_with_astro.md +246 -0
- package/docs/en/intlayer_with_create_react_app.md +4 -4
- package/docs/en/intlayer_with_express.md +3 -3
- package/docs/en/intlayer_with_lynx+react.md +1 -1
- package/docs/en/intlayer_with_nestjs.md +2 -2
- package/docs/en/intlayer_with_nextjs_14.md +13 -4
- package/docs/en/intlayer_with_nextjs_15.md +13 -4
- package/docs/en/intlayer_with_nextjs_page_router.md +5 -5
- package/docs/en/intlayer_with_nuxt.md +4 -4
- package/docs/en/intlayer_with_react_native+expo.md +46 -24
- package/docs/en/intlayer_with_react_router_v7.md +164 -211
- package/docs/en/intlayer_with_tanstack.md +166 -241
- package/docs/en/intlayer_with_vite+preact.md +12 -12
- package/docs/en/intlayer_with_vite+react.md +12 -12
- package/docs/en/intlayer_with_vite+solid.md +2 -2
- package/docs/en/intlayer_with_vite+svelte.md +2 -2
- package/docs/en/intlayer_with_vite+vue.md +12 -12
- package/docs/en/introduction.md +1 -1
- package/docs/en/packages/next-intlayer/useDictionary.md +1 -1
- package/docs/en/packages/next-intlayer/useIntlayer.md +1 -1
- package/docs/en/packages/react-intlayer/useDictionary.md +1 -1
- package/docs/en/packages/react-intlayer/useI18n.md +1 -1
- package/docs/en/packages/react-intlayer/useIntlayer.md +1 -1
- package/docs/en/releases/v6.md +1 -0
- package/docs/en/roadmap.md +1 -1
- package/docs/en-GB/intlayer_with_angular.md +3 -3
- package/docs/en-GB/intlayer_with_astro.md +246 -0
- package/docs/en-GB/intlayer_with_create_react_app.md +5 -4
- package/docs/en-GB/intlayer_with_express.md +2 -2
- package/docs/en-GB/intlayer_with_nestjs.md +2 -2
- package/docs/en-GB/intlayer_with_nextjs_14.md +4 -4
- package/docs/en-GB/intlayer_with_nextjs_15.md +2 -2
- package/docs/en-GB/intlayer_with_nextjs_page_router.md +2 -2
- package/docs/en-GB/intlayer_with_nuxt.md +2 -2
- package/docs/en-GB/intlayer_with_react_native+expo.md +11 -20
- package/docs/en-GB/intlayer_with_react_router_v7.md +171 -220
- package/docs/en-GB/intlayer_with_tanstack.md +174 -248
- package/docs/en-GB/intlayer_with_vite+preact.md +9 -9
- package/docs/en-GB/intlayer_with_vite+react.md +9 -9
- package/docs/en-GB/intlayer_with_vite+vue.md +11 -11
- package/docs/en-GB/packages/next-intlayer/useIntlayer.md +1 -1
- package/docs/en-GB/packages/react-intlayer/useIntlayer.md +1 -1
- package/docs/es/intlayer_with_angular.md +2 -2
- package/docs/es/intlayer_with_astro.md +246 -0
- package/docs/es/intlayer_with_create_react_app.md +3 -2
- package/docs/es/intlayer_with_express.md +2 -2
- package/docs/es/intlayer_with_nextjs_14.md +2 -2
- package/docs/es/intlayer_with_nextjs_15.md +2 -2
- package/docs/es/intlayer_with_react_native+expo.md +11 -20
- package/docs/es/intlayer_with_react_router_v7.md +188 -232
- package/docs/es/intlayer_with_tanstack.md +203 -273
- package/docs/es/intlayer_with_vite+preact.md +7 -7
- package/docs/es/intlayer_with_vite+react.md +7 -7
- package/docs/es/intlayer_with_vite+vue.md +9 -9
- package/docs/fr/intlayer_with_angular.md +2 -2
- package/docs/fr/intlayer_with_astro.md +246 -0
- package/docs/fr/intlayer_with_create_react_app.md +3 -2
- package/docs/fr/intlayer_with_express.md +2 -2
- package/docs/fr/intlayer_with_nestjs.md +2 -2
- package/docs/fr/intlayer_with_nextjs_14.md +2 -2
- package/docs/fr/intlayer_with_react_native+expo.md +11 -20
- package/docs/fr/intlayer_with_react_router_v7.md +188 -248
- package/docs/fr/intlayer_with_tanstack.md +192 -265
- package/docs/fr/intlayer_with_vite+preact.md +7 -7
- package/docs/fr/intlayer_with_vite+react.md +7 -7
- package/docs/fr/intlayer_with_vite+vue.md +9 -9
- package/docs/hi/intlayer_cli.md +1 -4
- package/docs/hi/intlayer_with_angular.md +2 -2
- package/docs/hi/intlayer_with_astro.md +246 -0
- package/docs/hi/intlayer_with_create_react_app.md +2 -2
- package/docs/hi/intlayer_with_express.md +2 -2
- package/docs/hi/intlayer_with_nestjs.md +2 -2
- package/docs/hi/intlayer_with_nextjs_14.md +2 -2
- package/docs/hi/intlayer_with_nextjs_15.md +2 -2
- package/docs/hi/intlayer_with_nextjs_page_router.md +2 -2
- package/docs/hi/intlayer_with_nuxt.md +2 -2
- package/docs/hi/intlayer_with_react_native+expo.md +11 -20
- package/docs/hi/intlayer_with_react_router_v7.md +199 -243
- package/docs/hi/intlayer_with_tanstack.md +210 -285
- package/docs/hi/intlayer_with_vite+preact.md +9 -9
- package/docs/hi/intlayer_with_vite+react.md +9 -9
- package/docs/hi/intlayer_with_vite+solid.md +1 -1
- package/docs/hi/intlayer_with_vite+vue.md +11 -11
- package/docs/it/intlayer_with_angular.md +2 -2
- package/docs/it/intlayer_with_astro.md +246 -0
- package/docs/it/intlayer_with_create_react_app.md +3 -2
- package/docs/it/intlayer_with_express.md +2 -2
- package/docs/it/intlayer_with_nestjs.md +2 -2
- package/docs/it/intlayer_with_nextjs_14.md +2 -2
- package/docs/it/intlayer_with_nextjs_15.md +2 -2
- package/docs/it/intlayer_with_nextjs_page_router.md +2 -2
- package/docs/it/intlayer_with_nuxt.md +2 -2
- package/docs/it/intlayer_with_react_native+expo.md +11 -21
- package/docs/it/intlayer_with_react_router_v7.md +195 -242
- package/docs/it/intlayer_with_tanstack.md +203 -267
- package/docs/it/intlayer_with_vite+preact.md +9 -9
- package/docs/it/intlayer_with_vite+react.md +13 -11
- package/docs/it/intlayer_with_vite+vue.md +11 -11
- package/docs/ja/intlayer_with_angular.md +2 -2
- package/docs/ja/intlayer_with_astro.md +246 -0
- package/docs/ja/intlayer_with_create_react_app.md +3 -2
- package/docs/ja/intlayer_with_express.md +2 -2
- package/docs/ja/intlayer_with_nestjs.md +2 -2
- package/docs/ja/intlayer_with_nextjs_14.md +2 -2
- package/docs/ja/intlayer_with_nextjs_15.md +2 -2
- package/docs/ja/intlayer_with_nextjs_page_router.md +2 -2
- package/docs/ja/intlayer_with_nuxt.md +2 -2
- package/docs/ja/intlayer_with_react_native+expo.md +18 -29
- package/docs/ja/intlayer_with_react_router_v7.md +204 -250
- package/docs/ja/intlayer_with_tanstack.md +218 -286
- package/docs/ja/intlayer_with_vite+preact.md +9 -9
- package/docs/ja/intlayer_with_vite+react.md +11 -11
- package/docs/ja/intlayer_with_vite+vue.md +11 -11
- package/docs/ko/intlayer_with_angular.md +2 -2
- package/docs/ko/intlayer_with_astro.md +246 -0
- package/docs/ko/intlayer_with_create_react_app.md +3 -2
- package/docs/ko/intlayer_with_express.md +2 -2
- package/docs/ko/intlayer_with_nestjs.md +2 -2
- package/docs/ko/intlayer_with_nextjs_14.md +2 -2
- package/docs/ko/intlayer_with_nextjs_15.md +2 -2
- package/docs/ko/intlayer_with_nextjs_page_router.md +2 -2
- package/docs/ko/intlayer_with_nuxt.md +2 -2
- package/docs/ko/intlayer_with_react_native+expo.md +19 -28
- package/docs/ko/intlayer_with_react_router_v7.md +190 -244
- package/docs/ko/intlayer_with_tanstack.md +200 -270
- package/docs/ko/intlayer_with_vite+preact.md +9 -9
- package/docs/ko/intlayer_with_vite+react.md +9 -9
- package/docs/ko/intlayer_with_vite+vue.md +11 -11
- package/docs/pt/intlayer_with_angular.md +2 -2
- package/docs/pt/intlayer_with_astro.md +246 -0
- package/docs/pt/intlayer_with_create_react_app.md +3 -2
- package/docs/pt/intlayer_with_express.md +2 -2
- package/docs/pt/intlayer_with_nestjs.md +2 -2
- package/docs/pt/intlayer_with_nextjs_14.md +2 -2
- package/docs/pt/intlayer_with_nextjs_15.md +2 -2
- package/docs/pt/intlayer_with_nextjs_page_router.md +2 -2
- package/docs/pt/intlayer_with_nuxt.md +2 -2
- package/docs/pt/intlayer_with_react_native+expo.md +11 -20
- package/docs/pt/intlayer_with_react_router_v7.md +7 -13
- package/docs/pt/intlayer_with_tanstack.md +183 -258
- package/docs/pt/intlayer_with_vite+preact.md +9 -9
- package/docs/pt/intlayer_with_vite+react.md +9 -9
- package/docs/pt/intlayer_with_vite+vue.md +9 -9
- package/docs/ru/intlayer_with_angular.md +2 -2
- package/docs/ru/intlayer_with_astro.md +246 -0
- package/docs/ru/intlayer_with_create_react_app.md +3 -2
- package/docs/ru/intlayer_with_express.md +2 -2
- package/docs/ru/intlayer_with_nestjs.md +2 -2
- package/docs/ru/intlayer_with_nextjs_14.md +2 -2
- package/docs/ru/intlayer_with_nextjs_15.md +2 -2
- package/docs/ru/intlayer_with_nextjs_page_router.md +2 -2
- package/docs/ru/intlayer_with_nuxt.md +2 -2
- package/docs/ru/intlayer_with_react_native+expo.md +11 -20
- package/docs/ru/intlayer_with_react_router_v7.md +192 -238
- package/docs/ru/intlayer_with_tanstack.md +197 -269
- package/docs/ru/intlayer_with_vite+preact.md +9 -9
- package/docs/ru/intlayer_with_vite+react.md +9 -9
- package/docs/ru/intlayer_with_vite+vue.md +11 -11
- package/docs/tr/how_works_intlayer.md +1 -1
- package/docs/tr/index.md +1 -1
- package/docs/tr/intlayer_cli.md +1 -1
- package/docs/tr/intlayer_with_angular.md +4 -4
- package/docs/tr/intlayer_with_astro.md +246 -0
- package/docs/tr/intlayer_with_create_react_app.md +4 -4
- package/docs/tr/intlayer_with_express.md +3 -3
- package/docs/tr/intlayer_with_lynx+react.md +1 -1
- package/docs/tr/intlayer_with_nestjs.md +2 -2
- package/docs/tr/intlayer_with_nextjs_14.md +2 -2
- package/docs/tr/intlayer_with_nextjs_15.md +4 -4
- package/docs/tr/intlayer_with_nextjs_page_router.md +5 -5
- package/docs/tr/intlayer_with_nuxt.md +4 -4
- package/docs/tr/intlayer_with_react_native+expo.md +12 -21
- package/docs/tr/intlayer_with_react_router_v7.md +222 -267
- package/docs/tr/intlayer_with_tanstack.md +400 -303
- package/docs/tr/intlayer_with_vite+preact.md +12 -12
- package/docs/tr/intlayer_with_vite+react.md +12 -12
- package/docs/tr/intlayer_with_vite+solid.md +2 -2
- package/docs/tr/intlayer_with_vite+svelte.md +2 -2
- package/docs/tr/intlayer_with_vite+vue.md +12 -12
- package/docs/tr/introduction.md +1 -1
- package/docs/tr/packages/react-intlayer/useDictionary.md +1 -1
- package/docs/tr/packages/react-intlayer/useI18n.md +1 -1
- package/docs/tr/roadmap.md +1 -1
- package/docs/zh/intlayer_with_angular.md +2 -2
- package/docs/zh/intlayer_with_astro.md +246 -0
- package/docs/zh/intlayer_with_create_react_app.md +3 -2
- package/docs/zh/intlayer_with_express.md +2 -2
- package/docs/zh/intlayer_with_nestjs.md +2 -2
- package/docs/zh/intlayer_with_nextjs_14.md +2 -2
- package/docs/zh/intlayer_with_nextjs_15.md +2 -2
- package/docs/zh/intlayer_with_nextjs_page_router.md +2 -2
- package/docs/zh/intlayer_with_nuxt.md +2 -2
- package/docs/zh/intlayer_with_react_native+expo.md +19 -28
- package/docs/zh/intlayer_with_react_router_v7.md +200 -248
- package/docs/zh/intlayer_with_tanstack.md +208 -283
- package/docs/zh/intlayer_with_vite+preact.md +9 -9
- package/docs/zh/intlayer_with_vite+react.md +9 -9
- package/docs/zh/intlayer_with_vite+vue.md +9 -9
- package/package.json +11 -11
- 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/
|
|
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/
|
|
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"
|
|
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"
|
|
95
|
+
```typescript fileName="vite.config.ts"
|
|
141
96
|
import { reactRouter } from "@react-router/dev/vite";
|
|
142
97
|
import { defineConfig } from "vite";
|
|
143
|
-
import {
|
|
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"
|
|
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={
|
|
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"
|
|
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/
|
|
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"
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
import { Link, type
|
|
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
|
|
246
|
-
} & Omit<
|
|
205
|
+
to?: To;
|
|
206
|
+
} & Omit<LinkComponentProps, "to">;
|
|
247
207
|
|
|
248
|
-
|
|
249
|
-
|
|
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
|
-
|
|
252
|
-
|
|
253
|
-
|
|
214
|
+
type RemoveLocaleFromString<S extends string> = CollapseDoubleSlashes<
|
|
215
|
+
RemoveAll<S, typeof LOCALE_ROUTE>
|
|
216
|
+
>;
|
|
254
217
|
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
: getLocalizedUrl(props.to, locale);
|
|
218
|
+
export const LocalizedLink: FC<LocalizedLinkProps> = (props) => {
|
|
219
|
+
const { locale } = useLocale();
|
|
258
220
|
|
|
259
|
-
return
|
|
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
|
-
|
|
234
|
+
This component has two objectives:
|
|
264
235
|
|
|
265
|
-
|
|
266
|
-
|
|
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
|
-
|
|
273
|
-
|
|
274
|
-
|
|
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
|
-
|
|
281
|
-
|
|
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
|
-
|
|
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({
|
|
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"
|
|
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
|
|
346
|
-
<div
|
|
320
|
+
<div>
|
|
321
|
+
<div>
|
|
347
322
|
{content.title}
|
|
348
323
|
<LocaleSwitcher />
|
|
349
|
-
<div
|
|
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
|
|
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"
|
|
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
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
const {
|
|
386
|
-
|
|
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
|
-
<
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
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
|
-
</
|
|
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"
|
|
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"
|
|
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
|
-
|
|
448
|
+
---
|
|
467
449
|
|
|
468
|
-
|
|
450
|
+
### Step 11: Add middleware (Optional)
|
|
469
451
|
|
|
470
|
-
|
|
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
|
-
|
|
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
|
-
```
|
|
479
|
-
|
|
480
|
-
|
|
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
|
-
|
|
483
|
-
|
|
463
|
+
export default defineConfig({
|
|
464
|
+
plugins: [
|
|
465
|
+
tailwindcss(),
|
|
466
|
+
reactRouter(),
|
|
467
|
+
tsconfigPaths(),
|
|
468
|
+
intlayer(),
|
|
469
|
+
intlayerMiddleware(),
|
|
470
|
+
],
|
|
471
|
+
});
|
|
484
472
|
```
|
|
485
473
|
|
|
486
|
-
|
|
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
|
-
|
|
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/
|
|
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 |
|