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