Skip to content

Commit 55d02c0

Browse files
committed
feat(vue-intlayer): prepare vue and svelte
1 parent 45d95ba commit 55d02c0

File tree

115 files changed

+1588
-60
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

115 files changed

+1588
-60
lines changed

CONTRIBUTING.md

+31-29
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,21 @@ pnpm install
2626
pnpm prepare
2727
```
2828

29-
### Building the source
29+
### Development mode
30+
31+
```sh
32+
# Start development mode for all packages
33+
# Watch the change related to each files. If the modified file is included in a package, the package will be rebuilt
34+
pnpm dev
35+
```
36+
37+
```sh
38+
# Start development mode for selected packages or apps
39+
# This command allow to pick the packages to execute in watch-mode, avoid conflicts, and optimize performances during development
40+
pnpm dev:pick
41+
```
42+
43+
### Building pacakges
3044

3145
```sh
3246
# Build all packages
@@ -43,49 +57,37 @@ pnpm build:pick
4357
pnpm build:changes
4458
```
4559

46-
### Setup environment variables
60+
### Reset the source
4761

48-
For each project necessitating environment variables, like `@intlayer/backend`, you can find a `.env.template` file in the root of the project. Copy the file and rename it to `.env`. Then, fill the variables with the correct values.
49-
50-
For specific environment, use `.env.local`, `.env.[environment]` or `.env.[environment].local` files.
62+
If you meet problems with the build, you can use the command `pnpm clean` to remove the dist folders of the packages.
5163

52-
### Development mode
64+
The following commands clean the packages output folders for then build them again.
5365

5466
```sh
55-
# Start development mode for all packages
56-
# Watch the change related to each files. If the modified file is included in a package, the package will be rebuilt
57-
pnpm dev
67+
# Reset all packages
68+
pnpm reset
5869
```
5970

6071
```sh
61-
# Start development mode for selected packages or apps
62-
# This command allow to pick the packages to execute in watch-mode, avoid conflicts, and optimize performances during development
63-
pnpm dev:pick
72+
# Select a package and reset it
73+
pnpm reset:pick
6474
```
6575

66-
### Resolve build error
67-
68-
If the build block using the commands `pnpm dev` or `pnpm build`, you can use the command `pnpm clean` to remove the dist folders of the packages.
69-
70-
As well,
71-
72-
- `reset`: Allows to pick one or multiple package. Clear the related `dist` folders and rebuild it.
73-
- `reset:packages`: or `reset-examples` also clear the related build/dist folders to build it again.
74-
75-
### Run tests
76-
7776
```sh
78-
# Tests related to the packages
79-
pnpm test
77+
# Detect all packages that include changes using git, and reset them
78+
pnpm reset:changes
8079
```
8180

82-
```sh
83-
# Pick a package or example to test
84-
pnpm test:pick
85-
```
81+
### Setup environment variables
82+
83+
For each project necessitating environment variables, like `@intlayer/backend`, you can find a `.env.template` file in the root of the project. Copy the file and rename it to `.env`. Then, fill the variables with the correct values.
84+
85+
For specific environment, use `.env.local`, `.env.[environment]` or `.env.[environment].local` files.
8686

8787
### Release and PR
8888

89+
> Dont works properly. Need to fix it.
90+
8991
This repo uses [changesets](https://github.com/changesets/changesets) to
9092
make releasing updates easier.
9193

docs/ar/intlayer_with_vite+svelte.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
this doc will be automatically generated translated from the english doc
2+
3+
see /docs/en/intlayer_with_vite+svelte.md

docs/ar/intlayer_with_vite+vue.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
this doc will be automatically generated translated from the english doc
2+
3+
see /docs/en/intlayer_with_vite+vue.md
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
this doc will be automatically generated translated from the english doc
2+
3+
see /docs/en/packages/svelte-intlayer/index.md
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
this doc will be automatically generated translated from the english doc
2+
3+
see /docs/en/packages/vue-intlayer/index.md

docs/de/intlayer_with_vite+svelte.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
this doc will be automatically generated translated from the english doc
2+
3+
see /docs/en/intlayer_with_vite+svelte.md

docs/de/intlayer_with_vite+vue.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
this doc will be automatically generated translated from the english doc
2+
3+
see /docs/en/intlayer_with_vite+vue.md
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
this doc will be automatically generated translated from the english doc
2+
3+
see /docs/en/packages/svelte-intlayer/index.md
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
this doc will be automatically generated translated from the english doc
2+
3+
see /docs/en/packages/vue-intlayer/index.md
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
this doc will be automatically generated translated from the english doc
2+
3+
see /docs/en/intlayer_with_vite+svelte.md

docs/en-GB/intlayer_with_vite+vue.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
this doc will be automatically generated translated from the english doc
2+
3+
see /docs/en/intlayer_with_vite+vue.md
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
this doc will be automatically generated translated from the english doc
2+
3+
see /docs/en/packages/svelte-intlayer/index.md
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
this doc will be automatically generated translated from the english doc
2+
3+
see /docs/en/packages/vue-intlayer/index.md

docs/en/intlayer_with_vite+svelte.md

+253
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,253 @@
1+
# Getting Started Internationalizing (i18n) with Intlayer and Vite and Svelte
2+
3+
<iframe title="Vite + Svelte: Build a Multilingual App from Scratch using Intlayer" class="m-auto aspect-[16/9] w-full overflow-hidden rounded-lg border-0" allow="autoplay; gyroscope;" loading="lazy" width="1080" height="auto" src="https://www.youtube.com/embed/dS9L7uJeak4?autoplay=0&amp;origin=http://intlayer.org&amp;controls=0&amp;rel=1"/>
4+
5+
See [Application Template](https://github.com/aymericzip/intlayer-vite-react-template) on GitHub.
6+
7+
## What is Intlayer?
8+
9+
**Intlayer** is an innovative, open-source internationalization (i18n) library designed to simplify multilingual support in modern web applications.
10+
11+
With Intlayer, you can:
12+
13+
- **Easily manage translations** using declarative dictionaries at the component level.
14+
- **Dynamically localize metadata**, routes, and content.
15+
- **Ensure TypeScript support** with autogenerated types, improving autocompletion and error detection.
16+
- **Benefit from advanced features**, like dynamic locale detection and switching.
17+
18+
---
19+
20+
## Step-by-Step Guide to Set Up Intlayer in a Vite and Svelte Application
21+
22+
### Step 1: Install Dependencies
23+
24+
Install the necessary packages using npm:
25+
26+
```bash packageManager="npm"
27+
npm install intlayer svelte-intlayer vite-intlayer
28+
```
29+
30+
```bash packageManager="pnpm"
31+
pnpm add intlayer svelte-intlayer vite-intlayer
32+
```
33+
34+
```bash packageManager="yarn"
35+
yarn add intlayer svelte-intlayer vite-intlayer
36+
```
37+
38+
- **intlayer**
39+
40+
The core package that provides internationalization tools for configuration management, translation, [content declaration](https://github.com/aymericzip/intlayer/blob/main/docs/en/dictionary/get_started.md), transpilation, and [CLI commands](https://github.com/aymericzip/intlayer/blob/main/docs/en/intlayer_cli.md).
41+
42+
- **svelte-intlayer**
43+
The package that integrates Intlayer with Svelte application. It provides context providers and hooks for Svelte internationalization.
44+
45+
- **vite-intlayer**
46+
Includes the Vite plugin for integrating Intlayer with the [Vite bundler](https://vite.dev/guide/why.html#why-bundle-for-production), as well as middleware for detecting the user's preferred locale, managing cookies, and handling URL redirection.
47+
48+
### Step 2: Configuration of your project
49+
50+
Create a config file to configure the languages of your application:
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: [
58+
Locales.ENGLISH,
59+
Locales.FRENCH,
60+
Locales.SPANISH,
61+
// Your other locales
62+
],
63+
defaultLocale: Locales.ENGLISH,
64+
},
65+
};
66+
67+
export default config;
68+
```
69+
70+
```javascript fileName="intlayer.config.mjs" codeFormat="esm"
71+
import { Locales } from "intlayer";
72+
73+
/** @type {import('intlayer').IntlayerConfig} */
74+
const config = {
75+
internationalization: {
76+
locales: [
77+
Locales.ENGLISH,
78+
Locales.FRENCH,
79+
Locales.SPANISH,
80+
// Your other locales
81+
],
82+
defaultLocale: Locales.ENGLISH,
83+
},
84+
};
85+
86+
export default config;
87+
```
88+
89+
```javascript fileName="intlayer.config.cjs" codeFormat="commonjs"
90+
const { Locales } = require("intlayer");
91+
92+
/** @type {import('intlayer').IntlayerConfig} */
93+
const config = {
94+
internationalization: {
95+
locales: [
96+
Locales.ENGLISH,
97+
Locales.FRENCH,
98+
Locales.SPANISH,
99+
// Your other locales
100+
],
101+
defaultLocale: Locales.ENGLISH,
102+
},
103+
};
104+
105+
module.exports = config;
106+
```
107+
108+
> Through this configuration file, you can set up localized URLs, middleware redirection, cookie names, the location and extension of your content declarations, disable Intlayer logs in the console, and more. For a complete list of available parameters, refer to the [configuration documentation](https://github.com/aymericzip/intlayer/blob/main/docs/en/configuration.md).
109+
110+
### Step 3: Integrate Intlayer in Your Vite Configuration
111+
112+
Add the intlayer plugin into your configuration.
113+
114+
```typescript fileName="vite.config.ts" codeFormat="typescript"
115+
import { defineConfig } from "vite";
116+
import react from "@vitejs/plugin-react-swc";
117+
import { intlayerPlugin } from "vite-intlayer";
118+
119+
// https://vitejs.dev/config/
120+
export default defineConfig({
121+
plugins: [react(), intlayerPlugin()],
122+
});
123+
```
124+
125+
```javascript fileName="vite.config.mjs" codeFormat="esm"
126+
import { defineConfig } from "vite";
127+
import react from "@vitejs/plugin-react-swc";
128+
import { intlayerPlugin } from "vite-intlayer";
129+
130+
// https://vitejs.dev/config/
131+
export default defineConfig({
132+
plugins: [react(), intlayerPlugin()],
133+
});
134+
```
135+
136+
```javascript fileName="vite.config.cjs" codeFormat="commonjs"
137+
const { defineConfig } = require("vite");
138+
const react = require("@vitejs/plugin-react-swc");
139+
const { intlayerPlugin } = require("vite-intlayer");
140+
141+
// https://vitejs.dev/config/
142+
module.exports = defineConfig({
143+
plugins: [react(), intlayerPlugin()],
144+
});
145+
```
146+
147+
> 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.
148+
149+
### Step 4: Declare Your Content
150+
151+
Create and manage your content declarations to store translations:
152+
153+
```tsx fileName="src/app.content.tsx" contentDeclarationFormat="typescript"
154+
import { t, type Dictionary } from "intlayer";
155+
156+
const appContent = {
157+
key: "app",
158+
content: {},
159+
} satisfies Dictionary;
160+
161+
export default appContent;
162+
```
163+
164+
```javascript fileName="src/app.content.mjs" contentDeclarationFormat="esm"
165+
import { t } from "intlayer";
166+
167+
/** @type {import('intlayer').Dictionary} */
168+
const appContent = {
169+
key: "app",
170+
content: {},
171+
};
172+
173+
export default appContent;
174+
```
175+
176+
```javascript fileName="src/app.content.cjs" contentDeclarationFormat="commonjs"
177+
const { t } = require("intlayer");
178+
179+
/** @type {import('intlayer').Dictionary} */
180+
const appContent = {
181+
key: "app",
182+
content: {},
183+
};
184+
185+
module.exports = appContent;
186+
```
187+
188+
```json fileName="src/app.content.json" contentDeclarationFormat="json"
189+
{
190+
"$schema": "https://intlayer.org/schema.json",
191+
"key": "app",
192+
"content": {}
193+
}
194+
```
195+
196+
> Your content declarations can be defined anywhere in your application as soon 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}`).
197+
> For more details, refer to the [content declaration documentation](https://github.com/aymericzip/intlayer/blob/main/docs/en/dictionary/get_started.md).
198+
199+
### Step 5: Utilize Intlayer in Your Code
200+
201+
[to complete]
202+
203+
### (Optional) Step 6: Change the language of your content
204+
205+
[to complete]
206+
207+
### (Optional) Step 7: Add localized Routing to your application
208+
209+
[to complete]
210+
211+
### (Optional) Step 8: Change the URL when the locale changes
212+
213+
[to complete]
214+
215+
### (Optional) Step 9: Switch the HTML Language and Direction Attributes
216+
217+
[to complete]
218+
219+
### (Optional) Step 10: Creating a Localized Link Component
220+
221+
[to complete]
222+
223+
### Git Configuration
224+
225+
It is recommended to ignore the files generated by Intlayer. This allows you to avoid committing them to your Git repository.
226+
227+
To do this, you can add the following instructions to your `.gitignore` file:
228+
229+
```plaintext
230+
# Ignore the files generated by Intlayer
231+
.intlayer
232+
```
233+
234+
### VS Code Extension
235+
236+
To improve your development experience with Intlayer, you can install the official **Intlayer VS Code Extension**.
237+
238+
[Install from the VS Code Marketplace](https://marketplace.visualstudio.com/items?itemName=intlayer.intlayer-vs-code-extension)
239+
240+
This extension provides:
241+
242+
- **Autocompletion** for translation keys.
243+
- **Real-time error detection** for missing translations.
244+
- **Inline previews** of translated content.
245+
- **Quick actions** to easily create and update translations.
246+
247+
For more details on how to use the extension, refer to the [Intlayer VS Code Extension documentation](https://intlayer.org/doc/vs-code-extension).
248+
249+
---
250+
251+
### Go Further
252+
253+
To go further, you can implement the [visual editor](https://github.com/aymericzip/intlayer/blob/main/docs/en/intlayer_visual_editor.md) or externalize your content using the [CMS](https://github.com/aymericzip/intlayer/blob/main/docs/en/intlayer_CMS.md).

0 commit comments

Comments
 (0)