vite-intlayer 4.0.0 → 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 +41 -236
  2. package/package.json +9 -34
package/README.md CHANGED
@@ -1,275 +1,80 @@
1
1
  <div align="center">
2
- <a href="https://www.npmjs.com/package/react-intlayer">
2
+ <a href="https://www.npmjs.com/package/vite-intlayer">
3
3
  <img src="https://raw.githubusercontent.com/aymericzip/intlayer/572ae9c9acafb74307b81530c1931a8e98990aef/docs/assets/logo.png" width="500" alt="intlayer" />
4
4
  </a>
5
5
  </div>
6
6
 
7
7
  <div align="center">
8
- <a href="https://www.npmjs.com/package/react-intlayer">
9
- <img alt="npm" src="https://img.shields.io/npm/v/react-intlayer.svg?labelColor=49516F&color=8994BC" />
8
+ <a href="https://www.npmjs.com/package/vite-intlayer">
9
+ <img alt="npm" src="https://img.shields.io/npm/v/vite-intlayer.svg?labelColor=49516F&color=8994BC" />
10
10
  </a>
11
- <a href="https://npmjs.org/package/react-intlayer">
12
- <img alt="downloads" src="https://badgen.net/npm/dm/react-intlayer?labelColor=49516F&color=8994BC" />
11
+ <a href="https://npmjs.org/package/vite-intlayer">
12
+ <img alt="downloads" src="https://badgen.net/npm/dm/vite-intlayer?labelColor=49516F&color=8994BC" />
13
13
  </a>
14
- <a href="https://npmjs.org/package/react-intlayer">
15
- <img alt="types included" src="https://badgen.net/npm/types/react-intlayer?labelColor=49516F&color=8994BC"
14
+ <a href="https://npmjs.org/package/vite-intlayer">
15
+ <img alt="types included" src="https://badgen.net/npm/types/vite-intlayer?labelColor=49516F&color=8994BC"
16
16
  />
17
17
  </a>
18
18
  </div>
19
19
 
20
- # Intlayer: Next-Level Content Management in JavaScript
20
+ # vite-intlayer: NPM Package to internationalize (i18n) an Vite application
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, React, and Express.js.
23
23
 
