@verbaly/sveltekit 0.77.0 → 0.79.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 CHANGED
@@ -21,7 +21,7 @@ pnpm add verbaly @verbaly/sveltekit @verbaly/svelte @verbaly/vite
21
21
 
22
22
  ## ⚡ Wire it up
23
23
 
24
- **1. Vite plugin** (extraction + the `virtual:verbaly` module):
24
+ **1. Vite plugin** (extraction + the `verbaly/app` module):
25
25
 
26
26
  ```ts
27
27
  // vite.config.ts
@@ -42,7 +42,7 @@ export default { plugins: [verbaly(), sveltekit()] };
42
42
  ```ts
43
43
  // src/hooks.server.ts
44
44
  import { verbalyHandle } from '@verbaly/sveltekit';
45
- import { locales, routing } from 'virtual:verbaly';
45
+ import { locales, routing } from 'verbaly/app';
46
46
 
47
47
  export const handle = verbalyHandle({ locales, routing });
48
48
  ```
@@ -65,7 +65,7 @@ right answer only when your URLs carry no language.
65
65
  ```ts
66
66
  // src/hooks.ts
67
67
  import { verbalyReroute } from '@verbaly/sveltekit';
68
- import { locales } from 'virtual:verbaly';
68
+ import { locales } from 'verbaly/app';
69
69
 
70
70
  export const reroute = verbalyReroute({ locales });
71
71
  ```
@@ -84,7 +84,7 @@ export const load = ({ locals }) => ({ locale: locals.verbalyLocale });
84
84
 
85
85
  ```ts
86
86
  // src/routes/+layout.ts
87
- import { createRequestInstance } from 'virtual:verbaly';
87
+ import { createRequestInstance } from 'verbaly/app';
88
88
 
89
89
  export const load = async ({ data }) => ({
90
90
  ...data,
@@ -108,17 +108,18 @@ export const load = async ({ data }) => ({
108
108
  {@render children()}
109
109
  ```
110
110
 
111
- **6. Switching languages** (client): persists the cookie the server hook reads:
111
+ **6. Switching languages** (client): with a prefix in your URLs it goes to the same page in the other language; without one it loads the catalog and switches this page. Either way it saves the choice in the cookie the server hook reads:
112
112
 
113
113
  ```svelte
114
114
  <script>
115
- import { switchLocale } from '@verbaly/sveltekit';
115
+ import { switchLocale } from 'verbaly/app';
116
116
  import { useVerbaly } from '@verbaly/svelte';
117
117
 
118
+ // the instance this page renders with: SvelteKit builds one per request in +layout.ts
118
119
  const verbaly = useVerbaly();
119
120
  </script>
120
121
 
121
- <button onclick={() => switchLocale(verbaly, 'es')}>Español</button>
122
+ <button onclick={() => switchLocale('es', { instance: verbaly })}>Español</button>
122
123
  ```
123
124
 
124
125
  ## 📖 API
@@ -127,7 +128,7 @@ export const load = async ({ data }) => ({
127
128
  | ----------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
128
129
  | `verbalyHandle({ locales, routing?, base?, fallback?, cookie? })` | SvelteKit `handle` hook: resolves the request locale (URL → cookie → `Accept-Language` → fallback), sets `event.locals.verbalyLocale`, fills `%verbaly.lang%` and `%verbaly.dir%` in `app.html`. |
129
130
  | `verbalyReroute({ locales, base? })` | Universal `reroute` hook for `hooks.ts`: `/es/docs` routes as `/docs`, so one route tree serves every language. |
130
- | `switchLocale(instance, locale, { cookie?, maxAge? })` | Awaits the catalog, switches the locale, writes the cookie and syncs `<html lang>`. SSR-safe. |
131
+ | `switchLocale(instance, locale, options?)` | The core's switch, which knows nothing of your project: pass `routing`, `supported` and `sourceLocale` yourself, or use the one from `verbaly/app` above, which already has them. |
131
132
  | `LOCALE_COOKIE` | Default cookie name (`verbaly-locale`), shared with core's `localStorage` key. |
132
133
 
133
134
  - **`routing` decides whether the URL is consulted.** With `prefix-except-source`, a prefixed URL is the answer and an unprefixed one means your source language, so a saved choice can never translate your source tree. Without `routing`, only the cookie and the header are read.
package/dist/index.js CHANGED
@@ -5,7 +5,7 @@ const LANG_PLACEHOLDER = "%verbaly.lang%";
5
5
  const DIR_PLACEHOLDER = "%verbaly.dir%";
6
6
  function verbalyHandle(options) {
7
7
  const { locales, cookie = LOCALE_COOKIE } = options;
8
- if (!Array.isArray(locales) || locales.length === 0) throw new Error("[verbaly] verbalyHandle needs `locales`: pass the `locales` export from 'virtual:verbaly' (requires @verbaly/vite ≥0.16) or list them yourself: verbalyHandle({ locales: [...] })");
8
+ if (!Array.isArray(locales) || locales.length === 0) throw new Error("[verbaly] verbalyHandle needs `locales`: pass the `locales` export from 'verbaly/app' (requires @verbaly/vite ≥0.16) or list them yourself: verbalyHandle({ locales: [...] })");
9
9
  const fallback = options.fallback ?? locales[0];
10
10
  return ({ event, resolve }) => {
11
11
  const resolved = resolveRequestLocale({
@@ -23,7 +23,7 @@ function verbalyHandle(options) {
23
23
  }
24
24
  function verbalyReroute(options) {
25
25
  const { locales } = options;
26
- if (!Array.isArray(locales) || locales.length === 0) throw new Error("[verbaly] verbalyReroute needs `locales`: pass the `locales` export from 'virtual:verbaly'");
26
+ if (!Array.isArray(locales) || locales.length === 0) throw new Error("[verbaly] verbalyReroute needs `locales`: pass the `locales` export from 'verbaly/app'");
27
27
  return ({ url }) => stripLocalePath({
28
28
  supported: locales,
29
29
  path: url.pathname,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@verbaly/sveltekit",
3
- "version": "0.77.0",
3
+ "version": "0.79.0",
4
4
  "description": "SvelteKit SSR integration for Verbaly: per-request locale negotiation and flash-free hydration.",
5
5
  "keywords": [
6
6
  "i18n",
@@ -44,12 +44,12 @@
44
44
  "access": "public"
45
45
  },
46
46
  "peerDependencies": {
47
- "verbaly": "^0.77.0"
47
+ "verbaly": "^0.79.0"
48
48
  },
49
49
  "devDependencies": {
50
50
  "@sveltejs/kit": "^3.1.1",
51
51
  "svelte": "^5.57.3",
52
- "verbaly": "^0.77.0"
52
+ "verbaly": "^0.79.0"
53
53
  },
54
54
  "scripts": {
55
55
  "build": "tsdown",