intlayer 3.5.11 → 4.0.2

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.
Files changed (2) hide show
  1. package/README.md +282 -149
  2. package/package.json +8 -8
package/README.md CHANGED
@@ -17,25 +17,78 @@
17
17
  </a>
18
18
  </div>
19
19
 
20
- # Intlayer: Next-Level Content Management in JavaScript
20
+ # intlayer: NPM Package to Manage Multilingual Content Declaration (i18n)
21
21
 
22
- **Intlayer** is an internationalization library designed specifically for JavaScript developers. It allow the declaration of your content everywhere in your code. It converts declaration of multilingual content into structured dictionaries to integrate easily in your code. Using TypeScript, **Intlayer** make your development stronger and more efficient.
22
+ **Intlayer** is a suite of packages designed specifically for JavaScript developers. It is compatible with frameworks like React, Next.js, and Express.js.
23
+
24
+ **The `intlayer` package** allows you to declare your content anywhere in your code. It converts multilingual content declarations into structured dictionaries that integrate seamlessly into your application. With TypeScript, **Intlayer** enhances your development by providing stronger, more efficient tools.
25
+
26
+ ## Why to integrate Intlayer?
27
+
28
+ - **JavaScript-Powered Content Management**: Harness the flexibility of JavaScript to define and manage your content efficiently.
29
+ - **Type-Safe Environment**: Leverage TypeScript to ensure all your content definitions are precise and error-free.
30
+ - **Integrated Content Files**: Keep your translations close to their respective components, enhancing maintainability and clarity.
31
+
32
+ ## Installation
33
+
34
+ Install the necessary package using your preferred package manager:
35
+
36
+ ```bash packageManager="npm"
37
+ npm install intlayer
38
+ ```
39
+
40
+ ```bash packageManager="pnpm"
41
+ pnpm add intlayer
42
+ ```
43
+
44
+ ```bash packageManager="yarn"
45
+ yarn add intlayer
46
+ ```
47
+
48
+ ### Configure Intlayer
49
+
50
+ Intlayer provides a configuration file to set up your project. Place this file in the root of your project.
51
+
52
+ ```typescript fileName="intlayer.config.ts" codeFormat="typescript"
53
+ import { Locales, type IntlayerConfig } from "intlayer";
54
+
55
+ const config: IntlayerConfig = {
56
+ internationalization: {
57
+ locales: [Locales.ENGLISH, Locales.FRENCH, Locales.SPANISH],
58
+ defaultLocale: Locales.ENGLISH,
59
+ },
60
+ };
61
+
62
+ export default config;
63
+ ```
64
+
65
+ > For a complete list of available parameters, refer to the [configuration documentation](https://github.com/aymericzip/intlayer/blob/main/docs/en/configuration.md).
23
66
 
24
67
  ## Example of usage
25
68
 
26
- ```bash
69
+ With Intlayer, you can declare your content in a structured way anywhere in your codebase.
70
+
71
+ By default, Intlayer scans for files with the extension `.content.{ts,tsx,js,jsx,mjs,cjs}`.
72
+
73
+ > YYou can modify the default extension by setting the `contentDir` property in the [configuration file](https://github.com/aymericzip/intlayer/blob/main/docs/en/configuration.md).
74
+
75
+ ```bash codeFormat="typescript"
27
76
  .
28
- ├── ClientComponent
29
- │   ├── index.content.ts
30
- │   └── index.tsx
31
- └── ServerComponent
32
-    ├── index.content.ts
33
-    └── index.tsx
77
+ ├── intlayer.config.ts
78
+ └── src
79
+ ├── ClientComponent
80
+ │   ├── index.content.ts
81
+ │   └── index.tsx
82
+ └── ServerComponent
83
+ ├── index.content.ts
84
+ └── index.tsx
34
85
  ```
35
86
 
36
- ```tsx
37
- // ./ClientComponent/index.content.ts
87
+ ### Declare your content
88
+
89
+ Here’s an example of content declaration:
38
90
 
91
+ ```tsx filePath="src/ClientComponent/index.content.ts" codeFormat="typescript"
39
92
  import { type DeclarationContent, t } from "intlayer";
40
93
 
41
94
  const clientComponentContent = {
@@ -46,195 +99,275 @@ const clientComponentContent = {
46
99
  fr: "Bonjour le monde",
47
100
  es: "Hola Mundo",
48
101
  }),
102
+ numberOfCar: enu({
103
+ "<-1": "Less than minus one car",
104
+ "-1": "Minus one car",
105
+ "0": "No cars",
106
+ "1": "One car",
107
+ ">5": "Some cars",
108
+ ">19": "Many cars",
109
+ }),
49
110
  },
50
111
  } satisfies DeclarationContent;
51
112
 
52
113
  export default clientComponentContent;
53
114
  ```
54
115
 
55
- ```tsx
56
- // ./ClientComponent/index.tsx
57
- "use client";
116
+ ### Build your dictionaries
58
117
 
59
- import { useIntlayer } from "next-intlayer";
118
+ You can build your dictionaries using the [intlayer-cli](https://github.com/aymericzip/intlayer/blob/main/packages/intlayer-cli/readme.md).
60
119
 
61
- export const ClientComponent = () => {
62
- const { myTranslatedContent } = useIntlayer("client-component");
120
+ ```bash packageManager="npm"
121
+ npx intlayer build
122
+ ```
63
123
 
64
- return <span>{myTranslatedContent}</span>;
65
- };
124
+ ```bash packageManager="yarn"
125
+ yarn intlayer build
66
126
  ```
67
127
 
68
- ## Why Choose Intlayer?
128
+ ```bash packageManager="pnpm"
129
+ pnpm intlayer build
130
+ ```
69
131
 
70
- - **JavaScript-Powered Content Management**: Harness the flexibility of JavaScript to define and manage your content efficiently.
71
- - **Type-Safe Environment**: Leverage TypeScript to ensure all your content definitions are precise and error-free.
72
- - **Integrated Content Files**: Keep your translations close to their respective components, enhancing maintainability and clarity.
132
+ This command scans all `*.content.*` files, compiles them, and writes the results to the directory specified in your **`intlayer.config.ts`** (by default, `./.intlayer`).
73
133
 
74
- ## intlayer package
134
+ A typical output might look like:
75
135
 
76
- `intlayer` package intend to declare your content in a structured way, using JavaScript.
136
+ ```bash
137
+ .
138
+ ├── .intlayer
139
+ │ ├── dictionary # Contain the dictionary of your content
140
+ │ │ ├── client-component.json
141
+ │ │ └── server-component.json
142
+ │ ├── main # Contain the entry point of your dictionary to be used in your application
143
+ │ │ ├── dictionary.cjs
144
+ │ │ └── dictionary.mjs
145
+ │ └── types # Contain the auto-generated type definitions of your dictionary
146
+ │ ├── client-component.d.ts
147
+ │ └── server-component.d.ts
148
+ └── types
149
+ └── intlayer.d.ts # Contain the auto-generated type definitions of Intlayer
150
+ ```
77
151
 
78
- To build dictionaries from this declaration, you can use [intlayer-cli](https://github.com/aymericzip/intlayer/blob/main/packages/intlayer-cli/readme.md).
79
- And to interpret intlayer dictionaries you can interpreters, such as [react-intlayer](https://github.com/aymericzip/intlayer/blob/main/packages/react-intlayer/README.md) [next-intlayer](https://github.com/aymericzip/intlayer/blob/main/packages/next-intlayer/README.md)
152
+ ### Build i18next resources
80
153
 
81
- ## Getting Started with Intlayer
154
+ Intlayer can be configured to build dictionaries for [i18next](https://www.i18next.com/). For that you need to add the following configuration to your `intlayer.config.ts` file:
82
155
 
83
- [See how to use intlayer with NextJS](https://github.com/aymericzip/intlayer/blob/main/README.md)
156
+ ```typescript fileName="intlayer.config.ts" codeFormat="typescript"
157
+ import { Locales, type IntlayerConfig } from "intlayer";
84
158
 
85
- ### Install Package
159
+ const config: IntlayerConfig = {
160
+ /* ... */
161
+ content: {
162
+ // Tells Intlayer to generate message files for i18next
163
+ dictionaryOutput: ["i18next"],
86
164
 
87
- Install the necessary packages using npm:
165
+ // The directory where Intlayer will write your message JSON files
166
+ i18nextResourcesDir: "./i18next/resources",
167
+ },
168
+ };
169
+ ```
88
170
 
89
- ```bash
90
- npm install intlayer
171
+ ```typescript fileName="intlayer.config.mjs" codeFormat="esm"
172
+ import { Locales } from "intlayer";
173
+
174
+ /** @type {import('intlayer').IntlayerConfig} */
175
+ const config = {
176
+ /* ... */
177
+ content: {
178
+ // Tells Intlayer to generate message files for i18next
179
+ dictionaryOutput: ["i18next"],
180
+
181
+ // The directory where Intlayer will write your message JSON files
182
+ i18nextResourcesDir: "./i18next/resources",
183
+ },
184
+ };
185
+
186
+ export default config;
91
187
  ```
92
188
 
93
- ```bash
94
- yarn add intlayer
189
+ ```javascript fileName="intlayer.config.cjs" codeFormat="commonjs"
190
+ const { Locales } = require("intlayer");
191
+
192
+ /** @type {import('intlayer').IntlayerConfig} */
193
+ const config = {
194
+ /* ... */
195
+ content: {
196
+ // Tells Intlayer to generate message files for i18next
197
+ dictionaryOutput: ["i18next"],
198
+
199
+ // The directory where Intlayer will write your message JSON files
200
+ i18nextResourcesDir: "./i18next/resources",
201
+ },
202
+ };
203
+
204
+ module.exports = config;
95
205
  ```
96
206
 
207
+ > For a complete list of available parameters, refer to the [configuration documentation](https://github.com/aymericzip/intlayer/blob/main/docs/en/configuration.md).
208
+
209
+ Output:
210
+
97
211
  ```bash
98
- pnpm add intlayer
212
+ .
213
+ └── i18next
214
+ └── resources
215
+ ├── en
216
+ │ ├── client-component.json
217
+ │ └── server-component.json
218
+ ├── es
219
+ │ ├── client-component.json
220
+ │ └── server-component.json
221
+ └── fr
222
+ ├── client-component.json
223
+ └── server-component.json
99
224
  ```
100
225
 
101
- ### Manage Your Content
226
+ For example, the **en/client-component.json** might look like:
102
227
 
103
- Create and manage your content dictionaries:
228
+ ```json filePath="intlayer/dictionary/en/client-component.json"
229
+ {
230
+ "myTranslatedContent": "Hello World",
231
+ "zero_numberOfCar": "No cars",
232
+ "one_numberOfCar": "One car",
233
+ "two_numberOfCar": "Two cars",
234
+ "other_numberOfCar": "Some cars"
235
+ }
236
+ ```
104
237
 
105
- #### Using typescript
238
+ ### Build i18next or next-intl dictionaries
106
239
 
107
- ```typescript
108
- // src/app/[locale]/page.content.ts
109
- import { t, enu, type DeclarationContent } from "intlayer";
240
+ Intlayer can be configured to build dictionaries for [i18next](https://www.i18next.com/) or [next-intl](https://github.com/formatjs/react-intl/tree/main/packages/next-intl). For that you need to add the following configuration to your `intlayer.config.ts` file:
110
241
 
111
- const pageContent = {
112
- key: "page",
242
+ ```typescript fileName="intlayer.config.ts" codeFormat="typescript"
243
+ import { Locales, type IntlayerConfig } from "intlayer";
244
+
245
+ const config: IntlayerConfig = {
246
+ /* ... */
113
247
  content: {
114
- getStarted: {
115
- main: t({
116
- en: "Get started by editing",
117
- fr: "Commencez par éditer",
118
- es: "Comience por editar",
119
- }),
120
- pageLink: "src/app/page.tsx",
121
- },
122
- nestedContent: {
123
- id: "enumeration",
124
- numberOfCar: enu({
125
- "<-1": "Less than minus one car",
126
- "-1": "Minus one car",
127
- "0": "No cars",
128
- "1": "One car",
129
- ">5": "Some cars",
130
- ">19": "Many cars",
131
- }),
132
- },
133
- },
134
- } satisfies DeclarationContent;
248
+ // Tells Intlayer to generate message files for i18next
249
+ dictionaryOutput: ["next-intl"],
135
250
 
136
- // Content should be exported as default
137
- export default pageContent;
251
+ // The directory where Intlayer will write your message JSON files
252
+ nextIntlMessagesDir: "./i18next/messages",
253
+ },
254
+ };
138
255
  ```
139
256
 
140
- #### Using ECMAScript modules
141
-
142
- ```javascript
143
- // src/app/[locale]/page.content.mjs
257
+ ```typescript fileName="intlayer.config.mjs" codeFormat="esm"
258
+ import { Locales } from "intlayer";
144
259
 
145
- import { t } from "intlayer";
260
+ /** @type {import('intlayer').IntlayerConfig} */
261
+ const config = {
262
+ /* ... */
263
+ content: {
264
+ // Tells Intlayer to generate message files for i18next
265
+ dictionaryOutput: ["next-intl"],
146
266
 
147
- /** @type {import('intlayer').DeclarationContent} */
148
- const pageContent = {
149
- "key": "page",
150
- getStarted: {
151
- main: t({
152
- en: "Get started by editing",
153
- fr: "Commencez par éditer",
154
- es: "Comience por editar",
155
- }),
156
- pageLink: "src/app/page.tsx",
157
- },
158
- nestedContent: {
159
- id: "enumeration",
160
- numberOfCar: enu({
161
- "<-1": "Less than minus one car",
162
- "-1": "Minus one car",
163
- 0: "No cars",
164
- 1: "One car",
165
- ">5": "Some cars",
166
- ">19": "Many cars",
167
- }),
267
+ // The directory where Intlayer will write your message JSON files
268
+ nextIntlMessagesDir: "./i18next/messages",
168
269
  },
169
270
  };
170
271
 
171
- // Content should be exported as default
172
- export default pageContent;
272
+ export default config;
173
273
  ```
174
274
 
175
- #### Using CommonJS modules
176
-
177
- ```javascript
178
- // src/app/[locale]/page.content.cjs
275
+ ```javascript fileName="intlayer.config.cjs" codeFormat="commonjs"
276
+ const { Locales } = require("intlayer");
179
277
 
180
- const { t } = require("intlayer");
278
+ /** @type {import('intlayer').IntlayerConfig} */
279
+ const config = {
280
+ /* ... */
281
+ content: {
282
+ // Tells Intlayer to generate message files for i18next
283
+ dictionaryOutput: ["next-intl"],
181
284
 
182
- /** @type {import('intlayer').DeclarationContent} */
183
- const pageContent = {
184
- "key": "page",
185
- getStarted: {
186
- main: t({
187
- en: "Get started by editing",
188
- fr: "Commencez par éditer",
189
- es: "Comience por editar",
190
- }),
191
- pageLink: "src/app/page.tsx",
192
- },
193
- nestedContent: {
194
- id: "enumeration",
195
- numberOfCar: enu({
196
- "<-1": "Less than minus one car",
197
- "-1": "Minus one car",
198
- 0: "No cars",
199
- 1: "One car",
200
- ">5": "Some cars",
201
- ">19": "Many cars",
202
- }),
285
+ // The directory where Intlayer will write your message JSON files
286
+ nextIntlMessagesDir: "./intl/messages",
203
287
  },
204
288
  };
205
289
 
206
- // Content should be exported as default
207
- module.exports = pageContent;
290
+ module.exports = config;
208
291
  ```
209
292
 
210
- #### Using JSON
293
+ > For a complete list of available parameters, refer to the [configuration documentation](https://github.com/aymericzip/intlayer/blob/main/docs/en/configuration.md).
294
+
295
+ Output:
211
296
 
212
- ```json5
213
- // src/app/[locale]/page.content.json
297
+ ```bash
298
+ .
299
+ └── intl
300
+ └── messages
301
+ ├── en
302
+ │ ├── client-component.json
303
+ │ └── server-component.json
304
+ ├── es
305
+ │ ├── client-component.json
306
+ │ └── server-component.json
307
+ └── fr
308
+ ├── client-component.json
309
+ └── server-component.json
310
+ ```
311
+
312
+ For example, the **en/client-component.json** might look like:
313
+
314
+ ```json filePath="intlayer/dictionary/en/client-component.json"
214
315
  {
215
- "key": "page",
216
- getStarted: {
217
- main: {
218
- nodeType: "translation",
219
- en: "Get started by editing",
220
- fr: "Commencez par éditer",
221
- es: "Comience por editar",
222
- },
223
- pageLink: "src/app/page.tsx",
224
- },
225
- nestedContent: {
226
- id: "enumeration",
227
- nodeType: "enumeration",
228
- numberOfCar: {
229
- "<-1": "Less than minus one car",
230
- "-1": "Minus one car",
231
- "0": "No cars",
232
- "1": "One car",
233
- ">5": "Some cars",
234
- ">19": "Many cars",
235
- },
236
- },
316
+ "myTranslatedContent": "Hello World",
317
+ "zero_numberOfCar": "No cars",
318
+ "one_numberOfCar": "One car",
319
+ "two_numberOfCar": "Two cars",
320
+ "other_numberOfCar": "Some cars"
237
321
  }
238
322
  ```
239
323
 
240
- This version emphasizes ease of use, practical steps, and the professional application of Intlayer in a Next.js environment.
324
+ ## CLI tools
325
+
326
+ Intlayer provides a CLI tool to:
327
+
328
+ - audit your content declarations and complete missing translations
329
+ - build dictionaries from your content declarations
330
+ - push and pull distant dictionaries from your CMS to your locale project
331
+
332
+ Consult [intlayer-cli](https://github.com/aymericzip/intlayer/blob/main/docs/en/intlayer_cli.md) for more information.
333
+
334
+ ## Use Intlayer into your application
335
+
336
+ One your content declared, you can consume your Intlayer dictionaries in your application.
337
+
338
+ Intlayer is available as a package for your application.
339
+
340
+ ### React Application
341
+
342
+ To use Intlayer in your React application, you can use [react-intlayer](https://github.com/aymericzip/intlayer/blob/main/docs/en/packages/react-intlayer/index.md).
343
+
344
+ ### Next.js Application
345
+
346
+ To use Intlayer in your Next.js application, you can use [next-intlayer](https://github.com/aymericzip/intlayer/blob/main/docs/en/packages/next-intlayer/index.md).
347
+
348
+ ### Express Application
349
+
350
+ To use Intlayer in your Express application, you can use [express-intlayer](https://github.com/aymericzip/intlayer/blob/main/docs/en/packages/express-intlayer/index.md).
351
+
352
+ ## Functions provided by `intlayer` package
353
+
354
+ The `intlayer` package also provides some functions to help you to internationalize your application.
355
+
356
+ - [`getConfiguration()`](https://github.com/aymericzip/intlayer/blob/main/docs/en/packages/intlayer/getConfiguration.md)
357
+ - [`getTranslationContent()`](https://github.com/aymericzip/intlayer/blob/main/docs/en/packages/intlayer/getTranslationContent.md)
358
+ - [`getEnumerationContent()`](https://github.com/aymericzip/intlayer/blob/main/docs/en/packages/intlayer/getEnumerationContent.md)
359
+ - [`getLocaleName()`](https://github.com/aymericzip/intlayer/blob/main/docs/en/packages/intlayer/getLocaleName.md)
360
+ - [`getLocaleLang()`](https://github.com/aymericzip/intlayer/blob/main/docs/en/packages/intlayer/getLocaleLang.md)
361
+ - [`getHTMLTextDir()`](https://github.com/aymericzip/intlayer/blob/main/docs/en/packages/intlayer/getHTMLTextDir.md)
362
+ - [`getPathWithoutLocale()`](https://github.com/aymericzip/intlayer/blob/main/docs/en/packages/intlayer/getPathWithoutLocale.md)
363
+ - [`getMultilingualUrls()`](https://github.com/aymericzip/intlayer/blob/main/docs/en/packages/intlayer/getMultilingualUrls.md)
364
+ - [`getLocalizedUrl()`](https://github.com/aymericzip/intlayer/blob/main/docs/en/packages/intlayer/getLocalizedUrl.md)
365
+ - [`getPathWithoutLocale()`](https://github.com/aymericzip/intlayer/blob/main/docs/en/packages/intlayer/getPathWithoutLocale.md)
366
+
367
+ ## Read about Intlayer
368
+
369
+ - [Intlayer Website](https://intlayer.org)
370
+ - [Intlayer Documentation](https://intlayer.org/docs)
371
+ - [Intlayer GitHub](https://github.com/aymericzip/intlayer)
372
+
373
+ - [Ask your questions to our smart documentation](https://intlayer.org/docs/chat)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "intlayer",
3
- "version": "3.5.11",
3
+ "version": "4.0.2",
4
4
  "private": false,
5
5
  "description": "Manage internationalization in a simple way, through TypeScript, declaration file, declare your multilingual every where in your code.",
6
6
  "keywords": [
@@ -58,9 +58,9 @@
58
58
  "./package.json"
59
59
  ],
60
60
  "dependencies": {
61
- "@intlayer/cli": "3.5.11",
62
- "@intlayer/config": "3.5.11",
63
- "@intlayer/core": "^3.5.11"
61
+ "@intlayer/config": "4.0.2",
62
+ "@intlayer/core": "^4.0.2",
63
+ "@intlayer/cli": "4.0.2"
64
64
  },
65
65
  "devDependencies": {
66
66
  "@changesets/changelog-github": "0.5.0",
@@ -74,15 +74,15 @@
74
74
  "tsc-alias": "^1.8.10",
75
75
  "tsup": "^8.3.5",
76
76
  "typescript": "^5.7.3",
77
- "@utils/eslint-config": "1.0.4",
78
77
  "@utils/ts-config": "1.0.4",
79
78
  "@utils/ts-config-types": "1.0.4",
79
+ "@utils/eslint-config": "1.0.4",
80
80
  "@utils/tsup-config": "1.0.4"
81
81
  },
82
82
  "peerDependencies": {
83
- "@intlayer/cli": "3.5.11",
84
- "@intlayer/config": "3.5.11",
85
- "@intlayer/core": "^3.5.11"
83
+ "@intlayer/cli": "4.0.2",
84
+ "@intlayer/config": "4.0.2",
85
+ "@intlayer/core": "^4.0.2"
86
86
  },
87
87
  "engines": {
88
88
  "node": ">=14.18"