@intlayer/docs 7.0.4-canary.0 → 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 +36 -1638
- package/blog/en/intlayer_with_next-i18next.md +22 -847
- package/blog/en/intlayer_with_next-intl.md +32 -1053
- package/blog/en/intlayer_with_react-i18next.md +38 -764
- package/blog/en/intlayer_with_react-intl.md +42 -1018
- 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/docs/ar/plugins/sync-json.md +244 -0
- package/docs/de/plugins/sync-json.md +244 -0
- package/docs/en/intlayer_cli.md +25 -0
- package/docs/en/intlayer_with_nextjs_14.md +2 -0
- package/docs/en/intlayer_with_nextjs_15.md +2 -0
- package/docs/en/intlayer_with_nextjs_16.md +2 -0
- package/docs/en/plugins/sync-json.md +1 -1
- package/docs/en-GB/plugins/sync-json.md +244 -0
- package/docs/es/plugins/sync-json.md +244 -0
- package/docs/fr/plugins/sync-json.md +244 -0
- package/docs/hi/plugins/sync-json.md +244 -0
- package/docs/id/plugins/sync-json.md +244 -0
- package/docs/it/plugins/sync-json.md +244 -0
- package/docs/ja/plugins/sync-json.md +244 -0
- package/docs/ko/plugins/sync-json.md +244 -0
- package/docs/pl/plugins/sync-json.md +244 -0
- 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
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
---
|
|
2
2
|
createdAt: 2025-08-23
|
|
3
|
-
updatedAt: 2025-
|
|
3
|
+
updatedAt: 2025-10-29
|
|
4
4
|
title: Intlayer et next-i18next
|
|
5
|
-
description:
|
|
5
|
+
description: Intégrer Intlayer avec next-i18next pour une solution complète d'internationalisation Next.js
|
|
6
6
|
keywords:
|
|
7
7
|
- i18next
|
|
8
8
|
- next-i18next
|
|
@@ -15,353 +15,150 @@ keywords:
|
|
|
15
15
|
slugs:
|
|
16
16
|
- blog
|
|
17
17
|
- intlayer-with-next-i18next
|
|
18
|
+
history:
|
|
19
|
+
- version: 7.0.0
|
|
20
|
+
date: 2025-10-29
|
|
21
|
+
changes: Passage au plugin syncJSON et réécriture complète
|
|
18
22
|
---
|
|
19
23
|
|
|
20
|
-
#
|
|
24
|
+
# Internationalisation (i18n) Next.js avec next-i18next et Intlayer
|
|
21
25
|
|
|
22
|
-
|
|
26
|
+
## Table des matières
|
|
23
27
|
|
|
24
|
-
|
|
28
|
+
<TOC/>
|
|
25
29
|
|
|
26
|
-
|
|
27
|
-
- Nommée `resource` dans le cas de `i18next`, la déclaration de contenu est un objet JSON structuré contenant des paires clé-valeur pour les traductions dans une ou plusieurs langues. Voir [documentation i18next](https://www.i18next.com/translation-function/essentials) pour plus d'informations.
|
|
28
|
-
- Nommée `content declaration file` dans le cas de `Intlayer`, la déclaration de contenu peut être un fichier JSON, JS ou TS exportant les données structurées. Voir [documentation Intlayer](https://github.com/aymericzip/intlayer/blob/main/docs/docs/fr/doc/concept/content) pour plus d'informations.
|
|
30
|
+
## Qu'est-ce que next-i18next ?
|
|
29
31
|
|
|
30
|
-
|
|
32
|
+
**next-i18next** est l’un des frameworks d’internationalisation (i18n) les plus populaires pour les applications Next.js. Construit sur l’écosystème puissant de **i18next**, il offre une solution complète pour gérer les traductions, la localisation et le changement de langue dans les projets Next.js.
|
|
31
33
|
|
|
32
|
-
|
|
34
|
+
Cependant, next-i18next présente certains défis :
|
|
33
35
|
|
|
34
|
-
|
|
36
|
+
- **Configuration complexe** : La mise en place de next-i18next nécessite plusieurs fichiers de configuration et une configuration minutieuse des instances i18n côté serveur et côté client.
|
|
37
|
+
- **Traductions dispersées** : Les fichiers de traduction sont généralement stockés dans des répertoires séparés des composants, ce qui complique le maintien de la cohérence.
|
|
38
|
+
- **Gestion manuelle des namespaces** : Les développeurs doivent gérer manuellement les namespaces et s’assurer du chargement correct des ressources de traduction.
|
|
39
|
+
- **Sécurité de type limitée** : La prise en charge de TypeScript nécessite une configuration supplémentaire et ne fournit pas de génération automatique de types pour les traductions.
|
|
35
40
|
|
|
36
|
-
|
|
41
|
+
## Qu’est-ce qu’Intlayer ?
|
|
37
42
|
|
|
38
|
-
|
|
43
|
+
**Intlayer** est une bibliothèque d’internationalisation innovante et open-source conçue pour pallier les lacunes des solutions i18n traditionnelles. Elle propose une approche moderne de la gestion de contenu dans les applications Next.js.
|
|
39
44
|
|
|
40
|
-
|
|
45
|
+
Consultez une comparaison concrète avec next-intl dans notre article de blog [next-i18next vs. next-intl vs. Intlayer](https://github.com/aymericzip/intlayer/blob/main/docs/blog/fr/next-i18next_vs_next-intl_vs_intlayer.md).
|
|
41
46
|
|
|
42
|
-
|
|
47
|
+
## Pourquoi combiner Intlayer avec next-i18next ?
|
|
43
48
|
|
|
44
|
-
|
|
49
|
+
Bien qu’Intlayer offre une excellente solution i18n autonome (voir notre [guide d’intégration Next.js](https://github.com/aymericzip/intlayer/blob/main/docs/docs/fr/intlayer_with_nextjs_16.md)), vous pourriez vouloir le combiner avec next-i18next pour plusieurs raisons :
|
|
45
50
|
|
|
46
|
-
|
|
51
|
+
1. **Base de code existante** : Vous disposez d’une implémentation next-i18next établie et souhaitez migrer progressivement vers la meilleure expérience développeur d’Intlayer.
|
|
52
|
+
2. **Exigences héritées** : Votre projet nécessite une compatibilité avec les plugins ou workflows i18next existants.
|
|
53
|
+
3. **Familiarité de l’équipe** : Votre équipe est à l’aise avec next-i18next mais souhaite une meilleure gestion du contenu.
|
|
47
54
|
|
|
48
|
-
|
|
49
|
-
.
|
|
50
|
-
└── src
|
|
51
|
-
└── components
|
|
52
|
-
└── MyComponent
|
|
53
|
-
├── index.content.ts # Fichier de déclaration de contenu
|
|
54
|
-
└── index.tsx
|
|
55
|
-
```
|
|
55
|
+
**Pour cela, Intlayer peut être implémenté comme un adaptateur pour next-i18next afin d’automatiser vos traductions JSON dans les pipelines CLI ou CI/CD, de tester vos traductions, et plus encore.**
|
|
56
56
|
|
|
57
|
-
|
|
58
|
-
.
|
|
59
|
-
└── src
|
|
60
|
-
└── components
|
|
61
|
-
└── MyComponent
|
|
62
|
-
├── index.content.mjs # Fichier de déclaration de contenu
|
|
63
|
-
└── index.mjx
|
|
64
|
-
```
|
|
57
|
+
Ce guide vous montre comment tirer parti du système supérieur de déclaration de contenu d’Intlayer tout en maintenant la compatibilité avec next-i18next.
|
|
65
58
|
|
|
66
|
-
|
|
67
|
-
.
|
|
68
|
-
└── src
|
|
69
|
-
└── components
|
|
70
|
-
└── MyComponent
|
|
71
|
-
├── index.content.cjs # Fichier de déclaration de contenu
|
|
72
|
-
└── index.cjx
|
|
73
|
-
```
|
|
59
|
+
---
|
|
74
60
|
|
|
75
|
-
|
|
76
|
-
.
|
|
77
|
-
└── src
|
|
78
|
-
└── components
|
|
79
|
-
└── MyComponent
|
|
80
|
-
├── index.content.json # Fichier de déclaration de contenu
|
|
81
|
-
└── index.jsx
|
|
82
|
-
```
|
|
61
|
+
## Guide étape par étape pour configurer Intlayer avec next-i18next
|
|
83
62
|
|
|
84
|
-
|
|
63
|
+
### Étape 1 : Installer les dépendances
|
|
85
64
|
|
|
86
|
-
|
|
65
|
+
Installez les paquets nécessaires en utilisant votre gestionnaire de paquets préféré :
|
|
87
66
|
|
|
88
67
|
```bash packageManager="npm"
|
|
89
|
-
npm install intlayer
|
|
90
|
-
```
|
|
91
|
-
|
|
92
|
-
```bash packageManager="yarn"
|
|
93
|
-
yarn add intlayer i18next next-i18next i18next-resources-to-backend
|
|
68
|
+
npm install intlayer @intlayer/sync-json-plugin
|
|
94
69
|
```
|
|
95
70
|
|
|
96
71
|
```bash packageManager="pnpm"
|
|
97
|
-
pnpm add intlayer
|
|
72
|
+
pnpm add intlayer @intlayer/sync-json-plugin
|
|
98
73
|
```
|
|
99
74
|
|
|
100
|
-
|
|
75
|
+
```bash packageManager="yarn"
|
|
76
|
+
yarn add intlayer @intlayer/sync-json-plugin
|
|
77
|
+
```
|
|
101
78
|
|
|
102
|
-
|
|
79
|
+
**Explications des paquets :**
|
|
103
80
|
|
|
104
|
-
|
|
81
|
+
- **intlayer** : Bibliothèque principale pour la déclaration et la gestion de contenu
|
|
82
|
+
- **next-intlayer** : Couche d’intégration Next.js avec des plugins de build
|
|
83
|
+
- **i18next** : Framework i18n principal
|
|
84
|
+
- **next-i18next** : Wrapper Next.js pour i18next
|
|
85
|
+
- **i18next-resources-to-backend** : Chargement dynamique des ressources pour i18next
|
|
86
|
+
- **@intlayer/sync-json-plugin** : Plugin pour synchroniser les déclarations de contenu Intlayer au format JSON i18next
|
|
105
87
|
|
|
106
|
-
|
|
107
|
-
import { Locales, type IntlayerConfig } from "intlayer";
|
|
88
|
+
### Étape 2 : Implémenter le plugin Intlayer pour envelopper le JSON
|
|
108
89
|
|
|
109
|
-
|
|
110
|
-
internationalization: {
|
|
111
|
-
locales: [Locales.ENGLISH, Locales.FRENCH, Locales.SPANISH],
|
|
112
|
-
defaultLocale: Locales.ENGLISH,
|
|
113
|
-
},
|
|
114
|
-
content: {
|
|
115
|
-
dictionaryOutput: ["i18next"],
|
|
116
|
-
i18nextResourcesDir: "./i18next/resources",
|
|
117
|
-
},
|
|
118
|
-
};
|
|
90
|
+
Créez un fichier de configuration Intlayer pour définir vos locales supportées :
|
|
119
91
|
|
|
120
|
-
|
|
121
|
-
```
|
|
92
|
+
**Si vous souhaitez également exporter des dictionnaires JSON pour i18next**, ajoutez le plugin `syncJSON` :
|
|
122
93
|
|
|
123
|
-
```
|
|
124
|
-
import { Locales } from "intlayer";
|
|
94
|
+
```typescript fileName="intlayer.config.ts"
|
|
95
|
+
import { Locales, type IntlayerConfig } from "intlayer";
|
|
96
|
+
import { syncJSON } from "@intlayer/sync-json-plugin";
|
|
125
97
|
|
|
126
|
-
|
|
127
|
-
const config = {
|
|
98
|
+
const config: IntlayerConfig = {
|
|
128
99
|
internationalization: {
|
|
129
100
|
locales: [Locales.ENGLISH, Locales.FRENCH, Locales.SPANISH],
|
|
130
101
|
defaultLocale: Locales.ENGLISH,
|
|
131
102
|
},
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
103
|
+
plugins: [
|
|
104
|
+
syncJSON({
|
|
105
|
+
source: ({ key, locale }) => `./messages/${locale}/${key}.json`,
|
|
106
|
+
}),
|
|
107
|
+
],
|
|
136
108
|
};
|
|
137
109
|
|
|
138
110
|
export default config;
|
|
139
111
|
```
|
|
140
112
|
|
|
141
|
-
|
|
142
|
-
const { Locales } = require("intlayer");
|
|
113
|
+
Le plugin `syncJSON` enveloppera automatiquement le JSON. Il lira et écrira les fichiers JSON sans modifier l'architecture du contenu.
|
|
143
114
|
|
|
144
|
-
|
|
145
|
-
const config = {
|
|
146
|
-
internationalization: {
|
|
147
|
-
locales: [Locales.ENGLISH, Locales.FRENCH, Locales.SPANISH],
|
|
148
|
-
defaultLocale: Locales.ENGLISH,
|
|
149
|
-
},
|
|
150
|
-
content: {
|
|
151
|
-
dictionaryOutput: ["i18next"],
|
|
152
|
-
i18nextResourcesDir: "./i18next/resources",
|
|
153
|
-
},
|
|
154
|
-
};
|
|
115
|
+
Si vous souhaitez faire coexister ce JSON avec les fichiers de déclaration de contenu intlayer (`.content`), Intlayer procédera de la manière suivante :
|
|
155
116
|
|
|
156
|
-
|
|
157
|
-
|
|
117
|
+
1. charger à la fois les fichiers JSON et les fichiers de déclaration de contenu et les transformer en un dictionnaire intlayer.
|
|
118
|
+
2. s'il y a des conflits entre les fichiers JSON et les fichiers de déclaration de contenu, Intlayer procédera à la fusion de tous ces dictionnaires. Cela dépendra de la priorité des plugins, ainsi que de celle du fichier de déclaration de contenu (tout est configurable).
|
|
158
119
|
|
|
159
|
-
|
|
120
|
+
Si des modifications sont effectuées via la CLI pour traduire le JSON, ou en utilisant le CMS, Intlayer mettra à jour le fichier JSON avec les nouvelles traductions.
|
|
160
121
|
|
|
161
122
|
---
|
|
162
123
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
Pour importer les ressources générées dans votre configuration i18next, utilisez `i18next-resources-to-backend`. Voici des exemples :
|
|
166
|
-
|
|
167
|
-
```typescript fileName="i18n/client.ts" codeFormat="typescript"
|
|
168
|
-
import i18next from "i18next";
|
|
169
|
-
import resourcesToBackend from "i18next-resources-to-backend";
|
|
170
|
-
|
|
171
|
-
i18next.use(
|
|
172
|
-
resourcesToBackend(
|
|
173
|
-
(language: string, namespace: string) =>
|
|
174
|
-
import(`../i18next/resources/${language}/${namespace}.json`)
|
|
175
|
-
)
|
|
176
|
-
);
|
|
177
|
-
```
|
|
124
|
+
## Configuration Git
|
|
178
125
|
|
|
179
|
-
|
|
180
|
-
import i18next from "i18next";
|
|
181
|
-
import resourcesToBackend from "i18next-resources-to-backend";
|
|
126
|
+
Exclure les fichiers générés du contrôle de version :
|
|
182
127
|
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
)
|
|
188
|
-
);
|
|
128
|
+
```plaintext fileName=".gitignore"
|
|
129
|
+
# Ignorer les fichiers générés par Intlayer
|
|
130
|
+
.intlayer
|
|
131
|
+
intl
|
|
189
132
|
```
|
|
190
133
|
|
|
191
|
-
|
|
192
|
-
const i18next = require("i18next");
|
|
193
|
-
const resourcesToBackend = require("i18next-resources-to-backend");
|
|
194
|
-
|
|
195
|
-
i18next.use(
|
|
196
|
-
resourcesToBackend(
|
|
197
|
-
(language, namespace) =>
|
|
198
|
-
import(`../i18next/resources/${language}/${namespace}.json`)
|
|
199
|
-
)
|
|
200
|
-
);
|
|
201
|
-
```
|
|
134
|
+
Ces fichiers sont automatiquement régénérés lors du processus de build et n'ont pas besoin d'être commités dans votre dépôt.
|
|
202
135
|
|
|
203
|
-
###
|
|
136
|
+
### Extension VS Code
|
|
204
137
|
|
|
205
|
-
|
|
138
|
+
Pour une meilleure expérience développeur, installez l'extension officielle **Intlayer VS Code Extension** :
|
|
206
139
|
|
|
207
|
-
|
|
208
|
-
import { t, type Dictionary } from "intlayer";
|
|
140
|
+
[Installer depuis le Marketplace VS Code](https://marketplace.visualstudio.com/items?itemName=intlayer.intlayer-vs-code-extension)
|
|
209
141
|
|
|
210
|
-
|
|
211
|
-
key: "my-content",
|
|
212
|
-
content: {
|
|
213
|
-
myTranslatedContent: t({
|
|
214
|
-
en: "Hello World",
|
|
215
|
-
es: "Hola Mundo",
|
|
216
|
-
fr: "Bonjour le monde",
|
|
217
|
-
}),
|
|
218
|
-
},
|
|
219
|
-
} satisfies Dictionary;
|
|
142
|
+
2. s'il y a des conflits entre les fichiers JSON et les fichiers de déclaration de contenu, Intlayer procédera à la fusion de tous ces dictionnaires. Cela dépendra de la priorité des plugins, ainsi que de celle du fichier de déclaration de contenu (tout est configurable).
|
|
220
143
|
|
|
221
|
-
|
|
222
|
-
```
|
|
144
|
+
Si des modifications sont effectuées via la CLI pour traduire le JSON, ou en utilisant le CMS, Intlayer mettra à jour le fichier JSON avec les nouvelles traductions.
|
|
223
145
|
|
|
224
|
-
|
|
225
|
-
import { t } from "intlayer";
|
|
226
|
-
|
|
227
|
-
/** @type {import('intlayer').Dictionary} */
|
|
228
|
-
const content = {
|
|
229
|
-
key: "my-content",
|
|
230
|
-
content: {
|
|
231
|
-
myTranslatedContent: t({
|
|
232
|
-
en: "Hello World",
|
|
233
|
-
es: "Hola Mundo",
|
|
234
|
-
fr: "Bonjour le monde",
|
|
235
|
-
}),
|
|
236
|
-
},
|
|
237
|
-
};
|
|
238
|
-
```
|
|
239
|
-
|
|
240
|
-
```javascript fileName="**/*.content.cjs" contentDeclarationFormat="commonjs"
|
|
241
|
-
const { t } = require("intlayer");
|
|
242
|
-
|
|
243
|
-
module.exports = {
|
|
244
|
-
key: "my-content",
|
|
245
|
-
content: {
|
|
246
|
-
myTranslatedContent: t({
|
|
247
|
-
en: "Hello World",
|
|
248
|
-
es: "Hola Mundo",
|
|
249
|
-
fr: "Bonjour le monde",
|
|
250
|
-
}),
|
|
251
|
-
},
|
|
252
|
-
};
|
|
253
|
-
```
|
|
254
|
-
|
|
255
|
-
```json fileName="**/*.content.json" contentDeclarationFormat="json"
|
|
256
|
-
{
|
|
257
|
-
"$schema": "https://intlayer.org/schema.json",
|
|
258
|
-
"key": "my-content",
|
|
259
|
-
"content": {
|
|
260
|
-
"myTranslatedContent": {
|
|
261
|
-
"nodeType": "translation",
|
|
262
|
-
"translation": {
|
|
263
|
-
"en": "Hello World",
|
|
264
|
-
"fr": "Bonjour le monde",
|
|
265
|
-
"es": "Hola Mundo"
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
```
|
|
271
|
-
|
|
272
|
-
### Construire les Ressources next-i18next
|
|
273
|
-
|
|
274
|
-
Pour construire les ressources next-i18next, exécutez la commande suivante :
|
|
275
|
-
|
|
276
|
-
```bash packageManager="npm"
|
|
277
|
-
npx run intlayer build
|
|
278
|
-
```
|
|
279
|
-
|
|
280
|
-
```bash packageManager="yarn"
|
|
281
|
-
yarn intlayer build
|
|
282
|
-
```
|
|
283
|
-
|
|
284
|
-
```bash packageManager="pnpm"
|
|
285
|
-
pnpm intlayer build
|
|
286
|
-
```
|
|
287
|
-
|
|
288
|
-
Cela générera des ressources dans le répertoire `./i18next/resources`. La sortie attendue :
|
|
289
|
-
|
|
290
|
-
```bash
|
|
291
|
-
.
|
|
292
|
-
└── i18next
|
|
293
|
-
└── resources
|
|
294
|
-
└── en
|
|
295
|
-
└── my-content.json
|
|
296
|
-
└── fr
|
|
297
|
-
└── my-content.json
|
|
298
|
-
└── es
|
|
299
|
-
└── my-content.json
|
|
300
|
-
```
|
|
301
|
-
|
|
302
|
-
Remarque : Le namespace i18next correspond à la clé de déclaration d'Intlayer.
|
|
303
|
-
|
|
304
|
-
### Implémenter le Plugin Next.js
|
|
305
|
-
|
|
306
|
-
Une fois configuré, implémentez le plugin Next.js pour reconstruire vos ressources i18next chaque fois que les fichiers de déclaration de contenu Intlayer sont mis à jour.
|
|
307
|
-
|
|
308
|
-
```typescript fileName="next.config.mjs"
|
|
309
|
-
import { withIntlayer } from "next-intlayer/server";
|
|
310
|
-
|
|
311
|
-
/** @type {import('next').NextConfig} */
|
|
312
|
-
const nextConfig = {};
|
|
313
|
-
|
|
314
|
-
export default withIntlayer(nextConfig);
|
|
315
|
-
```
|
|
316
|
-
|
|
317
|
-
### Utiliser le Contenu dans les Composants Next.js
|
|
318
|
-
|
|
319
|
-
Après avoir implémenté le plugin Next.js, vous pouvez utiliser le contenu dans vos composants :
|
|
320
|
-
|
|
321
|
-
```typescript fileName="src/components/myComponent/index.tsx" codeFormat="typescript"
|
|
322
|
-
import type { FC } from "react";
|
|
323
|
-
import { useTranslation } from "react-i18next";
|
|
146
|
+
---
|
|
324
147
|
|
|
325
|
-
|
|
326
|
-
const { t } = useTranslation();
|
|
148
|
+
## Configuration Git
|
|
327
149
|
|
|
328
|
-
|
|
329
|
-
<div>
|
|
330
|
-
<h1>{t("my-content.title")}</h1>
|
|
331
|
-
<p>{t("my-content.description")}</p>
|
|
332
|
-
</div>
|
|
333
|
-
);
|
|
334
|
-
};
|
|
150
|
+
Exclure les fichiers générés du contrôle de version :
|
|
335
151
|
|
|
336
|
-
|
|
152
|
+
```plaintext fileName=".gitignore"
|
|
153
|
+
# Ignorer les fichiers générés par Intlayer
|
|
154
|
+
.intlayer
|
|
155
|
+
intl
|
|
337
156
|
```
|
|
338
157
|
|
|
339
|
-
|
|
340
|
-
import { useTranslation } from "react-i18next";
|
|
158
|
+
Ces fichiers sont automatiquement régénérés lors du processus de build et n'ont pas besoin d'être commités dans votre dépôt.
|
|
341
159
|
|
|
342
|
-
|
|
343
|
-
const { t } = useTranslation();
|
|
160
|
+
### Extension VS Code
|
|
344
161
|
|
|
345
|
-
|
|
346
|
-
<div>
|
|
347
|
-
<h1>{t("my-content.title")}</h1>
|
|
348
|
-
<p>{t("my-content.description")}</p>
|
|
349
|
-
</div>
|
|
350
|
-
);
|
|
351
|
-
};
|
|
352
|
-
```
|
|
162
|
+
Pour une meilleure expérience développeur, installez l'extension officielle **Intlayer VS Code Extension** :
|
|
353
163
|
|
|
354
|
-
|
|
355
|
-
const { useTranslation } = require("react-i18next");
|
|
356
|
-
|
|
357
|
-
const IndexPage = () => {
|
|
358
|
-
const { t } = useTranslation();
|
|
359
|
-
|
|
360
|
-
return (
|
|
361
|
-
<div>
|
|
362
|
-
<h1>{t("my-content.title")}</h1>
|
|
363
|
-
<p>{t("my-content.description")}</p>
|
|
364
|
-
</div>
|
|
365
|
-
);
|
|
366
|
-
};
|
|
367
|
-
```
|
|
164
|
+
[Installer depuis le Marketplace VS Code](https://marketplace.visualstudio.com/items?itemName=intlayer.intlayer-vs-code-extension)
|