@intlayer/docs 7.1.8-canary.0 → 7.1.9
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/docs/ar/intlayer_with_vite+svelte.md +35 -8
- package/docs/de/intlayer_with_vite+svelte.md +35 -8
- package/docs/en/intlayer_with_vite+svelte.md +277 -13
- package/docs/en-GB/intlayer_with_vite+svelte.md +35 -8
- package/docs/es/intlayer_with_vite+svelte.md +35 -8
- package/docs/fr/intlayer_with_vite+svelte.md +35 -8
- package/docs/hi/intlayer_with_vite+svelte.md +28 -7
- package/docs/id/intlayer_with_vite+svelte.md +35 -8
- package/docs/it/intlayer_with_vite+svelte.md +35 -8
- package/docs/ja/intlayer_with_vite+svelte.md +35 -8
- package/docs/ko/intlayer_with_vite+svelte.md +46 -14
- package/docs/pl/intlayer_with_vite+svelte.md +35 -8
- package/docs/pt/intlayer_with_vite+svelte.md +35 -8
- package/docs/ru/intlayer_with_vite+svelte.md +35 -8
- package/docs/tr/intlayer_with_vite+svelte.md +35 -8
- package/docs/vi/intlayer_with_vite+svelte.md +35 -8
- package/docs/zh/intlayer_with_vite+svelte.md +35 -8
- package/package.json +6 -6
|
@@ -139,23 +139,23 @@ module.exports = config;
|
|
|
139
139
|
|
|
140
140
|
```typescript fileName="vite.config.ts" codeFormat="typescript"
|
|
141
141
|
import { defineConfig } from "vite";
|
|
142
|
-
import
|
|
142
|
+
import { svelte } from "@sveltejs/vite-plugin-svelte";
|
|
143
143
|
import { intlayer } from "vite-intlayer";
|
|
144
144
|
|
|
145
145
|
// https://vitejs.dev/config/
|
|
146
146
|
export default defineConfig({
|
|
147
|
-
plugins: [
|
|
147
|
+
plugins: [svelte(), intlayer()],
|
|
148
148
|
});
|
|
149
149
|
```
|
|
150
150
|
|
|
151
151
|
```javascript fileName="vite.config.mjs" codeFormat="esm"
|
|
152
152
|
import { defineConfig } from "vite";
|
|
153
|
-
import
|
|
153
|
+
import { svelte } from "@sveltejs/vite-plugin-svelte";
|
|
154
154
|
import { intlayer } from "vite-intlayer";
|
|
155
155
|
|
|
156
156
|
// https://vitejs.dev/config/
|
|
157
157
|
export default defineConfig({
|
|
158
|
-
plugins: [
|
|
158
|
+
plugins: [svelte(), intlayer()],
|
|
159
159
|
});
|
|
160
160
|
```
|
|
161
161
|
|
|
@@ -181,7 +181,13 @@ import { t, type Dictionary } from "intlayer";
|
|
|
181
181
|
|
|
182
182
|
const appContent = {
|
|
183
183
|
key: "app",
|
|
184
|
-
content: {
|
|
184
|
+
content: {
|
|
185
|
+
title: t({
|
|
186
|
+
en: "Hello World",
|
|
187
|
+
fr: "Bonjour le monde",
|
|
188
|
+
es: "Hola mundo",
|
|
189
|
+
}),
|
|
190
|
+
},
|
|
185
191
|
} satisfies Dictionary;
|
|
186
192
|
|
|
187
193
|
export default appContent;
|
|
@@ -193,7 +199,13 @@ import { t } from "intlayer";
|
|
|
193
199
|
/** @type {import('intlayer').Dictionary} */
|
|
194
200
|
const appContent = {
|
|
195
201
|
key: "app",
|
|
196
|
-
content: {
|
|
202
|
+
content: {
|
|
203
|
+
title: t({
|
|
204
|
+
en: "Hello World",
|
|
205
|
+
fr: "Bonjour le monde",
|
|
206
|
+
es: "Hola mundo",
|
|
207
|
+
}),
|
|
208
|
+
},
|
|
197
209
|
};
|
|
198
210
|
|
|
199
211
|
export default appContent;
|
|
@@ -206,7 +218,13 @@ const { t } = require("intlayer");
|
|
|
206
218
|
// تعريف محتوى التطبيق
|
|
207
219
|
const appContent = {
|
|
208
220
|
key: "app",
|
|
209
|
-
content: {
|
|
221
|
+
content: {
|
|
222
|
+
title: t({
|
|
223
|
+
en: "Hello World",
|
|
224
|
+
fr: "Bonjour le monde",
|
|
225
|
+
es: "Hola mundo",
|
|
226
|
+
}),
|
|
227
|
+
},
|
|
210
228
|
};
|
|
211
229
|
|
|
212
230
|
module.exports = appContent;
|
|
@@ -216,7 +234,16 @@ module.exports = appContent;
|
|
|
216
234
|
{
|
|
217
235
|
"$schema": "https://intlayer.org/schema.json",
|
|
218
236
|
"key": "app",
|
|
219
|
-
"content": {
|
|
237
|
+
"content": {
|
|
238
|
+
"title": {
|
|
239
|
+
"nodeType": "translation",
|
|
240
|
+
"translation": {
|
|
241
|
+
"en": "Hello World",
|
|
242
|
+
"fr": "Bonjour le monde",
|
|
243
|
+
"es": "Hola mundo"
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
}
|
|
220
247
|
}
|
|
221
248
|
```
|
|
222
249
|
|
|
@@ -142,23 +142,23 @@ Fügen Sie das Intlayer-Plugin in Ihre Konfiguration ein.
|
|
|
142
142
|
|
|
143
143
|
```typescript fileName="vite.config.ts" codeFormat="typescript"
|
|
144
144
|
import { defineConfig } from "vite";
|
|
145
|
-
import
|
|
145
|
+
import { svelte } from "@sveltejs/vite-plugin-svelte";
|
|
146
146
|
import { intlayer } from "vite-intlayer";
|
|
147
147
|
|
|
148
148
|
// https://vitejs.dev/config/
|
|
149
149
|
export default defineConfig({
|
|
150
|
-
plugins: [
|
|
150
|
+
plugins: [svelte(), intlayer()],
|
|
151
151
|
});
|
|
152
152
|
```
|
|
153
153
|
|
|
154
154
|
```javascript fileName="vite.config.mjs" codeFormat="esm"
|
|
155
155
|
import { defineConfig } from "vite";
|
|
156
|
-
import
|
|
156
|
+
import { svelte } from "@sveltejs/vite-plugin-svelte";
|
|
157
157
|
import { intlayer } from "vite-intlayer";
|
|
158
158
|
|
|
159
159
|
// https://vitejs.dev/config/
|
|
160
160
|
export default defineConfig({
|
|
161
|
-
plugins: [
|
|
161
|
+
plugins: [svelte(), intlayer()],
|
|
162
162
|
});
|
|
163
163
|
```
|
|
164
164
|
|
|
@@ -184,7 +184,13 @@ import { t, type Dictionary } from "intlayer";
|
|
|
184
184
|
|
|
185
185
|
const appContent = {
|
|
186
186
|
key: "app",
|
|
187
|
-
content: {
|
|
187
|
+
content: {
|
|
188
|
+
title: t({
|
|
189
|
+
en: "Hello World",
|
|
190
|
+
fr: "Bonjour le monde",
|
|
191
|
+
es: "Hola mundo",
|
|
192
|
+
}),
|
|
193
|
+
},
|
|
188
194
|
} satisfies Dictionary;
|
|
189
195
|
|
|
190
196
|
export default appContent;
|
|
@@ -196,7 +202,13 @@ import { t } from "intlayer";
|
|
|
196
202
|
/** @type {import('intlayer').Dictionary} */
|
|
197
203
|
const appContent = {
|
|
198
204
|
key: "app",
|
|
199
|
-
content: {
|
|
205
|
+
content: {
|
|
206
|
+
title: t({
|
|
207
|
+
en: "Hello World",
|
|
208
|
+
fr: "Bonjour le monde",
|
|
209
|
+
es: "Hola mundo",
|
|
210
|
+
}),
|
|
211
|
+
},
|
|
200
212
|
};
|
|
201
213
|
|
|
202
214
|
export default appContent;
|
|
@@ -209,7 +221,13 @@ const { t } = require("intlayer");
|
|
|
209
221
|
// Definiert den Inhalt der Anwendung
|
|
210
222
|
const appContent = {
|
|
211
223
|
key: "app",
|
|
212
|
-
content: {
|
|
224
|
+
content: {
|
|
225
|
+
title: t({
|
|
226
|
+
en: "Hello World",
|
|
227
|
+
fr: "Bonjour le monde",
|
|
228
|
+
es: "Hola mundo",
|
|
229
|
+
}),
|
|
230
|
+
},
|
|
213
231
|
};
|
|
214
232
|
|
|
215
233
|
module.exports = appContent;
|
|
@@ -219,7 +237,16 @@ module.exports = appContent;
|
|
|
219
237
|
{
|
|
220
238
|
"$schema": "https://intlayer.org/schema.json",
|
|
221
239
|
"key": "app",
|
|
222
|
-
"content": {
|
|
240
|
+
"content": {
|
|
241
|
+
"title": {
|
|
242
|
+
"nodeType": "translation",
|
|
243
|
+
"translation": {
|
|
244
|
+
"en": "Hello World",
|
|
245
|
+
"fr": "Bonjour le monde",
|
|
246
|
+
"es": "Hola mundo"
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
}
|
|
223
250
|
}
|
|
224
251
|
```
|
|
225
252
|
|
|
@@ -16,6 +16,9 @@ slugs:
|
|
|
16
16
|
- vite-and-svelte
|
|
17
17
|
applicationTemplate: https://github.com/aymericzip/intlayer-vite-svelte-template
|
|
18
18
|
history:
|
|
19
|
+
- version: 5.5.11
|
|
20
|
+
date: 2025-11-19
|
|
21
|
+
changes: Update doc
|
|
19
22
|
- version: 5.5.10
|
|
20
23
|
date: 2025-06-29
|
|
21
24
|
changes: Init history
|
|
@@ -25,8 +28,6 @@ history:
|
|
|
25
28
|
|
|
26
29
|
> This package is in development. See the [issue](https://github.com/aymericzip/intlayer/issues/114) for more information. Show your interest in Intlayer for Svelte by liking the issue
|
|
27
30
|
|
|
28
|
-
<!-- See [Application Template](https://github.com/aymericzip/intlayer-solid-template) on GitHub. -->
|
|
29
|
-
|
|
30
31
|
## Table of Contents
|
|
31
32
|
|
|
32
33
|
<TOC/>
|
|
@@ -46,6 +47,16 @@ With Intlayer, you can:
|
|
|
46
47
|
|
|
47
48
|
## Step-by-Step Guide to Set Up Intlayer in a Vite and Svelte Application
|
|
48
49
|
|
|
50
|
+
<iframe
|
|
51
|
+
src="https://stackblitz.com/github/aymericzip/intlayer-vite-react-template?embed=1&ctl=1&file=intlayer.config.ts"
|
|
52
|
+
className="m-auto overflow-hidden rounded-lg border-0 max-md:size-full max-md:h-[700px] md:aspect-16/9 md:w-full"
|
|
53
|
+
title="Demo CodeSandbox - How to Internationalize your application using Intlayer"
|
|
54
|
+
sandbox="allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts"
|
|
55
|
+
loading="lazy"
|
|
56
|
+
/>
|
|
57
|
+
|
|
58
|
+
See [Application Template](https://github.com/aymericzip/intlayer-vite-svelte-template) on GitHub.
|
|
59
|
+
|
|
49
60
|
### Step 1: Install Dependencies
|
|
50
61
|
|
|
51
62
|
Install the necessary packages using npm:
|
|
@@ -125,7 +136,13 @@ import { t, type Dictionary } from "intlayer";
|
|
|
125
136
|
|
|
126
137
|
const appContent = {
|
|
127
138
|
key: "app",
|
|
128
|
-
content: {
|
|
139
|
+
content: {
|
|
140
|
+
title: t({
|
|
141
|
+
en: "Hello World",
|
|
142
|
+
fr: "Bonjour le monde",
|
|
143
|
+
es: "Hola mundo",
|
|
144
|
+
}),
|
|
145
|
+
},
|
|
129
146
|
} satisfies Dictionary;
|
|
130
147
|
|
|
131
148
|
export default appContent;
|
|
@@ -137,7 +154,13 @@ import { t } from "intlayer";
|
|
|
137
154
|
/** @type {import('intlayer').Dictionary} */
|
|
138
155
|
const appContent = {
|
|
139
156
|
key: "app",
|
|
140
|
-
content: {
|
|
157
|
+
content: {
|
|
158
|
+
title: t({
|
|
159
|
+
en: "Hello World",
|
|
160
|
+
fr: "Bonjour le monde",
|
|
161
|
+
es: "Hola mundo",
|
|
162
|
+
}),
|
|
163
|
+
},
|
|
141
164
|
};
|
|
142
165
|
|
|
143
166
|
export default appContent;
|
|
@@ -149,7 +172,13 @@ const { t } = require("intlayer");
|
|
|
149
172
|
/** @type {import('intlayer').Dictionary} */
|
|
150
173
|
const appContent = {
|
|
151
174
|
key: "app",
|
|
152
|
-
content: {
|
|
175
|
+
content: {
|
|
176
|
+
title: t({
|
|
177
|
+
en: "Hello World",
|
|
178
|
+
fr: "Bonjour le monde",
|
|
179
|
+
es: "Hola mundo",
|
|
180
|
+
}),
|
|
181
|
+
},
|
|
153
182
|
};
|
|
154
183
|
|
|
155
184
|
module.exports = appContent;
|
|
@@ -159,7 +188,16 @@ module.exports = appContent;
|
|
|
159
188
|
{
|
|
160
189
|
"$schema": "https://intlayer.org/schema.json",
|
|
161
190
|
"key": "app",
|
|
162
|
-
"content": {
|
|
191
|
+
"content": {
|
|
192
|
+
"title": {
|
|
193
|
+
"nodeType": "translation",
|
|
194
|
+
"translation": {
|
|
195
|
+
"en": "Hello World",
|
|
196
|
+
"fr": "Bonjour le monde",
|
|
197
|
+
"es": "Hola mundo"
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
163
201
|
}
|
|
164
202
|
```
|
|
165
203
|
|
|
@@ -169,19 +207,247 @@ module.exports = appContent;
|
|
|
169
207
|
|
|
170
208
|
### Step 5: Utilize Intlayer in Your Code
|
|
171
209
|
|
|
172
|
-
|
|
210
|
+
```svelte fileName="src/App.svelte"
|
|
211
|
+
<script>
|
|
212
|
+
import { useIntlayer } from "svelte-intlayer";
|
|
213
|
+
|
|
214
|
+
const content = useIntlayer("app");
|
|
215
|
+
</script>
|
|
216
|
+
|
|
217
|
+
<div>
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
<!-- Render content as simple content -->
|
|
221
|
+
<h1>{$content.title}</h1>
|
|
222
|
+
<!-- To render the content editable using the editor -->
|
|
223
|
+
<h1><svelte:component this={$content.title} /></h1>
|
|
224
|
+
<!-- To render the content as a string -->
|
|
225
|
+
<div aria-label={$content.title.value}></div>
|
|
226
|
+
```
|
|
173
227
|
|
|
174
228
|
### (Optional) Step 6: Change the language of your content
|
|
175
229
|
|
|
176
|
-
|
|
230
|
+
```svelte fileName="src/App.svelte"
|
|
231
|
+
<script lang="ts">
|
|
232
|
+
import { getLocaleName } from 'intlayer';
|
|
233
|
+
import { useLocale } from 'svelte-intlayer';
|
|
234
|
+
|
|
235
|
+
// Get locale information and setLocale function
|
|
236
|
+
const { locale, availableLocales, setLocale } = useLocale();
|
|
237
|
+
|
|
238
|
+
// Handle locale change
|
|
239
|
+
const changeLocale = (event: Event) => {
|
|
240
|
+
const target = event.target as HTMLSelectElement;
|
|
241
|
+
const newLocale = target.value;
|
|
242
|
+
setLocale(newLocale);
|
|
243
|
+
};
|
|
244
|
+
</script>
|
|
245
|
+
|
|
246
|
+
<div>
|
|
247
|
+
<select value={$locale} on:change={changeLocale}>
|
|
248
|
+
{#each availableLocales ?? [] as loc}
|
|
249
|
+
<option value={loc}>
|
|
250
|
+
{getLocaleName(loc)}
|
|
251
|
+
</option>
|
|
252
|
+
{/each}
|
|
253
|
+
</select>
|
|
254
|
+
</div>
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
### (Optional) Step 7: Render Markdown
|
|
258
|
+
|
|
259
|
+
Intlayer supports rendering Markdown content directly in your Svelte application. By default, Markdown is treated as plain text. To convert Markdown into rich HTML, you can integrate `@humanspeak/svelte-markdown`, or a other markdown parser.
|
|
260
|
+
|
|
261
|
+
> To see how to declare markdown content using the `intlayer` package, see the [markdown doc](https://github.com/aymericzip/intlayer/tree/main/docs/en/dictionary/markdown.md).
|
|
262
|
+
|
|
263
|
+
```svelte fileName="src/App.svelte"
|
|
264
|
+
<script>
|
|
265
|
+
import { setIntlayerMarkdown } from "svelte-intlayer";
|
|
266
|
+
|
|
267
|
+
setIntlayerMarkdown((markdown) =>
|
|
268
|
+
// render the markdown content as a string
|
|
269
|
+
return markdown;
|
|
270
|
+
);
|
|
271
|
+
</script>
|
|
272
|
+
|
|
273
|
+
<h1>{$content.markdownContent}</h1>
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
> You can also access your markdown front-matter data using the `content.markdownContent.metadata.xxx` property.
|
|
277
|
+
|
|
278
|
+
### (Optional) Step 8: Set up the intlayer editor / CMS
|
|
279
|
+
|
|
280
|
+
To set up the intlayer editor, you must follow the [intlayer editor documentation](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/intlayer_visual_editor.md).
|
|
281
|
+
|
|
282
|
+
To set up the intlayer CMS, you must follow the [intlayer CMS documentation](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/intlayer_CMS.md).
|
|
283
|
+
|
|
284
|
+
In parallel, in your Svelte application, you must add the following line in a layout, or at the root of your application:
|
|
285
|
+
|
|
286
|
+
```svelte fileName="src/layout.svelte"
|
|
287
|
+
import { useIntlayerEditor } from "svelte-intlayer";
|
|
288
|
+
|
|
289
|
+
useIntlayerEditor();
|
|
290
|
+
```
|
|
177
291
|
|
|
178
292
|
### (Optional) Step 7: Add localized Routing to your application
|
|
179
293
|
|
|
180
|
-
|
|
294
|
+
To handle localized routing in your Svelte application, you can use `svelte-spa-router` along with Intlayer's `localeFlatMap` to generate routes for each locale.
|
|
295
|
+
|
|
296
|
+
First, install `svelte-spa-router`:
|
|
297
|
+
|
|
298
|
+
```bash packageManager="npm"
|
|
299
|
+
npm install svelte-spa-router
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
```bash packageManager="pnpm"
|
|
303
|
+
pnpm add svelte-spa-router
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
```bash packageManager="yarn"
|
|
307
|
+
yarn add svelte-spa-router
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
```bash packageManager="bun"
|
|
311
|
+
bun add svelte-spa-router
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
Then, create a `Router.svelte` file to define your routes:
|
|
315
|
+
|
|
316
|
+
```svelte fileName="src/Router.svelte"
|
|
317
|
+
<script lang="ts">
|
|
318
|
+
import { localeFlatMap } from "intlayer";
|
|
319
|
+
import Router from "svelte-spa-router";
|
|
320
|
+
import { wrap } from "svelte-spa-router/wrap";
|
|
321
|
+
import App from "./App.svelte";
|
|
322
|
+
|
|
323
|
+
const routes = Object.fromEntries(
|
|
324
|
+
localeFlatMap(({locale, urlPrefix}) => [
|
|
325
|
+
[
|
|
326
|
+
urlPrefix || '/',
|
|
327
|
+
wrap({
|
|
328
|
+
component: App as any,
|
|
329
|
+
props: {
|
|
330
|
+
locale,
|
|
331
|
+
},
|
|
332
|
+
}),
|
|
333
|
+
],
|
|
334
|
+
])
|
|
335
|
+
);
|
|
336
|
+
</script>
|
|
337
|
+
|
|
338
|
+
<Router {routes} />
|
|
339
|
+
```
|
|
340
|
+
|
|
341
|
+
Update your `main.ts` to mount the `Router` component instead of `App`:
|
|
342
|
+
|
|
343
|
+
```typescript fileName="src/main.ts"
|
|
344
|
+
import { mount } from "svelte";
|
|
345
|
+
import Router from "./Router.svelte";
|
|
346
|
+
|
|
347
|
+
const app = mount(Router, {
|
|
348
|
+
target: document.getElementById("app")!,
|
|
349
|
+
});
|
|
350
|
+
|
|
351
|
+
export default app;
|
|
352
|
+
```
|
|
353
|
+
|
|
354
|
+
Finally, update your `App.svelte` to receive the `locale` prop and use it with `useIntlayer`:
|
|
355
|
+
|
|
356
|
+
```svelte fileName="src/App.svelte"
|
|
357
|
+
<script lang="ts">
|
|
358
|
+
import type { Locale } from 'intlayer';
|
|
359
|
+
import { useIntlayer } from 'svelte-intlayer';
|
|
360
|
+
import Counter from './lib/Counter.svelte';
|
|
361
|
+
import LocaleSwitcher from './lib/LocaleSwitcher.svelte';
|
|
362
|
+
|
|
363
|
+
export let locale: Locale;
|
|
364
|
+
|
|
365
|
+
$: content = useIntlayer('app', locale);
|
|
366
|
+
</script>
|
|
367
|
+
|
|
368
|
+
<main>
|
|
369
|
+
<div class="locale-switcher-container">
|
|
370
|
+
<LocaleSwitcher currentLocale={locale} />
|
|
371
|
+
</div>
|
|
372
|
+
|
|
373
|
+
<!-- ... rest of your app ... -->
|
|
374
|
+
</main>
|
|
375
|
+
```
|
|
376
|
+
|
|
377
|
+
#### Configure Server-Side Routing (Optional)
|
|
378
|
+
|
|
379
|
+
In parallel, you can also use the `intlayerProxy` to 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.
|
|
380
|
+
|
|
381
|
+
> Note that to use the `intlayerProxy` in production, you need to switch the `vite-intlayer` package from `devDependencies` to `dependencies`.
|
|
382
|
+
|
|
383
|
+
```typescript {3,7} fileName="vite.config.ts" codeFormat="typescript"
|
|
384
|
+
import { defineConfig } from "vite";
|
|
385
|
+
import { svelte } from "@sveltejs/vite-plugin-svelte";
|
|
386
|
+
import { intlayer, intlayerProxy } from "vite-intlayer";
|
|
387
|
+
|
|
388
|
+
// https://vitejs.dev/config/
|
|
389
|
+
export default defineConfig({
|
|
390
|
+
plugins: [svelte(), intlayer(), intlayerProxy()],
|
|
391
|
+
});
|
|
392
|
+
```
|
|
393
|
+
|
|
394
|
+
```javascript {3,7} fileName="vite.config.mjs" codeFormat="esm"
|
|
395
|
+
import { defineConfig } from "vite";
|
|
396
|
+
import { svelte } from "@sveltejs/vite-plugin-svelte";
|
|
397
|
+
import { intlayer, intlayerProxy } from "vite-intlayer";
|
|
398
|
+
|
|
399
|
+
// https://vitejs.dev/config/
|
|
400
|
+
export default defineConfig({
|
|
401
|
+
plugins: [svelte(), intlayer(), intlayerProxy()],
|
|
402
|
+
});
|
|
403
|
+
```
|
|
404
|
+
|
|
405
|
+
```javascript {3,7} fileName="vite.config.cjs" codeFormat="commonjs"
|
|
406
|
+
const { defineConfig } = require("vite");
|
|
407
|
+
const { svelte } = require("@sveltejs/vite-plugin-svelte");
|
|
408
|
+
const { intlayer, intlayerProxy } = require("vite-intlayer");
|
|
409
|
+
|
|
410
|
+
// https://vitejs.dev/config/
|
|
411
|
+
module.exports = defineConfig({
|
|
412
|
+
plugins: [svelte(), intlayer(), intlayerProxy()],
|
|
413
|
+
});
|
|
414
|
+
```
|
|
181
415
|
|
|
182
416
|
### (Optional) Step 8: Change the URL when the locale changes
|
|
183
417
|
|
|
184
|
-
|
|
418
|
+
To allow users to switch languages and update the URL accordingly, you can create a `LocaleSwitcher` component. This component will use `getLocalizedUrl` from `intlayer` and `push` from `svelte-spa-router`.
|
|
419
|
+
|
|
420
|
+
```svelte fileName="src/lib/LocaleSwitcher.svelte"
|
|
421
|
+
<script lang="ts">
|
|
422
|
+
import { getLocaleName, getLocalizedUrl } from "intlayer";
|
|
423
|
+
import { useLocale } from "svelte-intlayer";
|
|
424
|
+
import { push } from "svelte-spa-router";
|
|
425
|
+
|
|
426
|
+
export let currentLocale: string | undefined = undefined;
|
|
427
|
+
|
|
428
|
+
// Get locale information
|
|
429
|
+
const { locale, availableLocales } = useLocale();
|
|
430
|
+
|
|
431
|
+
// Handle locale change
|
|
432
|
+
const changeLocale = (event: Event) => {
|
|
433
|
+
const target = event.target as HTMLSelectElement;
|
|
434
|
+
const newLocale = target.value;
|
|
435
|
+
const currentUrl = window.location.pathname;
|
|
436
|
+
const url = getLocalizedUrl( currentUrl, newLocale);
|
|
437
|
+
push(url);
|
|
438
|
+
};
|
|
439
|
+
</script>
|
|
440
|
+
|
|
441
|
+
<div class="locale-switcher">
|
|
442
|
+
<select value={currentLocale ?? $locale} onchange={changeLocale}>
|
|
443
|
+
{#each availableLocales ?? [] as loc}
|
|
444
|
+
<option value={loc}>
|
|
445
|
+
{getLocaleName(loc)}
|
|
446
|
+
</option>
|
|
447
|
+
{/each}
|
|
448
|
+
</select>
|
|
449
|
+
</div>
|
|
450
|
+
```
|
|
185
451
|
|
|
186
452
|
### (Optional) Step 9: Switch the HTML Language and Direction Attributes
|
|
187
453
|
|
|
@@ -189,7 +455,7 @@ module.exports = appContent;
|
|
|
189
455
|
|
|
190
456
|
### (Optional) Step 10: Creating a Localized Link Component
|
|
191
457
|
|
|
192
|
-
[to complete]
|
|
458
|
+
<!-- [to complete] -->
|
|
193
459
|
|
|
194
460
|
### Git Configuration
|
|
195
461
|
|
|
@@ -222,5 +488,3 @@ For more details on how to use the extension, refer to the [Intlayer VS Code Ext
|
|
|
222
488
|
### Go Further
|
|
223
489
|
|
|
224
490
|
To go further, you can implement the [visual editor](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/intlayer_visual_editor.md) or externalize your content using the [CMS](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/intlayer_CMS.md).
|
|
225
|
-
|
|
226
|
-
---
|
|
@@ -139,23 +139,23 @@ Add the intlayer plugin into your configuration.
|
|
|
139
139
|
|
|
140
140
|
```typescript fileName="vite.config.ts" codeFormat="typescript"
|
|
141
141
|
import { defineConfig } from "vite";
|
|
142
|
-
import
|
|
142
|
+
import { svelte } from "@sveltejs/vite-plugin-svelte";
|
|
143
143
|
import { intlayer } from "vite-intlayer";
|
|
144
144
|
|
|
145
145
|
// https://vitejs.dev/config/
|
|
146
146
|
export default defineConfig({
|
|
147
|
-
plugins: [
|
|
147
|
+
plugins: [svelte(), intlayer()],
|
|
148
148
|
});
|
|
149
149
|
```
|
|
150
150
|
|
|
151
151
|
```javascript fileName="vite.config.mjs" codeFormat="esm"
|
|
152
152
|
import { defineConfig } from "vite";
|
|
153
|
-
import
|
|
153
|
+
import { svelte } from "@sveltejs/vite-plugin-svelte";
|
|
154
154
|
import { intlayer } from "vite-intlayer";
|
|
155
155
|
|
|
156
156
|
// https://vitejs.dev/config/
|
|
157
157
|
export default defineConfig({
|
|
158
|
-
plugins: [
|
|
158
|
+
plugins: [svelte(), intlayer()],
|
|
159
159
|
});
|
|
160
160
|
```
|
|
161
161
|
|
|
@@ -181,7 +181,13 @@ import { t, type Dictionary } from "intlayer";
|
|
|
181
181
|
|
|
182
182
|
const appContent = {
|
|
183
183
|
key: "app",
|
|
184
|
-
content: {
|
|
184
|
+
content: {
|
|
185
|
+
title: t({
|
|
186
|
+
en: "Hello World",
|
|
187
|
+
fr: "Bonjour le monde",
|
|
188
|
+
es: "Hola mundo",
|
|
189
|
+
}),
|
|
190
|
+
},
|
|
185
191
|
} satisfies Dictionary;
|
|
186
192
|
|
|
187
193
|
export default appContent;
|
|
@@ -193,7 +199,13 @@ import { t } from "intlayer";
|
|
|
193
199
|
/** @type {import('intlayer').Dictionary} */
|
|
194
200
|
const appContent = {
|
|
195
201
|
key: "app",
|
|
196
|
-
content: {
|
|
202
|
+
content: {
|
|
203
|
+
title: t({
|
|
204
|
+
en: "Hello World",
|
|
205
|
+
fr: "Bonjour le monde",
|
|
206
|
+
es: "Hola mundo",
|
|
207
|
+
}),
|
|
208
|
+
},
|
|
197
209
|
};
|
|
198
210
|
|
|
199
211
|
export default appContent;
|
|
@@ -205,7 +217,13 @@ const { t } = require("intlayer");
|
|
|
205
217
|
/** @type {import('intlayer').Dictionary} */
|
|
206
218
|
const appContent = {
|
|
207
219
|
key: "app",
|
|
208
|
-
content: {
|
|
220
|
+
content: {
|
|
221
|
+
title: t({
|
|
222
|
+
en: "Hello World",
|
|
223
|
+
fr: "Bonjour le monde",
|
|
224
|
+
es: "Hola mundo",
|
|
225
|
+
}),
|
|
226
|
+
},
|
|
209
227
|
};
|
|
210
228
|
|
|
211
229
|
module.exports = appContent;
|
|
@@ -215,7 +233,16 @@ module.exports = appContent;
|
|
|
215
233
|
{
|
|
216
234
|
"$schema": "https://intlayer.org/schema.json",
|
|
217
235
|
"key": "app",
|
|
218
|
-
"content": {
|
|
236
|
+
"content": {
|
|
237
|
+
"title": {
|
|
238
|
+
"nodeType": "translation",
|
|
239
|
+
"translation": {
|
|
240
|
+
"en": "Hello World",
|
|
241
|
+
"fr": "Bonjour le monde",
|
|
242
|
+
"es": "Hola mundo"
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
}
|
|
219
246
|
}
|
|
220
247
|
```
|
|
221
248
|
|