@verbaly/sveltekit 0.23.0 → 0.25.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 +7 -7
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -34,7 +34,7 @@ export default { plugins: [verbaly(), sveltekit()] };
|
|
|
34
34
|
**2. The lang placeholder** in `src/app.html`:
|
|
35
35
|
|
|
36
36
|
```html
|
|
37
|
-
<html lang="%verbaly.lang%">
|
|
37
|
+
<html lang="%verbaly.lang%" dir="%verbaly.dir%"></html>
|
|
38
38
|
```
|
|
39
39
|
|
|
40
40
|
**3. Server hook**: negotiates the locale per request:
|
|
@@ -99,16 +99,16 @@ export const load = async ({ data }) => ({
|
|
|
99
99
|
const verbaly = useVerbaly();
|
|
100
100
|
</script>
|
|
101
101
|
|
|
102
|
-
<button on:click={()
|
|
102
|
+
<button on:click="{()" ="">switchLocale(verbaly, 'es')}>Español</button>
|
|
103
103
|
```
|
|
104
104
|
|
|
105
105
|
## 📖 API
|
|
106
106
|
|
|
107
|
-
| Export
|
|
108
|
-
|
|
|
109
|
-
| `verbalyHandle({ locales, fallback?, cookie? })`
|
|
110
|
-
| `switchLocale(instance, locale, { cookie?, maxAge? })` | Awaits the catalog, switches the locale, writes the cookie and syncs `<html lang>`. SSR-safe.
|
|
111
|
-
| `LOCALE_COOKIE`
|
|
107
|
+
| Export | What it does |
|
|
108
|
+
| ------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
109
|
+
| `verbalyHandle({ locales, fallback?, cookie? })` | SvelteKit `handle` hook: resolves the request locale (cookie → `Accept-Language` → fallback), sets `event.locals.verbalyLocale`, fills `%verbaly.lang%` and `%verbaly.dir%` in `app.html`. |
|
|
110
|
+
| `switchLocale(instance, locale, { cookie?, maxAge? })` | Awaits the catalog, switches the locale, writes the cookie and syncs `<html lang>`. SSR-safe. |
|
|
111
|
+
| `LOCALE_COOKIE` | Default cookie name (`verbaly-locale`), shared with core's `localStorage` key. |
|
|
112
112
|
|
|
113
113
|
- `cookie: false` disables cookie reading/writing (pure `Accept-Language`).
|
|
114
114
|
- No dependency on `@sveltejs/kit`: the hook is typed structurally and stays compatible across Kit 2.x.
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { LOCALE_STORAGE_KEY, resolveRequestLocale, switchLocale } from "verbaly";
|
|
1
|
+
import { LOCALE_STORAGE_KEY, localeDirection, resolveRequestLocale, switchLocale } from "verbaly";
|
|
2
2
|
//#region src/index.ts
|
|
3
3
|
const LOCALE_COOKIE = LOCALE_STORAGE_KEY;
|
|
4
4
|
const LANG_PLACEHOLDER = "%verbaly.lang%";
|
|
5
|
+
const DIR_PLACEHOLDER = "%verbaly.dir%";
|
|
5
6
|
function verbalyHandle(options) {
|
|
6
7
|
const { locales, cookie = LOCALE_COOKIE } = options;
|
|
7
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: [...] })");
|
|
@@ -14,7 +15,7 @@ function verbalyHandle(options) {
|
|
|
14
15
|
fallback
|
|
15
16
|
});
|
|
16
17
|
event.locals.verbalyLocale = resolved;
|
|
17
|
-
return resolve(event, { transformPageChunk: ({ html }) => html.replaceAll(LANG_PLACEHOLDER, resolved) });
|
|
18
|
+
return resolve(event, { transformPageChunk: ({ html }) => html.replaceAll(LANG_PLACEHOLDER, resolved).replaceAll(DIR_PLACEHOLDER, localeDirection(resolved)) });
|
|
18
19
|
};
|
|
19
20
|
}
|
|
20
21
|
//#endregion
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["import { LOCALE_STORAGE_KEY, resolveRequestLocale } from 'verbaly';\n\n// derived from core's localStorage key: one identity per user across channels\nexport const LOCALE_COOKIE: string = LOCALE_STORAGE_KEY;\nconst LANG_PLACEHOLDER = '%verbaly.lang%';\n\n// structural subset of @sveltejs/kit: no runtime or type dependency on kit\ninterface HandleEvent {\n request: Request;\n cookies: { get(name: string): string | undefined };\n locals: { verbalyLocale?: string };\n}\ninterface ResolveOptions {\n transformPageChunk?(input: { html: string; done: boolean }): string | undefined;\n}\ninterface HandleInput {\n event: HandleEvent;\n resolve(event: HandleEvent, opts?: ResolveOptions): Response | Promise<Response>;\n}\n\nexport interface VerbalyHandleOptions {\n locales: string[];\n fallback?: string;\n cookie?: string | false;\n}\n\n// server hook: cookie → Accept-Language → fallback, per request.\n// Sets event.locals.verbalyLocale and fills %verbaly.lang% in app.html.\nexport function verbalyHandle(options: VerbalyHandleOptions) {\n const { locales, cookie = LOCALE_COOKIE } = options;\n if (!Array.isArray(locales) || locales.length === 0) {\n throw new Error(\n \"[verbaly] verbalyHandle needs `locales`: pass the `locales` export from 'virtual:verbaly' \" +\n '(requires @verbaly/vite ≥0.16) or list them yourself: verbalyHandle({ locales: [...] })',\n );\n }\n const fallback = options.fallback ?? locales[0]!;\n\n return ({ event, resolve }: HandleInput): Response | Promise<Response> => {\n const resolved = resolveRequestLocale({\n supported: locales,\n cookie: cookie ? event.cookies.get(cookie) : undefined,\n header: event.request.headers.get('accept-language'),\n fallback,\n });\n\n event.locals.verbalyLocale = resolved;\n return resolve(event, {\n transformPageChunk: ({ html })
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["import { LOCALE_STORAGE_KEY, localeDirection, resolveRequestLocale } from 'verbaly';\n\n// derived from core's localStorage key: one identity per user across channels\nexport const LOCALE_COOKIE: string = LOCALE_STORAGE_KEY;\nconst LANG_PLACEHOLDER = '%verbaly.lang%';\nconst DIR_PLACEHOLDER = '%verbaly.dir%';\n\n// structural subset of @sveltejs/kit: no runtime or type dependency on kit\ninterface HandleEvent {\n request: Request;\n cookies: { get(name: string): string | undefined };\n locals: { verbalyLocale?: string };\n}\ninterface ResolveOptions {\n transformPageChunk?(input: { html: string; done: boolean }): string | undefined;\n}\ninterface HandleInput {\n event: HandleEvent;\n resolve(event: HandleEvent, opts?: ResolveOptions): Response | Promise<Response>;\n}\n\nexport interface VerbalyHandleOptions {\n locales: string[];\n fallback?: string;\n cookie?: string | false;\n}\n\n// server hook: cookie → Accept-Language → fallback, per request.\n// Sets event.locals.verbalyLocale and fills %verbaly.lang% / %verbaly.dir% in app.html.\nexport function verbalyHandle(options: VerbalyHandleOptions) {\n const { locales, cookie = LOCALE_COOKIE } = options;\n if (!Array.isArray(locales) || locales.length === 0) {\n throw new Error(\n \"[verbaly] verbalyHandle needs `locales`: pass the `locales` export from 'virtual:verbaly' \" +\n '(requires @verbaly/vite ≥0.16) or list them yourself: verbalyHandle({ locales: [...] })',\n );\n }\n const fallback = options.fallback ?? locales[0]!;\n\n return ({ event, resolve }: HandleInput): Response | Promise<Response> => {\n const resolved = resolveRequestLocale({\n supported: locales,\n cookie: cookie ? event.cookies.get(cookie) : undefined,\n header: event.request.headers.get('accept-language'),\n fallback,\n });\n\n event.locals.verbalyLocale = resolved;\n return resolve(event, {\n transformPageChunk: ({ html }) =>\n html\n .replaceAll(LANG_PLACEHOLDER, resolved)\n .replaceAll(DIR_PLACEHOLDER, localeDirection(resolved)),\n });\n };\n}\n\n// switchLocale moved to core in 0.18.0 (shared with @verbaly/nuxt): same API, re-exported\nexport { switchLocale } from 'verbaly';\nexport type { SwitchLocaleOptions } from 'verbaly';\n"],"mappings":";;AAGA,MAAa,gBAAwB;AACrC,MAAM,mBAAmB;AACzB,MAAM,kBAAkB;AAwBxB,SAAgB,cAAc,SAA+B;CAC3D,MAAM,EAAE,SAAS,SAAS,kBAAkB;CAC5C,IAAI,CAAC,MAAM,QAAQ,OAAO,KAAK,QAAQ,WAAW,GAChD,MAAM,IAAI,MACR,mLAEF;CAEF,MAAM,WAAW,QAAQ,YAAY,QAAQ;CAE7C,QAAQ,EAAE,OAAO,cAAyD;EACxE,MAAM,WAAW,qBAAqB;GACpC,WAAW;GACX,QAAQ,SAAS,MAAM,QAAQ,IAAI,MAAM,IAAI,KAAA;GAC7C,QAAQ,MAAM,QAAQ,QAAQ,IAAI,iBAAiB;GACnD;EACF,CAAC;EAED,MAAM,OAAO,gBAAgB;EAC7B,OAAO,QAAQ,OAAO,EACpB,qBAAqB,EAAE,WACrB,KACG,WAAW,kBAAkB,QAAQ,CAAC,CACtC,WAAW,iBAAiB,gBAAgB,QAAQ,CAAC,EAC5D,CAAC;CACH;AACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@verbaly/sveltekit",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.25.0",
|
|
4
4
|
"description": "SvelteKit SSR integration for Verbaly: per-request locale negotiation and flash-free hydration.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"i18n",
|
|
@@ -40,12 +40,12 @@
|
|
|
40
40
|
"access": "public"
|
|
41
41
|
},
|
|
42
42
|
"peerDependencies": {
|
|
43
|
-
"verbaly": "^0.
|
|
43
|
+
"verbaly": "^0.25.0"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"@sveltejs/kit": "^2.
|
|
47
|
-
"svelte": "^5.56.
|
|
48
|
-
"verbaly": "0.
|
|
46
|
+
"@sveltejs/kit": "^2.70.0",
|
|
47
|
+
"svelte": "^5.56.6",
|
|
48
|
+
"verbaly": "0.25.0"
|
|
49
49
|
},
|
|
50
50
|
"scripts": {
|
|
51
51
|
"build": "tsdown",
|