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