@intlayer/docs 7.1.9 → 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.
Files changed (44) hide show
  1. package/README.md +1 -0
  2. package/dist/cjs/generated/docs.entry.cjs +19 -0
  3. package/dist/cjs/generated/docs.entry.cjs.map +1 -1
  4. package/dist/esm/generated/docs.entry.mjs +19 -0
  5. package/dist/esm/generated/docs.entry.mjs.map +1 -1
  6. package/dist/types/generated/docs.entry.d.ts +1 -0
  7. package/dist/types/generated/docs.entry.d.ts.map +1 -1
  8. package/docs/ar/intlayer_with_svelte_kit.md +730 -0
  9. package/docs/ar/intlayer_with_vite+svelte.md +288 -104
  10. package/docs/de/intlayer_with_svelte_kit.md +730 -0
  11. package/docs/de/intlayer_with_vite+svelte.md +302 -101
  12. package/docs/en/intlayer_with_svelte_kit.md +560 -0
  13. package/docs/en/intlayer_with_vite+svelte.md +22 -6
  14. package/docs/en/introduction.md +2 -0
  15. package/docs/en-GB/intlayer_with_svelte_kit.md +730 -0
  16. package/docs/en-GB/intlayer_with_vite+svelte.md +262 -84
  17. package/docs/es/intlayer_with_svelte_kit.md +730 -0
  18. package/docs/es/intlayer_with_vite+svelte.md +300 -107
  19. package/docs/fr/intlayer_with_svelte_kit.md +762 -0
  20. package/docs/fr/intlayer_with_vite+svelte.md +297 -101
  21. package/docs/hi/intlayer_with_svelte_kit.md +730 -0
  22. package/docs/hi/intlayer_with_vite+svelte.md +298 -108
  23. package/docs/id/intlayer_with_svelte_kit.md +730 -0
  24. package/docs/id/intlayer_with_vite+svelte.md +277 -99
  25. package/docs/it/intlayer_with_svelte_kit.md +762 -0
  26. package/docs/it/intlayer_with_vite+svelte.md +275 -99
  27. package/docs/ja/intlayer_with_svelte_kit.md +730 -0
  28. package/docs/ja/intlayer_with_vite+svelte.md +295 -110
  29. package/docs/ko/intlayer_with_svelte_kit.md +730 -0
  30. package/docs/ko/intlayer_with_vite+svelte.md +286 -199
  31. package/docs/pl/intlayer_with_svelte_kit.md +732 -0
  32. package/docs/pl/intlayer_with_vite+svelte.md +273 -101
  33. package/docs/pt/intlayer_with_svelte_kit.md +764 -0
  34. package/docs/pt/intlayer_with_vite+svelte.md +290 -96
  35. package/docs/ru/intlayer_with_svelte_kit.md +730 -0
  36. package/docs/ru/intlayer_with_vite+svelte.md +275 -99
  37. package/docs/tr/intlayer_with_svelte_kit.md +730 -0
  38. package/docs/tr/intlayer_with_vite+svelte.md +297 -119
  39. package/docs/vi/intlayer_with_svelte_kit.md +730 -0
  40. package/docs/vi/intlayer_with_vite+svelte.md +275 -102
  41. package/docs/zh/intlayer_with_svelte_kit.md +730 -0
  42. package/docs/zh/intlayer_with_vite+svelte.md +309 -107
  43. package/package.json +6 -6
  44. package/src/generated/docs.entry.ts +19 -0
