@intlayer/docs 7.1.8 → 7.2.0
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 +1 -0
- package/dist/cjs/generated/docs.entry.cjs +19 -0
- package/dist/cjs/generated/docs.entry.cjs.map +1 -1
- package/dist/esm/generated/docs.entry.mjs +19 -0
- package/dist/esm/generated/docs.entry.mjs.map +1 -1
- package/dist/types/generated/docs.entry.d.ts +1 -0
- package/dist/types/generated/docs.entry.d.ts.map +1 -1
- package/docs/ar/intlayer_with_svelte_kit.md +730 -0
- package/docs/ar/intlayer_with_vite+svelte.md +288 -104
- package/docs/de/intlayer_with_svelte_kit.md +730 -0
- package/docs/de/intlayer_with_vite+svelte.md +302 -101
- package/docs/en/intlayer_with_svelte_kit.md +560 -0
- package/docs/en/intlayer_with_vite+svelte.md +153 -15
- package/docs/en/introduction.md +2 -0
- package/docs/en-GB/intlayer_with_svelte_kit.md +730 -0
- package/docs/en-GB/intlayer_with_vite+svelte.md +262 -84
- package/docs/es/intlayer_with_svelte_kit.md +730 -0
- package/docs/es/intlayer_with_vite+svelte.md +300 -107
- package/docs/fr/intlayer_with_svelte_kit.md +762 -0
- package/docs/fr/intlayer_with_vite+svelte.md +297 -101
- package/docs/hi/intlayer_with_svelte_kit.md +730 -0
- package/docs/hi/intlayer_with_vite+svelte.md +298 -108
- package/docs/id/intlayer_with_svelte_kit.md +730 -0
- package/docs/id/intlayer_with_vite+svelte.md +277 -99
- package/docs/it/intlayer_with_svelte_kit.md +762 -0
- package/docs/it/intlayer_with_vite+svelte.md +275 -99
- package/docs/ja/intlayer_with_svelte_kit.md +730 -0
- package/docs/ja/intlayer_with_vite+svelte.md +295 -110
- package/docs/ko/intlayer_with_svelte_kit.md +730 -0
- package/docs/ko/intlayer_with_vite+svelte.md +286 -199
- package/docs/pl/intlayer_with_svelte_kit.md +732 -0
- package/docs/pl/intlayer_with_vite+svelte.md +273 -101
- package/docs/pt/intlayer_with_svelte_kit.md +764 -0
- package/docs/pt/intlayer_with_vite+svelte.md +290 -96
- package/docs/ru/intlayer_with_svelte_kit.md +730 -0
- package/docs/ru/intlayer_with_vite+svelte.md +275 -99
- package/docs/tr/intlayer_with_svelte_kit.md +730 -0
- package/docs/tr/intlayer_with_vite+svelte.md +297 -119
- package/docs/vi/intlayer_with_svelte_kit.md +730 -0
- package/docs/vi/intlayer_with_vite+svelte.md +275 -102
- package/docs/zh/intlayer_with_svelte_kit.md +730 -0
- package/docs/zh/intlayer_with_vite+svelte.md +309 -107
- package/package.json +6 -6
- package/src/generated/docs.entry.ts +19 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
createdAt: 2025-04-18
|
|
3
|
-
updatedAt: 2025-
|
|
3
|
+
updatedAt: 2025-11-19
|
|
4
4
|
title: How to translate your Vite and Svelte app – i18n guide 2025
|
|
5
5
|
description: Discover how to make your Vite and Svelte website multilingual. Follow the documentation to internationalise (i18n) and translate it.
|
|
6
6
|
keywords:
|
|
@@ -14,18 +14,21 @@ slugs:
|
|
|
14
14
|
- doc
|
|
15
15
|
- environment
|
|
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
|
|
22
25
|
---
|
|
23
26
|
|
|
24
|
-
#
|
|
27
|
+
# Translate your Vite and Svelte website using Intlayer | Internationalisation (i18n)
|
|
25
28
|
|
|
26
|
-
|
|
29
|
+
## Table of Contents
|
|
27
30
|
|
|
28
|
-
|
|
31
|
+
<TOC/>
|
|
29
32
|
|
|
30
33
|
## What is Intlayer?
|
|
31
34
|
|
|
@@ -42,6 +45,16 @@ With Intlayer, you can:
|
|
|
42
45
|
|
|
43
46
|
## Step-by-Step Guide to Set Up Intlayer in a Vite and Svelte Application
|
|
44
47
|
|
|
48
|
+
<iframe
|
|
49
|
+
src="https://stackblitz.com/github/aymericzip/intlayer-vite-react-template?embed=1&ctl=1&file=intlayer.config.ts"
|
|
50
|
+
className="m-auto overflow-hidden rounded-lg border-0 max-md:size-full max-md:h-[700px] md:aspect-16/9 md:w-full"
|
|
51
|
+
title="Demo CodeSandbox - How to Internationalise your application using Intlayer"
|
|
52
|
+
sandbox="allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts"
|
|
53
|
+
loading="lazy"
|
|
54
|
+
/>
|
|
55
|
+
|
|
56
|
+
See [Application Template](https://github.com/aymericzip/intlayer-vite-svelte-template) on GitHub.
|
|
57
|
+
|
|
45
58
|
### Step 1: Install Dependencies
|
|
46
59
|
|
|
47
60
|
Install the necessary packages using npm:
|
|
@@ -61,9 +74,14 @@ yarn add intlayer svelte-intlayer
|
|
|
61
74
|
yarn add vite-intlayer --save-dev
|
|
62
75
|
```
|
|
63
76
|
|
|
77
|
+
```bash packageManager="bun"
|
|
78
|
+
bun add intlayer svelte-intlayer
|
|
79
|
+
bun add vite-intlayer --save-dev
|
|
80
|
+
```
|
|
81
|
+
|
|
64
82
|
- **intlayer**
|
|
65
83
|
|
|
66
|
-
The core package that provides internationalisation tools for configuration management, translation, [content declaration](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en-GB/dictionary/
|
|
84
|
+
The core package that provides internationalisation tools for configuration management, translation, [content declaration](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en-GB/dictionary/content_file.md), transpilation, and [CLI commands](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en-GB/intlayer_cli.md).
|
|
67
85
|
|
|
68
86
|
- **svelte-intlayer**
|
|
69
87
|
The package that integrates Intlayer with Svelte applications. It provides context providers and hooks for Svelte internationalisation.
|
|
@@ -75,7 +93,7 @@ yarn add vite-intlayer --save-dev
|
|
|
75
93
|
|
|
76
94
|
Create a config file to configure the languages of your application:
|
|
77
95
|
|
|
78
|
-
```typescript fileName="intlayer.config.ts"
|
|
96
|
+
```typescript fileName="intlayer.config.ts"
|
|
79
97
|
import { Locales, type IntlayerConfig } from "intlayer";
|
|
80
98
|
|
|
81
99
|
const config: IntlayerConfig = {
|
|
@@ -93,51 +111,13 @@ const config: IntlayerConfig = {
|
|
|
93
111
|
export default config;
|
|
94
112
|
```
|
|
95
113
|
|
|
96
|
-
```javascript fileName="intlayer.config.mjs" codeFormat="esm"
|
|
97
|
-
import { Locales } from "intlayer";
|
|
98
|
-
|
|
99
|
-
/** @type {import('intlayer').IntlayerConfig} */
|
|
100
|
-
const config = {
|
|
101
|
-
internationalization: {
|
|
102
|
-
locales: [
|
|
103
|
-
Locales.ENGLISH,
|
|
104
|
-
Locales.FRENCH,
|
|
105
|
-
Locales.SPANISH,
|
|
106
|
-
// Your other locales
|
|
107
|
-
],
|
|
108
|
-
defaultLocale: Locales.ENGLISH,
|
|
109
|
-
},
|
|
110
|
-
};
|
|
111
|
-
|
|
112
|
-
export default config;
|
|
113
|
-
```
|
|
114
|
-
|
|
115
|
-
```javascript fileName="intlayer.config.cjs" codeFormat="commonjs"
|
|
116
|
-
const { Locales } = require("intlayer");
|
|
117
|
-
|
|
118
|
-
/** @type {import('intlayer').IntlayerConfig} */
|
|
119
|
-
const config = {
|
|
120
|
-
internationalization: {
|
|
121
|
-
locales: [
|
|
122
|
-
Locales.ENGLISH,
|
|
123
|
-
Locales.FRENCH,
|
|
124
|
-
Locales.SPANISH,
|
|
125
|
-
// Your other locales
|
|
126
|
-
],
|
|
127
|
-
defaultLocale: Locales.ENGLISH,
|
|
128
|
-
},
|
|
129
|
-
};
|
|
130
|
-
|
|
131
|
-
module.exports = config;
|
|
132
|
-
```
|
|
133
|
-
|
|
134
114
|
> Through this configuration file, you can set up localised 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/docs/en-GB/configuration.md).
|
|
135
115
|
|
|
136
116
|
### Step 3: Integrate Intlayer in Your Vite Configuration
|
|
137
117
|
|
|
138
118
|
Add the intlayer plugin into your configuration.
|
|
139
119
|
|
|
140
|
-
```typescript fileName="vite.config.ts"
|
|
120
|
+
```typescript fileName="vite.config.ts"
|
|
141
121
|
import { defineConfig } from "vite";
|
|
142
122
|
import { svelte } from "@sveltejs/vite-plugin-svelte";
|
|
143
123
|
import { intlayer } from "vite-intlayer";
|
|
@@ -148,28 +128,6 @@ export default defineConfig({
|
|
|
148
128
|
});
|
|
149
129
|
```
|
|
150
130
|
|
|
151
|
-
```javascript fileName="vite.config.mjs" codeFormat="esm"
|
|
152
|
-
import { defineConfig } from "vite";
|
|
153
|
-
import { svelte } from "@sveltejs/vite-plugin-svelte";
|
|
154
|
-
import { intlayer } from "vite-intlayer";
|
|
155
|
-
|
|
156
|
-
// https://vitejs.dev/config/
|
|
157
|
-
export default defineConfig({
|
|
158
|
-
plugins: [svelte(), intlayer()],
|
|
159
|
-
});
|
|
160
|
-
```
|
|
161
|
-
|
|
162
|
-
```javascript fileName="vite.config.cjs" codeFormat="commonjs"
|
|
163
|
-
const { defineConfig } = require("vite");
|
|
164
|
-
const react = require("@vitejs/plugin-react-swc");
|
|
165
|
-
const { intlayer } = require("vite-intlayer");
|
|
166
|
-
|
|
167
|
-
// https://vitejs.dev/config/
|
|
168
|
-
module.exports = defineConfig({
|
|
169
|
-
plugins: [react(), intlayer()],
|
|
170
|
-
});
|
|
171
|
-
```
|
|
172
|
-
|
|
173
131
|
> The `intlayer()` 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 optimise performance.
|
|
174
132
|
|
|
175
133
|
### Step 4: Declare Your Content
|
|
@@ -197,6 +155,7 @@ export default appContent;
|
|
|
197
155
|
import { t } from "intlayer";
|
|
198
156
|
|
|
199
157
|
/** @type {import('intlayer').Dictionary} */
|
|
158
|
+
// Define the content dictionary for the app
|
|
200
159
|
const appContent = {
|
|
201
160
|
key: "app",
|
|
202
161
|
content: {
|
|
@@ -215,6 +174,7 @@ export default appContent;
|
|
|
215
174
|
const { t } = require("intlayer");
|
|
216
175
|
|
|
217
176
|
/** @type {import('intlayer').Dictionary} */
|
|
177
|
+
// Define the content dictionary for the app
|
|
218
178
|
const appContent = {
|
|
219
179
|
key: "app",
|
|
220
180
|
content: {
|
|
@@ -248,35 +208,255 @@ module.exports = appContent;
|
|
|
248
208
|
|
|
249
209
|
> Your content declarations can be defined anywhere in your application as soon as they are included in 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}`).
|
|
250
210
|
|
|
251
|
-
> For more details, refer to the [content declaration documentation](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en-GB/dictionary/
|
|
211
|
+
> For more details, refer to the [content declaration documentation](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en-GB/dictionary/content_file.md).
|
|
252
212
|
|
|
253
213
|
### Step 5: Utilise Intlayer in Your Code
|
|
254
214
|
|
|
255
|
-
|
|
215
|
+
```svelte fileName="src/App.svelte"
|
|
216
|
+
<script>
|
|
217
|
+
import { useIntlayer } from "svelte-intlayer";
|
|
256
218
|
|
|
257
|
-
|
|
219
|
+
const content = useIntlayer("app");
|
|
220
|
+
</script>
|
|
258
221
|
|
|
259
|
-
|
|
222
|
+
<div>
|
|
260
223
|
|
|
261
|
-
### (Optional) Step 7: Add Localised Routing to Your Application
|
|
262
224
|
|
|
263
|
-
|
|
225
|
+
<!-- Render content as simple content -->
|
|
226
|
+
<h1>{$content.title}</h1>
|
|
227
|
+
<!-- To render the content editable using the editor -->
|
|
228
|
+
<h1><svelte:component this={$content.title} /></h1>
|
|
229
|
+
<!-- To render the content as a string -->
|
|
230
|
+
<div aria-label={$content.title.value}></div>
|
|
231
|
+
```
|
|
264
232
|
|
|
265
|
-
### (Optional) Step
|
|
233
|
+
### (Optional) Step 6: Change the language of your content
|
|
266
234
|
|
|
267
|
-
|
|
235
|
+
```svelte fileName="src/App.svelte"
|
|
236
|
+
<script lang="ts">
|
|
237
|
+
import { getLocaleName } from 'intlayer';
|
|
238
|
+
import { useLocale } from 'svelte-intlayer';
|
|
268
239
|
|
|
269
|
-
|
|
240
|
+
// Get locale information and setLocale function
|
|
241
|
+
const { locale, availableLocales, setLocale } = useLocale();
|
|
270
242
|
|
|
271
|
-
|
|
243
|
+
// Handle locale change
|
|
244
|
+
const changeLocale = (event: Event) => {
|
|
245
|
+
const target = event.target as HTMLSelectElement;
|
|
246
|
+
const newLocale = target.value;
|
|
247
|
+
setLocale(newLocale);
|
|
248
|
+
};
|
|
249
|
+
</script>
|
|
250
|
+
|
|
251
|
+
<div>
|
|
252
|
+
<select value={$locale} on:change={changeLocale}>
|
|
253
|
+
{#each availableLocales ?? [] as loc}
|
|
254
|
+
<option value={loc}>
|
|
255
|
+
{getLocaleName(loc)}
|
|
256
|
+
</option>
|
|
257
|
+
{/each}
|
|
258
|
+
</select>
|
|
259
|
+
</div>
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
### (Optional) Step 7: Render Markdown
|
|
263
|
+
|
|
264
|
+
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 another markdown parser.
|
|
265
|
+
|
|
266
|
+
> To see how to declare markdown content using the `intlayer` package, see the [markdown doc](https://github.com/aymericzip/intlayer/tree/main/docs/docs/en-GB/dictionary/markdown.md).
|
|
267
|
+
|
|
268
|
+
```svelte fileName="src/App.svelte"
|
|
269
|
+
<script>
|
|
270
|
+
import { setIntlayerMarkdown } from "svelte-intlayer";
|
|
271
|
+
|
|
272
|
+
setIntlayerMarkdown((markdown) =>
|
|
273
|
+
// render the markdown content as a string
|
|
274
|
+
return markdown;
|
|
275
|
+
);
|
|
276
|
+
</script>
|
|
277
|
+
|
|
278
|
+
<h1>{$content.markdownContent}</h1>
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
> You can also access your markdown front-matter data using the `content.markdownContent.metadata.xxx` property.
|
|
282
|
+
|
|
283
|
+
### (Optional) Step 8: Set up the intlayer editor / CMS
|
|
284
|
+
|
|
285
|
+
To set up the intlayer editor, you must follow the [intlayer editor documentation](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en-GB/intlayer_visual_editor.md).
|
|
272
286
|
|
|
273
|
-
|
|
287
|
+
To set up the intlayer CMS, you must follow the [intlayer CMS documentation](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en-GB/intlayer_CMS.md).
|
|
288
|
+
|
|
289
|
+
In parallel, in your Svelte application, you must add the following line in a layout, or at the root of your application:
|
|
290
|
+
|
|
291
|
+
```svelte fileName="src/layout.svelte"
|
|
292
|
+
import { useIntlayerEditor } from "svelte-intlayer";
|
|
293
|
+
|
|
294
|
+
useIntlayerEditor();
|
|
295
|
+
```
|
|
274
296
|
|
|
275
|
-
|
|
297
|
+
### (Optional) Step 7: Add localised Routing to your application
|
|
298
|
+
|
|
299
|
+
To handle localised routing in your Svelte application, you can use `svelte-spa-router` along with Intlayer's `localeFlatMap` to generate routes for each locale.
|
|
300
|
+
|
|
301
|
+
First, install `svelte-spa-router`:
|
|
302
|
+
|
|
303
|
+
```bash packageManager="npm"
|
|
304
|
+
npm install svelte-spa-router
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
```bash packageManager="pnpm"
|
|
308
|
+
pnpm add svelte-spa-router
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
```bash packageManager="yarn"
|
|
312
|
+
yarn add svelte-spa-router
|
|
313
|
+
```
|
|
314
|
+
|
|
315
|
+
```bash packageManager="bun"
|
|
316
|
+
bun add svelte-spa-router
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
Then, create a `Router.svelte` file to define your routes:
|
|
320
|
+
|
|
321
|
+
```svelte fileName="src/Router.svelte"
|
|
322
|
+
<script lang="ts">
|
|
323
|
+
import { localeFlatMap } from "intlayer";
|
|
324
|
+
import Router from "svelte-spa-router";
|
|
325
|
+
import { wrap } from "svelte-spa-router/wrap";
|
|
326
|
+
import App from "./App.svelte";
|
|
327
|
+
|
|
328
|
+
const routes = Object.fromEntries(
|
|
329
|
+
localeFlatMap(({locale, urlPrefix}) => [
|
|
330
|
+
[
|
|
331
|
+
urlPrefix || '/',
|
|
332
|
+
wrap({
|
|
333
|
+
component: App as any,
|
|
334
|
+
props: {
|
|
335
|
+
locale,
|
|
336
|
+
},
|
|
337
|
+
}),
|
|
338
|
+
],
|
|
339
|
+
])
|
|
340
|
+
);
|
|
341
|
+
</script>
|
|
342
|
+
|
|
343
|
+
<Router {routes} />
|
|
344
|
+
```
|
|
345
|
+
|
|
346
|
+
Update your `main.ts` to mount the `Router` component instead of `App`:
|
|
347
|
+
|
|
348
|
+
```typescript fileName="src/main.ts"
|
|
349
|
+
import { mount } from "svelte";
|
|
350
|
+
import Router from "./Router.svelte";
|
|
351
|
+
|
|
352
|
+
const app = mount(Router, {
|
|
353
|
+
target: document.getElementById("app")!,
|
|
354
|
+
});
|
|
355
|
+
|
|
356
|
+
export default app;
|
|
357
|
+
```
|
|
358
|
+
|
|
359
|
+
Finally, update your `App.svelte` to receive the `locale` prop and use it with `useIntlayer`:
|
|
360
|
+
|
|
361
|
+
```svelte fileName="src/App.svelte"
|
|
362
|
+
<script lang="ts">
|
|
363
|
+
import type { Locale } from 'intlayer';
|
|
364
|
+
import { useIntlayer } from 'svelte-intlayer';
|
|
365
|
+
import Counter from './lib/Counter.svelte';
|
|
366
|
+
import LocaleSwitcher from './lib/LocaleSwitcher.svelte';
|
|
367
|
+
|
|
368
|
+
export let locale: Locale;
|
|
369
|
+
|
|
370
|
+
$: content = useIntlayer('app', locale);
|
|
371
|
+
</script>
|
|
372
|
+
|
|
373
|
+
<main>
|
|
374
|
+
<div class="locale-switcher-container">
|
|
375
|
+
<LocaleSwitcher currentLocale={locale} />
|
|
376
|
+
</div>
|
|
377
|
+
|
|
378
|
+
<!-- ... rest of your app ... -->
|
|
379
|
+
</main>
|
|
380
|
+
```
|
|
381
|
+
|
|
382
|
+
#### Configure Server-Side Routing (Optional)
|
|
383
|
+
|
|
384
|
+
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.
|
|
385
|
+
|
|
386
|
+
> Note that to use the `intlayerProxy` in production, you need to switch the `vite-intlayer` package from `devDependencies` to `dependencies`.
|
|
387
|
+
|
|
388
|
+
```typescript {3,7} fileName="vite.config.ts" codeFormat="typescript"
|
|
389
|
+
import { defineConfig } from "vite";
|
|
390
|
+
import { svelte } from "@sveltejs/vite-plugin-svelte";
|
|
391
|
+
import { intlayer, intlayerProxy } from "vite-intlayer";
|
|
392
|
+
|
|
393
|
+
// https://vitejs.dev/config/
|
|
394
|
+
export default defineConfig({
|
|
395
|
+
plugins: [svelte(), intlayer(), intlayerProxy()],
|
|
396
|
+
});
|
|
397
|
+
```
|
|
398
|
+
|
|
399
|
+
```javascript {3,7} fileName="vite.config.mjs" codeFormat="esm"
|
|
400
|
+
import { defineConfig } from "vite";
|
|
401
|
+
import { svelte } from "@sveltejs/vite-plugin-svelte";
|
|
402
|
+
import { intlayer, intlayerProxy } from "vite-intlayer";
|
|
403
|
+
|
|
404
|
+
// https://vitejs.dev/config/
|
|
405
|
+
export default defineConfig({
|
|
406
|
+
plugins: [svelte(), intlayer(), intlayerProxy()],
|
|
407
|
+
});
|
|
408
|
+
```
|
|
409
|
+
|
|
410
|
+
```javascript {3,7} fileName="vite.config.cjs" codeFormat="commonjs"
|
|
411
|
+
const { defineConfig } = require("vite");
|
|
412
|
+
const { svelte } = require("@sveltejs/vite-plugin-svelte");
|
|
413
|
+
const { intlayer, intlayerProxy } = require("vite-intlayer");
|
|
414
|
+
|
|
415
|
+
// https://vitejs.dev/config/
|
|
416
|
+
module.exports = defineConfig({
|
|
417
|
+
plugins: [svelte(), intlayer(), intlayerProxy()],
|
|
418
|
+
});
|
|
419
|
+
```
|
|
420
|
+
|
|
421
|
+
### (Optional) Step 8: Change the URL when the locale changes
|
|
422
|
+
|
|
423
|
+
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`.
|
|
424
|
+
|
|
425
|
+
```svelte fileName="src/lib/LocaleSwitcher.svelte"
|
|
426
|
+
<script lang="ts">
|
|
427
|
+
import { getLocaleName, getLocalizedUrl } from "intlayer";
|
|
428
|
+
import { useLocale } from "svelte-intlayer";
|
|
429
|
+
import { push } from "svelte-spa-router";
|
|
430
|
+
|
|
431
|
+
export let currentLocale: string | undefined = undefined;
|
|
432
|
+
|
|
433
|
+
// Get locale information
|
|
434
|
+
const { locale, availableLocales } = useLocale();
|
|
435
|
+
|
|
436
|
+
// Handle locale change
|
|
437
|
+
const changeLocale = (event: Event) => {
|
|
438
|
+
const target = event.target as HTMLSelectElement;
|
|
439
|
+
const newLocale = target.value;
|
|
440
|
+
const currentUrl = window.location.pathname;
|
|
441
|
+
const url = getLocalizedUrl(currentUrl, newLocale);
|
|
442
|
+
push(url);
|
|
443
|
+
};
|
|
444
|
+
</script>
|
|
445
|
+
|
|
446
|
+
<div class="locale-switcher">
|
|
447
|
+
<select value={currentLocale ?? $locale} onchange={changeLocale}>
|
|
448
|
+
{#each availableLocales ?? [] as loc}
|
|
449
|
+
<option value={loc}>
|
|
450
|
+
{getLocaleName(loc)}
|
|
451
|
+
</option>
|
|
452
|
+
{/each}
|
|
453
|
+
</select>
|
|
454
|
+
</div>
|
|
455
|
+
```
|
|
276
456
|
|
|
277
457
|
### Git Configuration
|
|
278
458
|
|
|
279
|
-
It is recommended to ignore the files generated by Intlayer. This
|
|
459
|
+
It is recommended to ignore the files generated by Intlayer. This prevents you from committing them to your Git repository.
|
|
280
460
|
|
|
281
461
|
To do this, you can add the following instructions to your `.gitignore` file:
|
|
282
462
|
|
|
@@ -287,7 +467,7 @@ To do this, you can add the following instructions to your `.gitignore` file:
|
|
|
287
467
|
|
|
288
468
|
### VS Code Extension
|
|
289
469
|
|
|
290
|
-
To
|
|
470
|
+
To improve your development experience with Intlayer, you can install the official **Intlayer VS Code Extension**.
|
|
291
471
|
|
|
292
472
|
[Install from the VS Code Marketplace](https://marketplace.visualstudio.com/items?itemName=intlayer.intlayer-vs-code-extension)
|
|
293
473
|
|
|
@@ -305,5 +485,3 @@ For more details on how to use the extension, refer to the [Intlayer VS Code Ext
|
|
|
305
485
|
### Go Further
|
|
306
486
|
|
|
307
487
|
To go further, you can implement the [visual editor](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en-GB/intlayer_visual_editor.md) or externalise your content using the [CMS](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en-GB/intlayer_CMS.md).
|
|
308
|
-
|
|
309
|
-
---
|