24
- ## Example of usage
25
-
26
- ```bash
27
- .
28
- ├── Component1
29
- │   ├── index.content.ts
30
- │   └── index.tsx
31
- └── Component2
32
-    ├── index.content.ts
33
-    └── index.tsx
34
- ```
35
-
36
- ```tsx
37
- // ./Component1/index.content.ts
38
-
39
- import { type DeclarationContent, t } from "intlayer";
40
-
41
- const component1Content = {
42
- key: "component1",
43
- content: {
44
- myTranslatedContent: t({
45
- en: "Hello World",
46
- fr: "Bonjour le monde",
47
- es: "Hola Mundo",
48
- }),
49
- },
50
- } satisfies DeclarationContent;
51
- ```
52
-
53
- ```tsx
54
- // ./Component1/index.tsx
55
-
56
- import { useIntlayer } from "react-intlayer";
57
-
58
- export const Component1 = () => {
59
- const { myTranslatedContent } = useIntlayer("component1");
60
-
61
- return <span>{myTranslatedContent}</span>;
62
- };
63
- ```
64
-
65
- ## Why Choose Intlayer?
66
-
67
- - **JavaScript-Powered Content Management**: Harness the flexibility of JavaScript to define and manage your content efficiently.
68
- - **Type-Safe Environment**: Leverage TypeScript to ensure all your content definitions are precise and error-free.
69
- - **Integrated Content Files**: Keep your translations close to their respective components, enhancing maintainability and clarity.
70
- - **Simplified Setup**: Get up and running quickly with minimal configuration, especially optimized for Next.js projects.
71
- - **Server Component Support**: Perfectly suited for Next.js server components, ensuring smooth server-side rendering.
72
- - **Enhanced Routing**: Full support for Next.js app routing, adapting seamlessly to complex application structures.
73
-
74
- # Getting Started with Intlayer and React Create App
75
-
76
- Setting up Intlayer in a Create React App application is straightforward:
77
-
78
- ## Step 1: Install Dependencies
79
-
80
- Install the necessary packages using npm:
81
-
82
- ```bash
83
- npm install intlayer react-intlayer
84
- ```
85
-
86
- ```bash
87
- yarn add intlayer react-intlayer
88
- ```
89
-
90
- ```bash
91
- pnpm add intlayer react-intlayer
92
- ```
93
-
94
- ## Step 2: Configuration of your project
95
-
96
- Create a config file to configure the languages of your application:
24
+ **The `vite-intlayer` package** allows you to internationalize your Vite application. It includes the Vite plugin to set the configuration through environment variables into the [Vite bundler](https://vitejs.dev/guide/why.html#why-bundle-for-production). It also provides middleware to detect the user's preferred locale, and redirect the user to the appropriate URL as specified in the [configuration](https://github.com/aymericzip/intlayer/blob/main/docs/en/configuration.md).
97
25
 
98
- ```typescript
99
- // intlayer.config.ts
26
+ ## Why Internationalize Your Vite Application?
100
27
 
101
- import { Locales, type IntlayerConfig } from "intlayer";
28
+ Internationalizing your Vite application is essential for serving a global audience effectively. It allows your application to deliver content and messages in the preferred language of each user. This capability enhances user experience and broadens your application's reach by making it more accessible and relevant to people from different linguistic backgrounds.
102
29
 
103
- const config: IntlayerConfig = {
104
- internationalization: {
105
- locales: [
106
- Locales.ENGLISH,
107
- Locales.FRENCH,
108
- Locales.SPANISH,
109
- // Your other locales
110
- ],
111
- defaultLocale: Locales.ENGLISH,
112
- },
113
- };
30
+ ## Configuration
114
31
 
115
- export default config;
116
- ```
117
-
118
- To see all available parameters, refer to the [configuration documentation here](https://github.com/aymericzip/intlayer/blob/main/docs/en/configuration.md).
32
+ The `vite-intlayer` package works seamlessly with the [`vite-intlayer` package](https://github.com/aymericzip/intlayer/blob/main/docs/en/packages/vite-intlayer/index.md), and the [`intlayer` package](https://github.com/aymericzip/intlayer/blob/main/docs/en/packages/intlayer/index.md). Have a look at the relevant documentation for more information.
119
33
 
120
- ## Step 3: Integrate Intlayer in Your CRA Configuration
34
+ ## Installation
121
35
 
122
- Change your scripts to use react-intlayer
36
+ Install the necessary package using your preferred package manager:
123
37
 
124
- ```json
125
- "scripts": {
126
- "build": "react-intlayer build",
127
- "start": "react-intlayer start",
128
- "transpile": "intlayer build"
129
- },
38
+ ```bash packageManager="npm"
39
+ npm install vite-intlayer
130
40
  ```
131
41
 
132
- Note: react-intlayer scripts are based on craco. You can also implement your own setup based on the intlayer craco plugin. [See example here](https://github.com/aymericzip/intlayer/blob/main/examples/react-app/craco.config.js).
133
-
134
- ## Step 4: Declare Your Content
135
-
136
- Create and manage your content dictionaries:
137
-
138
- ```tsx
139
- // src/app.content.tsx
140
- import { t, type DeclarationContent } from "intlayer";
141
- import { type ReactNode } from "react";
142
-
143
- const appContent = {
144
- key: "app",
145
- content: {
146
- getStarted: t<ReactNode>({
147
- en: (
148
- <>
149
- Edit <code>src/App.tsx</code> and save to reload
150
- </>
151
- ),
152
- fr: (
153
- <>
154
- Éditez <code>src/App.tsx</code> et enregistrez pour recharger
155
- </>
156
- ),
157
- es: (
158
- <>
159
- Edita <code>src/App.tsx</code> y guarda para recargar
160
- </>
161
- ),
162
- }),
163
- reactLink: {
164
- href: "https://reactjs.org",
165
- content: t({
166
- en: "Learn React",
167
- fr: "Apprendre React",
168
- es: "Aprender React",
169
- }),
170
- },
171
- },
172
- } satisfies DeclarationContent;
173
-
174
- export default appContent;
42
+ ```bash packageManager="yarn"
43
+ yarn add vite-intlayer
175
44
  ```
176
45
 
177
- [See how to declare your Intlayer declaration files](https://github.com/aymericzip/intlayer/blob/main/docs/en/content_declaration/get_started.md)
178
-
179
- ## Step 5: Utilize Intlayer in Your Code
180
-
181
- Access your content dictionaries throughout your application:
182
-
183
- ```tsx
184
- import logo from "./logo.svg";
185
- import "./App.css";
186
- import { IntlayerProvider, useIntlayer } from "react-intlayer";
187
- import { LocaleSwitcher } from "./components/LangSwitcherDropDown";
188
-
189
- function AppContent() {
190
- const content = useIntlayer("app");
191
-
192
- return (
193
- <header className="App-header">
194
- <img src={logo} className="App-logo" alt="logo" />
195
-
196
- {content.getStarted}
197
- <a
198
- className="App-link"
199
- href={content.reactLink.href.value}
200
- target="_blank"
201
- rel="noopener noreferrer"
202
- >
203
- {content.reactLink.content}
204
- </a>
205
- </header>
206
- );
207
- }
208
-
209
- function App() {
210
- return (
211
- <IntlayerProvider>
212
- <div className="App">
213
- {/* To use the useIntlayer hook properly, you should access your data in a children component */}
214
- <AppContent />
215
- </div>
216
- <div className="absolute bottom-5 right-5 z-50">
217
- <LocaleSwitcher />
218
- </div>
219
- </IntlayerProvider>
220
- );
221
- }
222
-
223
- export default App;
46
+ ```bash packageManager="pnpm"
47
+ pnpm add vite-intlayer
224
48
  ```
225
49
 
226
- > Note: If you want to use your content in a `string` attribute, such as `alt`, `title`, `href`, `aria-label`, etc., you must call the value of the function, like:
227
- >
228
- > ```tsx
229
- > <img src={content.image.src.value} alt={content.image.value} />
230
- > ```
231
-
232
- ## (Optional) Step 6: Change the language of your content
233
-
234
- To change the language of your content, you can use the `setLocale` function provided by the `useLocale` hook. This function allows you to set the locale of the application and update the content accordingly.
50
+ ## Example of usage
235
51
 
236
- ```tsx
237
- import { Locales } from "intlayer";
238
- import { useLocale } from "react-intlayer";
52
+ See an example of how to include the plugins into your vite configuration.
239
53
 
240
- const MyComponent = () => {
241
- const { setLocale } = useLocale();
54
+ ```typescript fileName="vite.config.ts"
55
+ import { defineConfig } from "vite";
56
+ import { intlayerPlugin, intLayerMiddlewarePlugin } from "vite-intlayer";
242
57
 
243
- return (
244
- <button onClick={() => setLocale(Locales.English)}>
245
- Change Language to English
246
- </button>
247
- );
248
- };
58
+ // https://vitejs.dev/config/
59
+ export default defineConfig({
60
+ plugins: [intlayerPlugin(), intLayerMiddlewarePlugin()],
61
+ });
249
62
  ```
250
63
 
251
- ## Configure TypeScript
64
+ > The `intlayerPlugin()` Vite plugin is used to integrate Intlayer with Vite. It ensures the building of content declaration files and monitors them in development mode. It defines Intlayer environment variables within the Vite application. Additionally, it provides aliases to optimize performance.
252
65
 
253
- Intlayer use module augmentation to get benefits of TypeScript and make your codebase stronger.
66
+ > The `intLayerMiddlewarePlugin()` add server-side routing to your application. This plugin will automatically detect the current locale based on the URL and set the appropriate locale cookie. If no locale is specified, the plugin will determine the most appropriate locale based on the user's browser language preferences. If no locale is detected, it will redirect to the default locale.
254
67
 
255
- ![alt text](https://github.com/aymericzip/intlayer/blob/main/docs/assets/autocompletion.png)
68
+ ## Mastering the internationalization of your Vite application
256
69
 
257
- ![alt text](https://github.com/aymericzip/intlayer/blob/main/docs/assets/translation_error.png)
70
+ Intlayer provides a lot of features to help you internationalize your Vite application.
258
71
 
259
- Ensure your TypeScript configuration includes the autogenerated types.
72
+ **To learn more about these features, refer to the [React Internationalization (i18n) with Intlayer and Vite and React](https://github.com/aymericzip/intlayer/blob/main/docs/en/intlayer_with_vite+react.md) guide for Vite and React Application.**
260
73
 
261
- ```json5
262
- // tsconfig.json
263
-
264
- {
265
- // your custom config
266
- "include": [
267
- "src",
268
- "types", // <- Include the auto generated types
269
- ],
270
- }
271
- ```
74
+ ## Read about Intlayer
272
75
 
273
- # Getting Started with Intlayer and Vite + React
76
+ - [Intlayer Website](https://intlayer.org)
77
+ - [Intlayer Documentation](https://intlayer.org/docs)
78
+ - [Intlayer GitHub](https://github.com/aymericzip/intlayer)
274
79
 
275
- For integration with Vite + React, refer to the [setup guide](https://github.com/aymericzip/intlayer/blob/main/docs/en/intlayer_with_vite_react.md)
80
+ - [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": "vite-intlayer",
3
- "version": "4.0.0",
3
+ "version": "4.0.2",
4
4
  "private": false,
5
5
  "description": "Intlayer for vite application",
6
6
  "keywords": [
@@ -40,31 +40,6 @@
40
40
  "require": "./dist/cjs/index.cjs",
41
41
  "import": "./dist/esm/index.mjs"
42
42
  },
43
- "./server": {
44
- "types": "./dist/types/server/index.d.ts",
45
- "require": "./dist/cjs/server/index.cjs",
46
- "import": "./dist/esm/server/index.mjs"
47
- },
48
- "./craco-plugin": {
49
- "types": "./dist/types/craco/intlayerCracoPlugin.d.ts",
50
- "require": "./dist/cjs/craco/intlayerCracoPlugin.cjs",
51
- "import": "./dist/esm/craco/intlayerCracoPlugin.mjs"
52
- },
53
- "./craco-config": {
54
- "types": "./dist/types/craco/craco.config.d.ts",
55
- "require": "./dist/cjs/craco/craco.config.cjs",
56
- "import": "./dist/esm/craco/craco.config.mjs"
57
- },
58
- "./vite": {
59
- "types": "./dist/types/vite/index.d.ts",
60
- "require": "./dist/cjs/vite/index.cjs",
61
- "import": "./dist/esm/vite/index.mjs"
62
- },
63
- "./editor": {
64
- "types": "./dist/types/editor/index.d.ts",
65
- "require": "./dist/cjs/editor/index.cjs",
66
- "import": "./dist/esm/editor/index.mjs"
67
- },
68
43
  "./package.json": "./package.json"
69
44
  },
70
45
  "main": "dist/cjs/index.cjs",
@@ -83,9 +58,9 @@
83
58
  ],
84
59
  "dependencies": {
85
60
  "vite": "^6.0.7",
86
- "@intlayer/config": "4.0.0",
87
- "@intlayer/core": "4.0.0",
88
- "@intlayer/chokidar": "4.0.0"
61
+ "@intlayer/config": "4.0.2",
62
+ "@intlayer/core": "4.0.2",
63
+ "@intlayer/chokidar": "4.0.2"
89
64
  },
90
65
  "devDependencies": {
91
66
  "@types/node": "^22.10.6",
@@ -97,16 +72,16 @@
97
72
  "tsc-alias": "^1.8.10",
98
73
  "tsup": "^8.3.5",
99
74
  "typescript": "^5.7.3",
100
- "@utils/eslint-config": "1.0.4",
101
75
  "@utils/tsup-config": "1.0.4",
102
76
  "@utils/ts-config": "1.0.4",
103
- "@utils/ts-config-types": "1.0.4"
77
+ "@utils/ts-config-types": "1.0.4",
78
+ "@utils/eslint-config": "1.0.4"
104
79
  },
105
80
  "peerDependencies": {
106
81
  "vite": ">=4.0.0",
107
- "@intlayer/chokidar": "4.0.0",
108
- "@intlayer/core": "4.0.0",
109
- "@intlayer/config": "4.0.0"
82
+ "@intlayer/chokidar": "4.0.2",
83
+ "@intlayer/config": "4.0.2",
84
+ "@intlayer/core": "4.0.2"
110
85
  },
111
86
  "engines": {
112
87
  "node": ">=14.18"