Skip to content

Commit cd71511

Browse files
committed
update examples
1 parent 346be27 commit cd71511

File tree

49 files changed

+336
-181
lines changed

Some content is hidden

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

49 files changed

+336
-181
lines changed
Lines changed: 1 addition & 0 deletions
Loading

examples/component-scoped-csr/src/lib/component/index.svelte

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,18 @@
22
import init from './translations';
33
const { t, locale, locales, translations, addTranslations, loadTranslations } = init();
44
5-
export let initLocale;
6-
export let initTranslations;
5+
let { initLocale = $bindable(), initTranslations = $bindable() } = $props();
76
87
addTranslations(initTranslations);
98
const promise = loadTranslations(initLocale);
109
11-
$: (initTranslations = $translations);
12-
$: ($locale = initLocale);
10+
$effect(() => {
11+
initTranslations = $translations;
12+
});
13+
14+
$effect(() => {
15+
$locale = initLocale;
16+
});
1317
</script>
1418

1519
<div>
@@ -19,7 +23,7 @@
1923
{:then}
2024
<p>{$t('common.info')}</p>
2125

22-
<select bind:value={initLocale} on:input={() => locale.set(initLocale)}>
26+
<select bind:value={initLocale} oninput={() => locale.set(initLocale)}>
2327
{#each $locales as l}
2428
<option value="{l}">{$t(`lang.${l}`)}</option>
2529
{/each}
@@ -33,4 +37,4 @@
3337
display: inline-block;
3438
padding: 20px;
3539
}
36-
</style>
40+
</style>
Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,36 @@
11
<script>
2+
import favicon from '$lib/assets/favicon.svg';
23
import { t, locale, locales } from '$lib/translations';
34
5+
let { children } = $props();
6+
47
const handleChange = ({ currentTarget }) => {
58
const { value } = currentTarget;
6-
79
document.cookie = `lang=${value} ;`;
810
};
911
10-
$: count = 2;
12+
let count = $state(2);
1113
</script>
1214

