@intlayer/docs 7.5.9 → 7.5.10
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/README.md +9 -2
- package/dist/cjs/generated/docs.entry.cjs +19 -0
- package/dist/cjs/generated/docs.entry.cjs.map +1 -1
- package/dist/esm/generated/docs.entry.mjs +19 -0
- package/dist/esm/generated/docs.entry.mjs.map +1 -1
- package/dist/types/generated/docs.entry.d.ts +1 -0
- package/dist/types/generated/docs.entry.d.ts.map +1 -1
- package/docs/ar/cli/push.md +1 -1
- package/docs/ar/configuration.md +3 -3
- package/docs/ar/interest_of_intlayer.md +1 -1
- package/docs/ar/intlayer_CMS.md +5 -5
- package/docs/ar/intlayer_with_express.md +1 -0
- package/docs/ar/intlayer_with_fastify.md +516 -0
- package/docs/ar/readme.md +1 -1
- package/docs/de/cli/push.md +1 -1
- package/docs/de/configuration.md +3 -3
- package/docs/de/interest_of_intlayer.md +1 -1
- package/docs/de/intlayer_CMS.md +5 -5
- package/docs/de/intlayer_with_express.md +1 -0
- package/docs/de/intlayer_with_fastify.md +449 -0
- package/docs/de/readme.md +1 -1
- package/docs/en/cli/push.md +1 -1
- package/docs/en/configuration.md +3 -3
- package/docs/en/interest_of_intlayer.md +1 -1
- package/docs/en/intlayer_CMS.md +5 -5
- package/docs/en/intlayer_with_express.md +1 -0
- package/docs/en/intlayer_with_fastify.md +439 -0
- package/docs/en/readme.md +3 -1
- package/docs/en-GB/cli/push.md +1 -1
- package/docs/en-GB/configuration.md +3 -3
- package/docs/en-GB/interest_of_intlayer.md +1 -1
- package/docs/en-GB/intlayer_CMS.md +5 -5
- package/docs/en-GB/intlayer_with_express.md +1 -0
- package/docs/en-GB/intlayer_with_fastify.md +445 -0
- package/docs/en-GB/readme.md +3 -1
- package/docs/es/cli/push.md +1 -1
- package/docs/es/configuration.md +3 -3
- package/docs/es/interest_of_intlayer.md +1 -1
- package/docs/es/intlayer_CMS.md +5 -5
- package/docs/es/intlayer_with_express.md +1 -0
- package/docs/es/intlayer_with_fastify.md +480 -0
- package/docs/es/readme.md +1 -1
- package/docs/fr/cli/push.md +1 -1
- package/docs/fr/configuration.md +3 -3
- package/docs/fr/interest_of_intlayer.md +1 -1
- package/docs/fr/intlayer_CMS.md +5 -5
- package/docs/fr/intlayer_with_express.md +1 -0
- package/docs/fr/intlayer_with_fastify.md +439 -0
- package/docs/fr/readme.md +1 -1
- package/docs/hi/cli/push.md +1 -1
- package/docs/hi/configuration.md +3 -3
- package/docs/hi/interest_of_intlayer.md +1 -1
- package/docs/hi/intlayer_CMS.md +5 -5
- package/docs/hi/intlayer_with_express.md +1 -0
- package/docs/hi/intlayer_with_fastify.md +540 -0
- package/docs/hi/readme.md +1 -1
- package/docs/id/cli/push.md +1 -1
- package/docs/id/configuration.md +3 -3
- package/docs/id/interest_of_intlayer.md +1 -1
- package/docs/id/intlayer_CMS.md +5 -5
- package/docs/id/intlayer_with_express.md +1 -0
- package/docs/id/intlayer_with_fastify.md +470 -0
- package/docs/id/readme.md +1 -1
- package/docs/it/cli/push.md +1 -1
- package/docs/it/configuration.md +3 -3
- package/docs/it/interest_of_intlayer.md +1 -1
- package/docs/it/intlayer_CMS.md +5 -5
- package/docs/it/intlayer_with_express.md +1 -0
- package/docs/it/intlayer_with_fastify.md +445 -0
- package/docs/it/readme.md +1 -1
- package/docs/ja/cli/push.md +1 -1
- package/docs/ja/configuration.md +3 -3
- package/docs/ja/interest_of_intlayer.md +1 -1
- package/docs/ja/intlayer_CMS.md +5 -5
- package/docs/ja/intlayer_with_express.md +1 -0
- package/docs/ja/intlayer_with_fastify.md +516 -0
- package/docs/ja/readme.md +1 -1
- package/docs/ko/cli/push.md +1 -1
- package/docs/ko/configuration.md +3 -3
- package/docs/ko/interest_of_intlayer.md +1 -1
- package/docs/ko/intlayer_CMS.md +5 -5
- package/docs/ko/intlayer_with_express.md +1 -0
- package/docs/ko/intlayer_with_fastify.md +463 -0
- package/docs/ko/readme.md +1 -1
- package/docs/pl/cli/push.md +1 -1
- package/docs/pl/configuration.md +3 -3
- package/docs/pl/interest_of_intlayer.md +1 -1
- package/docs/pl/intlayer_CMS.md +5 -5
- package/docs/pl/intlayer_with_express.md +1 -0
- package/docs/pl/intlayer_with_fastify.md +457 -0
- package/docs/pl/readme.md +1 -1
- package/docs/pt/cli/push.md +1 -1
- package/docs/pt/configuration.md +3 -3
- package/docs/pt/interest_of_intlayer.md +1 -1
- package/docs/pt/intlayer_CMS.md +5 -5
- package/docs/pt/intlayer_with_express.md +1 -0
- package/docs/pt/intlayer_with_fastify.md +502 -0
- package/docs/pt/readme.md +1 -1
- package/docs/ru/cli/push.md +1 -1
- package/docs/ru/configuration.md +3 -3
- package/docs/ru/interest_of_intlayer.md +1 -1
- package/docs/ru/intlayer_CMS.md +5 -5
- package/docs/ru/intlayer_with_express.md +1 -0
- package/docs/ru/intlayer_with_fastify.md +468 -0
- package/docs/ru/readme.md +1 -1
- package/docs/tr/cli/push.md +1 -1
- package/docs/tr/configuration.md +3 -3
- package/docs/tr/interest_of_intlayer.md +1 -1
- package/docs/tr/intlayer_CMS.md +5 -5
- package/docs/tr/intlayer_with_express.md +1 -0
- package/docs/tr/intlayer_with_fastify.md +471 -0
- package/docs/tr/readme.md +1 -1
- package/docs/vi/cli/push.md +1 -1
- package/docs/vi/configuration.md +3 -3
- package/docs/vi/interest_of_intlayer.md +1 -1
- package/docs/vi/intlayer_CMS.md +5 -5
- package/docs/vi/intlayer_with_express.md +1 -0
- package/docs/vi/intlayer_with_fastify.md +490 -0
- package/docs/vi/readme.md +1 -1
- package/docs/zh/cli/push.md +1 -1
- package/docs/zh/configuration.md +3 -3
- package/docs/zh/interest_of_intlayer.md +1 -1
- package/docs/zh/intlayer_CMS.md +5 -5
- package/docs/zh/intlayer_with_express.md +1 -0
- package/docs/zh/intlayer_with_fastify.md +451 -0
- package/docs/zh/readme.md +1 -1
- package/package.json +6 -6
- package/src/generated/docs.entry.ts +19 -0
|
@@ -0,0 +1,502 @@
|
|
|
1
|
+
---
|
|
2
|
+
createdAt: 2025-12-30
|
|
3
|
+
updatedAt: 2025-12-30
|
|
4
|
+
title: Como traduzir seu backend Fastify – guia i18n 2026
|
|
5
|
+
description: Descubra como tornar seu backend Fastify multilíngue. Siga a documentação para internacionalizar (i18n) e traduzir.
|
|
6
|
+
keywords:
|
|
7
|
+
- Internacionalização
|
|
8
|
+
- Documentação
|
|
9
|
+
- Intlayer
|
|
10
|
+
- Fastify
|
|
11
|
+
- JavaScript
|
|
12
|
+
- Backend
|
|
13
|
+
slugs:
|
|
14
|
+
- doc
|
|
15
|
+
- environment
|
|
16
|
+
- fastify
|
|
17
|
+
applicationTemplate: https://github.com/aymericzip/intlayer-fastify-template
|
|
18
|
+
history:
|
|
19
|
+
- version: 7.6.0
|
|
20
|
+
date: 2025-12-31
|
|
21
|
+
changes: Adicionar comando init
|
|
22
|
+
- version: 7.6.0
|
|
23
|
+
date: 2025-12-31
|
|
24
|
+
changes: Histórico inicial
|
|
25
|
+
---
|
|
26
|
+
|
|
27
|
+
# Traduza seu backend Fastify usando o Intlayer | Internacionalização (i18n)
|
|
28
|
+
|
|
29
|
+
`fastify-intlayer` é um plugin poderoso de internacionalização (i18n) para aplicações Fastify, concebido para tornar seus serviços backend acessíveis globalmente, fornecendo respostas localizadas com base nas preferências do cliente.
|
|
30
|
+
|
|
31
|
+
### Casos de uso práticos
|
|
32
|
+
|
|
33
|
+
- **Exibir erros do backend no idioma do usuário**: Quando um erro ocorre, exibir mensagens no idioma nativo do usuário melhora a compreensão e reduz a frustração. Isso é especialmente útil para mensagens de erro dinâmicas que podem ser exibidas em componentes front-end, como toasts ou modals.
|
|
34
|
+
- **Recuperação de Conteúdo Multilíngue**: Para aplicações que extraem conteúdo de um banco de dados, a internacionalização garante que você possa fornecer esse conteúdo em vários idiomas. Isso é crucial para plataformas como sites de e-commerce ou sistemas de gestão de conteúdo que precisam exibir descrições de produtos, artigos e outros conteúdos no idioma preferido pelo usuário.
|
|
35
|
+
- **Envio de E-mails Multilíngues**: Seja para e-mails transacionais, campanhas de marketing ou notificações, enviar e-mails no idioma do destinatário pode aumentar significativamente o engajamento e a eficácia.
|
|
36
|
+
- **Notificações Push Multilíngues**: Para aplicações móveis, enviar notificações push no idioma preferido do usuário pode aumentar a interação e a retenção. Esse toque pessoal pode fazer com que as notificações pareçam mais relevantes e acionáveis.
|
|
37
|
+
- **Outras Comunicações**: Qualquer forma de comunicação proveniente do backend, como mensagens SMS, alertas do sistema ou atualizações da interface do usuário, se beneficia por estar no idioma do usuário, garantindo clareza e melhorando a experiência geral do usuário.
|
|
38
|
+
|
|
39
|
+
Ao internacionalizar o backend, sua aplicação não apenas respeita as diferenças culturais, mas também se alinha melhor às necessidades do mercado global, tornando-se um passo-chave para escalar seus serviços mundialmente.
|
|
40
|
+
|
|
41
|
+
## Primeiros Passos
|
|
42
|
+
|
|
43
|
+
### Instalação
|
|
44
|
+
|
|
45
|
+
Para começar a usar `fastify-intlayer`, instale o pacote usando npm:
|
|
46
|
+
|
|
47
|
+
```bash packageManager="npm"
|
|
48
|
+
npm install intlayer fastify-intlayer
|
|
49
|
+
npx intlayer init
|
|
50
|
+
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
```bash packageManager="pnpm"
|
|
54
|
+
pnpm add intlayer fastify-intlayer
|
|
55
|
+
pnpm intlayer init
|
|
56
|
+
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
```bash packageManager="yarn"
|
|
60
|
+
yarn add intlayer fastify-intlayer
|
|
61
|
+
yarn intlayer init
|
|
62
|
+
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
```bash packageManager="bun"
|
|
66
|
+
bun add intlayer fastify-intlayer
|
|
67
|
+
bunx intlayer init
|
|
68
|
+
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### Configuração
|
|
72
|
+
|
|
73
|
+
Configure as definições de internacionalização criando um `intlayer.config.ts` na raiz do seu projeto:
|
|
74
|
+
|
|
75
|
+
```typescript fileName="intlayer.config.ts" codeFormat="typescript"
|
|
76
|
+
import { Locales, type IntlayerConfig } from "intlayer";
|
|
77
|
+
|
|
78
|
+
const config: IntlayerConfig = {
|
|
79
|
+
internationalization: {
|
|
80
|
+
locales: [
|
|
81
|
+
Locales.ENGLISH,
|
|
82
|
+
Locales.FRENCH,
|
|
83
|
+
Locales.SPANISH_MEXICO,
|
|
84
|
+
Locales.SPANISH_SPAIN,
|
|
85
|
+
],
|
|
86
|
+
defaultLocale: Locales.ENGLISH,
|
|
87
|
+
},
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
export default config;
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
```javascript fileName="intlayer.config.mjs" codeFormat="esm"
|
|
94
|
+
import { Locales } from "intlayer";
|
|
95
|
+
|
|
96
|
+
/** @type {import('intlayer').IntlayerConfig} */
|
|
97
|
+
const config = {
|
|
98
|
+
internationalization: {
|
|
99
|
+
locales: [
|
|
100
|
+
Locales.ENGLISH,
|
|
101
|
+
Locales.FRENCH,
|
|
102
|
+
Locales.SPANISH_MEXICO,
|
|
103
|
+
Locales.SPANISH_SPAIN,
|
|
104
|
+
],
|
|
105
|
+
defaultLocale: Locales.ENGLISH,
|
|
106
|
+
},
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
export default config;
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
```javascript fileName="intlayer.config.cjs" codeFormat="commonjs"
|
|
113
|
+
const { Locales } = require("intlayer");
|
|
114
|
+
|
|
115
|
+
/** @type {import('intlayer').IntlayerConfig} */
|
|
116
|
+
const config = {
|
|
117
|
+
internationalization: {
|
|
118
|
+
locales: [
|
|
119
|
+
Locales.ENGLISH,
|
|
120
|
+
Locales.FRENCH,
|
|
121
|
+
Locales.SPANISH_MEXICO,
|
|
122
|
+
Locales.SPANISH_SPAIN,
|
|
123
|
+
],
|
|
124
|
+
defaultLocale: Locales.ENGLISH,
|
|
125
|
+
},
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
export default config;
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
```javascript fileName="intlayer.config.mjs" codeFormat="esm"
|
|
132
|
+
import { Locales } from "intlayer";
|
|
133
|
+
|
|
134
|
+
/** @type {import('intlayer').IntlayerConfig} */
|
|
135
|
+
const config = {
|
|
136
|
+
internationalization: {
|
|
137
|
+
locales: [
|
|
138
|
+
Locales.ENGLISH,
|
|
139
|
+
Locales.FRENCH,
|
|
140
|
+
Locales.SPANISH_MEXICO,
|
|
141
|
+
Locales.SPANISH_SPAIN,
|
|
142
|
+
],
|
|
143
|
+
defaultLocale: Locales.ENGLISH,
|
|
144
|
+
},
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
export default config;
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
```javascript fileName="intlayer.config.cjs" codeFormat="commonjs"
|
|
151
|
+
const { Locales } = require("intlayer");
|
|
152
|
+
|
|
153
|
+
/** @type {import('intlayer').IntlayerConfig} */
|
|
154
|
+
const config = {
|
|
155
|
+
internationalization: {
|
|
156
|
+
locales: [
|
|
157
|
+
Locales.ENGLISH,
|
|
158
|
+
Locales.FRENCH,
|
|
159
|
+
Locales.SPANISH_MEXICO,
|
|
160
|
+
Locales.SPANISH_SPAIN,
|
|
161
|
+
],
|
|
162
|
+
defaultLocale: Locales.ENGLISH,
|
|
163
|
+
},
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
module.exports = config;
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
### Declare o seu conteúdo
|
|
170
|
+
|
|
171
|
+
Crie e gerencie as suas declarações de conteúdo para armazenar traduções:
|
|
172
|
+
|
|
173
|
+
```typescript fileName="src/index.content.ts" contentDeclarationFormat="typescript"
|
|
174
|
+
import { t, type Dictionary } from "intlayer";
|
|
175
|
+
|
|
176
|
+
const indexContent = {
|
|
177
|
+
key: "index",
|
|
178
|
+
content: {
|
|
179
|
+
exampleOfContent: t({
|
|
180
|
+
pt: "Exemplo de conteúdo retornado em português",
|
|
181
|
+
en: "Example of returned content in English",
|
|
182
|
+
fr: "Exemple de contenu renvoyé en français",
|
|
183
|
+
"es-ES": "Ejemplo de contenido devuelto en español (España)",
|
|
184
|
+
"es-MX": "Ejemplo de contenido devuelto en español (México)",
|
|
185
|
+
}),
|
|
186
|
+
},
|
|
187
|
+
} satisfies Dictionary;
|
|
188
|
+
|
|
189
|
+
export default indexContent;
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
```javascript fileName="src/index.content.mjs" contentDeclarationFormat="esm"
|
|
193
|
+
import { t } from "intlayer";
|
|
194
|
+
|
|
195
|
+
/** @type {import('intlayer').Dictionary} */
|
|
196
|
+
const indexContent = {
|
|
197
|
+
key: "index",
|
|
198
|
+
content: {
|
|
199
|
+
exampleOfContent: t({
|
|
200
|
+
pt: "Exemplo de conteúdo retornado em inglês",
|
|
201
|
+
en: "Example of returned content in English",
|
|
202
|
+
fr: "Exemple de contenu renvoyé en français",
|
|
203
|
+
"es-ES": "Ejemplo de contenido devuelto en español (España)",
|
|
204
|
+
"es-MX": "Ejemplo de contenido devuelto en español (México)",
|
|
205
|
+
}),
|
|
206
|
+
},
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
export default indexContent;
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
```javascript fileName="src/index.content.cjs" contentDeclarationFormat="commonjs"
|
|
213
|
+
const { t } = require("intlayer");
|
|
214
|
+
|
|
215
|
+
/** @type {import('intlayer').Dictionary} */
|
|
216
|
+
const indexContent = {
|
|
217
|
+
key: "index",
|
|
218
|
+
content: {
|
|
219
|
+
exampleOfContent: t({
|
|
220
|
+
pt: "Exemplo de conteúdo retornado em inglês",
|
|
221
|
+
en: "Example of returned content in English",
|
|
222
|
+
fr: "Exemple de contenu renvoyé en français",
|
|
223
|
+
"es-ES": "Ejemplo de contenido devuelto en español (España)",
|
|
224
|
+
"es-MX": "Ejemplo de contenido devuelto en español (México)",
|
|
225
|
+
}),
|
|
226
|
+
},
|
|
227
|
+
};
|
|
228
|
+
|
|
229
|
+
module.exports = indexContent;
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
```javascript fileName="src/index.content.cjs" contentDeclarationFormat="commonjs"
|
|
233
|
+
const { t } = require("intlayer");
|
|
234
|
+
|
|
235
|
+
/** @type {import('intlayer').Dictionary} */
|
|
236
|
+
const indexContent = {
|
|
237
|
+
key: "index",
|
|
238
|
+
content: {
|
|
239
|
+
exampleOfContent: t({
|
|
240
|
+
pt: "Exemplo de conteúdo retornado em português",
|
|
241
|
+
en: "Example of returned content in English",
|
|
242
|
+
fr: "Exemple de contenu renvoyé en français",
|
|
243
|
+
"es-ES": "Ejemplo de contenido devuelto en español (España)",
|
|
244
|
+
"es-MX": "Ejemplo de contenido devuelto en español (México)",
|
|
245
|
+
}),
|
|
246
|
+
},
|
|
247
|
+
};
|
|
248
|
+
|
|
249
|
+
module.exports = indexContent;
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
```json fileName="src/index.content.json" contentDeclarationFormat="json"
|
|
253
|
+
{
|
|
254
|
+
"$schema": "https://intlayer.org/schema.json",
|
|
255
|
+
"key": "index",
|
|
256
|
+
"content": {
|
|
257
|
+
"exampleOfContent": {
|
|
258
|
+
"nodeType": "translation",
|
|
259
|
+
"translation": {
|
|
260
|
+
"pt": "Exemplo de conteúdo retornado em português",
|
|
261
|
+
"en": "Example of returned content in English",
|
|
262
|
+
"fr": "Exemple de contenu renvoyé en français",
|
|
263
|
+
"es-ES": "Ejemplo de contenido devuelto en español (España)",
|
|
264
|
+
"es-MX": "Ejemplo de contenido devuelto en español (México)"
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
> As suas declarações de conteúdo podem ser definidas em qualquer lugar da sua aplicação desde que estejam incluídas no diretório `contentDir` (por padrão, `./src`). E correspondam à extensão de ficheiro de declaração de conteúdo (por padrão, `.content.{json,ts,tsx,js,jsx,mjs,mjx,cjs,cjx}`).
|
|
272
|
+
|
|
273
|
+
> Para mais detalhes, consulte a [documentação de declaração de conteúdo](https://github.com/aymericzip/intlayer/blob/main/docs/docs/pt/dictionary/content_file.md).
|
|
274
|
+
|
|
275
|
+
### Configuração da aplicação Fastify
|
|
276
|
+
|
|
277
|
+
Configure sua aplicação Fastify para usar `fastify-intlayer`:
|
|
278
|
+
|
|
279
|
+
```typescript fileName="src/index.ts" codeFormat="typescript"
|
|
280
|
+
import Fastify from "fastify";
|
|
281
|
+
import { intlayer, t, getDictionary, getIntlayer } from "fastify-intlayer";
|
|
282
|
+
import dictionaryExample from "./index.content";
|
|
283
|
+
|
|
284
|
+
const fastify = Fastify({ logger: true });
|
|
285
|
+
|
|
286
|
+
// Carregar plugin de internacionalização
|
|
287
|
+
await fastify.register(intlayer);
|
|
288
|
+
|
|
289
|
+
// Rotas
|
|
290
|
+
fastify.get("/t_example", async (_req, reply) => {
|
|
291
|
+
return t({
|
|
292
|
+
pt: "Exemplo de conteúdo retornado em inglês",
|
|
293
|
+
en: "Example of returned content in English",
|
|
294
|
+
fr: "Exemple de contenu renvoyé en français",
|
|
295
|
+
"es-ES": "Ejemplo de contenido devuelto en español (España)",
|
|
296
|
+
"es-MX": "Ejemplo de contenido devuelto en español (México)",
|
|
297
|
+
});
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
fastify.get("/getIntlayer_example", async (_req, reply) => {
|
|
301
|
+
return getIntlayer("index").exampleOfContent;
|
|
302
|
+
});
|
|
303
|
+
|
|
304
|
+
fastify.get("/getDictionary_example", async (_req, reply) => {
|
|
305
|
+
return getDictionary(dictionaryExample).exampleOfContent;
|
|
306
|
+
});
|
|
307
|
+
|
|
308
|
+
// Iniciar servidor
|
|
309
|
+
const start = async () => {
|
|
310
|
+
try {
|
|
311
|
+
await fastify.listen({ port: 3000 });
|
|
312
|
+
} catch (err) {
|
|
313
|
+
fastify.log.error(err);
|
|
314
|
+
process.exit(1);
|
|
315
|
+
}
|
|
316
|
+
};
|
|
317
|
+
|
|
318
|
+
start();
|
|
319
|
+
```
|
|
320
|
+
|
|
321
|
+
```javascript fileName="src/index.mjs" codeFormat="esm"
|
|
322
|
+
import Fastify from "fastify";
|
|
323
|
+
import { intlayer, t, getDictionary, getIntlayer } from "fastify-intlayer";
|
|
324
|
+
import dictionaryExample from "./index.content";
|
|
325
|
+
|
|
326
|
+
const fastify = Fastify({ logger: true });
|
|
327
|
+
|
|
328
|
+
// Carregar plugin de internacionalização
|
|
329
|
+
await fastify.register(intlayer);
|
|
330
|
+
|
|
331
|
+
// Rotas
|
|
332
|
+
fastify.get("/t_example", async (_req, reply) => {
|
|
333
|
+
return t({
|
|
334
|
+
en: "Example of returned content in English",
|
|
335
|
+
fr: "Exemple de contenu renvoyé en français",
|
|
336
|
+
"es-ES": "Ejemplo de contenido devuelto en español (España)",
|
|
337
|
+
"es-MX": "Ejemplo de contenido devuelto en español (México)",
|
|
338
|
+
});
|
|
339
|
+
});
|
|
340
|
+
|
|
341
|
+
fastify.get("/getIntlayer_example", async (_req, reply) => {
|
|
342
|
+
return getIntlayer("index").exampleOfContent;
|
|
343
|
+
});
|
|
344
|
+
|
|
345
|
+
fastify.get("/getDictionary_example", async (_req, reply) => {
|
|
346
|
+
return getDictionary(dictionaryExample).exampleOfContent;
|
|
347
|
+
});
|
|
348
|
+
|
|
349
|
+
// Iniciar o servidor
|
|
350
|
+
const start = async () => {
|
|
351
|
+
try {
|
|
352
|
+
await fastify.listen({ port: 3000 });
|
|
353
|
+
} catch (err) {
|
|
354
|
+
fastify.log.error(err);
|
|
355
|
+
process.exit(1);
|
|
356
|
+
}
|
|
357
|
+
};
|
|
358
|
+
|
|
359
|
+
start();
|
|
360
|
+
```
|
|
361
|
+
|
|
362
|
+
```javascript fileName="src/index.cjs" codeFormat="commonjs"
|
|
363
|
+
const Fastify = require("fastify");
|
|
364
|
+
const { intlayer, t, getDictionary, getIntlayer } = require("fastify-intlayer");
|
|
365
|
+
const dictionaryExample = require("./index.content");
|
|
366
|
+
|
|
367
|
+
const fastify = Fastify({ logger: true });
|
|
368
|
+
|
|
369
|
+
// Início do wrapper do servidor para async/await
|
|
370
|
+
const start = async () => {
|
|
371
|
+
try {
|
|
372
|
+
// Carrega o plugin de internacionalização
|
|
373
|
+
await fastify.register(intlayer);
|
|
374
|
+
|
|
375
|
+
// Rotas
|
|
376
|
+
fastify.get("/t_example", async (_req, reply) => {
|
|
377
|
+
return t({
|
|
378
|
+
pt: "Exemplo de conteúdo retornado em inglês",
|
|
379
|
+
en: "Example of returned content in English",
|
|
380
|
+
fr: "Exemple de contenu renvoyé en français",
|
|
381
|
+
"es-ES": "Ejemplo de contenido devuelto en español (España)",
|
|
382
|
+
"es-MX": "Ejemplo de contenido devuelto en español (México)",
|
|
383
|
+
});
|
|
384
|
+
});
|
|
385
|
+
|
|
386
|
+
fastify.get("/getIntlayer_example", async (_req, reply) => {
|
|
387
|
+
return getIntlayer("index").exampleOfContent;
|
|
388
|
+
});
|
|
389
|
+
|
|
390
|
+
fastify.get("/getDictionary_example", async (_req, reply) => {
|
|
391
|
+
return getDictionary(dictionaryExample).exampleOfContent;
|
|
392
|
+
});
|
|
393
|
+
|
|
394
|
+
await fastify.listen({ port: 3000 });
|
|
395
|
+
} catch (err) {
|
|
396
|
+
fastify.log.error(err);
|
|
397
|
+
process.exit(1);
|
|
398
|
+
}
|
|
399
|
+
};
|
|
400
|
+
|
|
401
|
+
start();
|
|
402
|
+
```
|
|
403
|
+
|
|
404
|
+
### Compatibilidade
|
|
405
|
+
|
|
406
|
+
`fastify-intlayer` é totalmente compatível com:
|
|
407
|
+
|
|
408
|
+
- [`react-intlayer`](<https://www.google.com/search?q=%5Bhttps://github.com/aymericzip/intlayer/blob/main/docs/docs/pt/packages/react-intlayer/index.md%5D(https://github.com/aymericzip/intlayer/blob/main/docs/docs/pt/packages/react-intlayer/index.md)>) para aplicações React
|
|
409
|
+
- [`next-intlayer`](<https://www.google.com/search?q=%5Bhttps://github.com/aymericzip/intlayer/blob/main/docs/docs/pt/packages/next-intlayer/index.md%5D(https://github.com/aymericzip/intlayer/blob/main/docs/docs/pt/packages/next-intlayer/index.md)>) para aplicações Next.js
|
|
410
|
+
- [`vite-intlayer`](<https://www.google.com/search?q=%5Bhttps://github.com/aymericzip/intlayer/blob/main/docs/docs/pt/packages/vite-intlayer/index.md%5D(https://github.com/aymericzip/intlayer/blob/main/docs/docs/pt/packages/vite-intlayer/index.md)>) para aplicações Vite
|
|
411
|
+
|
|
412
|
+
Também funciona perfeitamente com qualquer solução de internacionalização em vários ambientes, incluindo navegadores e requisições de API. Você pode customizar o middleware para detectar o locale através de headers ou cookies:
|
|
413
|
+
|
|
414
|
+
```typescript fileName="intlayer.config.ts" codeFormat="typescript"
|
|
415
|
+
import { Locales, type IntlayerConfig } from "intlayer";
|
|
416
|
+
|
|
417
|
+
const config: IntlayerConfig = {
|
|
418
|
+
// ... Outras opções de configuração
|
|
419
|
+
middleware: {
|
|
420
|
+
headerName: "my-locale-header",
|
|
421
|
+
cookieName: "my-locale-cookie",
|
|
422
|
+
},
|
|
423
|
+
};
|
|
424
|
+
|
|
425
|
+
export default config;
|
|
426
|
+
```
|
|
427
|
+
|
|
428
|
+
```javascript fileName="intlayer.config.mjs" codeFormat="esm"
|
|
429
|
+
import { Locales } from "intlayer";
|
|
430
|
+
|
|
431
|
+
/** @type {import('intlayer').IntlayerConfig} */
|
|
432
|
+
const config = {
|
|
433
|
+
// ... Outras opções de configuração
|
|
434
|
+
middleware: {
|
|
435
|
+
headerName: "my-locale-header",
|
|
436
|
+
cookieName: "my-locale-cookie",
|
|
437
|
+
},
|
|
438
|
+
};
|
|
439
|
+
|
|
440
|
+
export default config;
|
|
441
|
+
```
|
|
442
|
+
|
|
443
|
+
```javascript fileName="intlayer.config.cjs" codeFormat="commonjs"
|
|
444
|
+
const { Locales } = require("intlayer");
|
|
445
|
+
|
|
446
|
+
/** @type {import('intlayer').IntlayerConfig} */
|
|
447
|
+
const config = {
|
|
448
|
+
// ... Outras opções de configuração
|
|
449
|
+
middleware: {
|
|
450
|
+
headerName: "my-locale-header",
|
|
451
|
+
cookieName: "my-locale-cookie",
|
|
452
|
+
},
|
|
453
|
+
};
|
|
454
|
+
|
|
455
|
+
module.exports = config;
|
|
456
|
+
```
|
|
457
|
+
|
|
458
|
+
Por padrão, `fastify-intlayer` interpretará o cabeçalho `Accept-Language` para determinar o idioma preferido do cliente.
|
|
459
|
+
|
|
460
|
+
> Para mais informações sobre configuração e tópicos avançados, visite nossa [documentação](https://github.com/aymericzip/intlayer/blob/main/docs/docs/pt/configuration.md).
|
|
461
|
+
|
|
462
|
+
### Configurar TypeScript
|
|
463
|
+
|
|
464
|
+
`fastify-intlayer` aproveita as robustas capacidades do TypeScript para aprimorar o processo de internacionalização. A tipagem estática do TypeScript garante que cada chave de tradução seja considerada, reduzindo o risco de traduções faltantes e melhorando a manutenibilidade.
|
|
465
|
+
|
|
466
|
+
Garanta que os tipos gerados automaticamente (por padrão em ./types/intlayer.d.ts) estejam incluídos no seu arquivo tsconfig.json.
|
|
467
|
+
|
|
468
|
+
```json5 fileName="tsconfig.json"
|
|
469
|
+
{
|
|
470
|
+
// ... Suas configurações TypeScript existentes
|
|
471
|
+
"include": [
|
|
472
|
+
// ... Suas configurações TypeScript existentes
|
|
473
|
+
".intlayer/**/*.ts", // Incluir os tipos gerados automaticamente
|
|
474
|
+
],
|
|
475
|
+
}
|
|
476
|
+
```
|
|
477
|
+
|
|
478
|
+
### Extensão do VS Code
|
|
479
|
+
|
|
480
|
+
Para melhorar sua experiência de desenvolvimento com o Intlayer, você pode instalar a **Extensão Intlayer para VS Code** oficial.
|
|
481
|
+
|
|
482
|
+
[Instalar no VS Code Marketplace](https://marketplace.visualstudio.com/items?itemName=intlayer.intlayer-vs-code-extension)
|
|
483
|
+
|
|
484
|
+
Esta extensão fornece:
|
|
485
|
+
|
|
486
|
+
- **Autocompletar** para chaves de tradução.
|
|
487
|
+
- **Detecção de erros em tempo real** para traduções ausentes.
|
|
488
|
+
- **Visualizações inline** do conteúdo traduzido.
|
|
489
|
+
- **Ações rápidas** para criar e atualizar traduções com facilidade.
|
|
490
|
+
|
|
491
|
+
Para mais detalhes sobre como usar a extensão, consulte a [documentação da Extensão Intlayer para VS Code](https://intlayer.org/doc/vs-code-extension).
|
|
492
|
+
|
|
493
|
+
### Configuração do Git
|
|
494
|
+
|
|
495
|
+
Recomenda-se ignorar os arquivos gerados pelo Intlayer. Isso permite evitar que você os envie (commit) para o seu repositório Git.
|
|
496
|
+
|
|
497
|
+
Para isso, você pode adicionar as seguintes instruções ao seu arquivo `.gitignore`:
|
|
498
|
+
|
|
499
|
+
```plaintext fileName=".gitignore"
|
|
500
|
+
# Ignorar os arquivos gerados pelo Intlayer
|
|
501
|
+
.intlayer
|
|
502
|
+
```
|
package/docs/pt/readme.md
CHANGED
|
@@ -50,7 +50,7 @@ Com **arquivos de conteúdo por localidade**, **autocompletar em TypeScript**, *
|
|
|
50
50
|
| Recurso | Descrição |
|
|
51
51
|
| --------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
52
52
|
| <img src="https://github.com/aymericzip/intlayer/blob/main/docs/assets/frameworks.png?raw=true" alt="Feature" width="700"> | **Suporte Multiplataformas**<br><br>Intlayer é compatível com todos os principais frameworks e bibliotecas, incluindo Next.js, React, Vite, Vue.js, Nuxt, Preact, Express e muito mais. |
|
|
53
|
-
| <img src="https://github.com/aymericzip/intlayer/blob/main/docs/assets/javascript_content_management.
|
|
53
|
+
| <img src="https://github.com/aymericzip/intlayer/blob/main/docs/assets/javascript_content_management.jpg?raw=true" alt="Feature" width="700"> | **Gestão de Conteúdo com JavaScript**<br><br>Aproveite a flexibilidade do JavaScript para definir e gerir o seu conteúdo de forma eficiente. <br><br> - [Declaração de conteúdo](https://intlayer.org/doc/concept/content) |
|
|
54
54
|
| <img src="https://github.com/aymericzip/intlayer/blob/main/docs/assets/per_locale_content_declaration_file.png?raw=true" alt="Feature" width="700"> | **Ficheiro de Declaração de Conteúdo por Localidade**<br><br>Acelere o seu desenvolvimento declarando o seu conteúdo uma única vez, antes da geração automática.<br><br> - [Ficheiro de Declaração de Conteúdo por Localidade](https://intlayer.org/doc/concept/per-locale-file) |
|
|
55
55
|
| <img src="https://github.com/aymericzip/intlayer/blob/main/docs/assets/autocompletion.png?raw=true" alt="Feature" width="700"> | **Ambiente com Tipagem Segura**<br><br>Aproveite o TypeScript para garantir que as suas definições de conteúdo e código estão livres de erros, beneficiando também da autocompletação no IDE.<br><br> - [Configuração do TypeScript](https://intlayer.org/doc/environment/vite-and-react#configure-typescript) |
|
|
56
56
|
| <img src="https://github.com/aymericzip/intlayer/blob/main/docs/assets/config_file.png?raw=true" alt="Feature" width="700"> | **Configuração Simplificada**<br><br>Comece rapidamente com uma configuração mínima. Ajuste facilmente as definições para internacionalização, roteamento, IA, build e manipulação de conteúdo.<br><br> - [Explore a integração com Next.js](https://intlayer.org/doc/environment/nextjs) |
|
package/docs/ru/cli/push.md
CHANGED
|
@@ -23,7 +23,7 @@ slugs:
|
|
|
23
23
|
npx intlayer dictionary push
|
|
24
24
|
```
|
|
25
25
|
|
|
26
|
-
Если установлен [редактор intlayer](https://github.com/aymericzip/intlayer/blob/main/docs/docs/ru/intlayer_visual_editor.md), вы также можете отправлять словари в редактор. Эта команда позволит сделать словари доступными в [редакторе](https://intlayer.org/
|
|
26
|
+
Если установлен [редактор intlayer](https://github.com/aymericzip/intlayer/blob/main/docs/docs/ru/intlayer_visual_editor.md), вы также можете отправлять словари в редактор. Эта команда позволит сделать словари доступными в [редакторе](https://app.intlayer.org/). Таким образом, вы можете делиться своими словарями с командой и редактировать контент без изменения кода вашего приложения.
|
|
27
27
|
|
|
28
28
|
## Псевдонимы:
|
|
29
29
|
|
package/docs/ru/configuration.md
CHANGED
|
@@ -242,14 +242,14 @@ module.exports = config;
|
|
|
242
242
|
- **clientId**:
|
|
243
243
|
- _Тип_: `string` | `undefined`
|
|
244
244
|
- _По умолчанию_: `undefined`
|
|
245
|
-
- _Описание_: clientId и clientSecret позволяют пакетам intlayer аутентифицироваться на сервере с использованием аутентификации oAuth2. Токен доступа используется для аутентификации пользователя, связанного с проектом. Чтобы получить токен доступа, перейдите на https://intlayer.org/
|
|
245
|
+
- _Описание_: clientId и clientSecret позволяют пакетам intlayer аутентифицироваться на сервере с использованием аутентификации oAuth2. Токен доступа используется для аутентификации пользователя, связанного с проектом. Чтобы получить токен доступа, перейдите на https://app.intlayer.org/project и создайте учетную запись.
|
|
246
246
|
- _Пример_: `true`
|
|
247
247
|
- _Примечание_: Важно: clientId и clientSecret должны храниться в секрете и не должны быть доступны публично. Пожалуйста, убедитесь, что они хранятся в безопасном месте, например, в переменных окружения.
|
|
248
248
|
|
|
249
249
|
- **clientSecret**:
|
|
250
250
|
- _Тип_: `string` | `undefined`
|
|
251
251
|
- _По умолчанию_: `undefined`
|
|
252
|
-
- _Описание_: clientId и clientSecret позволяют пакетам intlayer аутентифицироваться на сервере с помощью аутентификации oAuth2. Токен доступа используется для аутентификации пользователя, связанного с проектом. Чтобы получить токен доступа, перейдите на https://intlayer.org/
|
|
252
|
+
- _Описание_: clientId и clientSecret позволяют пакетам intlayer аутентифицироваться на сервере с помощью аутентификации oAuth2. Токен доступа используется для аутентификации пользователя, связанного с проектом. Чтобы получить токен доступа, перейдите на https://app.intlayer.org/project и создайте учетную запись.
|
|
253
253
|
- _Пример_: `true`
|
|
254
254
|
- _Примечание_: Важно: clientId и clientSecret должны храниться в секрете и не должны быть доступны публично. Пожалуйста, храните их в безопасном месте, например, в переменных окружения.
|
|
255
255
|
|
|
@@ -465,7 +465,7 @@ module.exports = config;
|
|
|
465
465
|
|
|
466
466
|
Настройки, управляющие функциями ИИ в Intlayer, включая провайдера, модель и API-ключ.
|
|
467
467
|
|
|
468
|
-
Эта конфигурация является необязательной, если вы зарегистрированы на [Панели управления Intlayer](https://intlayer.org/
|
|
468
|
+
Эта конфигурация является необязательной, если вы зарегистрированы на [Панели управления Intlayer](https://app.intlayer.org/project) с использованием ключа доступа. Intlayer автоматически управляет наиболее эффективным и экономичным решением ИИ для ваших нужд. Использование настроек по умолчанию обеспечивает лучшую долгосрочную поддержку, поскольку Intlayer постоянно обновляется для использования наиболее актуальных моделей.
|
|
469
469
|
|
|
470
470
|
Если вы предпочитаете использовать собственный API-ключ или конкретную модель, вы можете определить свою собственную конфигурацию ИИ.
|
|
471
471
|
Эта конфигурация ИИ будет использоваться глобально во всей вашей среде Intlayer. Команды CLI будут использовать эти настройки по умолчанию для команд (например, `fill`), а также SDK, Визуальный редактор и CMS. Вы можете переопределить эти значения по умолчанию для конкретных случаев использования с помощью параметров команд.
|
|
@@ -228,7 +228,7 @@ const ComponentExample = () => {
|
|
|
228
228
|
| Функция | Описание |
|
|
229
229
|
| ------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
230
230
|
|  | **Поддержка нескольких фреймворков**<br><br>Intlayer совместим со всеми основными фреймворками и библиотеками, включая Next.js, React, Vite, Vue.js, Nuxt, Preact, Express и другие. |
|
|
231
|
-
|  | **Управление контентом на основе JavaScript**<br><br>Используйте гибкость JavaScript для эффективного определения и управления вашим контентом. <br><br> - [Объявление контента](https://intlayer.org/doc/concept/content) |
|
|
232
232
|
|  | **Файл объявления контента для каждого локалитета**<br><br>Ускорьте разработку, объявляя ваш контент один раз, до автоматической генерации.<br><br> - [Файл объявления контента для каждого локалитета](https://intlayer.org/doc/concept/per-locale-file) |
|
|
233
233
|
|  | **Типобезопасная среда**<br><br>Используйте TypeScript, чтобы гарантировать отсутствие ошибок в определениях контента и коде, а также получать преимущества автозаполнения в IDE.<br><br> - [Настройка TypeScript](https://intlayer.org/doc/environment/vite-and-react#configure-typescript) |
|
|
234
234
|
|  | **Упрощённая настройка**<br><br>Быстрый старт с минимальной конфигурацией. Легко настраивайте параметры интернационализации, маршрутизации, ИИ, сборки и обработки контента.<br><br> - [Изучите интеграцию с Next.js](https://intlayer.org/doc/environment/nextjs) |
|
package/docs/ru/intlayer_CMS.md
CHANGED
|
@@ -92,7 +92,7 @@ const config: IntlayerConfig = {
|
|
|
92
92
|
*
|
|
93
93
|
* Для включения редактора требуются client ID и client secret.
|
|
94
94
|
* Они позволяют идентифицировать пользователя, который редактирует контент.
|
|
95
|
-
* Их можно получить, создав нового клиента в Intlayer Dashboard - Projects (https://intlayer.org/
|
|
95
|
+
* Их можно получить, создав нового клиента в Intlayer Dashboard - Projects (https://app.intlayer.org/projects).
|
|
96
96
|
* clientId: process.env.INTLAYER_CLIENT_ID,
|
|
97
97
|
* clientSecret: process.env.INTLAYER_CLIENT_SECRET,
|
|
98
98
|
*/
|
|
@@ -142,7 +142,7 @@ const config = {
|
|
|
142
142
|
*
|
|
143
143
|
* Для включения редактора требуются client ID и client secret.
|
|
144
144
|
* Они позволяют идентифицировать пользователя, который редактирует контент.
|
|
145
|
-
* Их можно получить, создав нового клиента в Intlayer Dashboard - Projects (https://intlayer.org/
|
|
145
|
+
* Их можно получить, создав нового клиента в Intlayer Dashboard - Projects (https://app.intlayer.org/projects).
|
|
146
146
|
* clientId: process.env.INTLAYER_CLIENT_ID,
|
|
147
147
|
* clientSecret: process.env.INTLAYER_CLIENT_SECRET,
|
|
148
148
|
*/
|
|
@@ -192,7 +192,7 @@ const config = {
|
|
|
192
192
|
*
|
|
193
193
|
* Для включения редактора требуются client ID и client secret.
|
|
194
194
|
* Они позволяют идентифицировать пользователя, который редактирует контент.
|
|
195
|
-
* Их можно получить, создав нового клиента в Intlayer Dashboard - Projects (https://intlayer.org/
|
|
195
|
+
* Их можно получить, создав нового клиента в Intlayer Dashboard - Projects (https://app.intlayer.org/projects).
|
|
196
196
|
* clientId: process.env.INTLAYER_CLIENT_ID,
|
|
197
197
|
* clientSecret: process.env.INTLAYER_CLIENT_SECRET,
|
|
198
198
|
*/
|
|
@@ -224,7 +224,7 @@ const config = {
|
|
|
224
224
|
module.exports = config;
|
|
225
225
|
```
|
|
226
226
|
|
|
227
|
-
> Если у вас нет client ID и client secret, вы можете получить их, создав нового клиента в [Intlayer Dashboard - Projects](https://intlayer.org/
|
|
227
|
+
> Если у вас нет client ID и client secret, вы можете получить их, создав нового клиента в [Intlayer Dashboard - Projects](https://app.intlayer.org/projects).
|
|
228
228
|
|
|
229
229
|
> Чтобы увидеть все доступные параметры, обратитесь к [документации по конфигурации](https://github.com/aymericzip/intlayer/blob/main/docs/docs/ru/configuration.md).
|
|
230
230
|
|
|
@@ -264,7 +264,7 @@ npx intlayer dictionary push -d my-first-dictionary-key --env production
|
|
|
264
264
|
|
|
265
265
|
### Редактирование словаря
|
|
266
266
|
|
|
267
|
-
После этого вы сможете просматривать и управлять вашим словарём в [Intlayer CMS](https://intlayer.org/
|
|
267
|
+
После этого вы сможете просматривать и управлять вашим словарём в [Intlayer CMS](https://app.intlayer.org/content).
|
|
268
268
|
|
|
269
269
|
## Живая синхронизация
|
|
270
270
|
|