@intlayer/docs 7.5.9 → 7.5.11
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 +57 -0
- package/dist/cjs/generated/docs.entry.cjs.map +1 -1
- package/dist/esm/generated/docs.entry.mjs +57 -0
- package/dist/esm/generated/docs.entry.mjs.map +1 -1
- package/dist/types/generated/docs.entry.d.ts +3 -0
- package/dist/types/generated/docs.entry.d.ts.map +1 -1
- package/docs/ar/cli/ci.md +137 -0
- package/docs/ar/cli/index.md +7 -1
- package/docs/ar/cli/list.md +39 -2
- package/docs/ar/cli/list_projects.md +131 -0
- 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 +25 -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/ci.md +137 -0
- package/docs/de/cli/index.md +7 -1
- package/docs/de/cli/list.md +39 -2
- package/docs/de/cli/list_projects.md +130 -0
- 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 +25 -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/ci.md +137 -0
- package/docs/en/cli/index.md +14 -1
- package/docs/en/cli/list.md +39 -2
- package/docs/en/cli/list_projects.md +128 -0
- package/docs/en/cli/push.md +1 -1
- package/docs/en/configuration.md +3 -3
- package/docs/en/interest_of_intlayer.md +2 -2
- package/docs/en/intlayer_CMS.md +25 -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/ci.md +137 -0
- package/docs/en-GB/cli/index.md +7 -1
- package/docs/en-GB/cli/list.md +39 -2
- package/docs/en-GB/cli/list_projects.md +130 -0
- 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 +25 -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/ci.md +137 -0
- package/docs/es/cli/index.md +7 -1
- package/docs/es/cli/list.md +39 -2
- package/docs/es/cli/list_projects.md +130 -0
- 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 +25 -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/ci.md +137 -0
- package/docs/fr/cli/index.md +7 -1
- package/docs/fr/cli/list.md +39 -2
- package/docs/fr/cli/list_projects.md +131 -0
- 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 +25 -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/ci.md +137 -0
- package/docs/hi/cli/index.md +7 -1
- package/docs/hi/cli/list.md +38 -1
- package/docs/hi/cli/list_projects.md +130 -0
- 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 +25 -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/ci.md +137 -0
- package/docs/id/cli/index.md +7 -1
- package/docs/id/cli/list.md +38 -1
- package/docs/id/cli/list_projects.md +128 -0
- 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 +25 -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/ci.md +137 -0
- package/docs/it/cli/index.md +7 -1
- package/docs/it/cli/list.md +39 -2
- package/docs/it/cli/list_projects.md +130 -0
- 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 +25 -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/ci.md +137 -0
- package/docs/ja/cli/index.md +7 -1
- package/docs/ja/cli/list.md +38 -1
- package/docs/ja/cli/list_projects.md +136 -0
- 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 +25 -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/ci.md +137 -0
- package/docs/ko/cli/index.md +7 -1
- package/docs/ko/cli/list.md +38 -1
- package/docs/ko/cli/list_projects.md +128 -0
- 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 +25 -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/ci.md +137 -0
- package/docs/pl/cli/index.md +7 -1
- package/docs/pl/cli/list.md +39 -2
- package/docs/pl/cli/list_projects.md +130 -0
- 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 +25 -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/ci.md +137 -0
- package/docs/pt/cli/index.md +7 -1
- package/docs/pt/cli/list.md +39 -2
- package/docs/pt/cli/list_projects.md +134 -0
- 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 +25 -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/ci.md +137 -0
- package/docs/ru/cli/index.md +7 -1
- package/docs/ru/cli/list.md +39 -2
- package/docs/ru/cli/list_projects.md +130 -0
- 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 +25 -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/ci.md +137 -0
- package/docs/tr/cli/index.md +7 -1
- package/docs/tr/cli/list.md +39 -2
- package/docs/tr/cli/list_projects.md +134 -0
- 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 +25 -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/ci.md +137 -0
- package/docs/vi/cli/index.md +7 -1
- package/docs/vi/cli/list.md +38 -1
- package/docs/vi/cli/list_projects.md +130 -0
- 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 +25 -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/ci.md +137 -0
- package/docs/zh/cli/index.md +7 -1
- package/docs/zh/cli/list.md +38 -1
- package/docs/zh/cli/list_projects.md +130 -0
- 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 +25 -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 +57 -0
|
@@ -0,0 +1,445 @@
|
|
|
1
|
+
---
|
|
2
|
+
createdAt: 2025-12-30
|
|
3
|
+
updatedAt: 2025-12-30
|
|
4
|
+
title: How to translate your Fastify back end – i18n guide 2026
|
|
5
|
+
description: Discover how to make your Fastify back end multilingual. Follow the documentation to internationalise (i18n) and translate it.
|
|
6
|
+
keywords:
|
|
7
|
+
- Internationalization
|
|
8
|
+
- Documentation
|
|
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: Add init command
|
|
22
|
+
- version: 7.6.0
|
|
23
|
+
date: 2025-12-31
|
|
24
|
+
changes: Init history
|
|
25
|
+
---
|
|
26
|
+
|
|
27
|
+
# Translate your Fastify back end site using Intlayer | Internationalisation (i18n)
|
|
28
|
+
|
|
29
|
+
`fastify-intlayer` is a powerful internationalisation (i18n) plugin for Fastify applications, designed to make your back end services globally accessible by providing localised responses based on the client's preferences.
|
|
30
|
+
|
|
31
|
+
### Practical Use Cases
|
|
32
|
+
|
|
33
|
+
- **Displaying back end errors in the user's language**: When an error occurs, displaying messages in the user's native language improves understanding and reduces frustration. This is especially useful for dynamic error messages that might be shown in front end components like toasts or modals.
|
|
34
|
+
- **Retrieving multilingual content**: For applications pulling content from a database, internationalisation ensures that you can serve this content in multiple languages. This is crucial for platforms such as e-commerce sites or content management systems that need to display product descriptions, articles, and other content in the language preferred by the user.
|
|
35
|
+
- **Sending multilingual emails**: Whether it's transactional emails, marketing campaigns, or notifications, sending emails in the recipient's language can significantly increase engagement and effectiveness.
|
|
36
|
+
- **Multilingual push notifications**: For mobile applications, sending push notifications in a user's preferred language can enhance interaction and retention. This personal touch can make notifications feel more relevant and actionable.
|
|
37
|
+
- **Other communications**: Any form of communication from the backend, such as SMS messages, system alerts, or user interface updates, benefits from being in the user's language, ensuring clarity and improving the overall user experience.
|
|
38
|
+
|
|
39
|
+
By internationalising the backend, your application not only respects cultural differences but also better aligns with global market needs, making it a key step in scaling your services worldwide.
|
|
40
|
+
|
|
41
|
+
## Getting Started
|
|
42
|
+
|
|
43
|
+
### Installation
|
|
44
|
+
|
|
45
|
+
To begin using `fastify-intlayer`, install the package using 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
|
+
### Setup
|
|
72
|
+
|
|
73
|
+
Configure the internationalisation settings by creating an `intlayer.config.ts` in your project root:
|
|
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
|
+
module.exports = config;
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### Declare Your Content
|
|
132
|
+
|
|
133
|
+
Create and manage your content declarations to store translations:
|
|
134
|
+
|
|
135
|
+
```typescript fileName="src/index.content.ts" contentDeclarationFormat="typescript"
|
|
136
|
+
import { t, type Dictionary } from "intlayer";
|
|
137
|
+
|
|
138
|
+
const indexContent = {
|
|
139
|
+
key: "index",
|
|
140
|
+
content: {
|
|
141
|
+
exampleOfContent: t({
|
|
142
|
+
"en-GB": "Example of returned content in English",
|
|
143
|
+
en: "Example of returned content in English",
|
|
144
|
+
fr: "Exemple de contenu renvoyé en français",
|
|
145
|
+
"es-ES": "Ejemplo de contenido devuelto en español (España)",
|
|
146
|
+
"es-MX": "Ejemplo de contenido devuelto en español (México)",
|
|
147
|
+
}),
|
|
148
|
+
},
|
|
149
|
+
} satisfies Dictionary;
|
|
150
|
+
|
|
151
|
+
export default indexContent;
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
```javascript fileName="src/index.content.mjs" contentDeclarationFormat="esm"
|
|
155
|
+
import { t } from "intlayer";
|
|
156
|
+
|
|
157
|
+
/** @type {import('intlayer').Dictionary} */
|
|
158
|
+
const indexContent = {
|
|
159
|
+
key: "index",
|
|
160
|
+
content: {
|
|
161
|
+
exampleOfContent: t({
|
|
162
|
+
"en-GB": "Example of returned content in English",
|
|
163
|
+
en: "Example of returned content in English",
|
|
164
|
+
fr: "Exemple de contenu renvoyé en français",
|
|
165
|
+
"es-ES": "Ejemplo de contenido devuelto en español (España)",
|
|
166
|
+
"es-MX": "Ejemplo de contenido devuelto en español (México)",
|
|
167
|
+
}),
|
|
168
|
+
},
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
export default indexContent;
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
```javascript fileName="src/index.content.cjs" contentDeclarationFormat="commonjs"
|
|
175
|
+
const { t } = require("intlayer");
|
|
176
|
+
|
|
177
|
+
/** @type {import('intlayer').Dictionary} */
|
|
178
|
+
const indexContent = {
|
|
179
|
+
key: "index",
|
|
180
|
+
content: {
|
|
181
|
+
exampleOfContent: t({
|
|
182
|
+
"en-GB": "Example of returned content in English",
|
|
183
|
+
en: "Example of returned content in English",
|
|
184
|
+
fr: "Exemple de contenu renvoyé en français",
|
|
185
|
+
"es-ES": "Ejemplo de contenido devuelto en español (España)",
|
|
186
|
+
"es-MX": "Ejemplo de contenido devuelto en español (México)",
|
|
187
|
+
}),
|
|
188
|
+
},
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
module.exports = indexContent;
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
```json fileName="src/index.content.json" contentDeclarationFormat="json"
|
|
195
|
+
{
|
|
196
|
+
"$schema": "https://intlayer.org/schema.json",
|
|
197
|
+
"key": "index",
|
|
198
|
+
"content": {
|
|
199
|
+
"exampleOfContent": {
|
|
200
|
+
"nodeType": "translation",
|
|
201
|
+
"translation": {
|
|
202
|
+
"en-GB": "Example of returned content in English",
|
|
203
|
+
"en": "Example of returned content in English",
|
|
204
|
+
"fr": "Exemple de contenu renvoyé en français",
|
|
205
|
+
"es-ES": "Ejemplo de contenido devuelto en español (España)",
|
|
206
|
+
"es-MX": "Ejemplo de contenido devuelto en español (México)"
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
> Your content declarations can be placed anywhere in your application provided they are included in the `contentDir` directory (by default, `./src`) and match the content declaration file extension (by default, `.content.{json,ts,tsx,js,jsx,mjs,mjx,cjs,cjx}`).
|
|
214
|
+
|
|
215
|
+
> For more details, refer to the [content declaration documentation](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en-GB/dictionary/content_file.md).
|
|
216
|
+
|
|
217
|
+
### Fastify application setup
|
|
218
|
+
|
|
219
|
+
Set up your Fastify application to use `fastify-intlayer`:
|
|
220
|
+
|
|
221
|
+
```typescript fileName="src/index.ts" codeFormat="typescript"
|
|
222
|
+
import Fastify from "fastify";
|
|
223
|
+
import { intlayer, t, getDictionary, getIntlayer } from "fastify-intlayer";
|
|
224
|
+
import dictionaryExample from "./index.content";
|
|
225
|
+
|
|
226
|
+
const fastify = Fastify({ logger: true });
|
|
227
|
+
|
|
228
|
+
// Load internationalisation plugin
|
|
229
|
+
await fastify.register(intlayer);
|
|
230
|
+
|
|
231
|
+
// Routes
|
|
232
|
+
fastify.get("/t_example", async (_req, reply) => {
|
|
233
|
+
return t({
|
|
234
|
+
"en-GB": "Example of returned content in English",
|
|
235
|
+
en: "Example of returned content in English",
|
|
236
|
+
fr: "Exemple de contenu renvoyé en français",
|
|
237
|
+
"es-ES": "Ejemplo de contenido devuelto en español (España)",
|
|
238
|
+
"es-MX": "Ejemplo de contenido devuelto en español (México)",
|
|
239
|
+
});
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
fastify.get("/getIntlayer_example", async (_req, reply) => {
|
|
243
|
+
return getIntlayer("index").exampleOfContent;
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
fastify.get("/getDictionary_example", async (_req, reply) => {
|
|
247
|
+
return getDictionary(dictionaryExample).exampleOfContent;
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
// Start server
|
|
251
|
+
const start = async () => {
|
|
252
|
+
try {
|
|
253
|
+
await fastify.listen({ port: 3000 });
|
|
254
|
+
} catch (err) {
|
|
255
|
+
fastify.log.error(err);
|
|
256
|
+
process.exit(1);
|
|
257
|
+
}
|
|
258
|
+
};
|
|
259
|
+
|
|
260
|
+
start();
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
```javascript fileName="src/index.mjs" codeFormat="esm"
|
|
264
|
+
import Fastify from "fastify";
|
|
265
|
+
import { intlayer, t, getDictionary, getIntlayer } from "fastify-intlayer";
|
|
266
|
+
import dictionaryExample from "./index.content";
|
|
267
|
+
|
|
268
|
+
const fastify = Fastify({ logger: true });
|
|
269
|
+
|
|
270
|
+
// Load internationalisation plugin
|
|
271
|
+
await fastify.register(intlayer);
|
|
272
|
+
|
|
273
|
+
// Routes
|
|
274
|
+
fastify.get("/t_example", async (_req, reply) => {
|
|
275
|
+
return t({
|
|
276
|
+
en: "Example of returned content in English",
|
|
277
|
+
fr: "Exemple de contenu renvoyé en français",
|
|
278
|
+
"es-ES": "Ejemplo de contenido devuelto en español (España)",
|
|
279
|
+
"es-MX": "Ejemplo de contenido devuelto en español (México)",
|
|
280
|
+
});
|
|
281
|
+
});
|
|
282
|
+
|
|
283
|
+
fastify.get("/getIntlayer_example", async (_req, reply) => {
|
|
284
|
+
return getIntlayer("index").exampleOfContent;
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
fastify.get("/getDictionary_example", async (_req, reply) => {
|
|
288
|
+
return getDictionary(dictionaryExample).exampleOfContent;
|
|
289
|
+
});
|
|
290
|
+
|
|
291
|
+
// Start the server
|
|
292
|
+
const start = async () => {
|
|
293
|
+
try {
|
|
294
|
+
await fastify.listen({ port: 3000 });
|
|
295
|
+
} catch (err) {
|
|
296
|
+
fastify.log.error(err);
|
|
297
|
+
process.exit(1);
|
|
298
|
+
}
|
|
299
|
+
};
|
|
300
|
+
|
|
301
|
+
start();
|
|
302
|
+
```
|
|
303
|
+
|
|
304
|
+
```javascript fileName="src/index.cjs" codeFormat="commonjs"
|
|
305
|
+
const Fastify = require("fastify");
|
|
306
|
+
const { intlayer, t, getDictionary, getIntlayer } = require("fastify-intlayer");
|
|
307
|
+
const dictionaryExample = require("./index.content");
|
|
308
|
+
|
|
309
|
+
const fastify = Fastify({ logger: true });
|
|
310
|
+
|
|
311
|
+
// Start the server wrapper for async/await
|
|
312
|
+
const start = async () => {
|
|
313
|
+
try {
|
|
314
|
+
// Load internationalisation plugin
|
|
315
|
+
await fastify.register(intlayer);
|
|
316
|
+
|
|
317
|
+
// Routes
|
|
318
|
+
fastify.get("/t_example", async (_req, reply) => {
|
|
319
|
+
return t({
|
|
320
|
+
"en-GB": "Example of returned content in English",
|
|
321
|
+
en: "Example of returned content in English",
|
|
322
|
+
fr: "Exemple de contenu renvoyé en français",
|
|
323
|
+
"es-ES": "Ejemplo de contenido devuelto en español (España)",
|
|
324
|
+
"es-MX": "Ejemplo de contenido devuelto en español (México)",
|
|
325
|
+
});
|
|
326
|
+
});
|
|
327
|
+
|
|
328
|
+
fastify.get("/getIntlayer_example", async (_req, reply) => {
|
|
329
|
+
return getIntlayer("index").exampleOfContent;
|
|
330
|
+
});
|
|
331
|
+
|
|
332
|
+
fastify.get("/getDictionary_example", async (_req, reply) => {
|
|
333
|
+
return getDictionary(dictionaryExample).exampleOfContent;
|
|
334
|
+
});
|
|
335
|
+
|
|
336
|
+
await fastify.listen({ port: 3000 });
|
|
337
|
+
} catch (err) {
|
|
338
|
+
fastify.log.error(err);
|
|
339
|
+
process.exit(1);
|
|
340
|
+
}
|
|
341
|
+
};
|
|
342
|
+
|
|
343
|
+
start();
|
|
344
|
+
```
|
|
345
|
+
|
|
346
|
+
### Compatibility
|
|
347
|
+
|
|
348
|
+
`fastify-intlayer` is fully compatible with:
|
|
349
|
+
|
|
350
|
+
- [`react-intlayer`](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en-GB/packages/react-intlayer/index.md) for React applications
|
|
351
|
+
- [`next-intlayer`](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en-GB/packages/next-intlayer/index.md) for Next.js applications
|
|
352
|
+
- [`vite-intlayer`](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en-GB/packages/vite-intlayer/index.md) for Vite applications
|
|
353
|
+
|
|
354
|
+
It also works seamlessly with any internationalisation solution across various environments, including browsers and API requests. You can customise the middleware to detect locale through headers or cookies:
|
|
355
|
+
|
|
356
|
+
```typescript fileName="intlayer.config.ts" codeFormat="typescript"
|
|
357
|
+
import { Locales, type IntlayerConfig } from "intlayer";
|
|
358
|
+
|
|
359
|
+
const config: IntlayerConfig = {
|
|
360
|
+
// ... Other configuration options
|
|
361
|
+
middleware: {
|
|
362
|
+
headerName: "my-locale-header",
|
|
363
|
+
cookieName: "my-locale-cookie",
|
|
364
|
+
},
|
|
365
|
+
};
|
|
366
|
+
|
|
367
|
+
export default config;
|
|
368
|
+
```
|
|
369
|
+
|
|
370
|
+
```javascript fileName="intlayer.config.mjs" codeFormat="esm"
|
|
371
|
+
import { Locales } from "intlayer";
|
|
372
|
+
|
|
373
|
+
/** @type {import('intlayer').IntlayerConfig} */
|
|
374
|
+
const config = {
|
|
375
|
+
// ... Other configuration options
|
|
376
|
+
middleware: {
|
|
377
|
+
headerName: "my-locale-header",
|
|
378
|
+
cookieName: "my-locale-cookie",
|
|
379
|
+
},
|
|
380
|
+
};
|
|
381
|
+
|
|
382
|
+
export default config;
|
|
383
|
+
```
|
|
384
|
+
|
|
385
|
+
```javascript fileName="intlayer.config.cjs" codeFormat="commonjs"
|
|
386
|
+
const { Locales } = require("intlayer");
|
|
387
|
+
|
|
388
|
+
/** @type {import('intlayer').IntlayerConfig} */
|
|
389
|
+
const config = {
|
|
390
|
+
// ... Other configuration options
|
|
391
|
+
middleware: {
|
|
392
|
+
headerName: "my-locale-header",
|
|
393
|
+
cookieName: "my-locale-cookie",
|
|
394
|
+
},
|
|
395
|
+
};
|
|
396
|
+
|
|
397
|
+
module.exports = config;
|
|
398
|
+
```
|
|
399
|
+
|
|
400
|
+
By default, `fastify-intlayer` will interpret the `Accept-Language` header to determine the client's preferred language.
|
|
401
|
+
|
|
402
|
+
> For more information on configuration and advanced topics, visit our [documentation](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en-GB/configuration.md).
|
|
403
|
+
|
|
404
|
+
### Configure TypeScript
|
|
405
|
+
|
|
406
|
+
`fastify-intlayer` leverages the robust capabilities of TypeScript to enhance the internationalisation process. TypeScript's static typing ensures that every translation key is accounted for, reducing the risk of missing translations and improving maintainability.
|
|
407
|
+
|
|
408
|
+
Ensure the auto-generated types (by default at ./types/intlayer.d.ts) are included in your tsconfig.json file.
|
|
409
|
+
|
|
410
|
+
```json5 fileName="tsconfig.json"
|
|
411
|
+
{
|
|
412
|
+
// ... Your existing TypeScript configuration
|
|
413
|
+
"include": [
|
|
414
|
+
// ... Your existing TypeScript configuration
|
|
415
|
+
".intlayer/**/*.ts", // Include the auto-generated types
|
|
416
|
+
],
|
|
417
|
+
}
|
|
418
|
+
```
|
|
419
|
+
|
|
420
|
+
### VS Code Extension
|
|
421
|
+
|
|
422
|
+
To improve your development experience with Intlayer, you can install the official **Intlayer VS Code Extension**.
|
|
423
|
+
|
|
424
|
+
[Install from the Visual Studio Code Marketplace](https://marketplace.visualstudio.com/items?itemName=intlayer.intlayer-vs-code-extension)
|
|
425
|
+
|
|
426
|
+
This extension provides:
|
|
427
|
+
|
|
428
|
+
- **Auto-completion** for translation keys.
|
|
429
|
+
- **Real-time error detection** of missing translations.
|
|
430
|
+
- **Inline previews** of translated content.
|
|
431
|
+
- **Quick actions** to easily create and update translations.
|
|
432
|
+
|
|
433
|
+
For more details on how to use the extension, refer to the [Intlayer VS Code Extension documentation](https://intlayer.org/doc/vs-code-extension).
|
|
434
|
+
|
|
435
|
+
### Git Configuration
|
|
436
|
+
|
|
437
|
+
It is recommended to ignore files generated by Intlayer. This prevents them from being committed to your Git repository.
|
|
438
|
+
|
|
439
|
+
To do this, you can add the following instructions to your `.gitignore` file:
|
|
440
|
+
|
|
441
|
+
```plaintext fileName=".gitignore"
|
|
442
|
+
# Ignore the files generated by Intlayer
|
|
443
|
+
.intlayer
|
|
444
|
+
|
|
445
|
+
```
|
package/docs/en-GB/readme.md
CHANGED
|
@@ -50,7 +50,7 @@ With **per-locale content files**, **TypeScript autocompletion**, **tree-shakabl
|
|
|
50
50
|
| Feature | Description |
|
|
51
51
|
| --------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
52
52
|
| <img src="https://github.com/aymericzip/intlayer/blob/main/docs/assets/frameworks.png?raw=true" alt="Feature" width="700"> | **Cross-Framework Support**<br><br>Intlayer is compatible with all major frameworks and libraries, including Next.js, React, Vite, Vue.js, Nuxt, Preact, Express, and more. |
|
|
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"> | **JavaScript-Powered Content Management**<br><br>Harness the flexibility of JavaScript to define and manage your content efficiently. <br><br> - [Content declaration](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"> | **Per-Locale Content Declaration File**<br><br>Accelerate your development by declaring your content once, prior to auto-generation.<br><br> - [Per-Locale Content Declaration File](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"> | **Type-Safe Environment**<br><br>Utilise TypeScript to ensure your content definitions and code are error-free, while also benefiting from IDE autocompletion.<br><br> - [TypeScript configuration](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"> | **Simplified Setup**<br><br>Get up and running quickly with minimal configuration. Adjust settings for internationalisation, routing, AI, build, and content handling with ease. <br><br> - [Explore Next.js integration](https://intlayer.org/doc/environment/nextjs) |
|
|
@@ -254,6 +254,8 @@ You can also follow us on:
|
|
|
254
254
|
|
|
255
255
|
For more detailed guidelines on contributing to this project, please refer to the [`CONTRIBUTING.md`](https://github.com/aymericzip/intlayer/blob/main/CONTRIBUTING.md) file. It contains essential information on our development process, commit message conventions, and release procedures. Your contributions are valuable to us, and we appreciate your efforts in making this project better!
|
|
256
256
|
|
|
257
|
+
Contribute on [GitHub](https://github.com/aymericzip/intlayer), [GitLab](https://gitlab.com/ay.pineau/intlayer), or [Bitbucket](https://bitbucket.org/intlayer/intlayer/).
|
|
258
|
+
|
|
257
259
|
### Thank You for the Support
|
|
258
260
|
|
|
259
261
|
If you like Intlayer, give us a ⭐ on GitHub. It helps others discover the project!
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
---
|
|
2
|
+
createdAt: 2026-01-06
|
|
3
|
+
updatedAt: 2026-01-06
|
|
4
|
+
title: Comando CI
|
|
5
|
+
description: Aprende a usar el comando Intlayer CI para ejecutar comandos Intlayer con credenciales auto-inyectadas en pipelines CI/CD y monorepos.
|
|
6
|
+
keywords:
|
|
7
|
+
- CI
|
|
8
|
+
- CI/CD
|
|
9
|
+
- Automatización
|
|
10
|
+
- Monorepo
|
|
11
|
+
- Credenciales
|
|
12
|
+
- CLI
|
|
13
|
+
- Intlayer
|
|
14
|
+
slugs:
|
|
15
|
+
- doc
|
|
16
|
+
- concept
|
|
17
|
+
- cli
|
|
18
|
+
- ci
|
|
19
|
+
history:
|
|
20
|
+
- version: 7.5.11
|
|
21
|
+
date: 2026-01-06
|
|
22
|
+
changes: Agregar comando CI
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
# Comando CI
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
npx intlayer ci <command...>
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
El comando CI está diseñado para automatización y pipelines CI/CD. Inyecta automáticamente credenciales desde la variable de entorno `INTLAYER_PROJECT_CREDENTIALS` y puede ejecutar comandos Intlayer en múltiples proyectos en un monorepo.
|
|
32
|
+
|
|
33
|
+
## Cómo funciona
|
|
34
|
+
|
|
35
|
+
El comando CI opera en dos modos:
|
|
36
|
+
|
|
37
|
+
1. **Modo de proyecto único**: Si el directorio de trabajo actual coincide con una de las rutas de proyecto en `INTLAYER_PROJECT_CREDENTIALS`, ejecuta el comando solo para ese proyecto específico.
|
|
38
|
+
|
|
39
|
+
2. **Modo de iteración**: Si no se detecta un contexto de proyecto específico, itera sobre todos los proyectos configurados y ejecuta el comando para cada uno.
|
|
40
|
+
|
|
41
|
+
## Variable de entorno
|
|
42
|
+
|
|
43
|
+
El comando requiere que se establezca la variable de entorno `INTLAYER_PROJECT_CREDENTIALS`. Esta variable debe contener un objeto JSON que mapee las rutas de proyecto a sus credenciales:
|
|
44
|
+
|
|
45
|
+
```json
|
|
46
|
+
{
|
|
47
|
+
"packages/app": {
|
|
48
|
+
"clientId": "your-client-id-1",
|
|
49
|
+
"clientSecret": "your-client-secret-1"
|
|
50
|
+
},
|
|
51
|
+
"packages/admin": {
|
|
52
|
+
"clientId": "your-client-id-2",
|
|
53
|
+
"clientSecret": "your-client-secret-2"
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Detección del gestor de paquetes
|
|
59
|
+
|
|
60
|
+
El comando CI detecta automáticamente qué gestor de paquetes se está usando (npm, yarn, pnpm o bun) basándose en la variable de entorno `npm_config_user_agent` y usa el comando apropiado para ejecutar Intlayer.
|
|
61
|
+
|
|
62
|
+
## Argumentos
|
|
63
|
+
|
|
64
|
+
- **`<command...>`**: El comando Intlayer a ejecutar (por ejemplo, `fill`, `push`, `build`). Puedes pasar cualquier comando Intlayer y sus argumentos.
|
|
65
|
+
|
|
66
|
+
> Ejemplo: `npx intlayer ci fill --verbose`
|
|
67
|
+
>
|
|
68
|
+
> Ejemplo: `npx intlayer ci push`
|
|
69
|
+
>
|
|
70
|
+
> Ejemplo: `npx intlayer ci build`
|
|
71
|
+
|
|
72
|
+
## Ejemplos
|
|
73
|
+
|
|
74
|
+
### Ejecutar un comando en modo de proyecto único
|
|
75
|
+
|
|
76
|
+
Si estás en un directorio de proyecto que coincide con una de las rutas en `INTLAYER_PROJECT_CREDENTIALS`:
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
cd packages/app
|
|
80
|
+
npx intlayer ci fill
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
Esto ejecutará el comando `fill` con las credenciales inyectadas automáticamente para el proyecto `packages/app`.
|
|
84
|
+
|
|
85
|
+
### Ejecutar un comando en todos los proyectos
|
|
86
|
+
|
|
87
|
+
Si estás en un directorio que no coincide con ninguna ruta de proyecto, el comando iterará sobre todos los proyectos configurados:
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
cd /path/to/monorepo
|
|
91
|
+
npx intlayer ci push
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
Esto ejecutará el comando `push` para cada proyecto configurado en `INTLAYER_PROJECT_CREDENTIALS`.
|
|
95
|
+
|
|
96
|
+
### Pasar banderas adicionales
|
|
97
|
+
|
|
98
|
+
Puedes pasar cualquier bandera al comando Intlayer subyacente:
|
|
99
|
+
|
|
100
|
+
```bash
|
|
101
|
+
npx intlayer ci fill --verbose --mode complete
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
### Usar en pipelines CI/CD
|
|
105
|
+
|
|
106
|
+
En tu configuración CI/CD (por ejemplo, GitHub Actions, GitLab CI), establece `INTLAYER_PROJECT_CREDENTIALS` como secreto:
|
|
107
|
+
|
|
108
|
+
```yaml
|
|
109
|
+
# Ejemplo de GitHub Actions
|
|
110
|
+
env:
|
|
111
|
+
INTLAYER_PROJECT_CREDENTIALS: ${{ secrets.INTLAYER_PROJECT_CREDENTIALS }}
|
|
112
|
+
|
|
113
|
+
steps:
|
|
114
|
+
- name: Llenar diccionarios
|
|
115
|
+
run: npx intlayer ci fill
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
## Manejo de errores
|
|
119
|
+
|
|
120
|
+
- Si `INTLAYER_PROJECT_CREDENTIALS` no está establecida, el comando saldrá con un error.
|
|
121
|
+
- Si `INTLAYER_PROJECT_CREDENTIALS` no es un JSON válido, el comando saldrá con un error.
|
|
122
|
+
- Si una ruta de proyecto no existe, se omitirá con una advertencia.
|
|
123
|
+
- Si algún proyecto falla, el comando saldrá con un código de estado distinto de cero.
|
|
124
|
+
|
|
125
|
+
## Casos de uso
|
|
126
|
+
|
|
127
|
+
- **Automatización de monorepo**: Ejecutar comandos Intlayer en múltiples proyectos en un monorepo
|
|
128
|
+
- **Pipelines CI/CD**: Automatizar la gestión de diccionarios en flujos de trabajo de integración continua
|
|
129
|
+
- **Operaciones masivas**: Realizar la misma operación en múltiples proyectos Intlayer a la vez
|
|
130
|
+
- **Gestión de secretos**: Gestionar de forma segura las credenciales para múltiples proyectos usando variables de entorno
|
|
131
|
+
|
|
132
|
+
## Mejores prácticas de seguridad
|
|
133
|
+
|
|
134
|
+
- Almacena `INTLAYER_PROJECT_CREDENTIALS` como secretos cifrados en tu plataforma CI/CD
|
|
135
|
+
- Nunca comprometas las credenciales en el control de versiones
|
|
136
|
+
- Usa credenciales específicas del entorno para diferentes entornos de despliegue
|
|
137
|
+
- Rota las credenciales regularmente
|
package/docs/es/cli/index.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
createdAt: 2024-08-11
|
|
3
|
-
updatedAt:
|
|
3
|
+
updatedAt: 2026-01-06
|
|
4
4
|
title: CLI
|
|
5
5
|
description: Descubre cómo usar el CLI de Intlayer para gestionar tu sitio web multilingüe. Sigue los pasos en esta documentación en línea para configurar tu proyecto en pocos minutos.
|
|
6
6
|
keywords:
|
|
@@ -17,6 +17,9 @@ slugs:
|
|
|
17
17
|
- concept
|
|
18
18
|
- cli
|
|
19
19
|
history:
|
|
20
|
+
- version: 7.5.11
|
|
21
|
+
date: 2026-01-06
|
|
22
|
+
changes: Añadir comando projects list
|
|
20
23
|
- version: 7.5.9
|
|
21
24
|
date: 2025-12-30
|
|
22
25
|
changes: Añadir comando init
|
|
@@ -119,6 +122,7 @@ Para ver cómo configurar los locales disponibles u otros parámetros, consulta
|
|
|
119
122
|
- **[Construir Diccionarios](https://github.com/aymericzip/intlayer/blob/main/docs/docs/es/cli/build.md)** - Construye tus diccionarios a partir de archivos de declaración de contenido
|
|
120
123
|
- **[Observar Diccionarios](https://github.com/aymericzip/intlayer/blob/main/docs/docs/es/cli/watch.md)** - Observa cambios y construye diccionarios automáticamente
|
|
121
124
|
- **[Verificar Versión CLI](https://github.com/aymericzip/intlayer/blob/main/docs/docs/es/cli/version.md)** - Verifica la versión instalada del CLI de Intlayer
|
|
125
|
+
- **[Listar Proyectos](https://github.com/aymericzip/intlayer/blob/main/docs/docs/es/cli/list_projects.md)** - Lista todos los proyectos Intlayer en un directorio o repositorio git
|
|
122
126
|
|
|
123
127
|
### Gestión de Diccionarios
|
|
124
128
|
|
|
@@ -166,6 +170,7 @@ Para ver cómo configurar los locales disponibles u otros parámetros, consulta
|
|
|
166
170
|
"intlayer:list": "npx intlayer content list",
|
|
167
171
|
"intlayer:test": "npx intlayer content test",
|
|
168
172
|
"intlayer:transform": "npx intlayer transform",
|
|
173
|
+
"intlayer:projects": "npx intlayer projects list",
|
|
169
174
|
"intlayer:doc:translate": "npx intlayer doc translate",
|
|
170
175
|
"intlayer:doc:review": "npx intlayer doc review"
|
|
171
176
|
}
|
|
@@ -175,3 +180,4 @@ Para ver cómo configurar los locales disponibles u otros parámetros, consulta
|
|
|
175
180
|
>
|
|
176
181
|
> - `npx intlayer list` en lugar de `npx intlayer content list`
|
|
177
182
|
> - `npx intlayer test` en lugar de `npx intlayer content test`
|
|
183
|
+
> - `npx intlayer projects-list` o `npx intlayer pl` en lugar de `npx intlayer projects list`
|