@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,439 @@
|
|
|
1
|
+
---
|
|
2
|
+
createdAt: 2025-12-30
|
|
3
|
+
updatedAt: 2025-12-30
|
|
4
|
+
title: How to translate your Fastify backend – i18n guide 2026
|
|
5
|
+
description: Discover how to make your Fastify backend multilingual. Follow the documentation to internationalize (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 backend website using Intlayer | Internationalization (i18n)
|
|
28
|
+
|
|
29
|
+
`fastify-intlayer` is a powerful internationalization (i18n) plugin for Fastify applications, designed to make your backend services globally accessible by providing localized responses based on the client's preferences.
|
|
30
|
+
|
|
31
|
+
### Practical Use Cases
|
|
32
|
+
|
|
33
|
+
- **Displaying Backend Errors in 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, internationalization ensures that you can serve this content in multiple languages. This is crucial for platforms like 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 enhancing the overall user experience.
|
|
38
|
+
|
|
39
|
+
By internationalizing the backend, your application not only respects cultural differences but also aligns better 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 internationalization 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: "Example of returned content in English",
|
|
143
|
+
fr: "Exemple de contenu renvoyé en français",
|
|
144
|
+
"es-ES": "Ejemplo de contenido devuelto en español (España)",
|
|
145
|
+
"es-MX": "Ejemplo de contenido devuelto en español (México)",
|
|
146
|
+
}),
|
|
147
|
+
},
|
|
148
|
+
} satisfies Dictionary;
|
|
149
|
+
|
|
150
|
+
export default indexContent;
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
```javascript fileName="src/index.content.mjs" contentDeclarationFormat="esm"
|
|
154
|
+
import { t } from "intlayer";
|
|
155
|
+
|
|
156
|
+
/** @type {import('intlayer').Dictionary} */
|
|
157
|
+
const indexContent = {
|
|
158
|
+
key: "index",
|
|
159
|
+
content: {
|
|
160
|
+
exampleOfContent: t({
|
|
161
|
+
en: "Example of returned content in English",
|
|
162
|
+
fr: "Exemple de contenu renvoyé en français",
|
|
163
|
+
"es-ES": "Ejemplo de contenido devuelto en español (España)",
|
|
164
|
+
"es-MX": "Ejemplo de contenido devuelto en español (México)",
|
|
165
|
+
}),
|
|
166
|
+
},
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
export default indexContent;
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
```javascript fileName="src/index.content.cjs" contentDeclarationFormat="commonjs"
|
|
173
|
+
const { t } = require("intlayer");
|
|
174
|
+
|
|
175
|
+
/** @type {import('intlayer').Dictionary} */
|
|
176
|
+
const indexContent = {
|
|
177
|
+
key: "index",
|
|
178
|
+
content: {
|
|
179
|
+
exampleOfContent: t({
|
|
180
|
+
en: "Example of returned content in English",
|
|
181
|
+
fr: "Exemple de contenu renvoyé en français",
|
|
182
|
+
"es-ES": "Ejemplo de contenido devuelto en español (España)",
|
|
183
|
+
"es-MX": "Ejemplo de contenido devuelto en español (México)",
|
|
184
|
+
}),
|
|
185
|
+
},
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
module.exports = indexContent;
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
```json fileName="src/index.content.json" contentDeclarationFormat="json"
|
|
192
|
+
{
|
|
193
|
+
"$schema": "https://intlayer.org/schema.json",
|
|
194
|
+
"key": "index",
|
|
195
|
+
"content": {
|
|
196
|
+
"exampleOfContent": {
|
|
197
|
+
"nodeType": "translation",
|
|
198
|
+
"translation": {
|
|
199
|
+
"en": "Example of returned content in English",
|
|
200
|
+
"fr": "Exemple de contenu renvoyé en français",
|
|
201
|
+
"es-ES": "Ejemplo de contenido devuelto en español (España)",
|
|
202
|
+
"es-MX": "Ejemplo de contenido devuelto en español (México)"
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
> Your content declarations can be defined anywhere in your application as soon as they are included into 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}`).
|
|
210
|
+
|
|
211
|
+
> For more details, refer to the [content declaration documentation](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/dictionary/content_file.md).
|
|
212
|
+
|
|
213
|
+
### Fastify Application Setup
|
|
214
|
+
|
|
215
|
+
Setup your Fastify application to use `fastify-intlayer`:
|
|
216
|
+
|
|
217
|
+
```typescript fileName="src/index.ts" codeFormat="typescript"
|
|
218
|
+
import Fastify from "fastify";
|
|
219
|
+
import { intlayer, t, getDictionary, getIntlayer } from "fastify-intlayer";
|
|
220
|
+
import dictionaryExample from "./index.content";
|
|
221
|
+
|
|
222
|
+
const fastify = Fastify({ logger: true });
|
|
223
|
+
|
|
224
|
+
// Load internationalization plugin
|
|
225
|
+
await fastify.register(intlayer);
|
|
226
|
+
|
|
227
|
+
// Routes
|
|
228
|
+
fastify.get("/t_example", async (_req, reply) => {
|
|
229
|
+
return t({
|
|
230
|
+
en: "Example of returned content in English",
|
|
231
|
+
fr: "Exemple de contenu renvoyé en français",
|
|
232
|
+
"es-ES": "Ejemplo de contenido devuelto en español (España)",
|
|
233
|
+
"es-MX": "Ejemplo de contenido devuelto en español (México)",
|
|
234
|
+
});
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
fastify.get("/getIntlayer_example", async (_req, reply) => {
|
|
238
|
+
return getIntlayer("index").exampleOfContent;
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
fastify.get("/getDictionary_example", async (_req, reply) => {
|
|
242
|
+
return getDictionary(dictionaryExample).exampleOfContent;
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
// Start server
|
|
246
|
+
const start = async () => {
|
|
247
|
+
try {
|
|
248
|
+
await fastify.listen({ port: 3000 });
|
|
249
|
+
} catch (err) {
|
|
250
|
+
fastify.log.error(err);
|
|
251
|
+
process.exit(1);
|
|
252
|
+
}
|
|
253
|
+
};
|
|
254
|
+
|
|
255
|
+
start();
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
```javascript fileName="src/index.mjs" codeFormat="esm"
|
|
259
|
+
import Fastify from "fastify";
|
|
260
|
+
import { intlayer, t, getDictionary, getIntlayer } from "fastify-intlayer";
|
|
261
|
+
import dictionaryExample from "./index.content";
|
|
262
|
+
|
|
263
|
+
const fastify = Fastify({ logger: true });
|
|
264
|
+
|
|
265
|
+
// Load internationalization plugin
|
|
266
|
+
await fastify.register(intlayer);
|
|
267
|
+
|
|
268
|
+
// Routes
|
|
269
|
+
fastify.get("/t_example", async (_req, reply) => {
|
|
270
|
+
return t({
|
|
271
|
+
en: "Example of returned content in English",
|
|
272
|
+
fr: "Exemple de contenu renvoyé en français",
|
|
273
|
+
"es-ES": "Ejemplo de contenido devuelto en español (España)",
|
|
274
|
+
"es-MX": "Ejemplo de contenido devuelto en español (México)",
|
|
275
|
+
});
|
|
276
|
+
});
|
|
277
|
+
|
|
278
|
+
fastify.get("/getIntlayer_example", async (_req, reply) => {
|
|
279
|
+
return getIntlayer("index").exampleOfContent;
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
fastify.get("/getDictionary_example", async (_req, reply) => {
|
|
283
|
+
return getDictionary(dictionaryExample).exampleOfContent;
|
|
284
|
+
});
|
|
285
|
+
|
|
286
|
+
// Start server
|
|
287
|
+
const start = async () => {
|
|
288
|
+
try {
|
|
289
|
+
await fastify.listen({ port: 3000 });
|
|
290
|
+
} catch (err) {
|
|
291
|
+
fastify.log.error(err);
|
|
292
|
+
process.exit(1);
|
|
293
|
+
}
|
|
294
|
+
};
|
|
295
|
+
|
|
296
|
+
start();
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
```javascript fileName="src/index.cjs" codeFormat="commonjs"
|
|
300
|
+
const Fastify = require("fastify");
|
|
301
|
+
const { intlayer, t, getDictionary, getIntlayer } = require("fastify-intlayer");
|
|
302
|
+
const dictionaryExample = require("./index.content");
|
|
303
|
+
|
|
304
|
+
const fastify = Fastify({ logger: true });
|
|
305
|
+
|
|
306
|
+
// Start server wrapper for async/await
|
|
307
|
+
const start = async () => {
|
|
308
|
+
try {
|
|
309
|
+
// Load internationalization plugin
|
|
310
|
+
await fastify.register(intlayer);
|
|
311
|
+
|
|
312
|
+
// Routes
|
|
313
|
+
fastify.get("/t_example", async (_req, reply) => {
|
|
314
|
+
return t({
|
|
315
|
+
en: "Example of returned content in English",
|
|
316
|
+
fr: "Exemple de contenu renvoyé en français",
|
|
317
|
+
"es-ES": "Ejemplo de contenido devuelto en español (España)",
|
|
318
|
+
"es-MX": "Ejemplo de contenido devuelto en español (México)",
|
|
319
|
+
});
|
|
320
|
+
});
|
|
321
|
+
|
|
322
|
+
fastify.get("/getIntlayer_example", async (_req, reply) => {
|
|
323
|
+
return getIntlayer("index").exampleOfContent;
|
|
324
|
+
});
|
|
325
|
+
|
|
326
|
+
fastify.get("/getDictionary_example", async (_req, reply) => {
|
|
327
|
+
return getDictionary(dictionaryExample).exampleOfContent;
|
|
328
|
+
});
|
|
329
|
+
|
|
330
|
+
await fastify.listen({ port: 3000 });
|
|
331
|
+
} catch (err) {
|
|
332
|
+
fastify.log.error(err);
|
|
333
|
+
process.exit(1);
|
|
334
|
+
}
|
|
335
|
+
};
|
|
336
|
+
|
|
337
|
+
start();
|
|
338
|
+
```
|
|
339
|
+
|
|
340
|
+
### Compatibility
|
|
341
|
+
|
|
342
|
+
`fastify-intlayer` is fully compatible with:
|
|
343
|
+
|
|
344
|
+
- [`react-intlayer`](<https://www.google.com/search?q=%5Bhttps://github.com/aymericzip/intlayer/blob/main/docs/docs/en/packages/react-intlayer/index.md%5D(https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/packages/react-intlayer/index.md)>) for React applications
|
|
345
|
+
- [`next-intlayer`](<https://www.google.com/search?q=%5Bhttps://github.com/aymericzip/intlayer/blob/main/docs/docs/en/packages/next-intlayer/index.md%5D(https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/packages/next-intlayer/index.md)>) for Next.js applications
|
|
346
|
+
- [`vite-intlayer`](<https://www.google.com/search?q=%5Bhttps://github.com/aymericzip/intlayer/blob/main/docs/docs/en/packages/vite-intlayer/index.md%5D(https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/packages/vite-intlayer/index.md)>) for Vite applications
|
|
347
|
+
|
|
348
|
+
It also works seamlessly with any internationalization solution across various environments, including browsers and API requests. You can customize the middleware to detect locale through headers or cookies:
|
|
349
|
+
|
|
350
|
+
```typescript fileName="intlayer.config.ts" codeFormat="typescript"
|
|
351
|
+
import { Locales, type IntlayerConfig } from "intlayer";
|
|
352
|
+
|
|
353
|
+
const config: IntlayerConfig = {
|
|
354
|
+
// ... Other configuration options
|
|
355
|
+
middleware: {
|
|
356
|
+
headerName: "my-locale-header",
|
|
357
|
+
cookieName: "my-locale-cookie",
|
|
358
|
+
},
|
|
359
|
+
};
|
|
360
|
+
|
|
361
|
+
export default config;
|
|
362
|
+
```
|
|
363
|
+
|
|
364
|
+
```javascript fileName="intlayer.config.mjs" codeFormat="esm"
|
|
365
|
+
import { Locales } from "intlayer";
|
|
366
|
+
|
|
367
|
+
/** @type {import('intlayer').IntlayerConfig} */
|
|
368
|
+
const config = {
|
|
369
|
+
// ... Other configuration options
|
|
370
|
+
middleware: {
|
|
371
|
+
headerName: "my-locale-header",
|
|
372
|
+
cookieName: "my-locale-cookie",
|
|
373
|
+
},
|
|
374
|
+
};
|
|
375
|
+
|
|
376
|
+
export default config;
|
|
377
|
+
```
|
|
378
|
+
|
|
379
|
+
```javascript fileName="intlayer.config.cjs" codeFormat="commonjs"
|
|
380
|
+
const { Locales } = require("intlayer");
|
|
381
|
+
|
|
382
|
+
/** @type {import('intlayer').IntlayerConfig} */
|
|
383
|
+
const config = {
|
|
384
|
+
// ... Other configuration options
|
|
385
|
+
middleware: {
|
|
386
|
+
headerName: "my-locale-header",
|
|
387
|
+
cookieName: "my-locale-cookie",
|
|
388
|
+
},
|
|
389
|
+
};
|
|
390
|
+
|
|
391
|
+
module.exports = config;
|
|
392
|
+
```
|
|
393
|
+
|
|
394
|
+
By default, `fastify-intlayer` will interpret the `Accept-Language` header to determine the client's preferred language.
|
|
395
|
+
|
|
396
|
+
> For more information on configuration and advanced topics, visit our [documentation](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/configuration.md).
|
|
397
|
+
|
|
398
|
+
### Configure TypeScript
|
|
399
|
+
|
|
400
|
+
`fastify-intlayer` leverages the robust capabilities of TypeScript to enhance the internationalization process. TypeScript's static typing ensures that every translation key is accounted for, reducing the risk of missing translations and improving maintainability.
|
|
401
|
+
|
|
402
|
+
Ensure the autogenerated types (by default at ./types/intlayer.d.ts) are included in your tsconfig.json file.
|
|
403
|
+
|
|
404
|
+
```json5 fileName="tsconfig.json"
|
|
405
|
+
{
|
|
406
|
+
// ... Your existing TypeScript configurations
|
|
407
|
+
"include": [
|
|
408
|
+
// ... Your existing TypeScript configurations
|
|
409
|
+
".intlayer/**/*.ts", // Include the auto-generated types
|
|
410
|
+
],
|
|
411
|
+
}
|
|
412
|
+
```
|
|
413
|
+
|
|
414
|
+
### VS Code Extension
|
|
415
|
+
|
|
416
|
+
To improve your development experience with Intlayer, you can install the official **Intlayer VS Code Extension**.
|
|
417
|
+
|
|
418
|
+
[Install from the VS Code Marketplace](https://marketplace.visualstudio.com/items?itemName=intlayer.intlayer-vs-code-extension)
|
|
419
|
+
|
|
420
|
+
This extension provides:
|
|
421
|
+
|
|
422
|
+
- **Autocompletion** for translation keys.
|
|
423
|
+
- **Real-time error detection** for missing translations.
|
|
424
|
+
- **Inline previews** of translated content.
|
|
425
|
+
- **Quick actions** to easily create and update translations.
|
|
426
|
+
|
|
427
|
+
For more details on how to use the extension, refer to the [Intlayer VS Code Extension documentation](https://intlayer.org/doc/vs-code-extension).
|
|
428
|
+
|
|
429
|
+
### Git Configuration
|
|
430
|
+
|
|
431
|
+
It is recommended to ignore the files generated by Intlayer. This allows you to avoid committing them to your Git repository.
|
|
432
|
+
|
|
433
|
+
To do this, you can add the following instructions to your `.gitignore` file:
|
|
434
|
+
|
|
435
|
+
```plaintext fileName=".gitignore"
|
|
436
|
+
# Ignore the files generated by Intlayer
|
|
437
|
+
.intlayer
|
|
438
|
+
|
|
439
|
+
```
|
package/docs/en/readme.md
CHANGED
|
@@ -52,7 +52,7 @@ With **per-locale content files**, **TypeScript autocompletion**, **tree-shakabl
|
|
|
52
52
|
| Feature | Description |
|
|
53
53
|
| --------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
54
54
|
| <img src="https://github.com/aymericzip/intlayer/blob/main/docs/assets/frameworks.png?raw=true" alt="Feature" width="700"> | **Cross-Frameworks Support**<br><br>Intlayer is compatible with all major frameworks and libraries, including Next.js, React, Vite, Vue.js, Nuxt, Preact, Express, and more. |
|
|
55
|
-
| <img src="https://github.com/aymericzip/intlayer/blob/main/docs/assets/javascript_content_management.
|
|
55
|
+
| <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) |
|
|
56
56
|
| <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>Speed up your development by declaring your content once, before auto generation.<br><br> - [Per-Locale Content Declaration File](https://intlayer.org/doc/concept/per-locale-file) |
|
|
57
57
|
| <img src="https://github.com/aymericzip/intlayer/blob/main/docs/assets/autocompletion.png?raw=true" alt="Feature" width="700"> | **Type-Safe Environment**<br><br>Leverage 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) |
|
|
58
58
|
| <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 internationalization, routing, AI, build, and content handling with ease. <br><br> - [Explore Next.js integration](https://intlayer.org/doc/environment/nextjs) |
|
|
@@ -256,6 +256,8 @@ You can also follow us on :
|
|
|
256
256
|
|
|
257
257
|
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!
|
|
258
258
|
|
|
259
|
+
Contribute on [GitHub](https://github.com/aymericzip/intlayer), [GitLab](https://gitlab.com/ay.pineau/intlayer), or [Bitbucket](https://bitbucket.org/intlayer/intlayer/).
|
|
260
|
+
|
|
259
261
|
### Thank You for the Support
|
|
260
262
|
|
|
261
263
|
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: CI Command
|
|
5
|
+
description: Learn how to use the Intlayer CI command to run Intlayer commands with auto-injected credentials in CI/CD pipelines and monorepos.
|
|
6
|
+
keywords:
|
|
7
|
+
- CI
|
|
8
|
+
- CI/CD
|
|
9
|
+
- Automation
|
|
10
|
+
- Monorepo
|
|
11
|
+
- Credentials
|
|
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: Add CI command
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
# CI Command
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
npx intlayer ci <command...>
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
The CI command is designed for automation and CI/CD pipelines. It automatically injects credentials from the `INTLAYER_PROJECT_CREDENTIALS` environment variable and can run Intlayer commands across multiple projects in a monorepo.
|
|
32
|
+
|
|
33
|
+
## How it works
|
|
34
|
+
|
|
35
|
+
The CI command operates in two modes:
|
|
36
|
+
|
|
37
|
+
1. **Single Project Mode**: If the current working directory matches one of the project paths in `INTLAYER_PROJECT_CREDENTIALS`, it runs the command for that specific project only.
|
|
38
|
+
|
|
39
|
+
2. **Iteration Mode**: If no specific project context is detected, it iterates over all configured projects and runs the command for each one.
|
|
40
|
+
|
|
41
|
+
## Environment Variable
|
|
42
|
+
|
|
43
|
+
The command requires the `INTLAYER_PROJECT_CREDENTIALS` environment variable to be set. This variable should contain a JSON object mapping project paths to their credentials:
|
|
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
|
+
## Package Manager Detection
|
|
59
|
+
|
|
60
|
+
The CI command automatically detects which package manager is being used (npm, yarn, pnpm, or bun) based on the `npm_config_user_agent` environment variable and uses the appropriate command to execute Intlayer.
|
|
61
|
+
|
|
62
|
+
## Arguments
|
|
63
|
+
|
|
64
|
+
- **`<command...>`**: The Intlayer command to execute (e.g., `fill`, `push`, `build`). You can pass any Intlayer command and its arguments.
|
|
65
|
+
|
|
66
|
+
> Example: `npx intlayer ci fill --verbose`
|
|
67
|
+
>
|
|
68
|
+
> Example: `npx intlayer ci push`
|
|
69
|
+
>
|
|
70
|
+
> Example: `npx intlayer ci build`
|
|
71
|
+
|
|
72
|
+
## Examples
|
|
73
|
+
|
|
74
|
+
### Run a command in single project mode
|
|
75
|
+
|
|
76
|
+
If you're in a project directory that matches one of the paths in `INTLAYER_PROJECT_CREDENTIALS`:
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
cd packages/app
|
|
80
|
+
npx intlayer ci fill
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
This will run the `fill` command with credentials automatically injected for the `packages/app` project.
|
|
84
|
+
|
|
85
|
+
### Run a command across all projects
|
|
86
|
+
|
|
87
|
+
If you're in a directory that doesn't match any project path, the command will iterate over all configured projects:
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
cd /path/to/monorepo
|
|
91
|
+
npx intlayer ci push
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
This will run the `push` command for each project configured in `INTLAYER_PROJECT_CREDENTIALS`.
|
|
95
|
+
|
|
96
|
+
### Pass additional flags
|
|
97
|
+
|
|
98
|
+
You can pass any flags to the underlying Intlayer command:
|
|
99
|
+
|
|
100
|
+
```bash
|
|
101
|
+
npx intlayer ci fill --verbose --mode complete
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
### Use in CI/CD pipelines
|
|
105
|
+
|
|
106
|
+
In your CI/CD configuration (e.g., GitHub Actions, GitLab CI), set the `INTLAYER_PROJECT_CREDENTIALS` as a secret:
|
|
107
|
+
|
|
108
|
+
```yaml
|
|
109
|
+
# GitHub Actions example
|
|
110
|
+
env:
|
|
111
|
+
INTLAYER_PROJECT_CREDENTIALS: ${{ secrets.INTLAYER_PROJECT_CREDENTIALS }}
|
|
112
|
+
|
|
113
|
+
steps:
|
|
114
|
+
- name: Fill dictionaries
|
|
115
|
+
run: npx intlayer ci fill
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
## Error Handling
|
|
119
|
+
|
|
120
|
+
- If `INTLAYER_PROJECT_CREDENTIALS` is not set, the command will exit with an error.
|
|
121
|
+
- If `INTLAYER_PROJECT_CREDENTIALS` is not valid JSON, the command will exit with an error.
|
|
122
|
+
- If a project path doesn't exist, it will be skipped with a warning.
|
|
123
|
+
- If any project fails, the command will exit with a non-zero status code.
|
|
124
|
+
|
|
125
|
+
## Use Cases
|
|
126
|
+
|
|
127
|
+
- **Monorepo automation**: Run Intlayer commands across multiple projects in a monorepo
|
|
128
|
+
- **CI/CD pipelines**: Automate dictionary management in continuous integration workflows
|
|
129
|
+
- **Bulk operations**: Perform the same operation on multiple Intlayer projects at once
|
|
130
|
+
- **Secret management**: Securely manage credentials for multiple projects using environment variables
|
|
131
|
+
|
|
132
|
+
## Security Best Practices
|
|
133
|
+
|
|
134
|
+
- Store `INTLAYER_PROJECT_CREDENTIALS` as encrypted secrets in your CI/CD platform
|
|
135
|
+
- Never commit credentials to version control
|
|
136
|
+
- Use environment-specific credentials for different deployment environments
|
|
137
|
+
- Rotate credentials regularly
|
package/docs/en-GB/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: Discover how to use the Intlayer CLI to manage your multilingual website. Follow the steps in this online documentation to set up your project in a few minutes.
|
|
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: Add projects list command
|
|
20
23
|
- version: 7.5.9
|
|
21
24
|
date: 2025-12-30
|
|
22
25
|
changes: Add init command
|
|
@@ -119,6 +122,7 @@ To see how to configure available locales, or other parameters, refer to the [co
|
|
|
119
122
|
- **[Build Dictionaries](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en-GB/cli/build.md)** - Build your dictionaries from content declaration files
|
|
120
123
|
- **[Watch Dictionaries](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en-GB/cli/watch.md)** - Watch for changes and automatically build dictionaries
|
|
121
124
|
- **[Check CLI Version](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en-GB/cli/version.md)** - Check the installed Intlayer CLI version
|
|
125
|
+
- **[List Projects](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en-GB/cli/list_projects.md)** - List all Intlayer projects in a directory or git repository
|
|
122
126
|
|
|
123
127
|
### Dictionary Management
|
|
124
128
|
|
|
@@ -166,6 +170,7 @@ To see how to configure available locales, or other parameters, refer to the [co
|
|
|
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 @@ To see how to configure available locales, or other parameters, refer to the [co
|
|
|
175
180
|
>
|
|
176
181
|
> - `npx intlayer list` instead of `npx intlayer content list`
|
|
177
182
|
> - `npx intlayer test` instead of `npx intlayer content test`
|
|
183
|
+
> - `npx intlayer projects-list` or `npx intlayer pl` instead of `npx intlayer projects list`
|