@intlayer/docs 7.5.11 → 7.5.12
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/ar/intlayer_with_i18next.md +0 -2
- package/blog/ar/intlayer_with_next-i18next.md +0 -2
- package/blog/ar/intlayer_with_react-i18next.md +0 -2
- package/blog/de/intlayer_with_i18next.md +0 -45
- package/blog/de/intlayer_with_next-i18next.md +0 -46
- package/blog/de/intlayer_with_react-i18next.md +0 -2
- package/blog/en/intlayer_with_i18next.md +0 -46
- package/blog/en/intlayer_with_next-i18next.md +0 -48
- package/blog/en/intlayer_with_next-intl.md +0 -44
- package/blog/en/intlayer_with_react-i18next.md +0 -44
- package/blog/en/intlayer_with_react-intl.md +0 -42
- package/blog/en/intlayer_with_vue-i18n.md +0 -44
- package/blog/en-GB/intlayer_with_i18next.md +0 -45
- package/blog/en-GB/intlayer_with_next-i18next.md +0 -47
- package/blog/en-GB/intlayer_with_next-intl.md +0 -42
- package/blog/en-GB/intlayer_with_react-i18next.md +0 -43
- package/blog/en-GB/intlayer_with_react-intl.md +0 -42
- package/blog/en-GB/intlayer_with_vue-i18n.md +0 -46
- package/blog/es/intlayer_with_i18next.md +0 -45
- package/blog/es/intlayer_with_next-i18next.md +0 -47
- package/blog/es/intlayer_with_next-intl.md +0 -42
- package/blog/es/intlayer_with_react-i18next.md +0 -43
- package/blog/es/intlayer_with_react-intl.md +0 -42
- package/blog/es/intlayer_with_vue-i18n.md +0 -46
- package/blog/fr/intlayer_with_i18next.md +0 -45
- package/blog/fr/intlayer_with_next-i18next.md +0 -47
- package/blog/fr/intlayer_with_next-intl.md +0 -42
- package/blog/fr/intlayer_with_react-i18next.md +0 -43
- package/blog/fr/intlayer_with_react-intl.md +0 -42
- package/blog/fr/intlayer_with_vue-i18n.md +0 -46
- package/blog/hi/intlayer_with_i18next.md +0 -2
- package/blog/hi/intlayer_with_next-i18next.md +0 -2
- package/blog/hi/intlayer_with_react-i18next.md +0 -2
- package/blog/id/intlayer_with_i18next.md +0 -2
- package/blog/id/intlayer_with_next-i18next.md +0 -2
- package/blog/id/intlayer_with_react-i18next.md +0 -2
- package/blog/it/intlayer_with_i18next.md +0 -2
- package/blog/it/intlayer_with_next-i18next.md +0 -2
- package/blog/it/intlayer_with_react-i18next.md +0 -2
- package/blog/ja/intlayer_with_i18next.md +0 -45
- package/blog/ja/intlayer_with_next-i18next.md +0 -46
- package/blog/ja/intlayer_with_next-intl.md +0 -42
- package/blog/ja/intlayer_with_react-i18next.md +0 -42
- package/blog/ja/intlayer_with_react-intl.md +0 -42
- package/blog/ja/intlayer_with_vue-i18n.md +0 -46
- package/blog/ko/intlayer_with_i18next.md +0 -2
- package/blog/ko/intlayer_with_next-i18next.md +0 -2
- package/blog/ko/intlayer_with_react-i18next.md +0 -1
- package/blog/pl/intlayer_with_i18next.md +0 -45
- package/blog/pl/intlayer_with_next-i18next.md +0 -46
- package/blog/pl/intlayer_with_next-intl.md +0 -42
- package/blog/pl/intlayer_with_react-i18next.md +0 -43
- package/blog/pl/intlayer_with_react-intl.md +0 -42
- package/blog/pl/intlayer_with_vue-i18n.md +0 -46
- package/blog/pt/intlayer_with_i18next.md +0 -2
- package/blog/pt/intlayer_with_next-i18next.md +0 -2
- package/blog/pt/intlayer_with_react-i18next.md +0 -2
- package/blog/ru/intlayer_with_i18next.md +0 -45
- package/blog/ru/intlayer_with_next-i18next.md +0 -47
- package/blog/ru/intlayer_with_next-intl.md +0 -42
- package/blog/ru/intlayer_with_react-i18next.md +0 -43
- package/blog/ru/intlayer_with_react-intl.md +0 -42
- package/blog/ru/intlayer_with_vue-i18n.md +0 -46
- package/blog/tr/intlayer_with_i18next.md +0 -2
- package/blog/tr/intlayer_with_next-i18next.md +0 -1
- package/blog/tr/intlayer_with_react-i18next.md +0 -2
- package/blog/vi/intlayer_with_i18next.md +0 -2
- package/blog/vi/intlayer_with_next-i18next.md +0 -2
- package/blog/vi/intlayer_with_react-i18next.md +0 -2
- package/blog/zh/intlayer_with_i18next.md +0 -2
- package/blog/zh/intlayer_with_next-i18next.md +0 -2
- package/blog/zh/intlayer_with_react-i18next.md +0 -2
- package/blog/zh/intlayer_with_vue-i18n.md +0 -46
- package/dist/cjs/generated/blog.entry.cjs +58 -29
- package/dist/cjs/generated/blog.entry.cjs.map +1 -1
- package/dist/cjs/generated/docs.entry.cjs +218 -99
- package/dist/cjs/generated/docs.entry.cjs.map +1 -1
- package/dist/cjs/generated/frequentQuestions.entry.cjs +30 -15
- package/dist/cjs/generated/frequentQuestions.entry.cjs.map +1 -1
- package/dist/cjs/generated/legal.entry.cjs +4 -2
- package/dist/cjs/generated/legal.entry.cjs.map +1 -1
- package/dist/esm/generated/blog.entry.mjs +58 -29
- package/dist/esm/generated/blog.entry.mjs.map +1 -1
- package/dist/esm/generated/docs.entry.mjs +218 -99
- package/dist/esm/generated/docs.entry.mjs.map +1 -1
- package/dist/esm/generated/frequentQuestions.entry.mjs +30 -15
- package/dist/esm/generated/frequentQuestions.entry.mjs.map +1 -1
- package/dist/esm/generated/legal.entry.mjs +4 -2
- package/dist/esm/generated/legal.entry.mjs.map +1 -1
- package/dist/types/generated/blog.entry.d.ts.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/dist/types/generated/frequentQuestions.entry.d.ts.map +1 -1
- package/dist/types/generated/legal.entry.d.ts.map +1 -1
- package/docs/ar/intlayer_with_next-i18next.md +0 -1
- package/docs/ar/intlayer_with_nextjs_14.md +28 -0
- package/docs/ar/intlayer_with_nextjs_15.md +28 -0
- package/docs/ar/intlayer_with_nextjs_16.md +28 -0
- package/docs/ar/intlayer_with_nextjs_no_locale_path.md +1159 -0
- package/docs/ar/plugins/sync-json.md +6 -2
- package/docs/de/intlayer_with_next-i18next.md +0 -1
- package/docs/de/intlayer_with_nextjs_14.md +28 -0
- package/docs/de/intlayer_with_nextjs_15.md +28 -0
- package/docs/de/intlayer_with_nextjs_16.md +28 -0
- package/docs/de/intlayer_with_nextjs_no_locale_path.md +1152 -0
- package/docs/de/plugins/sync-json.md +6 -2
- package/docs/en/intlayer_with_next-i18next.md +0 -1
- package/docs/en/intlayer_with_nextjs_14.md +28 -0
- package/docs/en/intlayer_with_nextjs_15.md +28 -0
- package/docs/en/intlayer_with_nextjs_16.md +31 -1
- package/docs/en/intlayer_with_nextjs_no_locale_path.md +1132 -0
- package/docs/en/plugins/sync-json.md +6 -2
- package/docs/en-GB/intlayer_with_next-i18next.md +0 -1
- package/docs/en-GB/intlayer_with_nextjs_14.md +28 -0
- package/docs/en-GB/intlayer_with_nextjs_15.md +28 -0
- package/docs/en-GB/intlayer_with_nextjs_16.md +28 -0
- package/docs/en-GB/intlayer_with_nextjs_no_locale_path.md +1154 -0
- package/docs/en-GB/plugins/sync-json.md +6 -2
- package/docs/es/intlayer_with_next-i18next.md +0 -1
- package/docs/es/intlayer_with_nextjs_14.md +28 -0
- package/docs/es/intlayer_with_nextjs_15.md +28 -0
- package/docs/es/intlayer_with_nextjs_16.md +28 -0
- package/docs/es/intlayer_with_nextjs_no_locale_path.md +1143 -0
- package/docs/es/plugins/sync-json.md +6 -2
- package/docs/fr/intlayer_with_next-i18next.md +0 -1
- package/docs/fr/intlayer_with_nextjs_14.md +28 -0
- package/docs/fr/intlayer_with_nextjs_15.md +28 -0
- package/docs/fr/intlayer_with_nextjs_16.md +28 -0
- package/docs/fr/intlayer_with_nextjs_no_locale_path.md +1174 -0
- package/docs/fr/plugins/sync-json.md +9 -5
- package/docs/hi/intlayer_with_next-i18next.md +0 -1
- package/docs/hi/intlayer_with_nextjs_14.md +28 -0
- package/docs/hi/intlayer_with_nextjs_15.md +28 -0
- package/docs/hi/intlayer_with_nextjs_16.md +28 -0
- package/docs/hi/intlayer_with_nextjs_no_locale_path.md +1151 -0
- package/docs/hi/plugins/sync-json.md +6 -2
- package/docs/id/intlayer_with_next-i18next.md +0 -1
- package/docs/id/intlayer_with_nextjs_14.md +28 -0
- package/docs/id/intlayer_with_nextjs_15.md +28 -0
- package/docs/id/intlayer_with_nextjs_16.md +28 -0
- package/docs/id/intlayer_with_nextjs_no_locale_path.md +1154 -0
- package/docs/id/plugins/sync-json.md +6 -2
- package/docs/it/intlayer_with_next-i18next.md +0 -1
- package/docs/it/intlayer_with_nextjs_14.md +28 -0
- package/docs/it/intlayer_with_nextjs_15.md +28 -0
- package/docs/it/intlayer_with_nextjs_16.md +28 -0
- package/docs/it/intlayer_with_nextjs_no_locale_path.md +1148 -0
- package/docs/it/plugins/sync-json.md +6 -2
- package/docs/ja/intlayer_with_next-i18next.md +0 -1
- package/docs/ja/intlayer_with_nextjs_14.md +28 -0
- package/docs/ja/intlayer_with_nextjs_15.md +28 -0
- package/docs/ja/intlayer_with_nextjs_16.md +28 -0
- package/docs/ja/intlayer_with_nextjs_no_locale_path.md +1222 -0
- package/docs/ja/plugins/sync-json.md +6 -2
- package/docs/ko/intlayer_with_next-i18next.md +0 -1
- package/docs/ko/intlayer_with_nextjs_14.md +28 -0
- package/docs/ko/intlayer_with_nextjs_15.md +28 -0
- package/docs/ko/intlayer_with_nextjs_16.md +28 -0
- package/docs/ko/intlayer_with_nextjs_no_locale_path.md +1205 -0
- package/docs/ko/plugins/sync-json.md +6 -2
- package/docs/pl/intlayer_with_next-i18next.md +0 -1
- package/docs/pl/intlayer_with_nextjs_14.md +28 -0
- package/docs/pl/intlayer_with_nextjs_15.md +28 -0
- package/docs/pl/intlayer_with_nextjs_16.md +28 -0
- package/docs/pl/intlayer_with_nextjs_no_locale_path.md +1149 -0
- package/docs/pl/plugins/sync-json.md +6 -2
- package/docs/pt/intlayer_with_next-i18next.md +0 -1
- package/docs/pt/intlayer_with_nextjs_14.md +28 -0
- package/docs/pt/intlayer_with_nextjs_15.md +28 -0
- package/docs/pt/intlayer_with_nextjs_16.md +28 -0
- package/docs/pt/intlayer_with_nextjs_no_locale_path.md +1152 -0
- package/docs/pt/plugins/sync-json.md +6 -2
- package/docs/ru/intlayer_with_next-i18next.md +0 -1
- package/docs/ru/intlayer_with_nextjs_14.md +28 -0
- package/docs/ru/intlayer_with_nextjs_15.md +28 -0
- package/docs/ru/intlayer_with_nextjs_16.md +28 -0
- package/docs/ru/intlayer_with_nextjs_no_locale_path.md +1204 -0
- package/docs/ru/plugins/sync-json.md +6 -2
- package/docs/tr/intlayer_with_next-i18next.md +0 -1
- package/docs/tr/intlayer_with_nextjs_14.md +28 -0
- package/docs/tr/intlayer_with_nextjs_15.md +28 -0
- package/docs/tr/intlayer_with_nextjs_16.md +28 -0
- package/docs/tr/intlayer_with_nextjs_no_locale_path.md +1159 -0
- package/docs/tr/plugins/sync-json.md +6 -2
- package/docs/uk/compiler.md +133 -0
- package/docs/uk/component_i18n.md +194 -0
- package/docs/uk/intlayer_with_nextjs_14.md +1646 -0
- package/docs/uk/intlayer_with_nextjs_15.md +1910 -0
- package/docs/uk/intlayer_with_nextjs_16.md +1763 -0
- package/docs/uk/intlayer_with_nextjs_no_locale_path.md +1159 -0
- package/docs/uk/intlayer_with_react_native+expo.md +715 -0
- package/docs/uk/packages/intlayer/getConfiguration.md +145 -0
- package/docs/uk/vs_code_extension.md +133 -0
- package/docs/vi/intlayer_with_next-i18next.md +0 -1
- package/docs/vi/intlayer_with_nextjs_14.md +28 -0
- package/docs/vi/intlayer_with_nextjs_15.md +28 -0
- package/docs/vi/intlayer_with_nextjs_16.md +28 -0
- package/docs/vi/intlayer_with_nextjs_no_locale_path.md +1151 -0
- package/docs/vi/plugins/sync-json.md +6 -2
- package/docs/zh/intlayer_with_next-i18next.md +0 -1
- package/docs/zh/intlayer_with_nextjs_14.md +28 -0
- package/docs/zh/intlayer_with_nextjs_15.md +28 -0
- package/docs/zh/intlayer_with_nextjs_16.md +28 -0
- package/docs/zh/intlayer_with_nextjs_no_locale_path.md +1206 -0
- package/docs/zh/plugins/sync-json.md +9 -5
- package/frequent_questions/ar/SSR_Next_no_[locale].md +1 -1
- package/frequent_questions/de/SSR_Next_no_[locale].md +1 -1
- package/frequent_questions/en/SSR_Next_no_[locale].md +1 -1
- package/frequent_questions/en-GB/SSR_Next_no_[locale].md +1 -1
- package/frequent_questions/es/SSR_Next_no_[locale].md +1 -1
- package/frequent_questions/fr/SSR_Next_no_[locale].md +1 -1
- package/frequent_questions/hi/SSR_Next_no_[locale].md +1 -1
- package/frequent_questions/id/SSR_Next_no_[locale].md +1 -1
- package/frequent_questions/it/SSR_Next_no_[locale].md +1 -1
- package/frequent_questions/ja/SSR_Next_no_[locale].md +1 -1
- package/frequent_questions/ko/SSR_Next_no_[locale].md +1 -1
- package/frequent_questions/pl/SSR_Next_no_[locale].md +1 -1
- package/frequent_questions/pt/SSR_Next_no_[locale].md +1 -1
- package/frequent_questions/ru/SSR_Next_no_[locale].md +1 -1
- package/frequent_questions/tr/SSR_Next_no_[locale].md +1 -1
- package/frequent_questions/vi/SSR_Next_no_[locale].md +1 -1
- package/frequent_questions/zh/SSR_Next_no_[locale].md +1 -1
- package/package.json +6 -6
- package/src/generated/blog.entry.ts +29 -0
- package/src/generated/docs.entry.ts +119 -0
- package/src/generated/frequentQuestions.entry.ts +15 -0
- package/src/generated/legal.entry.ts +2 -0
|
@@ -0,0 +1,1132 @@
|
|
|
1
|
+
---
|
|
2
|
+
createdAt: 2026-01-10
|
|
3
|
+
updatedAt: 2026-01-10
|
|
4
|
+
title: How to translate your Next.js 16 app (without [locale] in the page path) – i18n guide 2026
|
|
5
|
+
description: Discover how to make your Next.js 16 website multilingual without [locale] in the page path. Follow the documentation to internationalize (i18n) and translate it.
|
|
6
|
+
keywords:
|
|
7
|
+
- Internationalization
|
|
8
|
+
- Documentation
|
|
9
|
+
- Intlayer
|
|
10
|
+
- Next.js 16
|
|
11
|
+
- JavaScript
|
|
12
|
+
- React
|
|
13
|
+
slugs:
|
|
14
|
+
- doc
|
|
15
|
+
- environment
|
|
16
|
+
- nextjs
|
|
17
|
+
- no-locale-path
|
|
18
|
+
applicationTemplate: https://github.com/aymericzip/intlayer-next-no-lolale-path-template
|
|
19
|
+
youtubeVideo: https://www.youtube.com/watch?v=e_PPG7PTqGU
|
|
20
|
+
history:
|
|
21
|
+
- version: 1.0.0
|
|
22
|
+
date: 2026-01-10
|
|
23
|
+
changes: Initial release
|
|
24
|
+
---
|
|
25
|
+
|
|
26
|
+
# Translate your Next.js 16 website (without [locale] in the page path) using Intlayer | Internationalization (i18n)
|
|
27
|
+
|
|
28
|
+
<Tab defaultTab="video">
|
|
29
|
+
<TabItem label="Video" value="video">
|
|
30
|
+
|
|
31
|
+
<iframe title="The best i18n solution for Next.js? Discover Intlayer" class="m-auto aspect-16/9 w-full overflow-hidden rounded-lg border-0" allow="autoplay; gyroscope;" loading="lazy" width="1080" height="auto" src="https://www.youtube.com/embed/e_PPG7PTqGU?autoplay=0&origin=http://intlayer.org&controls=0&rel=1"/>
|
|
32
|
+
|
|
33
|
+
</TabItem>
|
|
34
|
+
<TabItem label="Code" value="code">
|
|
35
|
+
|
|
36
|
+
<iframe
|
|
37
|
+
src="https://stackblitz.com/github/aymericzip/intlayer-next-16-no-locale-path-template?embed=1&ctl=1&file=intlayer.config.ts"
|
|
38
|
+
className="m-auto overflow-hidden rounded-lg border-0 max-md:size-full max-md:h-[700px] md:aspect-16/9 md:w-full"
|
|
39
|
+
title="Demo CodeSandbox - How to Internationalize your application using Intlayer"
|
|
40
|
+
sandbox="allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts"
|
|
41
|
+
loading="lazy"
|
|
42
|
+
/>
|
|
43
|
+
|
|
44
|
+
</TabItem>
|
|
45
|
+
</Tab>
|
|
46
|
+
|
|
47
|
+
See [Application Template](https://github.com/aymericzip/intlayer-next-no-lolale-path-template) on GitHub.
|
|
48
|
+
|
|
49
|
+
## Table of Contents
|
|
50
|
+
|
|
51
|
+
<TOC/>
|
|
52
|
+
|
|
53
|
+
## What is Intlayer?
|
|
54
|
+
|
|
55
|
+
**Intlayer** is an innovative, open-source internationalization (i18n) library designed to simplify multilingual support in modern web applications. Intlayer seamlessly integrates with the latest **Next.js 16** framework, including its powerful **App Router**. It is optimized to work with **Server Components** for efficient rendering and is fully compatible with [**Turbopack**](https://nextjs.org/docs/architecture/turbopack).
|
|
56
|
+
|
|
57
|
+
With Intlayer, you can:
|
|
58
|
+
|
|
59
|
+
- **Easily manage translations** using declarative dictionaries at the component level.
|
|
60
|
+
- **Dynamically localize metadata**, routes, and content.
|
|
61
|
+
- **Access translations in both client-side and server-side components**.
|
|
62
|
+
- **Ensure TypeScript support** with autogenerated types, improving autocompletion and error detection.
|
|
63
|
+
- **Benefit from advanced features**, like dynamic locale detection and switching.
|
|
64
|
+
|
|
65
|
+
> Intlayer is compatible with Next.js 12, 13, 14, and 16. If you are using Next.js Page Router, you can refer to this [guide](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/intlayer_with_nextjs_page_router.md). For Next.js 12, 13, 14 with App Router, refer to this [guide](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/intlayer_with_nextjs_14.md).
|
|
66
|
+
|
|
67
|
+
---
|
|
68
|
+
|
|
69
|
+
## Step-by-Step Guide to Set Up Intlayer in a Next.js Application
|
|
70
|
+
|
|
71
|
+
### Step 1: Install Dependencies
|
|
72
|
+
|
|
73
|
+
Install the necessary packages using npm:
|
|
74
|
+
|
|
75
|
+
```bash packageManager="npm"
|
|
76
|
+
npm install intlayer next-intlayer
|
|
77
|
+
npx intlayer init
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
```bash packageManager="pnpm"
|
|
81
|
+
pnpm add intlayer next-intlayer
|
|
82
|
+
pnpm intlayer init
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
```bash packageManager="yarn"
|
|
86
|
+
yarn add intlayer next-intlayer
|
|
87
|
+
yarn intlayer init
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
```bash packageManager="bun"
|
|
91
|
+
bun add intlayer next-intlayer
|
|
92
|
+
bunx intlayer init
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
- **intlayer**
|
|
96
|
+
|
|
97
|
+
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/cli/index.md).
|
|
98
|
+
|
|
99
|
+
- **next-intlayer**
|
|
100
|
+
|
|
101
|
+
The package that integrates Intlayer with Next.js. It provides context providers and hooks for Next.js internationalization. Additionally, it includes the Next.js plugin for integrating Intlayer with [Webpack](https://webpack.js.org/) or [Turbopack](https://nextjs.org/docs/app/api-reference/turbopack), as well as proxy for detecting the user's preferred locale, managing cookies, and handling URL redirection.
|
|
102
|
+
|
|
103
|
+
### Step 2: Configure Your Project
|
|
104
|
+
|
|
105
|
+
Here is the final structure that we will make:
|
|
106
|
+
|
|
107
|
+
```bash
|
|
108
|
+
.
|
|
109
|
+
├── src
|
|
110
|
+
│ ├── app
|
|
111
|
+
│ │ ├── layout.tsx
|
|
112
|
+
│ │ ├── page.content.ts
|
|
113
|
+
│ │ └── page.tsx
|
|
114
|
+
│ ├── components
|
|
115
|
+
│ │ ├── clientComponentExample
|
|
116
|
+
│ │ │ ├── client-component-example.content.ts
|
|
117
|
+
│ │ │ └── ClientComponentExample.tsx
|
|
118
|
+
│ │ ├── localeSwitcher
|
|
119
|
+
│ │ │ ├── localeSwitcher.content.ts
|
|
120
|
+
│ │ │ └── LocaleSwitcher.tsx
|
|
121
|
+
│ │ └── serverComponentExample
|
|
122
|
+
│ │ ├── server-component-example.content.ts
|
|
123
|
+
│ │ └── ServerComponentExample.tsx
|
|
124
|
+
│ └── proxy.ts
|
|
125
|
+
├── intlayer.config.ts
|
|
126
|
+
├── next.config.ts
|
|
127
|
+
├── package.json
|
|
128
|
+
└── tsconfig.json
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
> If you don't want locale routing, intlayer can be used as a simple provider / hook. See [this guide](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/intlayer_with_nextjs_no_locale_path.md) for more details.
|
|
132
|
+
|
|
133
|
+
Create a config file to configure the languages of your application:
|
|
134
|
+
|
|
135
|
+
```typescript fileName="intlayer.config.ts" codeFormat="typescript"
|
|
136
|
+
import { Locales, type IntlayerConfig } from "intlayer";
|
|
137
|
+
|
|
138
|
+
const config: IntlayerConfig = {
|
|
139
|
+
internationalization: {
|
|
140
|
+
locales: [
|
|
141
|
+
Locales.ENGLISH,
|
|
142
|
+
Locales.FRENCH,
|
|
143
|
+
Locales.SPANISH,
|
|
144
|
+
// Your other locales
|
|
145
|
+
],
|
|
146
|
+
defaultLocale: Locales.ENGLISH,
|
|
147
|
+
},
|
|
148
|
+
routing: {
|
|
149
|
+
mode: "search-params", // or `no-prefix` - Useful for middleware detection
|
|
150
|
+
},
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
export default config;
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
```javascript fileName="intlayer.config.mjs" codeFormat="esm"
|
|
157
|
+
import { Locales } from "intlayer";
|
|
158
|
+
|
|
159
|
+
/** @type {import('intlayer').IntlayerConfig} */
|
|
160
|
+
const config = {
|
|
161
|
+
internationalization: {
|
|
162
|
+
locales: [
|
|
163
|
+
Locales.ENGLISH,
|
|
164
|
+
Locales.FRENCH,
|
|
165
|
+
Locales.SPANISH,
|
|
166
|
+
// Your other locales
|
|
167
|
+
],
|
|
168
|
+
defaultLocale: Locales.ENGLISH,
|
|
169
|
+
},
|
|
170
|
+
routing: {
|
|
171
|
+
mode: "search-params", // or `no-prefix` - Useful for middleware detection
|
|
172
|
+
},
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
export default config;
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
```javascript fileName="intlayer.config.cjs" codeFormat="commonjs"
|
|
179
|
+
const { Locales } = require("intlayer");
|
|
180
|
+
|
|
181
|
+
/** @type {import('intlayer').IntlayerConfig} */
|
|
182
|
+
const config = {
|
|
183
|
+
internationalization: {
|
|
184
|
+
locales: [
|
|
185
|
+
Locales.ENGLISH,
|
|
186
|
+
Locales.FRENCH,
|
|
187
|
+
Locales.SPANISH,
|
|
188
|
+
// Your other locales
|
|
189
|
+
],
|
|
190
|
+
defaultLocale: Locales.ENGLISH,
|
|
191
|
+
},
|
|
192
|
+
routing: {
|
|
193
|
+
mode: "search-params", // or `no-prefix` - Useful for middleware detection
|
|
194
|
+
},
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
module.exports = config;
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
> Through this configuration file, you can set up localized URLs, proxy 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).
|
|
201
|
+
|
|
202
|
+
### Step 3: Integrate Intlayer in Your Next.js Configuration
|
|
203
|
+
|
|
204
|
+
Configure your Next.js setup to use Intlayer:
|
|
205
|
+
|
|
206
|
+
```typescript fileName="next.config.ts" codeFormat="typescript"
|
|
207
|
+
import type { NextConfig } from "next";
|
|
208
|
+
import { withIntlayer } from "next-intlayer/server";
|
|
209
|
+
|
|
210
|
+
const nextConfig: NextConfig = {
|
|
211
|
+
/* config options here */
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
export default withIntlayer(nextConfig);
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
```typescript fileName="next.config.mjs" codeFormat="esm"
|
|
218
|
+
import { withIntlayer } from "next-intlayer/server";
|
|
219
|
+
|
|
220
|
+
/** @type {import('next').NextConfig} */
|
|
221
|
+
const nextConfig = {
|
|
222
|
+
/* config options here */
|
|
223
|
+
};
|
|
224
|
+
|
|
225
|
+
export default withIntlayer(nextConfig);
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
```typescript fileName="next.config.cjs" codeFormat="commonjs"
|
|
229
|
+
const { withIntlayer } = require("next-intlayer/server");
|
|
230
|
+
|
|
231
|
+
/** @type {import('next').NextConfig} */
|
|
232
|
+
const nextConfig = {
|
|
233
|
+
/* config options here */
|
|
234
|
+
};
|
|
235
|
+
|
|
236
|
+
module.exports = withIntlayer(nextConfig);
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
> The `withIntlayer()` Next.js plugin is used to integrate Intlayer with Next.js. It ensures the building of content declaration files and monitors them in development mode. It defines Intlayer environment variables within the [Webpack](https://webpack.js.org/) or [Turbopack](https://nextjs.org/docs/app/api-reference/turbopack) environments. Additionally, it provides aliases to optimize performance and ensures compatibility with server components.
|
|
240
|
+
|
|
241
|
+
> The `withIntlayer()` function is a promise function. It allows to prepare the intlayer dictionaries before the build starts. If you want to use it with other plugins, you can await it. Example:
|
|
242
|
+
>
|
|
243
|
+
> ```ts
|
|
244
|
+
> const nextConfig = await withIntlayer(nextConfig);
|
|
245
|
+
> const nextConfigWithOtherPlugins = withOtherPlugins(nextConfig);
|
|
246
|
+
>
|
|
247
|
+
> export default nextConfigWithOtherPlugins;
|
|
248
|
+
> ```
|
|
249
|
+
>
|
|
250
|
+
> If you want to use it synchronously, you can use the `withIntlayerSync()` function. Example:
|
|
251
|
+
>
|
|
252
|
+
> ```ts
|
|
253
|
+
> const nextConfig = withIntlayerSync(nextConfig);
|
|
254
|
+
> const nextConfigWithOtherPlugins = withOtherPlugins(nextConfig);
|
|
255
|
+
>
|
|
256
|
+
> export default nextConfigWithOtherPlugins;
|
|
257
|
+
> ```
|
|
258
|
+
|
|
259
|
+
> Intlayer automatically detects whether your project is using **webpack** or **Turbopack** based on the command-line flags `--webpack`, `--turbo`, or `--turbopack`, as well as your current **Next.js version**.
|
|
260
|
+
>
|
|
261
|
+
> Since `next>=16`, if you are using **Rspack**, you must explicitly force Intlayer to use the webpack configuration by disabling Turbopack:
|
|
262
|
+
>
|
|
263
|
+
> ```ts
|
|
264
|
+
> withRspack(withIntlayer(nextConfig, { enableTurbopack: false }));
|
|
265
|
+
> ```
|
|
266
|
+
|
|
267
|
+
### Step 4: Define Dynamic Locale Routes
|
|
268
|
+
|
|
269
|
+
Remove everything from `RootLayout` and replace it with the following code:
|
|
270
|
+
|
|
271
|
+
```tsx {3} fileName="src/app/layout.tsx" codeFormat="typescript"
|
|
272
|
+
import type { Metadata } from "next";
|
|
273
|
+
import type { ReactNode } from "react";
|
|
274
|
+
import "./globals.css";
|
|
275
|
+
import { IntlayerClientProvider, LocalPromiseParams } from "next-intlayer";
|
|
276
|
+
import { getHTMLTextDir, getIntlayer } from "intlayer";
|
|
277
|
+
import { getLocale } from "next-intlayer/server";
|
|
278
|
+
export { generateStaticParams } from "next-intlayer";
|
|
279
|
+
|
|
280
|
+
export const generateMetadata = async ({
|
|
281
|
+
params,
|
|
282
|
+
}: LocalPromiseParams): Promise<Metadata> => {
|
|
283
|
+
const { locale } = await params;
|
|
284
|
+
const { title, description, keywords } = getIntlayer("metadata", locale);
|
|
285
|
+
|
|
286
|
+
return {
|
|
287
|
+
title,
|
|
288
|
+
description,
|
|
289
|
+
keywords,
|
|
290
|
+
};
|
|
291
|
+
};
|
|
292
|
+
|
|
293
|
+
const RootLayout = async ({
|
|
294
|
+
children,
|
|
295
|
+
}: Readonly<{
|
|
296
|
+
children: ReactNode;
|
|
297
|
+
}>) => {
|
|
298
|
+
const locale = await getLocale();
|
|
299
|
+
|
|
300
|
+
return (
|
|
301
|
+
<html lang={locale} dir={getHTMLTextDir(locale)}>
|
|
302
|
+
<IntlayerClientProvider defaultLocale={locale}>
|
|
303
|
+
<body>{children}</body>
|
|
304
|
+
</IntlayerClientProvider>
|
|
305
|
+
</html>
|
|
306
|
+
);
|
|
307
|
+
};
|
|
308
|
+
|
|
309
|
+
export default RootLayout;
|
|
310
|
+
```
|
|
311
|
+
|
|
312
|
+
```jsx {3} fileName="src/app/layout.mjx" codeFormat="esm"
|
|
313
|
+
import "./globals.css";
|
|
314
|
+
import { IntlayerClientProvider } from "next-intlayer";
|
|
315
|
+
import { getHTMLTextDir, getIntlayer } from "intlayer";
|
|
316
|
+
import { getLocale } from "next-intlayer/server";
|
|
317
|
+
export { generateStaticParams } from "next-intlayer";
|
|
318
|
+
|
|
319
|
+
export const generateMetadata = async ({ params }) => {
|
|
320
|
+
const { locale } = await params;
|
|
321
|
+
const { title, description, keywords } = getIntlayer("metadata", locale);
|
|
322
|
+
|
|
323
|
+
return {
|
|
324
|
+
title,
|
|
325
|
+
description,
|
|
326
|
+
keywords,
|
|
327
|
+
};
|
|
328
|
+
};
|
|
329
|
+
|
|
330
|
+
const RootLayout = async ({ children }) => {
|
|
331
|
+
const locale = await getLocale();
|
|
332
|
+
|
|
333
|
+
return (
|
|
334
|
+
<html lang={locale} dir={getHTMLTextDir(locale)}>
|
|
335
|
+
<IntlayerClientProvider defaultLocale={locale}>
|
|
336
|
+
<body>{children}</body>
|
|
337
|
+
</IntlayerClientProvider>
|
|
338
|
+
</html>
|
|
339
|
+
);
|
|
340
|
+
};
|
|
341
|
+
|
|
342
|
+
export default RootLayout;
|
|
343
|
+
```
|
|
344
|
+
|
|
345
|
+
```jsx {1,8} fileName="src/app/layout.csx" codeFormat="commonjs"
|
|
346
|
+
require("./globals.css");
|
|
347
|
+
const { IntlayerClientProvider } = require("next-intlayer");
|
|
348
|
+
const { getHTMLTextDir, getIntlayer } = require("intlayer");
|
|
349
|
+
const { getLocale } = require("next-intlayer/server");
|
|
350
|
+
const { generateStaticParams } = require("next-intlayer");
|
|
351
|
+
|
|
352
|
+
const generateMetadata = async ({ params }) => {
|
|
353
|
+
const { locale } = await params;
|
|
354
|
+
const { title, description, keywords } = getIntlayer("metadata", locale);
|
|
355
|
+
|
|
356
|
+
return {
|
|
357
|
+
title,
|
|
358
|
+
description,
|
|
359
|
+
keywords,
|
|
360
|
+
};
|
|
361
|
+
};
|
|
362
|
+
|
|
363
|
+
const RootLayout = async ({ children }) => {
|
|
364
|
+
const locale = await getLocale();
|
|
365
|
+
|
|
366
|
+
return (
|
|
367
|
+
<html lang={locale} dir={getHTMLTextDir(locale)}>
|
|
368
|
+
<IntlayerClientProvider defaultLocale={locale}>
|
|
369
|
+
<body>{children}</body>
|
|
370
|
+
</IntlayerClientProvider>
|
|
371
|
+
</html>
|
|
372
|
+
);
|
|
373
|
+
};
|
|
374
|
+
|
|
375
|
+
module.exports = {
|
|
376
|
+
default: RootLayout,
|
|
377
|
+
generateStaticParams,
|
|
378
|
+
generateMetadata,
|
|
379
|
+
};
|
|
380
|
+
```
|
|
381
|
+
|
|
382
|
+
### Step 5: Declare Your Content
|
|
383
|
+
|
|
384
|
+
Create and manage your content declarations to store translations:
|
|
385
|
+
|
|
386
|
+
```tsx fileName="src/app/metadata.content.ts" contentDeclarationFormat="typescript"
|
|
387
|
+
import { t, type Dictionary } from "intlayer";
|
|
388
|
+
import { Metadata } from "next";
|
|
389
|
+
|
|
390
|
+
const metadataContent = {
|
|
391
|
+
key: "metadata",
|
|
392
|
+
content: {
|
|
393
|
+
title: t({
|
|
394
|
+
en: "My Project Title",
|
|
395
|
+
fr: "Le Titre de mon Projet",
|
|
396
|
+
es: "El Título de mi Proyecto",
|
|
397
|
+
}),
|
|
398
|
+
|
|
399
|
+
description: t({
|
|
400
|
+
en: "Discover our innovative platform designed to streamline your workflow and boost productivity.",
|
|
401
|
+
fr: "Découvrez notre plateforme innovante conçue pour simplifier votre flux de travail et booster votre productivité.",
|
|
402
|
+
es: "Descubra nuestra plataforma innovadora diseñada para simplificar su flujo de trabajo y aumentar su productividad.",
|
|
403
|
+
}),
|
|
404
|
+
|
|
405
|
+
keywords: t({
|
|
406
|
+
en: ["innovation", "productivity", "workflow", "SaaS"],
|
|
407
|
+
fr: ["innovation", "productivité", "flux de travail", "SaaS"],
|
|
408
|
+
es: ["innovación", "productividad", "flujo de trabajo", "SaaS"],
|
|
409
|
+
}),
|
|
410
|
+
},
|
|
411
|
+
} as Dictionary<Metadata>;
|
|
412
|
+
|
|
413
|
+
export default metadataContent;
|
|
414
|
+
```
|
|
415
|
+
|
|
416
|
+
```tsx fileName="src/app/metadata.content.mjs" contentDeclarationFormat="typescript"
|
|
417
|
+
import { t, type Dictionary } from "intlayer";
|
|
418
|
+
|
|
419
|
+
/** @type {import('intlayer').Dictionary<import('next').Metadata>} */
|
|
420
|
+
const metadataContent = {
|
|
421
|
+
key: "metadata",
|
|
422
|
+
content: {
|
|
423
|
+
title: t({
|
|
424
|
+
en: "My Project Title",
|
|
425
|
+
fr: "Le Titre de mon Projet",
|
|
426
|
+
es: "El Título de mi Proyecto",
|
|
427
|
+
}),
|
|
428
|
+
|
|
429
|
+
description: t({
|
|
430
|
+
en: "Discover our innovative platform designed to streamline your workflow and boost productivity.",
|
|
431
|
+
fr: "Découvrez notre plateforme innovante conçue pour simplifier votre flux de travail et booster votre productivité.",
|
|
432
|
+
es: "Descubra nuestra plataforma innovadora diseñada para simplificar su flujo de trabajo y aumentar su productividad.",
|
|
433
|
+
}),
|
|
434
|
+
|
|
435
|
+
keywords: t({
|
|
436
|
+
en: ["innovation", "productivity", "workflow", "SaaS"],
|
|
437
|
+
fr: ["innovation", "productivité", "flux de travail", "SaaS"],
|
|
438
|
+
es: ["innovación", "productividad", "flujo de trabajo", "SaaS"],
|
|
439
|
+
}),
|
|
440
|
+
},
|
|
441
|
+
};
|
|
442
|
+
|
|
443
|
+
export default metadataContent;
|
|
444
|
+
```
|
|
445
|
+
|
|
446
|
+
```javascript fileName="src/app/metadata.content.cjs" contentDeclarationFormat="commonjs"
|
|
447
|
+
const { t } = require("intlayer");
|
|
448
|
+
|
|
449
|
+
/** @type {import('intlayer').Dictionary<import('next').Metadata>} */
|
|
450
|
+
const metadataContent = {
|
|
451
|
+
key: "metadata",
|
|
452
|
+
content: {
|
|
453
|
+
title: t({
|
|
454
|
+
en: "My Project Title",
|
|
455
|
+
fr: "Le Titre de mon Projet",
|
|
456
|
+
es: "El Título de mi Proyecto",
|
|
457
|
+
}),
|
|
458
|
+
|
|
459
|
+
description: t({
|
|
460
|
+
en: "Discover our innovative platform designed to streamline your workflow and boost productivity.",
|
|
461
|
+
fr: "Découvrez notre plateforme innovante conçue pour simplifier votre flux de travail et booster votre productivité.",
|
|
462
|
+
es: "Descubra nuestra plataforma innovadora diseñada para simplificar su flujo de trabajo y aumentar su productividad.",
|
|
463
|
+
}),
|
|
464
|
+
|
|
465
|
+
keywords: t({
|
|
466
|
+
en: ["innovation", "productivity", "workflow", "SaaS"],
|
|
467
|
+
fr: ["innovation", "productivité", "flux de travail", "SaaS"],
|
|
468
|
+
es: ["innovación", "productividad", "flujo de trabajo", "SaaS"],
|
|
469
|
+
}),
|
|
470
|
+
},
|
|
471
|
+
};
|
|
472
|
+
|
|
473
|
+
module.exports = metadataContent;
|
|
474
|
+
```
|
|
475
|
+
|
|
476
|
+
```json fileName="src/app/metadata.content.json" contentDeclarationFormat="json"
|
|
477
|
+
{
|
|
478
|
+
"key": "metadata",
|
|
479
|
+
"content": {
|
|
480
|
+
"title": {
|
|
481
|
+
"nodeType": "translation",
|
|
482
|
+
"translation": {
|
|
483
|
+
"en": "My Project Title",
|
|
484
|
+
"fr": "Le Titre de mon Projet",
|
|
485
|
+
"es": "El Título de mi Proyecto"
|
|
486
|
+
}
|
|
487
|
+
},
|
|
488
|
+
"description": {
|
|
489
|
+
"nodeType": "translation",
|
|
490
|
+
"translation": {
|
|
491
|
+
"en": "Discover our innovative platform designed to streamline your workflow and boost productivity.",
|
|
492
|
+
"fr": "Découvrez notre plateforme innovante conçue pour simplifier votre flux de travail et booster votre productivité.",
|
|
493
|
+
"es": "Descubra nuestra plataforma innovadora diseñada para simplificar su flujo de trabajo y aumentar su productividad."
|
|
494
|
+
}
|
|
495
|
+
},
|
|
496
|
+
"keywords": {
|
|
497
|
+
"nodeType": "translation",
|
|
498
|
+
"translation": {
|
|
499
|
+
"en": ["innovation", "productivity", "workflow", "SaaS"],
|
|
500
|
+
"fr": ["innovation", "productivité", "flux de travail", "SaaS"],
|
|
501
|
+
"es": ["innovación", "productividad", "flujo de trabajo", "SaaS"]
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
```
|
|
507
|
+
|
|
508
|
+
```tsx fileName="src/app/page.content.ts" contentDeclarationFormat="typescript"
|
|
509
|
+
import { t, type Dictionary } from "intlayer";
|
|
510
|
+
|
|
511
|
+
const pageContent = {
|
|
512
|
+
key: "page",
|
|
513
|
+
content: {
|
|
514
|
+
getStarted: {
|
|
515
|
+
main: t({
|
|
516
|
+
en: "Get started by editing",
|
|
517
|
+
fr: "Commencez par éditer",
|
|
518
|
+
es: "Comience por editar",
|
|
519
|
+
}),
|
|
520
|
+
pageLink: "src/app/page.tsx",
|
|
521
|
+
},
|
|
522
|
+
},
|
|
523
|
+
} satisfies Dictionary;
|
|
524
|
+
|
|
525
|
+
export default pageContent;
|
|
526
|
+
```
|
|
527
|
+
|
|
528
|
+
```javascript fileName="src/app/page.content.mjs" contentDeclarationFormat="esm"
|
|
529
|
+
import { t } from "intlayer";
|
|
530
|
+
|
|
531
|
+
/** @type {import('intlayer').Dictionary} */
|
|
532
|
+
const pageContent = {
|
|
533
|
+
key: "page",
|
|
534
|
+
content: {
|
|
535
|
+
getStarted: {
|
|
536
|
+
main: t({
|
|
537
|
+
en: "Get started by editing",
|
|
538
|
+
fr: "Commencez par éditer",
|
|
539
|
+
es: "Comience por editar",
|
|
540
|
+
}),
|
|
541
|
+
pageLink: "src/app/page.tsx",
|
|
542
|
+
},
|
|
543
|
+
},
|
|
544
|
+
};
|
|
545
|
+
|
|
546
|
+
export default pageContent;
|
|
547
|
+
```
|
|
548
|
+
|
|
549
|
+
```javascript fileName="src/app/page.content.cjs" contentDeclarationFormat="commonjs"
|
|
550
|
+
const { t } = require("intlayer");
|
|
551
|
+
|
|
552
|
+
/** @type {import('intlayer').Dictionary} */
|
|
553
|
+
const pageContent = {
|
|
554
|
+
key: "page",
|
|
555
|
+
content: {
|
|
556
|
+
getStarted: {
|
|
557
|
+
main: t({
|
|
558
|
+
en: "Get started by editing",
|
|
559
|
+
fr: "Commencez par éditer",
|
|
560
|
+
es: "Comience por editar",
|
|
561
|
+
}),
|
|
562
|
+
pageLink: "src/app/page.tsx",
|
|
563
|
+
},
|
|
564
|
+
},
|
|
565
|
+
};
|
|
566
|
+
|
|
567
|
+
module.exports = pageContent;
|
|
568
|
+
```
|
|
569
|
+
|
|
570
|
+
```json fileName="src/app/page.content.json" contentDeclarationFormat="json"
|
|
571
|
+
{
|
|
572
|
+
"$schema": "https://intlayer.org/schema.json",
|
|
573
|
+
"key": "page",
|
|
574
|
+
"content": {
|
|
575
|
+
"getStarted": {
|
|
576
|
+
"nodeType": "translation",
|
|
577
|
+
"translation": {
|
|
578
|
+
"en": "Get started by editing",
|
|
579
|
+
"fr": "Commencez par éditer",
|
|
580
|
+
"es": "Comience por editar"
|
|
581
|
+
}
|
|
582
|
+
},
|
|
583
|
+
"pageLink": "src/app/page.tsx"
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
```
|
|
587
|
+
|
|
588
|
+
> Your content declarations can be defined anywhere in your application as soon they are included into the `contentDir` directory (by default, `./src`). And match the content declaration file extension (by default, `.content.{json,ts,tsx,js,jsx,mjs,mjx,cjs,cjx}`).
|
|
589
|
+
|
|
590
|
+
> For more details, refer to the [content declaration documentation](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/dictionary/content_file.md).
|
|
591
|
+
|
|
592
|
+
### Step 6: Utilize Content in Your Code
|
|
593
|
+
|
|
594
|
+
Access your content dictionaries throughout your application:
|
|
595
|
+
|
|
596
|
+
```tsx fileName="src/app/page.tsx" codeFormat="typescript"
|
|
597
|
+
import type { FC } from "react";
|
|
598
|
+
import { ClientComponentExample } from "@components/clientComponentExample/ClientComponentExample";
|
|
599
|
+
import { ServerComponentExample } from "@components/serverComponentExample/ServerComponentExample";
|
|
600
|
+
import {
|
|
601
|
+
IntlayerServerProvider,
|
|
602
|
+
useIntlayer,
|
|
603
|
+
getLocale,
|
|
604
|
+
} from "next-intlayer/server";
|
|
605
|
+
import { NextPage } from "next";
|
|
606
|
+
import { headers, cookies } from "next/headers";
|
|
607
|
+
|
|
608
|
+
const PageContent: FC = () => {
|
|
609
|
+
const content = useIntlayer("page");
|
|
610
|
+
|
|
611
|
+
return (
|
|
612
|
+
<>
|
|
613
|
+
<p>{content.getStarted.main}</p>
|
|
614
|
+
<code>{content.getStarted.pageLink}</code>
|
|
615
|
+
</>
|
|
616
|
+
);
|
|
617
|
+
};
|
|
618
|
+
|
|
619
|
+
const Page: NextPage = async () => {
|
|
620
|
+
const locale = await getLocale();
|
|
621
|
+
|
|
622
|
+
return (
|
|
623
|
+
<IntlayerServerProvider locale={locale}>
|
|
624
|
+
<PageContent />
|
|
625
|
+
<ServerComponentExample />
|
|
626
|
+
<ClientComponentExample />
|
|
627
|
+
</IntlayerServerProvider>
|
|
628
|
+
);
|
|
629
|
+
};
|
|
630
|
+
|
|
631
|
+
export default Page;
|
|
632
|
+
```
|
|
633
|
+
|
|
634
|
+
```jsx fileName="src/app/page.mjx" codeFormat="esm"
|
|
635
|
+
import { ClientComponentExample } from "@components/clientComponentExample/ClientComponentExample";
|
|
636
|
+
import { ServerComponentExample } from "@components/serverComponentExample/ServerComponentExample";
|
|
637
|
+
import { IntlayerServerProvider, useIntlayer } from "next-intlayer/server";
|
|
638
|
+
import { getLocale } from "intlayer";
|
|
639
|
+
import { headers, cookies } from "next/headers";
|
|
640
|
+
import { NextPage } from "next";
|
|
641
|
+
|
|
642
|
+
const Page: NextPage = async () => {
|
|
643
|
+
const content = useIntlayer("page");
|
|
644
|
+
|
|
645
|
+
return (
|
|
646
|
+
<>
|
|
647
|
+
<p>{content.getStarted.main}</p>
|
|
648
|
+
<code>{content.getStarted.pageLink}</code>
|
|
649
|
+
</>
|
|
650
|
+
);
|
|
651
|
+
};
|
|
652
|
+
|
|
653
|
+
const Page = async () => {
|
|
654
|
+
|
|
655
|
+
const locale = await getLocale();
|
|
656
|
+
|
|
657
|
+
return (
|
|
658
|
+
<IntlayerServerProvider locale={locale}>
|
|
659
|
+
<PageContent />
|
|
660
|
+
<ServerComponentExample />
|
|
661
|
+
<ClientComponentExample />
|
|
662
|
+
</IntlayerServerProvider>
|
|
663
|
+
);
|
|
664
|
+
};
|
|
665
|
+
|
|
666
|
+
export default Page;
|
|
667
|
+
```
|
|
668
|
+
|
|
669
|
+
```jsx fileName="src/app/page.csx" codeFormat="commonjs"
|
|
670
|
+
import { ClientComponentExample } from "@components/clientComponentExample/ClientComponentExample";
|
|
671
|
+
import { ServerComponentExample } from "@components/serverComponentExample/ServerComponentExample";
|
|
672
|
+
import { IntlayerServerProvider, useIntlayer, getLocale } from "next-intlayer/server";
|
|
673
|
+
import { NextPage } from "next";
|
|
674
|
+
import { headers, cookies } from "next/headers";
|
|
675
|
+
|
|
676
|
+
const Page: NextPage = async () => {
|
|
677
|
+
const content = useIntlayer("page");
|
|
678
|
+
|
|
679
|
+
return (
|
|
680
|
+
<>
|
|
681
|
+
<p>{content.getStarted.main}</p>
|
|
682
|
+
<code>{content.getStarted.pageLink}</code>
|
|
683
|
+
</>
|
|
684
|
+
);
|
|
685
|
+
};
|
|
686
|
+
|
|
687
|
+
const Page: NextPage = async () => {
|
|
688
|
+
const locale = await getLocale();
|
|
689
|
+
|
|
690
|
+
return (
|
|
691
|
+
<IntlayerServerProvider locale={locale}>
|
|
692
|
+
<PageContent />
|
|
693
|
+
<ServerComponentExample />
|
|
694
|
+
<ClientComponentExample />
|
|
695
|
+
</IntlayerServerProvider>
|
|
696
|
+
);
|
|
697
|
+
};
|
|
698
|
+
```
|
|
699
|
+
|
|
700
|
+
- **`IntlayerClientProvider`** is used to provide the locale to client-side components. It can be placed in any parent component, including the layout. However, placing it in a layout is recommended because Next.js shares layout code across pages, making it more efficient. By using `IntlayerClientProvider` in the layout, you avoid reinitializing it for every page, improving performance and maintaining a consistent localization context throughout your application.
|
|
701
|
+
- **`IntlayerServerProvider`** is used to provide the locale to the server children. It cannot be set set in the layout.
|
|
702
|
+
|
|
703
|
+
> Layout and page cannot share a common server context because the server context system is based on a per-request data store (via [React's cache](https://react.dev/reference/react/cache) mechanism), causing each "context" to be re-created for different segments of the application. Placing the provider in a shared layout would break this isolation, preventing the correct propagation of the server context values to your server components.
|
|
704
|
+
|
|
705
|
+
```tsx {4,7} fileName="src/components/clientComponentExample/ClientComponentExample.tsx" codeFormat="typescript"
|
|
706
|
+
"use client";
|
|
707
|
+
|
|
708
|
+
import type { FC } from "react";
|
|
709
|
+
import { useIntlayer } from "next-intlayer";
|
|
710
|
+
|
|
711
|
+
export const ClientComponentExample: FC = () => {
|
|
712
|
+
const content = useIntlayer("client-component-example"); // Create related content declaration
|
|
713
|
+
|
|
714
|
+
return (
|
|
715
|
+
<div>
|
|
716
|
+
<h2>{content.title}</h2>
|
|
717
|
+
<p>{content.content}</p>
|
|
718
|
+
</div>
|
|
719
|
+
);
|
|
720
|
+
};
|
|
721
|
+
```
|
|
722
|
+
|
|
723
|
+
```jsx {3,6} fileName="src/components/clientComponentExample/ClientComponentExample.mjx" codeFormat="esm"
|
|
724
|
+
"use client";
|
|
725
|
+
|
|
726
|
+
import { useIntlayer } from "next-intlayer";
|
|
727
|
+
|
|
728
|
+
const ClientComponentExample = () => {
|
|
729
|
+
const content = useIntlayer("client-component-example"); // Create related content declaration
|
|
730
|
+
|
|
731
|
+
return (
|
|
732
|
+
<div>
|
|
733
|
+
<h2>{content.title}</h2>
|
|
734
|
+
<p>{content.content}</p>
|
|
735
|
+
</div>
|
|
736
|
+
);
|
|
737
|
+
};
|
|
738
|
+
```
|
|
739
|
+
|
|
740
|
+
```jsx {3,6} fileName="src/components/clientComponentExample/ClientComponentExample.csx" codeFormat="commonjs"
|
|
741
|
+
"use client";
|
|
742
|
+
|
|
743
|
+
const { useIntlayer } = require("next-intlayer");
|
|
744
|
+
|
|
745
|
+
const ClientComponentExample = () => {
|
|
746
|
+
const content = useIntlayer("client-component-example"); // Create related content declaration
|
|
747
|
+
|
|
748
|
+
return (
|
|
749
|
+
<div>
|
|
750
|
+
<h2>{content.title}</h2>
|
|
751
|
+
<p>{content.content}</p>
|
|
752
|
+
</div>
|
|
753
|
+
);
|
|
754
|
+
};
|
|
755
|
+
```
|
|
756
|
+
|
|
757
|
+
```tsx {2} fileName="src/components/serverComponentExample/ServerComponentExample.tsx" codeFormat="typescript"
|
|
758
|
+
import type { FC } from "react";
|
|
759
|
+
import { useIntlayer } from "next-intlayer/server";
|
|
760
|
+
|
|
761
|
+
export const ServerComponentExample: FC = () => {
|
|
762
|
+
const content = useIntlayer("server-component-example"); // Create related content declaration
|
|
763
|
+
|
|
764
|
+
return (
|
|
765
|
+
<div>
|
|
766
|
+
<h2>{content.title}</h2>
|
|
767
|
+
<p>{content.content}</p>
|
|
768
|
+
</div>
|
|
769
|
+
);
|
|
770
|
+
};
|
|
771
|
+
```
|
|
772
|
+
|
|
773
|
+
```jsx {1} fileName="src/components/serverComponentExample/ServerComponentExample.mjx" codeFormat="esm"
|
|
774
|
+
import { useIntlayer } from "next-intlayer/server";
|
|
775
|
+
|
|
776
|
+
const ServerComponentExample = () => {
|
|
777
|
+
const content = useIntlayer("server-component-example"); // Create related content declaration
|
|
778
|
+
|
|
779
|
+
return (
|
|
780
|
+
<div>
|
|
781
|
+
<h2>{content.title}</h2>
|
|
782
|
+
<p>{content.content}</p>
|
|
783
|
+
</div>
|
|
784
|
+
);
|
|
785
|
+
};
|
|
786
|
+
```
|
|
787
|
+
|
|
788
|
+
```jsx {1} fileName="src/components/serverComponentExample/ServerComponentExample.csx" codeFormat="commonjs"
|
|
789
|
+
const { useIntlayer } = require("next-intlayer/server");
|
|
790
|
+
|
|
791
|
+
const ServerComponentExample = () => {
|
|
792
|
+
const content = useIntlayer("server-component-example"); // Create related content declaration
|
|
793
|
+
|
|
794
|
+
return (
|
|
795
|
+
<div>
|
|
796
|
+
<h2>{content.title}</h2>
|
|
797
|
+
<p>{content.content}</p>
|
|
798
|
+
</div>
|
|
799
|
+
);
|
|
800
|
+
};
|
|
801
|
+
```
|
|
802
|
+
|
|
803
|
+
> If you want to use your content in a `string` attribute, such as `alt`, `title`, `href`, `aria-label`, etc., you must call the value of the function, like:
|
|
804
|
+
|
|
805
|
+
> ```jsx
|
|
806
|
+
> <img src={content.image.src.value} alt={content.image.value} />
|
|
807
|
+
> ```
|
|
808
|
+
|
|
809
|
+
> To Learn more about the `useIntlayer` hook, refer to the [documentation](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/packages/next-intlayer/useIntlayer.md).
|
|
810
|
+
|
|
811
|
+
### (Optional) Step 7: Configure Proxy for Locale Detection
|
|
812
|
+
|
|
813
|
+
Set up proxy to detect the user's preferred locale:
|
|
814
|
+
|
|
815
|
+
```typescript fileName="src/proxy.ts" codeFormat="typescript"
|
|
816
|
+
export { intlayerProxy as proxy } from "next-intlayer/proxy";
|
|
817
|
+
|
|
818
|
+
export const config = {
|
|
819
|
+
matcher:
|
|
820
|
+
"/((?!api|static|assets|robots|sitemap|sw|service-worker|manifest|.*\\..*|_next).*)",
|
|
821
|
+
};
|
|
822
|
+
```
|
|
823
|
+
|
|
824
|
+
```javascript fileName="src/proxy.mjs" codeFormat="esm"
|
|
825
|
+
export { intlayerProxy as proxy } from "next-intlayer/proxy";
|
|
826
|
+
|
|
827
|
+
export const config = {
|
|
828
|
+
matcher:
|
|
829
|
+
"/((?!api|static|assets|robots|sitemap|sw|service-worker|manifest|.*\\..*|_next).*)",
|
|
830
|
+
};
|
|
831
|
+
```
|
|
832
|
+
|
|
833
|
+
```javascript fileName="src/proxy.cjs" codeFormat="commonjs"
|
|
834
|
+
const { intlayerProxy } = require("next-intlayer/proxy");
|
|
835
|
+
|
|
836
|
+
const config = {
|
|
837
|
+
matcher:
|
|
838
|
+
"/((?!api|static|assets|robots|sitemap|sw|service-worker|manifest|.*\\..*|_next).*)",
|
|
839
|
+
};
|
|
840
|
+
|
|
841
|
+
module.exports = { proxy: intlayerProxy, config };
|
|
842
|
+
```
|
|
843
|
+
|
|
844
|
+
> The `intlayerProxy` is used to detect the user's preferred locale and redirect them to the appropriate URL as specified in the [configuration](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/configuration.md). Additionally, it enables saving the user's preferred locale in a cookie.
|
|
845
|
+
|
|
846
|
+
> If you need to chain several proxies together (for example, `intlayerProxy` with authentication or custom proxies), Intlayer now provides a helper called `multipleProxies`.
|
|
847
|
+
|
|
848
|
+
```ts
|
|
849
|
+
import { multipleProxies, intlayerProxy } from "next-intlayer/proxy";
|
|
850
|
+
import { customProxy } from "@utils/customProxy";
|
|
851
|
+
|
|
852
|
+
export const proxy = multipleProxies([intlayerProxy, customProxy]);
|
|
853
|
+
```
|
|
854
|
+
|
|
855
|
+
### (Optional) Step 8: Change the language of your content
|
|
856
|
+
|
|
857
|
+
To change the language of your content in Next.js, the recommended way is to use the `Link` component to redirect users to the appropriate localized page. The `Link` component enables prefetching of the page, which helps avoid a full page reload.
|
|
858
|
+
|
|
859
|
+
```tsx fileName="src/components/localeSwitcher/LocaleSwitcher.tsx" codeFormat="typescript"
|
|
860
|
+
"use client";
|
|
861
|
+
|
|
862
|
+
import type { FC } from "react";
|
|
863
|
+
import { Locales, getHTMLTextDir, getLocaleName } from "intlayer";
|
|
864
|
+
import { useLocale } from "next-intlayer";
|
|
865
|
+
|
|
866
|
+
export const LocaleSwitcher: FC = () => {
|
|
867
|
+
const { locale, availableLocales, setLocale } = useLocale({
|
|
868
|
+
onChange: () => window.location.reload(),
|
|
869
|
+
});
|
|
870
|
+
|
|
871
|
+
return (
|
|
872
|
+
<div>
|
|
873
|
+
<button popoverTarget="localePopover">{getLocaleName(locale)}</button>
|
|
874
|
+
<div id="localePopover" popover="auto">
|
|
875
|
+
{availableLocales.map((localeItem) => (
|
|
876
|
+
<button
|
|
877
|
+
key={localeItem}
|
|
878
|
+
aria-current={locale === localeItem ? "page" : undefined}
|
|
879
|
+
onClick={() => setLocale(localeItem)}
|
|
880
|
+
>
|
|
881
|
+
<span>
|
|
882
|
+
{/* Locale - e.g. FR */}
|
|
883
|
+
{localeItem}
|
|
884
|
+
</span>
|
|
885
|
+
<span>
|
|
886
|
+
{/* Language in its own Locale - e.g. Français */}
|
|
887
|
+
{getLocaleName(localeItem, locale)}
|
|
888
|
+
</span>
|
|
889
|
+
<span dir={getHTMLTextDir(localeItem)} lang={localeItem}>
|
|
890
|
+
{/* Language in current Locale - e.g. Francés with current locale set to Locales.SPANISH */}
|
|
891
|
+
{getLocaleName(localeItem)}
|
|
892
|
+
</span>
|
|
893
|
+
<span dir="ltr" lang={Locales.ENGLISH}>
|
|
894
|
+
{/* Language in English - e.g. French */}
|
|
895
|
+
{getLocaleName(localeItem, Locales.ENGLISH)}
|
|
896
|
+
</span>
|
|
897
|
+
</button>
|
|
898
|
+
))}
|
|
899
|
+
</div>
|
|
900
|
+
</div>
|
|
901
|
+
);
|
|
902
|
+
};
|
|
903
|
+
```
|
|
904
|
+
|
|
905
|
+
```jsx fileName="src/components/localeSwitcher/LocaleSwitcher.msx" codeFormat="esm"
|
|
906
|
+
"use client";
|
|
907
|
+
|
|
908
|
+
import { Locales, getHTMLTextDir, getLocaleName } from "intlayer";
|
|
909
|
+
import { useLocale } from "next-intlayer";
|
|
910
|
+
|
|
911
|
+
export const LocaleSwitcher = () => {
|
|
912
|
+
const { locale, availableLocales, setLocale } = useLocale({
|
|
913
|
+
onChange: () => window.location.reload(),
|
|
914
|
+
});
|
|
915
|
+
|
|
916
|
+
return (
|
|
917
|
+
<div>
|
|
918
|
+
<button popoverTarget="localePopover">{getLocaleName(locale)}</button>
|
|
919
|
+
<div id="localePopover" popover="auto">
|
|
920
|
+
{availableLocales.map((localeItem) => (
|
|
921
|
+
<button
|
|
922
|
+
key={localeItem}
|
|
923
|
+
aria-current={locale === localeItem ? "page" : undefined}
|
|
924
|
+
onClick={() => setLocale(localeItem)}
|
|
925
|
+
>
|
|
926
|
+
<span>
|
|
927
|
+
{/* Locale - e.g. FR */}
|
|
928
|
+
{localeItem}
|
|
929
|
+
</span>
|
|
930
|
+
<span>
|
|
931
|
+
{/* Language in its own Locale - e.g. Français */}
|
|
932
|
+
{getLocaleName(localeItem, locale)}
|
|
933
|
+
</span>
|
|
934
|
+
<span dir={getHTMLTextDir(localeItem)} lang={localeItem}>
|
|
935
|
+
{/* Language in current Locale - e.g. Francés with current locale set to Locales.SPANISH */}
|
|
936
|
+
{getLocaleName(localeItem)}
|
|
937
|
+
</span>
|
|
938
|
+
<span dir="ltr" lang={Locales.ENGLISH}>
|
|
939
|
+
{/* Language in English - e.g. French */}
|
|
940
|
+
{getLocaleName(localeItem, Locales.ENGLISH)}
|
|
941
|
+
</span>
|
|
942
|
+
</button>
|
|
943
|
+
))}
|
|
944
|
+
</div>
|
|
945
|
+
</div>
|
|
946
|
+
);
|
|
947
|
+
};
|
|
948
|
+
```
|
|
949
|
+
|
|
950
|
+
```jsx fileName="src/components/localeSwitcher/LocaleSwitcher.csx" codeFormat="commonjs"
|
|
951
|
+
"use client";
|
|
952
|
+
|
|
953
|
+
const { Locales, getHTMLTextDir, getLocaleName } = require("intlayer");
|
|
954
|
+
const { useLocale } = require("next-intlayer");
|
|
955
|
+
|
|
956
|
+
export const LocaleSwitcher = () => {
|
|
957
|
+
const path
|
|
958
|
+
const { locale availableLocales, setLocale } = useLocale({
|
|
959
|
+
onChange: ()=> window.location.reload(),
|
|
960
|
+
});
|
|
961
|
+
|
|
962
|
+
return (
|
|
963
|
+
<div>
|
|
964
|
+
<button popoverTarget="localePopover">{getLocaleName(locale)}</button>
|
|
965
|
+
<div id="localePopover" popover="auto">
|
|
966
|
+
{availableLocales.map((localeItem) => (
|
|
967
|
+
<button
|
|
968
|
+
key={localeItem}
|
|
969
|
+
aria-current={locale === localeItem ? "page" : undefined}
|
|
970
|
+
onClick={() => setLocale(localeItem)}
|
|
971
|
+
>
|
|
972
|
+
<span>
|
|
973
|
+
{/* Locale - e.g. FR */}
|
|
974
|
+
{localeItem}
|
|
975
|
+
</span>
|
|
976
|
+
<span>
|
|
977
|
+
{/* Language in its own Locale - e.g. Français */}
|
|
978
|
+
{getLocaleName(localeItem, locale)}
|
|
979
|
+
</span>
|
|
980
|
+
<span dir={getHTMLTextDir(localeItem)} lang={localeItem}>
|
|
981
|
+
{/* Language in current Locale - e.g. Francés with current locale set to Locales.SPANISH */}
|
|
982
|
+
{getLocaleName(localeItem)}
|
|
983
|
+
</span>
|
|
984
|
+
<span dir="ltr" lang={Locales.ENGLISH}>
|
|
985
|
+
{/* Language in English - e.g. French */}
|
|
986
|
+
{getLocaleName(localeItem, Locales.ENGLISH)}
|
|
987
|
+
</span>
|
|
988
|
+
</button>
|
|
989
|
+
))}
|
|
990
|
+
</div>
|
|
991
|
+
</div>
|
|
992
|
+
);
|
|
993
|
+
};
|
|
994
|
+
```
|
|
995
|
+
|
|
996
|
+
> An alternative way is to use the `setLocale` function provided by the `useLocale` hook. This function will not allow prefetching the page. See the [`useLocale` hook documentation](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/packages/next-intlayer/useLocale.md) for more details.
|
|
997
|
+
|
|
998
|
+
> Documentation references:
|
|
999
|
+
>
|
|
1000
|
+
> - [`useLocale` hook](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/packages/next-intlayer/useLocale.md)
|
|
1001
|
+
> - [`getLocaleName` hook](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/packages/intlayer/getLocaleName.md)
|
|
1002
|
+
> - [`getLocalizedUrl` hook](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/packages/intlayer/getLocalizedUrl.md)
|
|
1003
|
+
> - [`getHTMLTextDir` hook](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/packages/intlayer/getHTMLTextDir.md)
|
|
1004
|
+
> - [`hrefLang` attribute](https://developers.google.com/search/docs/specialty/international/localized-versions?hl=fr)
|
|
1005
|
+
> - [`lang` attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/lang)
|
|
1006
|
+
> - [`dir` attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/dir)
|
|
1007
|
+
> - [`aria-current` attribute](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-current)
|
|
1008
|
+
|
|
1009
|
+
### (Optional) Step 9: Get the current locale in Server Actions
|
|
1010
|
+
|
|
1011
|
+
If you need the active locale inside a Server Action (e.g., to localize emails or run locale-aware logic), call `getLocale` from `next-intlayer/server`:
|
|
1012
|
+
|
|
1013
|
+
```tsx fileName="src/app/actions/getLocale.ts" codeFormat="typescript"
|
|
1014
|
+
"use server";
|
|
1015
|
+
|
|
1016
|
+
import { getLocale } from "next-intlayer/server";
|
|
1017
|
+
|
|
1018
|
+
export const myServerAction = async () => {
|
|
1019
|
+
const locale = await getLocale();
|
|
1020
|
+
|
|
1021
|
+
// Do something with the locale
|
|
1022
|
+
};
|
|
1023
|
+
```
|
|
1024
|
+
|
|
1025
|
+
> The `getLocale` function follows a cascading strategy to determine the user's locale:
|
|
1026
|
+
>
|
|
1027
|
+
> 1. First, it checks the request headers for a locale value that may have been set by the proxy
|
|
1028
|
+
> 2. If no locale is found in headers, it looks for a locale stored in cookies
|
|
1029
|
+
> 3. If no cookie is found, it attempts to detect the user's preferred language from their browser settings
|
|
1030
|
+
> 4. As a last resort, it falls back to the application's configured default locale
|
|
1031
|
+
>
|
|
1032
|
+
> This ensures the most appropriate locale is selected based on available context.
|
|
1033
|
+
|
|
1034
|
+
### (Optional) Step 10: Optmize your bundle size
|
|
1035
|
+
|
|
1036
|
+
When using `next-intlayer`, dictionaries are included in the bundle for every page by default. To optimize bundle size, Intlayer provides an optional SWC plugin that intelligently replace `useIntlayer` calls using macros. This ensures dictionaries are only included in bundles for pages that actually use them.
|
|
1037
|
+
|
|
1038
|
+
To enable this optimization, install the `@intlayer/swc` package. Once installed, `next-intlayer` will automatically detect and use the plugin:
|
|
1039
|
+
|
|
1040
|
+
```bash packageManager="npm"
|
|
1041
|
+
npm install @intlayer/swc --save-dev
|
|
1042
|
+
npx intlayer init
|
|
1043
|
+
```
|
|
1044
|
+
|
|
1045
|
+
```bash packageManager="pnpm"
|
|
1046
|
+
pnpm add @intlayer/swc --save-dev
|
|
1047
|
+
pnpm intlayer init
|
|
1048
|
+
```
|
|
1049
|
+
|
|
1050
|
+
```bash packageManager="yarn"
|
|
1051
|
+
yarn add @intlayer/swc --save-dev
|
|
1052
|
+
yarn intlayer init
|
|
1053
|
+
```
|
|
1054
|
+
|
|
1055
|
+
```bash packageManager="bun"
|
|
1056
|
+
bun add @intlayer/swc --dev
|
|
1057
|
+
bunx intlayer init
|
|
1058
|
+
```
|
|
1059
|
+
|
|
1060
|
+
> Note: This optimization is only available for Next.js 13 and above.
|
|
1061
|
+
|
|
1062
|
+
> Note: This package is not installed by default because SWC plugins are still experimental on Next.js. It may change in the future.
|
|
1063
|
+
|
|
1064
|
+
> Note: If you set the option as `importMode: 'dynamic'` or `importMode: 'live'`, it will rely on Suspense, so you will have to wrap your `useIntlayer` calls in a `Suspense` boundary. That means, you will not be able to use the `useIntlayer` directly at the top level of your Page / Layout component.
|
|
1065
|
+
|
|
1066
|
+
### Watch dictionaries changes on Turbopack
|
|
1067
|
+
|
|
1068
|
+
When using Turbopack as your development server with the `next dev` command, dictionary changes will not be automatically detected by default.
|
|
1069
|
+
|
|
1070
|
+
This limitation occurs because Turbopack cannot run webpack plugins in parallel to monitor changes in your content files. To work around this, you'll need to use the `intlayer watch` command to run both the development server and the Intlayer build watcher simultaneously.
|
|
1071
|
+
|
|
1072
|
+
```json5 fileName="package.json"
|
|
1073
|
+
{
|
|
1074
|
+
// ... Your existing package.json configurations
|
|
1075
|
+
"scripts": {
|
|
1076
|
+
// ... Your existing scripts configurations
|
|
1077
|
+
"dev": "intlayer watch --with 'next dev'",
|
|
1078
|
+
},
|
|
1079
|
+
}
|
|
1080
|
+
```
|
|
1081
|
+
|
|
1082
|
+
> If you are using next-intlayer@<=6.x.x, you need to keep the `--turbopack` flag to make the Next.js 16 application work correctly with Turbopack. We recommend using next-intlayer@>=7.x.x to avoid this limitation.
|
|
1083
|
+
|
|
1084
|
+
### Configure TypeScript
|
|
1085
|
+
|
|
1086
|
+
Intlayer use module augmentation to get benefits of TypeScript and make your codebase stronger.
|
|
1087
|
+
|
|
1088
|
+

|
|
1089
|
+
|
|
1090
|
+

|
|
1091
|
+
|
|
1092
|
+
Ensure your TypeScript configuration includes the autogenerated types.
|
|
1093
|
+
|
|
1094
|
+
```json5 fileName="tsconfig.json"
|
|
1095
|
+
{
|
|
1096
|
+
// ... Your existing TypeScript configurations
|
|
1097
|
+
"include": [
|
|
1098
|
+
// ... Your existing TypeScript configurations
|
|
1099
|
+
".intlayer/**/*.ts", // Include the auto-generated types
|
|
1100
|
+
],
|
|
1101
|
+
}
|
|
1102
|
+
```
|
|
1103
|
+
|
|
1104
|
+
### Git Configuration
|
|
1105
|
+
|
|
1106
|
+
It is recommended to ignore the files generated by Intlayer. This allows you to avoid committing them to your Git repository.
|
|
1107
|
+
|
|
1108
|
+
To do this, you can add the following instructions to your `.gitignore` file:
|
|
1109
|
+
|
|
1110
|
+
```plaintext fileName=".gitignore"
|
|
1111
|
+
# Ignore the files generated by Intlayer
|
|
1112
|
+
.intlayer
|
|
1113
|
+
```
|
|
1114
|
+
|
|
1115
|
+
### VS Code Extension
|
|
1116
|
+
|
|
1117
|
+
To improve your development experience with Intlayer, you can install the official **Intlayer VS Code Extension**.
|
|
1118
|
+
|
|
1119
|
+
[Install from the VS Code Marketplace](https://marketplace.visualstudio.com/items?itemName=intlayer.intlayer-vs-code-extension)
|
|
1120
|
+
|
|
1121
|
+
This extension provides:
|
|
1122
|
+
|
|
1123
|
+
- **Autocompletion** for translation keys.
|
|
1124
|
+
- **Real-time error detection** for missing translations.
|
|
1125
|
+
- **Inline previews** of translated content.
|
|
1126
|
+
- **Quick actions** to easily create and update translations.
|
|
1127
|
+
|
|
1128
|
+
For more details on how to use the extension, refer to the [Intlayer VS Code Extension documentation](https://intlayer.org/doc/vs-code-extension).
|
|
1129
|
+
|
|
1130
|
+
### Go Further
|
|
1131
|
+
|
|
1132
|
+
To go further, you can implement the [visual editor](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/intlayer_visual_editor.md) or externalize your content using the [CMS](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/intlayer_CMS.md).
|