@intlayer/docs 7.0.3 → 7.0.4
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 +68 -106
- package/blog/ar/intlayer_with_next-i18next.md +84 -288
- package/blog/ar/intlayer_with_next-intl.md +58 -337
- package/blog/ar/intlayer_with_react-i18next.md +68 -290
- package/blog/ar/intlayer_with_react-intl.md +63 -266
- package/blog/de/intlayer_with_i18next.md +77 -97
- package/blog/de/intlayer_with_next-i18next.md +69 -296
- package/blog/de/intlayer_with_next-intl.md +59 -340
- package/blog/de/intlayer_with_react-i18next.md +68 -290
- package/blog/de/intlayer_with_react-intl.md +62 -264
- package/blog/en/intlayer_with_i18next.md +67 -103
- package/blog/en/intlayer_with_next-i18next.md +69 -294
- package/blog/en/intlayer_with_next-intl.md +48 -300
- package/blog/en/intlayer_with_react-i18next.md +61 -289
- package/blog/en/intlayer_with_react-intl.md +61 -284
- package/blog/en/next-i18next_vs_next-intl_vs_intlayer.md +1 -1
- package/blog/en-GB/intlayer_with_i18next.md +67 -103
- package/blog/en-GB/intlayer_with_next-i18next.md +71 -292
- package/blog/en-GB/intlayer_with_next-intl.md +58 -337
- package/blog/en-GB/intlayer_with_react-i18next.md +67 -289
- package/blog/en-GB/intlayer_with_react-intl.md +61 -264
- package/blog/es/intlayer_with_i18next.md +67 -103
- package/blog/es/intlayer_with_next-i18next.md +71 -296
- package/blog/es/intlayer_with_next-intl.md +57 -338
- package/blog/es/intlayer_with_react-i18next.md +68 -290
- package/blog/es/intlayer_with_react-intl.md +62 -265
- package/blog/fr/intlayer_with_i18next.md +66 -104
- package/blog/fr/intlayer_with_next-i18next.md +82 -285
- package/blog/fr/intlayer_with_next-intl.md +57 -338
- package/blog/fr/intlayer_with_react-i18next.md +67 -289
- package/blog/fr/intlayer_with_react-intl.md +61 -264
- package/blog/hi/intlayer_with_i18next.md +68 -104
- package/blog/hi/intlayer_with_next-i18next.md +74 -299
- package/blog/hi/intlayer_with_next-intl.md +57 -239
- package/blog/hi/intlayer_with_react-i18next.md +69 -291
- package/blog/hi/intlayer_with_react-intl.md +65 -268
- package/blog/id/intlayer_with_i18next.md +126 -0
- package/blog/id/intlayer_with_next-i18next.md +142 -0
- package/blog/id/intlayer_with_next-intl.md +113 -0
- package/blog/id/intlayer_with_react-i18next.md +124 -0
- package/blog/id/intlayer_with_react-intl.md +122 -0
- package/blog/it/intlayer_with_i18next.md +67 -103
- package/blog/it/intlayer_with_next-i18next.md +71 -296
- package/blog/it/intlayer_with_next-intl.md +57 -338
- package/blog/it/intlayer_with_react-i18next.md +68 -290
- package/blog/it/intlayer_with_react-intl.md +62 -265
- package/blog/ja/intlayer_with_i18next.md +68 -103
- package/blog/ja/intlayer_with_next-i18next.md +85 -283
- package/blog/ja/intlayer_with_next-intl.md +58 -336
- package/blog/ja/intlayer_with_react-i18next.md +68 -290
- package/blog/ja/intlayer_with_react-intl.md +62 -264
- package/blog/ko/intlayer_with_i18next.md +80 -96
- package/blog/ko/intlayer_with_next-i18next.md +85 -287
- package/blog/ko/intlayer_with_next-intl.md +68 -327
- package/blog/ko/intlayer_with_react-i18next.md +68 -290
- package/blog/ko/intlayer_with_react-intl.md +64 -266
- package/blog/pl/intlayer_with_i18next.md +126 -0
- package/blog/pl/intlayer_with_next-i18next.md +142 -0
- package/blog/pl/intlayer_with_next-intl.md +111 -0
- package/blog/pl/intlayer_with_react-i18next.md +124 -0
- package/blog/pl/intlayer_with_react-intl.md +122 -0
- package/blog/pt/intlayer_with_i18next.md +67 -103
- package/blog/pt/intlayer_with_next-i18next.md +72 -293
- package/blog/pt/intlayer_with_next-intl.md +57 -256
- package/blog/pt/intlayer_with_react-i18next.md +104 -78
- package/blog/pt/intlayer_with_react-intl.md +62 -266
- package/blog/ru/intlayer_with_i18next.md +66 -104
- package/blog/ru/intlayer_with_next-i18next.md +71 -296
- package/blog/ru/intlayer_with_next-intl.md +58 -337
- package/blog/ru/intlayer_with_react-i18next.md +68 -290
- package/blog/ru/intlayer_with_react-intl.md +62 -265
- package/blog/tr/intlayer_with_i18next.md +71 -107
- package/blog/tr/intlayer_with_next-i18next.md +72 -297
- package/blog/tr/intlayer_with_next-intl.md +58 -339
- package/blog/tr/intlayer_with_react-i18next.md +69 -291
- package/blog/tr/intlayer_with_react-intl.md +63 -285
- package/blog/vi/intlayer_with_i18next.md +126 -0
- package/blog/vi/intlayer_with_next-i18next.md +142 -0
- package/blog/vi/intlayer_with_next-intl.md +111 -0
- package/blog/vi/intlayer_with_react-i18next.md +124 -0
- package/blog/vi/intlayer_with_react-intl.md +122 -0
- package/blog/zh/intlayer_with_i18next.md +67 -102
- package/blog/zh/intlayer_with_next-i18next.md +72 -296
- package/blog/zh/intlayer_with_next-intl.md +58 -336
- package/blog/zh/intlayer_with_react-i18next.md +68 -290
- package/blog/zh/intlayer_with_react-intl.md +63 -106
- package/dist/cjs/generated/blog.entry.cjs +13 -1
- package/dist/cjs/generated/blog.entry.cjs.map +1 -1
- package/dist/cjs/generated/docs.entry.cjs +13 -1
- package/dist/cjs/generated/docs.entry.cjs.map +1 -1
- package/dist/cjs/generated/frequentQuestions.entry.cjs +13 -1
- package/dist/cjs/generated/frequentQuestions.entry.cjs.map +1 -1
- package/dist/cjs/generated/legal.entry.cjs +13 -1
- package/dist/cjs/generated/legal.entry.cjs.map +1 -1
- package/dist/esm/generated/blog.entry.mjs +13 -2
- package/dist/esm/generated/blog.entry.mjs.map +1 -1
- package/dist/esm/generated/docs.entry.mjs +13 -2
- package/dist/esm/generated/docs.entry.mjs.map +1 -1
- package/dist/esm/generated/frequentQuestions.entry.mjs +13 -2
- package/dist/esm/generated/frequentQuestions.entry.mjs.map +1 -1
- package/dist/esm/generated/legal.entry.mjs +13 -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.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/plugins/sync-json.md +244 -0
- package/docs/de/plugins/sync-json.md +244 -0
- package/docs/de/releases/v7.md +1 -18
- package/docs/en/CI_CD.md +1 -1
- package/docs/en/configuration.md +1 -1
- package/docs/en/formatters.md +1 -1
- package/docs/en/how_works_intlayer.md +1 -1
- package/docs/en/intlayer_CMS.md +1 -1
- package/docs/en/intlayer_cli.md +26 -1
- package/docs/en/intlayer_with_nextjs_14.md +3 -1
- package/docs/en/intlayer_with_nextjs_15.md +3 -1
- package/docs/en/intlayer_with_nextjs_16.md +3 -1
- package/docs/en/intlayer_with_nextjs_page_router.md +1 -1
- package/docs/en/intlayer_with_nuxt.md +1 -1
- package/docs/en/intlayer_with_react_native+expo.md +1 -1
- package/docs/en/intlayer_with_react_router_v7.md +1 -1
- package/docs/en/intlayer_with_tanstack.md +1 -1
- package/docs/en/intlayer_with_vite+preact.md +1 -1
- package/docs/en/intlayer_with_vite+react.md +1 -1
- package/docs/en/intlayer_with_vite+solid.md +1 -1
- package/docs/en/intlayer_with_vite+svelte.md +1 -1
- package/docs/en/intlayer_with_vite+vue.md +1 -1
- package/docs/en/plugins/sync-json.md +1 -1
- package/docs/en/roadmap.md +1 -1
- package/docs/en-GB/plugins/sync-json.md +244 -0
- package/docs/es/plugins/sync-json.md +244 -0
- package/docs/es/releases/v7.md +1 -18
- package/docs/fr/intlayer_with_nextjs_16.md +2 -51
- package/docs/fr/plugins/sync-json.md +244 -0
- package/docs/fr/releases/v7.md +1 -18
- package/docs/hi/intlayer_with_nextjs_16.md +3 -2
- package/docs/hi/plugins/sync-json.md +244 -0
- package/docs/id/plugins/sync-json.md +244 -0
- package/docs/id/releases/v7.md +1 -18
- package/docs/it/plugins/sync-json.md +244 -0
- package/docs/it/releases/v7.md +1 -18
- package/docs/ja/intlayer_with_nextjs_16.md +44 -205
- package/docs/ja/plugins/sync-json.md +244 -0
- package/docs/ja/releases/v7.md +1 -18
- package/docs/ko/plugins/sync-json.md +244 -0
- package/docs/ko/releases/v7.md +1 -18
- package/docs/pl/plugins/sync-json.md +244 -0
- package/docs/pt/intlayer_with_nextjs_16.md +1 -52
- package/docs/pt/plugins/sync-json.md +244 -0
- package/docs/ru/plugins/sync-json.md +244 -0
- package/docs/tr/plugins/sync-json.md +245 -0
- package/docs/vi/plugins/sync-json.md +244 -0
- package/docs/zh/plugins/sync-json.md +244 -0
- package/package.json +14 -14
- package/src/generated/blog.entry.ts +26 -3
- package/src/generated/docs.entry.ts +26 -3
- package/src/generated/frequentQuestions.entry.ts +26 -3
- package/src/generated/legal.entry.ts +26 -3
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
---
|
|
2
2
|
createdAt: 2025-01-02
|
|
3
3
|
updatedAt: 2025-10-29
|
|
4
|
-
title:
|
|
5
|
-
description:
|
|
4
|
+
title: How to automate your react-i18next JSON translations using Intlayer
|
|
5
|
+
description: Automate your JSON translations with Intlayer and react-i18next for enhanced internationalization in React applications.
|
|
6
6
|
keywords:
|
|
7
7
|
- react-i18next
|
|
8
8
|
- i18next
|
|
9
9
|
- Intlayer
|
|
10
10
|
- Internationalization
|
|
11
|
+
- i18n
|
|
11
12
|
- Blog
|
|
12
|
-
- Next.js
|
|
13
|
-
- JavaScript
|
|
14
13
|
- React
|
|
14
|
+
- JavaScript
|
|
15
|
+
- TypeScript
|
|
16
|
+
- Content Management
|
|
15
17
|
slugs:
|
|
16
18
|
- blog
|
|
17
19
|
- intlayer-with-react-i18next
|
|
@@ -21,110 +23,71 @@ history:
|
|
|
21
23
|
changes: Change to syncJSON plugin
|
|
22
24
|
---
|
|
23
25
|
|
|
24
|
-
#
|
|
26
|
+
# How to automate your react-i18next JSON translations using Intlayer
|
|
27
|
+
|
|
28
|
+
## What is Intlayer?
|
|
29
|
+
|
|
30
|
+
**Intlayer** is an innovative, open-source internationalization library designed to address the shortcomings of traditional i18n solutions. It offers a modern approach to content management in React applications.
|
|
25
31
|
|
|
26
|
-
|
|
32
|
+
See a concrete comparison with react-i18next in our [react-i18next vs. react-intl vs. Intlayer](https://github.com/aymericzip/intlayer/blob/main/docs/blog/en/react-i18next_vs_react-intl_vs_intlayer.md) blog post.
|
|
27
33
|
|
|
28
|
-
|
|
29
|
-
- **react-i18next** is a popular React integration for **i18next** that provides hooks like `useTranslation` to fetch localized strings in your components.
|
|
34
|
+
## Why Combine Intlayer with react-i18next?
|
|
30
35
|
|
|
31
|
-
|
|
36
|
+
While Intlayer provides an excellent standalone i18n solution (see our [React integration guide](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/intlayer_with_vite+react.md)), you might want to combine it with react-i18next for several reasons:
|
|
37
|
+
|
|
38
|
+
1. **Existing codebase**: You have an established react-i18next implementation and want to gradually migrate to Intlayer's improved developer experience.
|
|
39
|
+
2. **Legacy requirements**: Your project requires compatibility with existing react-i18next plugins or workflows.
|
|
40
|
+
3. **Team familiarity**: Your team is comfortable with react-i18next but wants better content management.
|
|
41
|
+
|
|
42
|
+
**For that, Intlayer can be implemented as an adapter for react-i18next to help automating your JSON translations in CLI or CI/CD pipelines, testing your translations, and more.**
|
|
43
|
+
|
|
44
|
+
This guide shows you how to leverage Intlayer's superior content declaration system while maintaining compatibility with react-i18next.
|
|
32
45
|
|
|
33
46
|
## Table of Contents
|
|
34
47
|
|
|
35
|
-
<TOC
|
|
36
|
-
|
|
37
|
-
##
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
.
|
|
46
|
-
└── src
|
|
47
|
-
└── components
|
|
48
|
-
└── MyComponent
|
|
49
|
-
├── index.content.ts # Content declaration file
|
|
50
|
-
└── index.tsx
|
|
51
|
-
```
|
|
52
|
-
|
|
53
|
-
```bash codeFormat="esm"
|
|
54
|
-
.
|
|
55
|
-
└── src
|
|
56
|
-
└── components
|
|
57
|
-
└── MyComponent
|
|
58
|
-
├── index.content.mjs # Content declaration file
|
|
59
|
-
└── index.mjx
|
|
60
|
-
```
|
|
61
|
-
|
|
62
|
-
```bash codeFormat="cjs"
|
|
63
|
-
.
|
|
64
|
-
└── src
|
|
65
|
-
└── components
|
|
66
|
-
└── MyComponent
|
|
67
|
-
├── index.content.cjs # Content declaration file
|
|
68
|
-
└── index.cjx
|
|
69
|
-
```
|
|
70
|
-
|
|
71
|
-
```bash codeFormat="json"
|
|
72
|
-
.
|
|
73
|
-
└── src
|
|
74
|
-
└── components
|
|
75
|
-
└── MyComponent
|
|
76
|
-
├── index.content.json # Content declaration file
|
|
77
|
-
└── index.jsx
|
|
78
|
-
```
|
|
79
|
-
|
|
80
|
-
2. **Centralized Translations**
|
|
81
|
-
A single content declaration file collects all necessary translations for a component, making missing translations easier to catch.
|
|
82
|
-
With TypeScript, you even get compile-time errors if translations are missing.
|
|
83
|
-
|
|
84
|
-
## Installation
|
|
85
|
-
|
|
86
|
-
In a Create React App project, install these dependencies:
|
|
87
|
-
|
|
88
|
-
```bash
|
|
89
|
-
# With npm
|
|
90
|
-
npm install intlayer react-i18next i18next i18next-resources-to-backend @intlayer/sync-json-plugin
|
|
48
|
+
<TOC/>
|
|
49
|
+
|
|
50
|
+
## Step-by-Step Guide to Set Up Intlayer with react-i18next
|
|
51
|
+
|
|
52
|
+
### Step 1: Install Dependencies
|
|
53
|
+
|
|
54
|
+
Install the necessary packages:
|
|
55
|
+
|
|
56
|
+
```bash packageManager="npm"
|
|
57
|
+
npm install intlayer @intlayer/sync-json-plugin
|
|
91
58
|
```
|
|
92
59
|
|
|
93
|
-
```bash
|
|
94
|
-
|
|
95
|
-
yarn add intlayer react-i18next i18next i18next-resources-to-backend @intlayer/sync-json-plugin
|
|
60
|
+
```bash packageManager="pnpm"
|
|
61
|
+
pnpm add intlayer @intlayer/sync-json-plugin
|
|
96
62
|
```
|
|
97
63
|
|
|
98
|
-
```bash
|
|
99
|
-
|
|
100
|
-
pnpm add intlayer react-i18next i18next i18next-resources-to-backend @intlayer/sync-json-plugin
|
|
64
|
+
```bash packageManager="yarn"
|
|
65
|
+
yarn add intlayer @intlayer/sync-json-plugin
|
|
101
66
|
```
|
|
102
67
|
|
|
103
|
-
|
|
68
|
+
**Package descriptions:**
|
|
69
|
+
|
|
70
|
+
- **intlayer**: Core library for internationalization management, content declaration, and building
|
|
71
|
+
- **@intlayer/sync-json-plugin**: Plugin to export Intlayer content declarations to react-i18next compatible JSON format
|
|
104
72
|
|
|
105
|
-
|
|
106
|
-
- **react-intlayer** – React-specific integration for Intlayer, providing notably some script to automate the build of dictionaries.
|
|
107
|
-
- **react-i18next** – React-specific integration library for i18next, including the `useTranslation` hook.
|
|
108
|
-
- **i18next** – The underlying framework for translation handling.
|
|
109
|
-
- **i18next-resources-to-backend** – An i18next backend that dynamically imports JSON resources.
|
|
110
|
-
- **@intlayer/sync-json-plugin** – A plugin for Intlayer that syncs JSON files to dictionaries.
|
|
73
|
+
### Step 2: Implement the Intlayer plugin to wrap the JSON
|
|
111
74
|
|
|
112
|
-
|
|
75
|
+
Create an Intlayer configuration file to define your supported locales:
|
|
113
76
|
|
|
114
|
-
|
|
77
|
+
**If you want to also export JSON dictionaries for react-i18next**, add the `syncJSON` plugin:
|
|
115
78
|
|
|
116
|
-
```typescript
|
|
79
|
+
```typescript fileName="intlayer.config.ts"
|
|
117
80
|
import { Locales, type IntlayerConfig } from "intlayer";
|
|
81
|
+
import { syncJSON } from "@intlayer/sync-json-plugin";
|
|
118
82
|
|
|
119
83
|
const config: IntlayerConfig = {
|
|
120
84
|
internationalization: {
|
|
121
|
-
// Add as many locales as you wish
|
|
122
85
|
locales: [Locales.ENGLISH, Locales.FRENCH, Locales.SPANISH],
|
|
123
86
|
defaultLocale: Locales.ENGLISH,
|
|
124
87
|
},
|
|
125
88
|
plugins: [
|
|
126
89
|
syncJSON({
|
|
127
|
-
source: ({ key, locale }) => `./
|
|
90
|
+
source: ({ key, locale }) => `./messages/${locale}/${key}.json`,
|
|
128
91
|
}),
|
|
129
92
|
],
|
|
130
93
|
};
|
|
@@ -132,221 +95,30 @@ const config: IntlayerConfig = {
|
|
|
132
95
|
export default config;
|
|
133
96
|
```
|
|
134
97
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
## Building the i18next Resources
|
|
138
|
-
|
|
139
|
-
Once your content declarations are in place (next section), run the **Intlayer build command**:
|
|
140
|
-
|
|
141
|
-
```bash
|
|
142
|
-
# With npm
|
|
143
|
-
npx run intlayer build
|
|
144
|
-
```
|
|
145
|
-
|
|
146
|
-
```bash
|
|
147
|
-
# With yarn
|
|
148
|
-
yarn intlayer build
|
|
149
|
-
```
|
|
150
|
-
|
|
151
|
-
```bash
|
|
152
|
-
# With pnpm
|
|
153
|
-
pnpm intlayer build
|
|
154
|
-
```
|
|
155
|
-
|
|
156
|
-
> This will generate your i18next resources inside the `./i18next/resources` directory by default.
|
|
157
|
-
|
|
158
|
-
A typical output might look like this:
|
|
159
|
-
|
|
160
|
-
```bash
|
|
161
|
-
.
|
|
162
|
-
└── i18next
|
|
163
|
-
└── resources
|
|
164
|
-
├── en
|
|
165
|
-
│ └── my-content.json
|
|
166
|
-
├── fr
|
|
167
|
-
│ └── my-content.json
|
|
168
|
-
└── es
|
|
169
|
-
└── my-content.json
|
|
170
|
-
```
|
|
171
|
-
|
|
172
|
-
Where each **Intlayer** declaration key is used as an **i18next namespace** (e.g., `my-content.json`).
|
|
173
|
-
|
|
174
|
-
## Importing Dictionaries into Your react-i18next Configuration
|
|
175
|
-
|
|
176
|
-
To dynamically load these resources at runtime, use [`i18next-resources-to-backend`](https://www.npmjs.com/package/i18next-resources-to-backend). For instance, create an `i18n.ts` (or `.js`) file in your project:
|
|
177
|
-
|
|
178
|
-
```typescript title="i18n.ts"
|
|
179
|
-
import i18next from "i18next";
|
|
180
|
-
import { initReactI18next } from "react-i18next";
|
|
181
|
-
import resourcesToBackend from "i18next-resources-to-backend";
|
|
182
|
-
|
|
183
|
-
i18next
|
|
184
|
-
// react-i18next plugin
|
|
185
|
-
.use(initReactI18next)
|
|
186
|
-
// dynamically load resources
|
|
187
|
-
.use(
|
|
188
|
-
resourcesToBackend((language: string, namespace: string) => {
|
|
189
|
-
// Adjust the import path to your resources directory
|
|
190
|
-
return import(`../i18next/resources/${language}/${namespace}.json`);
|
|
191
|
-
})
|
|
192
|
-
)
|
|
193
|
-
// Initialize i18next
|
|
194
|
-
.init({
|
|
195
|
-
// Fallback locale
|
|
196
|
-
fallbackLng: "en",
|
|
197
|
-
|
|
198
|
-
// You can add other i18next config options here, see:
|
|
199
|
-
// https://www.i18next.com/overview/configuration-options
|
|
200
|
-
});
|
|
201
|
-
|
|
202
|
-
export default i18next;
|
|
203
|
-
```
|
|
204
|
-
|
|
205
|
-
```javascript title="i18n.js"
|
|
206
|
-
import i18next from "i18next";
|
|
207
|
-
import { initReactI18next } from "react-i18next";
|
|
208
|
-
import resourcesToBackend from "i18next-resources-to-backend";
|
|
209
|
-
|
|
210
|
-
i18next
|
|
211
|
-
.use(initReactI18next)
|
|
212
|
-
.use(
|
|
213
|
-
resourcesToBackend(
|
|
214
|
-
(language, namespace) =>
|
|
215
|
-
import(`../i18next/resources/${language}/${namespace}.json`)
|
|
216
|
-
)
|
|
217
|
-
)
|
|
218
|
-
.init({
|
|
219
|
-
fallbackLng: "en",
|
|
220
|
-
});
|
|
221
|
-
|
|
222
|
-
export default i18next;
|
|
223
|
-
```
|
|
224
|
-
|
|
225
|
-
Then, in your **root** or **index** file (e.g., `src/index.tsx`), import this `i18n` setup **before** rendering the `App`:
|
|
226
|
-
|
|
227
|
-
```typescript
|
|
228
|
-
import React from "react";
|
|
229
|
-
import ReactDOM from "react-dom/client";
|
|
230
|
-
// Initialize i18n before anything else
|
|
231
|
-
import "./i18n";
|
|
232
|
-
import App from "./App";
|
|
233
|
-
|
|
234
|
-
ReactDOM.createRoot(document.getElementById("root") as HTMLElement).render(
|
|
235
|
-
<React.StrictMode>
|
|
236
|
-
<App />
|
|
237
|
-
</React.StrictMode>
|
|
238
|
-
);
|
|
239
|
-
```
|
|
240
|
-
|
|
241
|
-
## Creating and Managing Your Dictionarys
|
|
242
|
-
|
|
243
|
-
Intlayer extracts translations from “content declaration files” located anywhere under `./src` (by default).
|
|
244
|
-
Here’s a minimal example in TypeScript:
|
|
245
|
-
|
|
246
|
-
```typescript title="src/components/MyComponent/MyComponent.content.ts"
|
|
247
|
-
import { t, type Dictionary } from "intlayer";
|
|
248
|
-
|
|
249
|
-
const content = {
|
|
250
|
-
// The "key" will be your i18next namespace (e.g., "my-component")
|
|
251
|
-
key: "my-component",
|
|
252
|
-
content: {
|
|
253
|
-
// Each "t" call is a separate translation node
|
|
254
|
-
heading: t({
|
|
255
|
-
en: "Hello World",
|
|
256
|
-
es: "Hola Mundo",
|
|
257
|
-
fr: "Bonjour le monde",
|
|
258
|
-
}),
|
|
259
|
-
description: t({
|
|
260
|
-
en: "My i18n description text...",
|
|
261
|
-
fr: "Ma description en i18n...",
|
|
262
|
-
es: "Mi descripción en i18n...",
|
|
263
|
-
}),
|
|
264
|
-
},
|
|
265
|
-
} satisfies Dictionary;
|
|
266
|
-
|
|
267
|
-
export default content;
|
|
268
|
-
```
|
|
269
|
-
|
|
270
|
-
If you prefer JSON, `.cjs`, or `.mjs`, refer to the [Intlayer docs](https://intlayer.org/en/doc/concept/content).
|
|
271
|
-
|
|
272
|
-
> By default, valid content declarations match the file extension pattern:
|
|
98
|
+
The `syncJSON` plugin will automatically wrap the JSON. It will read and write the JSON files without changing the content architecture.
|
|
273
99
|
|
|
274
|
-
|
|
100
|
+
If you want to make coexist that JSON with intlayer content declaration files (`.content` files), Intlayer will proceed this way:
|
|
275
101
|
|
|
276
|
-
|
|
102
|
+
1. load both JSON and content declaration files and transform them into a intlayer dictionary.
|
|
103
|
+
2. if there is conflicts between the JSON and the content declaration files, Intlayer will process to the merge of that all dictionaries. Depending of the priority of the plugins, and the one of the content declaration file (all are configurable).
|
|
277
104
|
|
|
278
|
-
|
|
279
|
-
For instance:
|
|
105
|
+
If changes are made using the CLI to translate the JSON, or using the CMS, Intlayer will update the JSON file with the new translations.
|
|
280
106
|
|
|
281
|
-
|
|
282
|
-
import type { FC } from "react";
|
|
283
|
-
import { useTranslation } from "react-i18next";
|
|
107
|
+
To see more details about the `syncJSON` plugin, please refer to the [syncJSON plugin documentation](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/plugins/sync-json.md).
|
|
284
108
|
|
|
285
|
-
|
|
286
|
-
* The i18next "namespace" is the Intlayer `key` from "MyComponent.content.ts"
|
|
287
|
-
* so we'll pass "my-component" to useTranslation().
|
|
288
|
-
*/
|
|
289
|
-
const MyComponent: FC = () => {
|
|
290
|
-
const { t } = useTranslation("my-component");
|
|
291
|
-
|
|
292
|
-
return (
|
|
293
|
-
<div>
|
|
294
|
-
<h1>{t("heading")}</h1>
|
|
295
|
-
<p>{t("description")}</p>
|
|
296
|
-
</div>
|
|
297
|
-
);
|
|
298
|
-
};
|
|
299
|
-
|
|
300
|
-
export default MyComponent;
|
|
301
|
-
```
|
|
302
|
-
|
|
303
|
-
> Note that the `t` function references **keys** inside your generated JSON. For an Intlayer content entry named `heading`, you’ll use `t("heading")`.
|
|
304
|
-
|
|
305
|
-
## Optional: Integrate with Create React App Scripts (CRACO)
|
|
306
|
-
|
|
307
|
-
**react-intlayer** provides a CRACO-based approach for custom builds and dev server configuration. If you want Intlayer’s build step integrated seamlessly, you can:
|
|
308
|
-
|
|
309
|
-
1. **Install react-intlayer** (if you haven’t):
|
|
310
|
-
```bash
|
|
311
|
-
npm install react-intlayer --save-dev
|
|
312
|
-
```
|
|
313
|
-
2. **Adjust your `package.json` scripts** to use `react-intlayer` scripts:
|
|
314
|
-
|
|
315
|
-
```jsonc
|
|
316
|
-
"scripts": {
|
|
317
|
-
"start": "react-intlayer start",
|
|
318
|
-
"build": "react-intlayer build",
|
|
319
|
-
"transpile": "intlayer build"
|
|
320
|
-
}
|
|
321
|
-
```
|
|
322
|
-
|
|
323
|
-
> `react-intlayer` scripts are based on [CRACO](https://craco.js.org/). You can also implement your own setup based on the intlayer craco plugin. [See example here](https://github.com/aymericzip/intlayer/blob/main/examples/react-app/craco.config.js).
|
|
324
|
-
|
|
325
|
-
Now, running `npm run build`, `yarn build`, or `pnpm build` triggers both Intlayer and CRA builds.
|
|
326
|
-
|
|
327
|
-
## TypeScript Configuration
|
|
109
|
+
## Git Configuration
|
|
328
110
|
|
|
329
|
-
|
|
111
|
+
It's recommended to ignore auto-generated Intlayer files:
|
|
330
112
|
|
|
331
|
-
```
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
// ...
|
|
335
|
-
},
|
|
336
|
-
"include": ["src", "types"],
|
|
337
|
-
}
|
|
113
|
+
```plaintext fileName=".gitignore"
|
|
114
|
+
# Ignore files generated by Intlayer
|
|
115
|
+
.intlayer
|
|
338
116
|
```
|
|
339
117
|
|
|
340
|
-
|
|
118
|
+
These files can be regenerated during your build process and don't need to be committed to version control.
|
|
341
119
|
|
|
342
|
-
|
|
120
|
+
### VS Code Extension
|
|
343
121
|
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
```plaintext
|
|
347
|
-
# Ignore the files generated by Intlayer
|
|
348
|
-
.intlayer
|
|
349
|
-
i18next
|
|
350
|
-
```
|
|
122
|
+
For improved developer experience, install the official **Intlayer VS Code Extension**:
|
|
351
123
|
|
|
352
|
-
|
|
124
|
+
[Install from the VS Code Marketplace](https://marketplace.visualstudio.com/items?itemName=intlayer.intlayer-vs-code-extension)
|