@@ -0,0 +1,560 @@
1
+ ---
2
+ createdAt: 2025-11-20
3
+ updatedAt: 2025-11-20
4
+ title: How to translate your SvelteKit app – i18n guide 2025
5
+ description: Discover how to make your SvelteKit website multilingual. Follow the documentation to internationalize (i18n) and translate it using Server-Side Rendering (SSR).
6
+ keywords:
7
+ - Internationalization
8
+ - Documentation
9
+ - Intlayer
10
+ - SvelteKit
11
+ - JavaScript
12
+ - SSR
13
+ slugs:
14
+ - doc
15
+ - environment
16
+ - sveltekit
17
+ applicationTemplate: https://github.com/aymericzip/intlayer-sveltekit-template
18
+ history:
19
+ - version: 7.1.10
20
+ date: 2025-11-20
21
+ changes: Init history
22
+ ---
23
+
24
+ # Translate your SvelteKit website using Intlayer | Internationalization (i18n)
25
+
26
+ ## Table of Contents
27
+
28
+ <TOC/>
29
+
30
+ ## What is Intlayer?
31
+
32
+ **Intlayer** is an innovative, open-source internationalization (i18n) library designed to simplify multilingual support in modern web applications. It works seamlessly with **SvelteKit's** Server-Side Rendering (SSR) capabilities.
33
+
34
+ With Intlayer, you can:
35
+
36
+ - **Easily manage translations** using declarative dictionaries at the component level.
37
+ - **Dynamically localize metadata**, routes, and content.
38
+ - **Ensure TypeScript support** with autogenerated types.
39
+ - **Leverage SvelteKit's SSR** for SEO-friendly internationalization.
40
+
41
+ ---
42
+
43
+ ## Step-by-Step Guide to Set Up Intlayer in a SvelteKit Application
44
+
45
+ To get started, create a new SvelteKit project. Here is the final structure that we will make:
46
+
47
+ ```bash
48
+ .
49
+ ├── intlayer.config.ts
50
+ ├── package.json
51
+ ├── src
52
+ │ ├── app.d.ts
53
+ │   ├── app.html
54
+ │   ├── hooks.server.ts
55
+ │   ├── lib
56
+ │   │   ├── getLocale.ts
57
+ │   │   ├── LocaleSwitcher.svelte
58
+ │   │   └── LocalizedLink.svelte
59
+ │   ├── params
60
+ │   │   └── locale.ts
61
+ │   └── routes
62
+ │   ├── [[locale=locale]]
63
+ │   │   ├── +layout.svelte
64
+ │   │   ├── +layout.ts
65
+ │   │   ├── +page.svelte
66
+ │   │   ├── +page.ts
67
+ │   │   ├── about
68
+ │   │   │   ├── +page.svelte
69
+ │   │   │   ├── +page.ts
70
+ │   │   │   └── page.content.ts
71
+ │   │   ├── Counter.content.ts
72
+ │   │   ├── Counter.svelte
73
+ │   │   ├── Header.content.ts
74
+ │   │   ├── Header.svelte
75
+ │   │   ├── home.content.ts
76
+ │   │   └── layout.content.ts
77
+ │   ├── +layout.svelte
78
+ │   └── layout.css
79
+ ├── static
80
+ │   ├── favicon.svg
81
+ │   └── robots.txt
82
+ ├── svelte.config.js
83
+ ├── tsconfig.json
84
+ └── vite.config.ts
85
+ ```
86
+
87
+ ### Step 1: Install Dependencies
88
+
89
+ Install the necessary packages using npm:
90
+
91
+ ```bash packageManager="npm"
92
+ npm install intlayer svelte-intlayer
93
+ npm install vite-intlayer --save-dev
94
+ ```
95
+
96
+ ```bash packageManager="pnpm"
97
+ pnpm add intlayer svelte-intlayer
98
+ pnpm add vite-intlayer --save-dev
99
+ ```
100
+
101
+ ```bash packageManager="yarn"
102
+ yarn add intlayer svelte-intlayer
103
+ yarn add vite-intlayer --save-dev
104
+ ```
105
+
106
+ ```bash packageManager="bun"
107
+ bun add intlayer svelte-intlayer
108
+ bun add vite-intlayer --save-dev
109
+ ```
110
+
111
+ - **intlayer**: The core i18n package.
112
+ - **svelte-intlayer**: Provides context providers and stores for Svelte/SvelteKit.
113
+ - **vite-intlayer**: The Vite plugin to integrate content declarations with the build process.
114
+
115
+ ### Step 2: Configuration of your project
116
+
117
+ Create a config file in your project root:
118
+
119
+ ```typescript fileName="intlayer.config.ts"
120
+ import { Locales, type IntlayerConfig } from "intlayer";
121
+
122
+ const config: IntlayerConfig = {
123
+ internationalization: {
124
+ locales: [Locales.ENGLISH, Locales.FRENCH, Locales.SPANISH],
125
+ defaultLocale: Locales.ENGLISH,
126
+ },
127
+ };
128
+
129
+ export default config;
130
+ ```
131
+
132
+ ### Step 3: Integrate Intlayer in Your Vite Configuration
133
+
134
+ Update your `vite.config.ts` to include the Intlayer plugin. This plugin handles the transpilation of your content files.
135
+
136
+ ```typescript fileName="vite.config.ts"
137
+ import { sveltekit } from "@sveltejs/kit/vite";
138
+ import { defineConfig } from "vite";
139
+ import { intlayer } from "vite-intlayer";
140
+
141
+ export default defineConfig({
142
+ plugins: [intlayer(), sveltekit()], // order matters, Intlayer should be placed before SvelteKit
143
+ });
144
+ ```
145
+
146
+ ### Step 4: Declare Your Content
147
+
148
+ Create your content declaration files anywhere in your `src` folder (e.g., `src/lib/content` or alongside your components). These files define the translatable content for your application using the `t()` function for each locale.
149
+
150
+ ```ts fileName="src/features/hero/hero.content.ts" contentDeclarationFormat="typescript"
151
+ import { t, type Dictionary } from "intlayer";
152
+
153
+ const heroContent = {
154
+ key: "hero-section",
155
+ content: {
156
+ title: t({
157
+ en: "Welcome to SvelteKit",
158
+ fr: "Bienvenue sur SvelteKit",
159
+ es: "Bienvenido a SvelteKit",
160
+ }),
161
+ },
162
+ } satisfies Dictionary;
163
+
164
+ export default heroContent;
165
+ ```
166
+
167
+ ### Step 5: Utilize Intlayer in Your Components
168
+
169
+ Now you can use the `useIntlayer` function in any Svelte component. It returns a reactive store that automatically updates when the locale changes. The function will automatically respect the current locale (both during SSR and client-side navigation).
170
+
171
+ > **Note:** `useIntlayer` returns a Svelte store, so you need to use the `$` prefix to access its reactive value (e.g., `$content.title`).
172
+
173
+ ```svelte fileName="src/lib/components/Component.svelte"
174
+ <script lang="ts">
175
+ import { useIntlayer } from "svelte-intlayer";
176
+
177
+ // "hero-section" corresponds to the key defined in Step 4
178
+ const content = useIntlayer("hero-section");
179
+ </script>
180
+
181
+ <!-- Render content as simple content -->
182
+ <h1>{$content.title}</h1>
183
+ <!-- To render the content editable using the editor -->
184
+ <h1><svelte:component this={$content.title} /></h1>
185
+ <!-- To render the content as a string -->
186
+ <div aria-label={$content.title.value}></div>
187
+ ```
188
+
189
+ ### (Optional) Step 6: Set up routing
190
+
191
+ The following steps show how to set up locale-based routing in SvelteKit. This allows your URLs to include the locale prefix (e.g., `/en/about`, `/fr/about`) for better SEO and user experience.
192
+
193
+ ```bash
194
+ .
195
+ └─── src
196
+ ├── app.d.ts # Define the locale type
197
+ ├── hooks.server.ts # Manage locale routing
198
+ ├── lib
199
+ │   └── getLocale.ts # Check the locale from the header, cookies
200
+ ├── params
201
+ │   └── locale.ts # Define the locale parameter
202
+ └── routes
203
+ ├── [[locale=locale]] # Wrap in a route group to set the locale
204
+ │   ├── +layout.svelte # Local layout for the route
205
+ │   ├── +layout.ts
206
+ │   ├── +page.svelte
207
+ │   ├── +page.ts
208
+ │   └── about
209
+ │      ├── +page.svelte
210
+ │      └── +page.ts
211
+ └── +layout.svelte # Root layout for fonts and global styles
212
+ ```
213
+
214
+ ### Step 7: Handle Server-Side Locale Detection (Hooks)
215
+
216
+ In SvelteKit, the server needs to know the user's locale to render the correct content during SSR. We use `hooks.server.ts` to detect the locale from the URL or cookies.
217
+
218
+ Create or modify `src/hooks.server.ts`:
219
+
220
+ ```typescript fileName="src/hooks.server.ts"
221
+ import type { Handle } from "@sveltejs/kit";
222
+ import { getLocalizedUrl } from "intlayer";
223
+ import { getLocale } from "$lib/getLocale";
224
+
225
+ export const handle: Handle = async ({ event, resolve }) => {
226
+ const detectedLocale = getLocale(event);
227
+
228
+ // Check if the current path already starts with a locale (e.g. /fr, /en)
229
+ const pathname = event.url.pathname;
230
+ const targetPathname = getLocalizedUrl(pathname, detectedLocale);
231
+
232
+ // If NO locale is present in the URL (e.g. user visits "/"), redirect them
233
+ if (targetPathname !== pathname) {
234
+ return new Response(undefined, {
235
+ headers: { Location: targetPathname },
236
+ status: 307, // Temporary redirect
237
+ });
238
+ }
239
+
240
+ return resolve(event, {
241
+ transformPageChunk: ({ html }) => html.replace("%lang%", detectedLocale),
242
+ });
243
+ };
244
+ ```
245
+
246
+ Then, create a helper to get the user's locale from the request event:
247
+
248
+ ```typescript fileName="src/lib/getLocale.ts"
249
+ import {
250
+ configuration,
251
+ getLocaleFromStorage,
252
+ localeDetector,
253
+ type Locale,
254
+ } from "intlayer";
255
+ import type { RequestEvent } from "@sveltejs/kit";
256
+
257
+ /**
258
+ * Get the user's locale from the request event.
259
+ * This function is used in the `handle` hook in `src/hooks.server.ts`.
260
+ *
261
+ * It first tries to get the locale from the Intlayer storage (cookies or custom headers).
262
+ * If the locale is not found, it falls back to the browser's "Accept-Language" negotiation.
263
+ *
264
+ * @param event - The request event from SvelteKit
265
+ * @returns The user's locale
266
+ */
267
+ export const getLocale = (event: RequestEvent): Locale => {
268
+ const defaultLocale = configuration?.internationalization?.defaultLocale;
269
+
270
+ // Try to get locale from Intlayer storage (Cookies or headers)
271
+ const storedLocale = getLocaleFromStorage({
272
+ // SvelteKit cookies access
273
+ getCookie: (name: string) => event.cookies.get(name) ?? null,
274
+ // SvelteKit headers access
275
+ getHeader: (name: string) => event.request.headers.get(name) ?? null,
276
+ });
277
+
278
+ if (storedLocale) {
279
+ return storedLocale;
280
+ }
281
+
282
+ // Fallback to Browser "Accept-Language" negotiation
283
+ const negotiatorHeaders: Record<string, string> = {};
284
+
285
+ // Convert SvelteKit Headers object to a plain Record<string, string>
286
+ event.request.headers.forEach((value, key) => {
287
+ negotiatorHeaders[key] = value;
288
+ });
289
+
290
+ // Check the locale from the `Accept-Language` header
291
+ const userFallbackLocale = localeDetector(negotiatorHeaders);
292
+
293
+ if (userFallbackLocale) {
294
+ return userFallbackLocale;
295
+ }
296
+
297
+ // Return default locale if no match is found
298
+ return defaultLocale;
299
+ };
300
+ ```
301
+
302
+ > `getLocaleFromStorage` will check the locale from header or cookie depending on your configuration. See [Configuration](https://intlayer.org/doc/configuration) for more details.
303
+
304
+ > The `localeDetector` function will treat the `Accept-Language` header and return the best match.
305
+
306
+ If the locale is not configured, we want to return a 404 error. To make it easier, we can create a `match` function to check if the locale is valid:
307
+
308
+ ```ts fileName="/src/params/locale.ts"
309
+ import { configuration, type Locale } from "intlayer";
310
+
311
+ export const match = (
312
+ param: Locale = configuration.internationalization.defaultLocale
313
+ ): boolean => {
314
+ return configuration.internationalization.locales.includes(param);
315
+ };
316
+ ```
317
+
318
+ > **Note:** Ensure your `src/app.d.ts` includes the locale definition:
319
+ >
320
+ > ```typescript
321
+ > declare global {
322
+ > namespace App {
323
+ > interface Locals {
324
+ > locale: import("intlayer").Locale;
325
+ > }
326
+ > }
327
+ > }
328
+ > ```
329
+
330
+ For the `+layout.svelte` file, we can remove everything, to keep only static content, not related to i18n:
331
+
332
+ ```svelte fileName="src/+layout.svelte"
333
+ <script lang="ts">
334
+ import './layout.css';
335
+
336
+ let { children } = $props();
337
+ </script>
338
+
339
+ <div class="app">
340
+ {@render children()}
341
+ </div>
342
+
343
+ <style>
344
+ .app {
345
+ /* */
346
+ }
347
+ </style>
348
+ ```
349
+
350
+ Then, create a new page and layout under the `[[locale=locale]]` group:
351
+
352
+ ```ts fileName="src/routes/[[locale=locale]]/+layout.ts"
353
+ import type { Load } from "@sveltejs/kit";
354
+ import { configuration, type Locale } from "intlayer";
355
+
356
+ export const prerender = true;
357
+
358
+ // Use the generic Load type
359
+ export const load: Load = ({ params }) => {
360
+ const locale: Locale =
361
+ (params.locale as Locale) ??
362
+ configuration.internationalization.defaultLocale;
363
+
364
+ return {
365
+ locale,
366
+ };
367
+ };
368
+ ```
369
+
370
+ ```svelte fileName="src/routes/[[locale=locale]]/+layout.svelte"
371
+ <script lang="ts">
372
+ import type { Snippet } from 'svelte';
373
+ import { useIntlayer, setupIntlayer } from 'svelte-intlayer';
374
+ import Header from './Header.svelte';
375
+ import type { LayoutData } from './$types';
376
+
377
+ let { children, data }: { children: Snippet, data: LayoutData } = $props();
378
+
379
+ // Initialize Intlayer with the locale from the route
380
+ setupIntlayer(data.locale);
381
+
382
+ // Use the layout content dictionary
383
+ const layoutContent = useIntlayer('layout');
384
+ </script>
385
+
386
+ <Header />
387
+
388
+ <main>
389
+ {@render children()}
390
+ </main>
391
+
392
+ <footer>
393
+ <p>
394
+ {$layoutContent.footer.prefix.value}{' '}
395
+ <a href="https://svelte.dev/docs/kit">{$layoutContent.footer.linkLabel.value}</a>{' '}
396
+ {$layoutContent.footer.suffix.value}
397
+ </p>
398
+ </footer>
399
+
400
+ <style>
401
+ /* */
402
+ </style>
403
+ ```
404
+
405
+ ```ts fileName="src/routes/[[locale=locale]]/+page.ts"
406
+ export const prerender = true;
407
+ ```
408
+
409
+ ```svelte fileName="src/routes/[[locale=locale]]/+page.svelte"
410
+ <script lang="ts">
411
+ import { useIntlayer } from 'svelte-intlayer';
412
+
413
+ // Use the home content dictionary
414
+ const homeContent = useIntlayer('home');
415
+ </script>
416
+
417
+ <svelte:head>
418
+ <title>{$homeContent.title.value}</title>
419
+ </svelte:head>
420
+
421
+ <section>
422
+ <h1>
423
+ {$homeContent.title}
424
+ </h1>
425
+ </section>
426
+
427
+ <style>
428
+ /* */
429
+ </style>
430
+ ```
431
+
432
+ ### (Optional) Step 8: Internationalized Links
433
+
434
+ For SEO, it is recommended to prefix your routes with the locale (e.g., `/en/about`, `/fr/about`). This component automatically prefixes any link with the current locale.
435
+
436
+ ```svelte fileName="src/lib/components/LocalizedLink.svelte"
437
+ <script lang="ts">
438
+ import { getLocalizedUrl } from "intlayer";
439
+ import { useLocale } from 'svelte-intlayer';
440
+
441
+ let { href = "" } = $props();
442
+ const { locale } = useLocale();
443
+
444
+ // Helper to prefix URL with current locale
445
+ $: localizedHref = getLocalizedUrl(href, $locale);
446
+ </script>
447
+
448
+ <a href={localizedHref}>
449
+ <slot />
450
+ </a>
451
+ ```
452
+
453
+ If you use `goto` from SvelteKit, you can use the same logic with `getLocalizedUrl` to navigate to the localized URL:
454
+
455
+ ```typescript
456
+ import { goto } from "$app/navigation";
457
+ import { getLocalizedUrl } from "intlayer";
458
+ import { useLocale } from "svelte-intlayer";
459
+
460
+ const { locale } = useLocale();
461
+ const localizedPath = getLocalizedUrl("/about", $locale);
462
+ goto(localizedPath); // Navigates to /en/about or /fr/about depending on locale
463
+ ```
464
+
465
+ ### (Optional) Step 9: Language Switcher
466
+
467
+ To allow users to switch languages, update the URL.
468
+
469
+ ```svelte fileName="src/lib/components/LanguageSwitcher.svelte"
470
+ <script lang="ts">
471
+ import { getLocalizedUrl, getLocaleName } from 'intlayer';
472
+ import { useLocale } from 'svelte-intlayer';
473
+ import { page } from '$app/stores';
474
+ import { goto } from '$app/navigation';
475
+
476
+ const { locale, setLocale, availableLocales } = useLocale({
477
+ onLocaleChange: (newLocale) => {
478
+ const localizedPath = getLocalizedUrl($page.url.pathname, newLocale);
479
+ goto(localizedPath);
480
+ },
481
+ });
482
+ </script>
483
+
484
+ <ul class="locale-list">
485
+ {#each availableLocales as localeEl}
486
+ <li>
487
+ <a
488
+ href={getLocalizedUrl($page.url.pathname, localeEl)}
489
+ onclick={(e) => {
490
+ e.preventDefault();
491
+ setLocale(localeEl); // Will set the locale in the store and trigger onLocaleChange
492
+ }}
493
+ class:active={$locale === localeEl}
494
+ >
495
+ {getLocaleName(localeEl)}
496
+ </a>
497
+ </li>
498
+ {/each}
499
+ </ul>
500
+
501
+ <style>
502
+ /* */
503
+ </style>
504
+ ```
505
+
506
+ ### (Optional) Step 10: Add backend proxy
507
+
508
+ To add a backend proxy to your SvelteKit application, you can use the `intlayerProxy` function provided by the `vite-intlayer` plugin. This plugin will automatically detect the best locale for the user based on the URL, cookies, and browser language preferences.
509
+
510
+ ```ts fileName="vite.config.ts"
511
+ import { defineConfig } from "vite";
512
+ import { intlayer, intlayerProxy } from "vite-intlayer";
513
+ import { sveltekit } from "@sveltejs/kit/vite";
514
+
515
+ // https://vitejs.dev/config/
516
+ export default defineConfig({
517
+ plugins: [intlayer(), intlayerProxy(), sveltekit()],
518
+ });
519
+ ```
520
+
521
+ ### (Optional) Step 11: Set up the intlayer editor / CMS
522
+
523
+ 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).
524
+
525
+ 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).
526
+
527
+ To be able to visualize the intlayer editor selector, you will have to use the component syntax in your intlayer content.
528
+
529
+ ```svelte fileName="Component.svelte"
530
+ <script lang="ts">
531
+ import { useIntlayer } from "svelte-intlayer";
532
+
533
+ const content = useIntlayer("component");
534
+ </script>
535
+
536
+ <div>
537
+
538
+ <!-- Render content as simple content -->
539
+ <h1>{$content.title}</h1>
540
+
541
+ <!-- Render content as a component (required by the editor) -->
542
+ <svelte:component this={$content.component} />
543
+ </div>
544
+ ```
545
+
546
+ ### Git Configuration
547
+
548
+ It is recommended to ignore the files generated by Intlayer.
549
+
550
+ ```plaintext fileName=".gitignore"
551
+ # Ignore the files generated by Intlayer
552
+ .intlayer
553
+ ```
554
+
555
+ ---
556
+
557
+ ### Go Further
558
+
559
+ - **Visual Editor**: Integrate the [Intlayer Visual Editor](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/intlayer_visual_editor.md) to edit translations directly from the UI.
560
+ - **CMS**: Externalize your content management using the [Intlayer CMS](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/intlayer_CMS.md).
@@ -26,8 +26,6 @@ history:
26
26
 
