@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
|
@@ -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).
|
|
@@ -214,8 +217,15 @@ module.exports = appContent;
|
|
|
214
217
|
const content = useIntlayer("app");
|
|
215
218
|
</script>
|
|
216
219
|
|
|
217
|
-
<
|
|
220
|
+
<div>
|
|
218
221
|
|
|
222
|
+
|
|
223
|
+
<!-- Render content as simple content -->
|
|
224
|
+
<h1>{$content.title}</h1>
|
|
225
|
+
<!-- To render the content editable using the editor -->
|
|
226
|
+
<h1><svelte:component this={$content.title} /></h1>
|
|
227
|
+
<!-- To render the content as a string -->
|
|
228
|
+
<div aria-label={$content.title.value}></div>
|
|
219
229
|
```
|
|
220
230
|
|
|
221
231
|
### (Optional) Step 6: Change the language of your content
|
|
@@ -284,7 +294,90 @@ useIntlayerEditor();
|
|
|
284
294
|
|
|
285
295
|
### (Optional) Step 7: Add localized Routing to your application
|
|
286
296
|
|
|
287
|
-
|
|
297
|
+
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.
|
|
298
|
+
|
|
299
|
+
First, install `svelte-spa-router`:
|
|
300
|
+
|
|
301
|
+
```bash packageManager="npm"
|
|
302
|
+
npm install svelte-spa-router
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
```bash packageManager="pnpm"
|
|
306
|
+
pnpm add svelte-spa-router
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
```bash packageManager="yarn"
|
|
310
|
+
yarn add svelte-spa-router
|
|
311
|
+
```
|
|
312
|
+
|
|
313
|
+
```bash packageManager="bun"
|
|
314
|
+
bun add svelte-spa-router
|
|
315
|
+
```
|
|
316
|
+
|
|
317
|
+
Then, create a `Router.svelte` file to define your routes:
|
|
318
|
+
|
|
319
|
+
```svelte fileName="src/Router.svelte"
|
|
320
|
+
<script lang="ts">
|
|
321
|
+
import { localeFlatMap } from "intlayer";
|
|
322
|
+
import Router from "svelte-spa-router";
|
|
323
|
+
import { wrap } from "svelte-spa-router/wrap";
|
|
324
|
+
import App from "./App.svelte";
|
|
325
|
+
|
|
326
|
+
const routes = Object.fromEntries(
|
|
327
|
+
localeFlatMap(({locale, urlPrefix}) => [
|
|
328
|
+
[
|
|
329
|
+
urlPrefix || '/',
|
|
330
|
+
wrap({
|
|
331
|
+
component: App as any,
|
|
332
|
+
props: {
|
|
333
|
+
locale,
|
|
334
|
+
},
|
|
335
|
+
}),
|
|
336
|
+
],
|
|
337
|
+
])
|
|
338
|
+
);
|
|
339
|
+
</script>
|
|
340
|
+
|
|
341
|
+
<Router {routes} />
|
|
342
|
+
```
|
|
343
|
+
|
|
344
|
+
Update your `main.ts` to mount the `Router` component instead of `App`:
|
|
345
|
+
|
|
346
|
+
```typescript fileName="src/main.ts"
|
|
347
|
+
import { mount } from "svelte";
|
|
348
|
+
import Router from "./Router.svelte";
|
|
349
|
+
|
|
350
|
+
const app = mount(Router, {
|
|
351
|
+
target: document.getElementById("app")!,
|
|
352
|
+
});
|
|
353
|
+
|
|
354
|
+
export default app;
|
|
355
|
+
```
|
|
356
|
+
|
|
357
|
+
Finally, update your `App.svelte` to receive the `locale` prop and use it with `useIntlayer`:
|
|
358
|
+
|
|
359
|
+
```svelte fileName="src/App.svelte"
|
|
360
|
+
<script lang="ts">
|
|
361
|
+
import type { Locale } from 'intlayer';
|
|
362
|
+
import { useIntlayer } from 'svelte-intlayer';
|
|
363
|
+
import Counter from './lib/Counter.svelte';
|
|
364
|
+
import LocaleSwitcher from './lib/LocaleSwitcher.svelte';
|
|
365
|
+
|
|
366
|
+
export let locale: Locale;
|
|
367
|
+
|
|
368
|
+
$: content = useIntlayer('app', locale);
|
|
369
|
+
</script>
|
|
370
|
+
|
|
371
|
+
<main>
|
|
372
|
+
<div class="locale-switcher-container">
|
|
373
|
+
<LocaleSwitcher currentLocale={locale} />
|
|
374
|
+
</div>
|
|
375
|
+
|
|
376
|
+
<!-- ... rest of your app ... -->
|
|
377
|
+
</main>
|
|
378
|
+
```
|
|
379
|
+
|
|
380
|
+
#### Configure Server-Side Routing (Optional)
|
|
288
381
|
|
|
289
382
|
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.
|
|
290
383
|
|
|
@@ -292,48 +385,93 @@ In parallel, you can also use the `intlayerProxy` to add server-side routing to
|
|
|
292
385
|
|
|
293
386
|
```typescript {3,7} fileName="vite.config.ts" codeFormat="typescript"
|
|
294
387
|
import { defineConfig } from "vite";
|
|
295
|
-
import
|
|
388
|
+
import { svelte } from "@sveltejs/vite-plugin-svelte";
|
|
296
389
|
import { intlayer, intlayerProxy } from "vite-intlayer";
|
|
297
390
|
|
|
298
391
|
// https://vitejs.dev/config/
|
|
299
392
|
export default defineConfig({
|
|
300
|
-
plugins: [
|
|
393
|
+
plugins: [svelte(), intlayer(), intlayerProxy()],
|
|
301
394
|
});
|
|
302
395
|
```
|
|
303
396
|
|
|
304
397
|
```javascript {3,7} fileName="vite.config.mjs" codeFormat="esm"
|
|
305
398
|
import { defineConfig } from "vite";
|
|
306
|
-
import
|
|
399
|
+
import { svelte } from "@sveltejs/vite-plugin-svelte";
|
|
307
400
|
import { intlayer, intlayerProxy } from "vite-intlayer";
|
|
308
401
|
|
|
309
402
|
// https://vitejs.dev/config/
|
|
310
403
|
export default defineConfig({
|
|
311
|
-
plugins: [
|
|
404
|
+
plugins: [svelte(), intlayer(), intlayerProxy()],
|
|
312
405
|
});
|
|
313
406
|
```
|
|
314
407
|
|
|
315
408
|
```javascript {3,7} fileName="vite.config.cjs" codeFormat="commonjs"
|
|
316
409
|
const { defineConfig } = require("vite");
|
|
317
|
-
const
|
|
410
|
+
const { svelte } = require("@sveltejs/vite-plugin-svelte");
|
|
318
411
|
const { intlayer, intlayerProxy } = require("vite-intlayer");
|
|
319
412
|
|
|
320
413
|
// https://vitejs.dev/config/
|
|
321
414
|
module.exports = defineConfig({
|
|
322
|
-
plugins: [
|
|
415
|
+
plugins: [svelte(), intlayer(), intlayerProxy()],
|
|
323
416
|
});
|
|
324
417
|
```
|
|
325
418
|
|
|
326
419
|
### (Optional) Step 8: Change the URL when the locale changes
|
|
327
420
|
|
|
328
|
-
|
|
421
|
+
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`.
|
|
422
|
+
|
|
423
|
+
```svelte fileName="src/lib/LocaleSwitcher.svelte"
|
|
424
|
+
<script lang="ts">
|
|
425
|
+
import { getLocaleName, getLocalizedUrl } from "intlayer";
|
|
426
|
+
import { useLocale } from "svelte-intlayer";
|
|
427
|
+
import { push } from "svelte-spa-router";
|
|
329
428
|
|
|
330
|
-
|
|
429
|
+
export let currentLocale: string | undefined = undefined;
|
|
331
430
|
|
|
332
|
-
|
|
431
|
+
// Get locale information
|
|
432
|
+
const { locale, availableLocales } = useLocale();
|
|
333
433
|
|
|
334
|
-
|
|
434
|
+
// Handle locale change
|
|
435
|
+
const changeLocale = (event: Event) => {
|
|
436
|
+
const target = event.target as HTMLSelectElement;
|
|
437
|
+
const newLocale = target.value;
|
|
438
|
+
const currentUrl = window.location.pathname;
|
|
439
|
+
const url = getLocalizedUrl( currentUrl, newLocale);
|
|
440
|
+
push(url);
|
|
441
|
+
};
|
|
442
|
+
</script>
|
|
335
443
|
|
|
336
|
-
|
|
444
|
+
<div class="locale-switcher">
|
|
445
|
+
<select value={currentLocale ?? $locale} onchange={changeLocale}>
|
|
446
|
+
{#each availableLocales ?? [] as loc}
|
|
447
|
+
<option value={loc}>
|
|
448
|
+
{getLocaleName(loc)}
|
|
449
|
+
</option>
|
|
450
|
+
{/each}
|
|
451
|
+
</select>
|
|
452
|
+
</div>
|
|
453
|
+
```
|
|
454
|
+
|
|
455
|
+
### (Optional) Step 9: Internationalized Links
|
|
456
|
+
|
|
457
|
+
For SEO, it is recommended to prefix your routes with the locale (e.g., `/about`, `/fr/about`).
|
|
458
|
+
|
|
459
|
+
```svelte fileName="src/lib/components/Link.svelte"
|
|
460
|
+
<script lang="ts">
|
|
461
|
+
import { getLocalizedUrl } from "intlayer";
|
|
462
|
+
import { useLocale } from 'svelte-intlayer';
|
|
463
|
+
|
|
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
|
+
```
|
|
337
475
|
|
|
338
476
|
### Git Configuration
|
|
339
477
|
|
package/docs/en/introduction.md
CHANGED
|
@@ -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)**
|