@intlayer/docs 7.0.4-canary.0 → 7.0.5
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,310 +1,111 @@
|
|
|
1
1
|
---
|
|
2
2
|
createdAt: 2025-01-02
|
|
3
|
-
updatedAt: 2025-
|
|
4
|
-
title:
|
|
5
|
-
description:
|
|
6
|
-
keywords:
|
|
7
|
-
- next-intl
|
|
8
|
-
- Intlayer
|
|
9
|
-
- Internacionalização
|
|
10
|
-
- Blogumentação
|
|
11
|
-
- Next.js
|
|
12
|
-
- JavaScript
|
|
13
|
-
- React
|
|
3
|
+
updatedAt: 2025-10-29
|
|
4
|
+
title: Como automatizar suas traduções JSON do next-intl usando Intlayer
|
|
5
|
+
description: Automatize suas traduções JSON com Intlayer e next-intl para uma internacionalização aprimorada em aplicações Next.js.
|
|
14
6
|
slugs:
|
|
15
7
|
- blog
|
|
16
8
|
- intlayer-with-next-intl
|
|
9
|
+
history:
|
|
10
|
+
- version: 7.0.0
|
|
11
|
+
date: 2025-10-29
|
|
12
|
+
changes: Alteração para o plugin syncJSON
|
|
17
13
|
---
|
|
18
14
|
|
|
19
|
-
#
|
|
15
|
+
# Como automatizar suas traduções JSON do next-intl usando Intlayer
|
|
20
16
|
|
|
21
|
-
|
|
17
|
+
## O que é o Intlayer?
|
|
22
18
|
|
|
23
|
-
|
|
19
|
+
**Intlayer** é uma biblioteca inovadora e de código aberto para internacionalização, projetada para resolver as limitações das soluções tradicionais de i18n. Ela oferece uma abordagem moderna para o gerenciamento de conteúdo em aplicações Next.js.
|
|
24
20
|
|
|
25
|
-
|
|
26
|
-
- Chamado de `arquivo de declaração de conteúdo` no Intlayer, que pode ser um arquivo JSON, JS ou TS exportando os dados estruturados. Veja [documentação do Intlayer](https://github.com/aymericzip/intlayer/blob/main/docs/docs/pt/doc/concept/content) para mais informações.
|
|
27
|
-
- Chamado de `messages` ou `locale messages` no next-intl, geralmente em arquivos JSON. Veja [documentação do next-intl](https://github.com/amannn/next-intl) para mais informações.
|
|
21
|
+
Veja uma comparação concreta com next-intl em nosso post no blog [next-i18next vs. next-intl vs. Intlayer](https://github.com/aymericzip/intlayer/blob/main/docs/blog/pt/next-i18next_vs_next-intl_vs_intlayer.md).
|
|
28
22
|
|
|
29
|
-
|
|
23
|
+
## Por que combinar Intlayer com next-intl?
|
|
30
24
|
|
|
31
|
-
|
|
25
|
+
Embora o Intlayer forneça uma excelente solução de i18n independente (veja nosso [guia de integração com Next.js](https://github.com/aymericzip/intlayer/blob/main/docs/docs/pt/intlayer_with_nextjs_16.md)), você pode querer combiná-lo com o next-intl por várias razões:
|
|
32
26
|
|
|
33
|
-
|
|
27
|
+
1. **Base de código existente**: Você tem uma implementação estabelecida do next-intl e deseja migrar gradualmente para a melhor experiência de desenvolvedor do Intlayer.
|
|
28
|
+
2. **Requisitos legados**: Seu projeto requer compatibilidade com plugins ou fluxos de trabalho existentes do next-intl.
|
|
29
|
+
3. **Familiaridade da equipe**: Sua equipe está confortável com o next-intl, mas deseja um melhor gerenciamento de conteúdo.
|
|
34
30
|
|
|
35
|
-
Para
|
|
31
|
+
**Para isso, o Intlayer pode ser implementado como um adaptador para o next-intl para ajudar a automatizar suas traduções JSON em pipelines CLI ou CI/CD, testar suas traduções e muito mais.**
|
|
36
32
|
|
|
37
|
-
|
|
33
|
+
Este guia mostra como aproveitar o sistema superior de declaração de conteúdo do Intlayer enquanto mantém a compatibilidade com o next-intl.
|
|
38
34
|
|
|
39
|
-
|
|
35
|
+
## Índice
|
|
40
36
|
|
|
41
|
-
|
|
37
|
+
<TOC/>
|
|
42
38
|
|
|
43
|
-
|
|
39
|
+
## Guia passo a passo para configurar o Intlayer com next-intl
|
|
44
40
|
|
|
45
|
-
|
|
41
|
+
### Passo 1: Instalar dependências
|
|
46
42
|
|
|
47
|
-
|
|
48
|
-
.
|
|
49
|
-
└── src
|
|
50
|
-
└── components
|
|
51
|
-
└── MyComponent
|
|
52
|
-
├── index.content.ts # Arquivo de declaração de conteúdo
|
|
53
|
-
└── index.tsx
|
|
54
|
-
```
|
|
55
|
-
|
|
56
|
-
```bash codeFormat="esm"
|
|
57
|
-
.
|
|
58
|
-
└── src
|
|
59
|
-
└── components
|
|
60
|
-
└── MyComponent
|
|
61
|
-
├── index.content.mjs # Arquivo de declaração de conteúdo
|
|
62
|
-
└── index.mjx
|
|
63
|
-
```
|
|
64
|
-
|
|
65
|
-
```bash codeFormat="cjs"
|
|
66
|
-
.
|
|
67
|
-
└── src
|
|
68
|
-
└── components
|
|
69
|
-
└── MyComponent
|
|
70
|
-
├── index.content.cjs # Arquivo de declaração de conteúdo
|
|
71
|
-
└── index.cjx
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
```bash codeFormat="json"
|
|
75
|
-
.
|
|
76
|
-
└── src
|
|
77
|
-
└── components
|
|
78
|
-
└── MyComponent
|
|
79
|
-
├── index.content.json # Arquivo de declaração de conteúdo
|
|
80
|
-
└── index.jsx
|
|
81
|
-
```
|
|
82
|
-
|
|
83
|
-
2. **Traduções Centralizadas**: O Intlayer armazena todas as traduções em uma única declaração de conteúdo, garantindo que nenhuma tradução esteja faltando. Em projetos TypeScript, traduções ausentes são sinalizadas automaticamente como erros de tipo, fornecendo feedback imediato aos desenvolvedores.
|
|
84
|
-
|
|
85
|
-
### Instalação
|
|
86
|
-
|
|
87
|
-
Para usar o Intlayer e o next-intl juntos, instale ambas as bibliotecas:
|
|
43
|
+
Instale os pacotes necessários:
|
|
88
44
|
|
|
89
45
|
```bash packageManager="npm"
|
|
90
|
-
npm install intlayer
|
|
46
|
+
npm install intlayer @intlayer/sync-json-plugin
|
|
91
47
|
```
|
|
92
48
|
|
|
93
|
-
```bash packageManager="
|
|
94
|
-
|
|
49
|
+
```bash packageManager="pnpm"
|
|
50
|
+
pnpm add intlayer @intlayer/sync-json-plugin
|
|
95
51
|
```
|
|
96
52
|
|
|
97
|
-
```bash packageManager="
|
|
98
|
-
|
|
53
|
+
```bash packageManager="yarn"
|
|
54
|
+
yarn add intlayer @intlayer/sync-json-plugin
|
|
99
55
|
```
|
|
100
56
|
|
|
101
|
-
|
|
57
|
+
**Descrição dos pacotes:**
|
|
102
58
|
|
|
103
|
-
|
|
59
|
+
- **intlayer**: Biblioteca principal para gerenciamento de internacionalização, declaração de conteúdo e construção
|
|
60
|
+
- **@intlayer/sync-json-plugin**: Plugin para exportar declarações de conteúdo do Intlayer para o formato JSON compatível com next-intl
|
|
104
61
|
|
|
105
|
-
|
|
62
|
+
### Passo 2: Implementar o plugin Intlayer para encapsular o JSON
|
|
106
63
|
|
|
107
|
-
|
|
108
|
-
import { Locales, type IntlayerConfig } from "intlayer";
|
|
64
|
+
Crie um arquivo de configuração do Intlayer para definir os locais suportados:
|
|
109
65
|
|
|
110
|
-
|
|
111
|
-
internationalization: {
|
|
112
|
-
locales: [Locales.ENGLISH, Locales.FRENCH, Locales.SPANISH],
|
|
113
|
-
defaultLocale: Locales.ENGLISH,
|
|
114
|
-
},
|
|
115
|
-
content: {
|
|
116
|
-
dictionaryOutput: ["next-intl"], // Usar a saída do next-intl
|
|
117
|
-
nextIntlMessagesDir: "./intl/messages", // Onde salvar mensagens next-intl
|
|
118
|
-
},
|
|
119
|
-
};
|
|
66
|
+
**Se você também quiser exportar dicionários JSON para o next-intl**, adicione o plugin `syncJSON`:
|
|
120
67
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
```javascript fileName="intlayer.config.mjs" codeFormat="esm"
|
|
125
|
-
import { Locales } from "intlayer";
|
|
126
|
-
|
|
127
|
-
/** @type {import('intlayer').IntlayerConfig} */
|
|
128
|
-
const config = {
|
|
129
|
-
internationalization: {
|
|
130
|
-
locales: [Locales.ENGLISH, Locales.FRENCH, Locales.SPANISH],
|
|
131
|
-
defaultLocale: Locales.ENGLISH,
|
|
132
|
-
},
|
|
133
|
-
content: {
|
|
134
|
-
dictionaryOutput: ["react-intl"],
|
|
135
|
-
nextIntlMessagesDir: "./intl/messages",
|
|
136
|
-
},
|
|
137
|
-
};
|
|
138
|
-
|
|
139
|
-
export default config;
|
|
140
|
-
```
|
|
141
|
-
|
|
142
|
-
```javascript fileName="intlayer.config.cjs" codeFormat="commonjs"
|
|
143
|
-
const { Locales } = require("intlayer");
|
|
68
|
+
```typescript fileName="intlayer.config.ts"
|
|
69
|
+
import { Locales, type IntlayerConfig } from "intlayer";
|
|
70
|
+
import { syncJSON } from "@intlayer/sync-json-plugin";
|
|
144
71
|
|
|
145
|
-
|
|
146
|
-
const config = {
|
|
72
|
+
const config: IntlayerConfig = {
|
|
147
73
|
internationalization: {
|
|
148
74
|
locales: [Locales.ENGLISH, Locales.FRENCH, Locales.SPANISH],
|
|
149
75
|
defaultLocale: Locales.ENGLISH,
|
|
150
76
|
},
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
},
|
|
155
|
-
};
|
|
156
|
-
|
|
157
|
-
module.exports = config;
|
|
158
|
-
```
|
|
159
|
-
|
|
160
|
-
### Declaração de Conteúdo
|
|
161
|
-
|
|
162
|
-
Abaixo estão exemplos de arquivos de declaração de conteúdo em múltiplos formatos. O Intlayer compilará isso em arquivos de mensagem que o next-intl pode consumir.
|
|
163
|
-
|
|
164
|
-
```typescript fileName="**/*.content.ts" contentDeclarationFormat="typescript"
|
|
165
|
-
import { t, type Dictionary } from "intlayer";
|
|
166
|
-
|
|
167
|
-
const content = {
|
|
168
|
-
key: "my-component",
|
|
169
|
-
content: {
|
|
170
|
-
helloWorld: t({
|
|
171
|
-
en: "Hello World",
|
|
172
|
-
es: "Hola Mundo",
|
|
173
|
-
fr: "Bonjour le monde",
|
|
174
|
-
}),
|
|
175
|
-
},
|
|
176
|
-
} satisfies Dictionary;
|
|
177
|
-
|
|
178
|
-
export default content;
|
|
179
|
-
```
|
|
180
|
-
|
|
181
|
-
```javascript fileName="**/*.content.mjs" contentDeclarationFormat="esm"
|
|
182
|
-
import { t } from "intlayer";
|
|
183
|
-
|
|
184
|
-
/** @type {import('intlayer').Dictionary} */
|
|
185
|
-
const content = {
|
|
186
|
-
key: "my-component",
|
|
187
|
-
content: {
|
|
188
|
-
helloWorld: t({
|
|
189
|
-
en: "Hello World",
|
|
190
|
-
es: "Hola Mundo",
|
|
191
|
-
fr: "Bonjour le monde",
|
|
77
|
+
plugins: [
|
|
78
|
+
syncJSON({
|
|
79
|
+
source: ({ key, locale }) => `./messages/${locale}/${key}.json`,
|
|
192
80
|
}),
|
|
193
|
-
|
|
81
|
+
],
|
|
194
82
|
};
|
|
195
83
|
|
|
196
|
-
export default
|
|
197
|
-
```
|
|
198
|
-
|
|
199
|
-
```javascript fileName="**/*.content.cjs" contentDeclarationFormat="commonjs"
|
|
200
|
-
const { t } = require("intlayer");
|
|
201
|
-
|
|
202
|
-
module.exports = {
|
|
203
|
-
key: "my-component",
|
|
204
|
-
content: {
|
|
205
|
-
helloWorld: t({
|
|
206
|
-
en: "Hello World",
|
|
207
|
-
es: "Hola Mundo",
|
|
208
|
-
fr: "Bonjour le monde",
|
|
209
|
-
}),
|
|
210
|
-
},
|
|
211
|
-
};
|
|
84
|
+
export default config;
|
|
212
85
|
```
|
|
213
86
|
|
|
214
|
-
|
|
215
|
-
{
|
|
216
|
-
"$schema": "https://intlayer.org/schema.json",
|
|
217
|
-
"key": "my-component",
|
|
218
|
-
"content": {
|
|
219
|
-
"helloWorld": {
|
|
220
|
-
"nodeType": "translation",
|
|
221
|
-
"translation": {
|
|
222
|
-
"en": "Hello World",
|
|
223
|
-
"fr": "Bonjour le monde",
|
|
224
|
-
"es": "Hola Mundo"
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
```
|
|
87
|
+
O plugin `syncJSON` irá automaticamente encapsular o JSON. Ele irá ler e escrever os arquivos JSON sem alterar a arquitetura do conteúdo.
|
|
230
88
|
|
|
231
|
-
|
|
89
|
+
Se você quiser fazer coexistir esse JSON com arquivos de declaração de conteúdo do intlayer (`.content` files), o Intlayer procederá da seguinte forma:
|
|
232
90
|
|
|
233
|
-
|
|
91
|
+
1. carregar tanto os arquivos JSON quanto os arquivos de declaração de conteúdo e transformá-los em um dicionário do intlayer.
|
|
92
|
+
2. se houver conflitos entre o JSON e os arquivos de declaração de conteúdo, o Intlayer irá proceder à mesclagem de todos esses dicionários. Dependendo da prioridade dos plugins e da do arquivo de declaração de conteúdo (todos são configuráveis).
|
|
234
93
|
|
|
235
|
-
|
|
236
|
-
npx intlayer dictionaries build
|
|
237
|
-
```
|
|
94
|
+
Se alterações forem feitas usando o CLI para traduzir o JSON, ou usando o CMS, o Intlayer atualizará o arquivo JSON com as novas traduções.
|
|
238
95
|
|
|
239
|
-
|
|
240
|
-
yarn intlayer build
|
|
241
|
-
```
|
|
96
|
+
## Configuração do Git
|
|
242
97
|
|
|
243
|
-
|
|
244
|
-
pnpm intlayer build
|
|
245
|
-
```
|
|
98
|
+
É recomendado ignorar os arquivos gerados automaticamente pelo Intlayer:
|
|
246
99
|
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
.
|
|
251
|
-
└── intl
|
|
252
|
-
└── messages
|
|
253
|
-
└── pt
|
|
254
|
-
└── my-content.json
|
|
255
|
-
└── fr
|
|
256
|
-
└── my-content.json
|
|
257
|
-
└── es
|
|
258
|
-
└── my-content.json
|
|
100
|
+
```plaintext fileName=".gitignore"
|
|
101
|
+
# Ignorar arquivos gerados pelo Intlayer
|
|
102
|
+
.intlayer
|
|
259
103
|
```
|
|
260
104
|
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
### Usando next-intl em Seu App Next.js
|
|
264
|
-
|
|
265
|
-
> Para mais detalhes, veja a [documentação oficial de uso do next-intl](https://github.com/amannn/next-intl#readme).
|
|
266
|
-
|
|
267
|
-
1. **Criar um Middleware (opcional):**
|
|
268
|
-
Se você quiser gerenciar a detecção automática de idioma ou redirecionamento, use o [createMiddleware do next-intl](https://github.com/amannn/next-intl#createMiddleware).
|
|
269
|
-
|
|
270
|
-
```typescript fileName="middleware.ts"
|
|
271
|
-
import createMiddleware from "next-intl/middleware";
|
|
272
|
-
import { NextResponse } from "next/server";
|
|
273
|
-
|
|
274
|
-
export default createMiddleware({
|
|
275
|
-
locales: ["en", "fr", "es"],
|
|
276
|
-
defaultLocale: "en",
|
|
277
|
-
});
|
|
278
|
-
|
|
279
|
-
export const config = {
|
|
280
|
-
matcher: ["/((?!api|_next|.*\\..*).*)"],
|
|
281
|
-
};
|
|
282
|
-
```
|
|
283
|
-
|
|
284
|
-
2. **Criar um `layout.tsx` ou `_app.tsx` para Carregar Mensagens:**
|
|
285
|
-
Se você está usando o App Router (Next.js 13+), crie um layout:
|
|
286
|
-
|
|
287
|
-
```typescript fileName="app/[locale]/layout.tsx"
|
|
288
|
-
import { NextIntlClientProvider } from 'next-intl';
|
|
289
|
-
import { notFound } from 'next/navigation';
|
|
290
|
-
import React, { ReactNode } from 'react';
|
|
105
|
+
Esses arquivos podem ser regenerados durante o processo de build e não precisam ser commitados no controle de versão.
|
|
291
106
|
|
|
107
|
+
### Extensão VS Code
|
|
292
108
|
|
|
293
|
-
|
|
294
|
-
children,
|
|
295
|
-
params
|
|
296
|
-
}: {
|
|
297
|
-
children: ReactNode;
|
|
298
|
-
params: { locale: string };
|
|
299
|
-
}) {
|
|
300
|
-
let messages;
|
|
301
|
-
try {
|
|
302
|
-
messages = (await import(`../../intl/messages/${params.locale}.json`)).default;
|
|
303
|
-
} catch (error) {
|
|
304
|
-
notFound();
|
|
305
|
-
}
|
|
109
|
+
Para melhorar a experiência do desenvolvedor, instale a extensão oficial **Intlayer VS Code Extension**:
|
|
306
110
|
|
|
307
|
-
|
|
308
|
-
<html lang={params.locale}>
|
|
309
|
-
<body>
|
|
310
|
-
```
|
|
111
|
+
[Instalar a partir do Marketplace do VS Code](https://marketplace.visualstudio.com/items?itemName=intlayer.intlayer-vs-code-extension)
|
|
@@ -1,98 +1,124 @@
|
|
|
1
1
|
---
|
|
2
2
|
createdAt: 2025-01-02
|
|
3
|
-
updatedAt: 2025-
|
|
4
|
-
title:
|
|
5
|
-
description:
|
|
3
|
+
updatedAt: 2025-10-29
|
|
4
|
+
title: Como automatizar suas traduções JSON do react-i18next usando Intlayer
|
|
5
|
+
description: Automatize suas traduções JSON com Intlayer e react-i18next para uma internacionalização aprimorada em aplicações React.
|
|
6
6
|
keywords:
|
|
7
7
|
- react-i18next
|
|
8
8
|
- i18next
|
|
9
9
|
- Intlayer
|
|
10
10
|
- Internacionalização
|
|
11
|
-
-
|
|
12
|
-
-
|
|
13
|
-
- JavaScript
|
|
11
|
+
- i18n
|
|
12
|
+
- Blog
|
|
14
13
|
- React
|
|
14
|
+
- JavaScript
|
|
15
|
+
- TypeScript
|
|
16
|
+
- Gestão de Conteúdo
|
|
15
17
|
slugs:
|
|
16
18
|
- blog
|
|
17
19
|
- intlayer-with-react-i18next
|
|
20
|
+
history:
|
|
21
|
+
- version: 7.0.0
|
|
22
|
+
date: 2025-10-29
|
|
23
|
+
changes: Mudança para o plugin syncJSON
|
|
18
24
|
---
|
|
19
25
|
|
|
20
|
-
#
|
|
21
|
-
|
|
22
|
-
##
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
└── src
|
|
57
|
-
└── components
|
|
58
|
-
└── MyComponent
|
|
59
|
-
├── index.content.cjs # Arquivo de declaração de conteúdo
|
|
60
|
-
└── index.cjx
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
```bash codeFormat="json"
|
|
64
|
-
.
|
|
65
|
-
└── src
|
|
66
|
-
└── components
|
|
67
|
-
└── MyComponent
|
|
68
|
-
├── index.content.json # Arquivo de declaração de conteúdo
|
|
69
|
-
└── index.jsx
|
|
70
|
-
```
|
|
71
|
-
|
|
72
|
-
2. **Traduções Centralizadas**
|
|
73
|
-
Um único arquivo de declaração de conteúdo coleta todas as traduções necessárias para um componente, tornando mais fácil identificar traduções ausentes.
|
|
74
|
-
Com TypeScript, você ainda recebe erros em tempo de compilação se traduções estiverem faltando.
|
|
75
|
-
|
|
76
|
-
## Instalação
|
|
77
|
-
|
|
78
|
-
Em um projeto Create React App, instale essas dependências:
|
|
79
|
-
|
|
80
|
-
```bash
|
|
81
|
-
# Com npm
|
|
82
|
-
npm install intlayer react-i18next i18next i18next-resources-to-backend
|
|
26
|
+
# Como automatizar suas traduções JSON do react-i18next usando Intlayer
|
|
27
|
+
|
|
28
|
+
## O que é o Intlayer?
|
|
29
|
+
|
|
30
|
+
**Intlayer** é uma biblioteca inovadora e de código aberto para internacionalização, projetada para resolver as limitações das soluções tradicionais de i18n. Ela oferece uma abordagem moderna para a gestão de conteúdo em aplicações React.
|
|
31
|
+
|
|
32
|
+
Veja uma comparação concreta com react-i18next em nosso post no blog [react-i18next vs. react-intl vs. Intlayer](https://github.com/aymericzip/intlayer/blob/main/docs/blog/pt/react-i18next_vs_react-intl_vs_intlayer.md).
|
|
33
|
+
|
|
34
|
+
## Por que combinar Intlayer com react-i18next?
|
|
35
|
+
|
|
36
|
+
Embora o Intlayer forneça uma excelente solução de i18n independente (veja nosso [guia de integração com React](https://github.com/aymericzip/intlayer/blob/main/docs/docs/pt/intlayer_with_vite+react.md)), você pode querer combiná-lo com react-i18next por vários motivos:
|
|
37
|
+
|
|
38
|
+
1. **Base de código existente**: Você possui uma implementação estabelecida do react-i18next e deseja migrar gradualmente para a melhor experiência de desenvolvedor oferecida pelo Intlayer.
|
|
39
|
+
2. **Requisitos legados**: Seu projeto exige compatibilidade com plugins ou fluxos de trabalho existentes do react-i18next.
|
|
40
|
+
3. **Familiaridade da equipe**: Sua equipe está confortável com o react-i18next, mas deseja uma melhor gestão de conteúdo.
|
|
41
|
+
|
|
42
|
+
**Para isso, o Intlayer pode ser implementado como um adaptador para o react-i18next, ajudando a automatizar suas traduções JSON em pipelines CLI ou CI/CD, testar suas traduções e muito mais.**
|
|
43
|
+
|
|
44
|
+
Este guia mostra como aproveitar o sistema superior de declaração de conteúdo do Intlayer enquanto mantém a compatibilidade com o react-i18next.
|
|
45
|
+
|
|
46
|
+
## Índice
|
|
47
|
+
|
|
48
|
+
<TOC/>
|
|
49
|
+
|
|
50
|
+
## Guia passo a passo para configurar o Intlayer com react-i18next
|
|
51
|
+
|
|
52
|
+
### Passo 1: Instalar Dependências
|
|
53
|
+
|
|
54
|
+
Instale os pacotes necessários:
|
|
55
|
+
|
|
56
|
+
```bash packageManager="npm"
|
|
57
|
+
npm install intlayer @intlayer/sync-json-plugin
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
```bash packageManager="pnpm"
|
|
61
|
+
pnpm add intlayer @intlayer/sync-json-plugin
|
|
83
62
|
```
|
|
84
63
|
|
|
85
|
-
```bash
|
|
86
|
-
|
|
87
|
-
yarn add intlayer react-i18next i18next i18next-resources-to-backend
|
|
64
|
+
```bash packageManager="yarn"
|
|
65
|
+
yarn add intlayer @intlayer/sync-json-plugin
|
|
88
66
|
```
|
|
89
67
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
68
|
+
**Descrição dos pacotes:**
|
|
69
|
+
|
|
70
|
+
- **intlayer**: Biblioteca principal para gerenciamento de internacionalização, declaração de conteúdo e construção
|
|
71
|
+
- **@intlayer/sync-json-plugin**: Plugin para exportar declarações de conteúdo do Intlayer para o formato JSON compatível com react-i18next
|
|
72
|
+
|
|
73
|
+
### Passo 2: Implementar o plugin Intlayer para encapsular o JSON
|
|
74
|
+
|
|
75
|
+
Crie um arquivo de configuração do Intlayer para definir os seus locais suportados:
|
|
76
|
+
|
|
77
|
+
**Se você também quiser exportar dicionários JSON para o react-i18next**, adicione o plugin `syncJSON`:
|
|
78
|
+
|
|
79
|
+
```typescript fileName="intlayer.config.ts"
|
|
80
|
+
import { Locales, type IntlayerConfig } from "intlayer";
|
|
81
|
+
import { syncJSON } from "@intlayer/sync-json-plugin";
|
|
82
|
+
|
|
83
|
+
const config: IntlayerConfig = {
|
|
84
|
+
internationalization: {
|
|
85
|
+
locales: [Locales.ENGLISH, Locales.FRENCH, Locales.SPANISH],
|
|
86
|
+
defaultLocale: Locales.ENGLISH,
|
|
87
|
+
},
|
|
88
|
+
plugins: [
|
|
89
|
+
syncJSON({
|
|
90
|
+
source: ({ key, locale }) => `./messages/${locale}/${key}.json`,
|
|
91
|
+
}),
|
|
92
|
+
],
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
export default config;
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
O plugin `syncJSON` irá automaticamente encapsular o JSON. Ele irá ler e escrever os arquivos JSON sem alterar a arquitetura do conteúdo.
|
|
99
|
+
|
|
100
|
+
Se você quiser fazer coexistir esse JSON com arquivos de declaração de conteúdo do intlayer (`.content` files), o Intlayer procederá da seguinte forma:
|
|
101
|
+
|
|
102
|
+
1. carregar tanto os arquivos JSON quanto os arquivos de declaração de conteúdo e transformá-los em um dicionário intlayer.
|
|
103
|
+
2. se houver conflitos entre o JSON e os arquivos de declaração de conteúdo, o Intlayer irá proceder à mesclagem de todos esses dicionários. Dependendo da prioridade dos plugins e da do arquivo de declaração de conteúdo (todos são configuráveis).
|
|
104
|
+
|
|
105
|
+
Se alterações forem feitas usando o CLI para traduzir o JSON, ou usando o CMS, o Intlayer atualizará o arquivo JSON com as novas traduções.
|
|
106
|
+
|
|
107
|
+
Para ver mais detalhes sobre o plugin `syncJSON`, por favor consulte a [documentação do plugin syncJSON](https://github.com/aymericzip/intlayer/blob/main/docs/docs/pt/plugins/sync-json.md).
|
|
108
|
+
|
|
109
|
+
## Configuração do Git
|
|
110
|
+
|
|
111
|
+
É recomendado ignorar os arquivos gerados automaticamente pelo Intlayer:
|
|
112
|
+
|
|
113
|
+
```plaintext fileName=".gitignore"
|
|
114
|
+
# Ignorar arquivos gerados pelo Intlayer
|
|
115
|
+
.intlayer
|
|
93
116
|
```
|
|
94
117
|
|
|
95
|
-
|
|
118
|
+
Estes arquivos podem ser regenerados durante o seu processo de build e não precisam ser commitados no controle de versão.
|
|
119
|
+
|
|
120
|
+
### Extensão VS Code
|
|
121
|
+
|
|
122
|
+
Para uma melhor experiência de desenvolvimento, instale a **Extensão oficial Intlayer para VS Code**:
|
|
96
123
|
|
|
97
|
-
|
|
98
|
-
- **react-intlayer** –
|
|
124
|
+
[Instalar no VS Code Marketplace](https://marketplace.visualstudio.com/items?itemName=intlayer.intlayer-vs-code-extension)
|