27
27
  # Translate your Vite and Svelte website using Intlayer | Internationalization (i18n)
28
28
 
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
30
-
31
29
  ## Table of Contents
32
30
 
33
31
  <TOC/>
@@ -76,6 +74,11 @@ yarn add intlayer svelte-intlayer
76
74
  yarn add vite-intlayer --save-dev
77
75
  ```
78
76
 
77
+ ```bash packageManager="bun"
78
+ bun add intlayer svelte-intlayer
79
+ bun add vite-intlayer --save-dev
80
+ ```
81
+
79
82
  - **intlayer**
80
83
 
81
84
  The core package that provides internationalization tools for configuration management, translation, [content declaration](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/dictionary/content_file.md), transpilation, and [CLI commands](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/intlayer_cli.md).
@@ -449,13 +452,26 @@ const changeLocale = (event: Event) => {
449
452
  </div>
450
453
  ```
451
454
 
452
- ### (Optional) Step 9: Switch the HTML Language and Direction Attributes
455
+ ### (Optional) Step 9: Internationalized Links
453
456
 
454
- [to complete]
457
+ For SEO, it is recommended to prefix your routes with the locale (e.g., `/about`, `/fr/about`).
455
458
 
456
- ### (Optional) Step 10: Creating a Localized Link Component
459
+ ```svelte fileName="src/lib/components/Link.svelte"
460
+ <script lang="ts">
461
+ import { getLocalizedUrl } from "intlayer";
462
+ import { useLocale } from 'svelte-intlayer';
457
463
 
458
- <!-- [to complete] -->
464
+ export let href = "";
465
+ const { locale } = useLocale();
466
+
467
+ // Helper to prefix URL
468
+ $: localizedHref = getLocalizedUrl(href, $locale);
469
+ </script>
470
+
471
+ <a href={localizedHref}>
472
+ <slot />
473
+ </a>
474
+ ```
459
475
 
460
476
  ### Git Configuration
461
477
 
@@ -200,6 +200,8 @@ We’ve built Intlayer with flexibility in mind, offering seamless integration a
200
200
  - **[Intlayer with Vite + Preact](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/intlayer_with_vite+preact.md)**
201
201
  - **[Intlayer with Vite + Vue](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/intlayer_with_vite+vue.md)**
202
202
  - **[Intlayer with Nuxt](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/intlayer_with_nuxt.md)**
203
+ - **[Intlayer with Vite + Svelte](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/intlayer_with_vite+svelte.md)**
204
+ - **[Intlayer with SvelteKit](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/intlayer_with_svelte_kit.md)**
203
205
  - **[Intlayer with Express](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/intlayer_with_express.md)**
204
206
  - **[Intlayer with NestJS](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/intlayer_with_nestjs.md)**
205
207
  - **[Intlayer with Angular](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/intlayer_with_angular.md)**