15+
<svelte:head>
16+
<link rel="icon" href={favicon} />
17+
</svelte:head>
18+
1319
<a href="/">{$t('menu.home')}</a>
1420
<a href="/about">{$t('menu.about')}</a>
1521
<br/>
1622
<br/>
1723
{$t('menu.notification', { count })}<br />
18-
<button on:click="{() => {if (count) count -= 1;}}">–</button>
19-
<button on:click="{() => {count += 1;}}">+</button>
24+
<button onclick={() => {if (count) count -= 1;}}>–</button>
25+
<button onclick={() => {count += 1;}}>+</button>
2026
<hr />
21-
<slot />
27+
{@render children()}
2228
<br />
2329
<br />
2430
<br />
2531
<br />
26-
<select bind:value="{$locale}" on:change={handleChange}>
32+
<select bind:value="{$locale}" onchange={handleChange}>
2733
{#each $locales as value}
2834
<option value="{value}">{$t(`lang.${value}`)}</option>
2935
{/each}
30-
</select>
36+
</select>

examples/component-scoped-csr/src/routes/+page.svelte

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
55
const link = 'https://kit.svelte.dev';
66
7-
let props = [
7+
let props = $state([
88
{
99
initLocale: 'cs',
1010
initTranslations: {},
@@ -13,11 +13,11 @@
1313
initLocale: 'de',
1414
initTranslations: {},
1515
},
16-
];
16+
]);
1717
1818
/** @type {import('./$types').Snapshot} */
1919
export const snapshot = {
20-
capture: () => props,
20+
capture: () => $state.snapshot(props),
2121
restore: (value) => { props = value; },
2222
};
2323
</script>
@@ -26,4 +26,4 @@
2626
<p>{@html $t('home.text', { link })}</p>
2727

2828
<Component bind:initLocale={props[0].initLocale} bind:initTranslations={props[0].initTranslations} />
29-
<Component bind:initLocale={props[1].initLocale} bind:initTranslations={props[1].initTranslations} />
29+
<Component bind:initLocale={props[1].initLocale} bind:initTranslations={props[1].initTranslations} />
Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
1-
import { sveltekit } from '@sveltejs/kit/vite';
2-
import { defineConfig } from 'vite';
1+
import { sveltekit } from "@sveltejs/kit/vite";
2+
import { defineConfig } from "vite";
3+
import path from "path";
34

45
export default defineConfig({
56
plugins: [sveltekit()],
7+
resolve: {
8+
alias: {
9+
"sveltekit-i18n": path.resolve(__dirname, "../../src/index.ts"),
10+
},
11+
},
612
});
Lines changed: 1 addition & 0 deletions
Loading
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
<script context="module">
1+
<script module>
22
export { default as init } from './translations';
33
</script>
44

55
<script>
6-
export let props;
6+
let { props = $bindable() } = $props();
77
88
const { translations, locale, locales, t } = props;
99
</script>
@@ -13,8 +13,8 @@
1313
<p>{$t('common.info')}</p>
1414

1515
<select bind:value="{$locale}">
16-
{#each $locales as locale}
17-
<option value="{locale}">{$t(`lang.${locale}`)}</option>
16+
{#each $locales as loc}
17+
<option value="{loc}">{$t(`lang.${loc}`)}</option>
1818
{/each}
1919
</select>
2020
</div>
@@ -25,4 +25,4 @@
2525
display: inline-block;
2626
padding: 20px;
2727
}
28-
</style>
28+
</style>
Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,36 @@
11
<script>
2+
import favicon from '$lib/assets/favicon.svg';
23
import { t, locale, locales } from '$lib/translations';
34
5+
let { children } = $props();
6+
47
const handleChange = ({ currentTarget }) => {
58
const { value } = currentTarget;
6-
79
document.cookie = `lang=${value} ;`;
810
};
911
10-
$: count = 2;
12+
let count = $state(2);
1113
</script>
1214

15+
<svelte:head>
16+
<link rel="icon" href={favicon} />
17+
</svelte:head>
18+
1319
<a href="/">{$t('menu.home')}</a>
1420
<a href="/about">{$t('menu.about')}</a>
1521
<br/>
1622
<br/>
1723
{$t('menu.notification', { count })}<br />
18-
<button on:click="{() => {if (count) count -= 1;}}">–</button>
19-
<button on:click="{() => {count += 1;}}">+</button>
24+
<button onclick={() => {if (count) count -= 1;}}>–</button>
25+
<button onclick={() => {count += 1;}}>+</button>
2026
<hr />
21-
<slot />
27+
{@render children()}
2228
<br />
2329
<br />
2430
<br />
2531
<br />
26-
<select bind:value="{$locale}" on:change={handleChange}>
32+
<select bind:value="{$locale}" onchange={handleChange}>
2733
{#each $locales as value}
2834
<option value="{value}">{$t(`lang.${value}`)}</option>
2935
{/each}
30-
</select>
36+
</select>

examples/component-scoped-ssr/src/routes/+page.svelte

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@
22
import Component from '$lib/component/index.svelte';
33
import { t } from '$lib/translations';
44
5-
export let data;
5+
let { data } = $props();
66
77
const link = 'https://kit.svelte.dev';
8-
98
</script>
109

1110
<h1>{$t('home.title')}</h1>
1211
<p>{@html $t('home.text', { link })}</p>
1312

1413
<Component bind:props={data.cs}/>
15-
<Component bind:props={data.de} />
14+
<Component bind:props={data.de} />
Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1-
import { sveltekit } from '@sveltejs/kit/vite';
1+
import { sveltekit } from "@sveltejs/kit/vite";
2+
import { defineConfig } from "vite";
3+
import path from "path";
24

3-
/** @type {import('vite').UserConfig} */
4-
const config = {
5+
export default defineConfig({
56
plugins: [sveltekit()],
6-
};
7-
8-
export default config;
7+
resolve: {
8+
alias: {
9+
"sveltekit-i18n": path.resolve(__dirname, "../../src/index.ts"),
10+
},
11+
},
12+
});

0 commit comments

Comments
 (0)