diff --git a/package.json b/package.json
index 6e42b710..50ada7c9 100644
--- a/package.json
+++ b/package.json
@@ -13,8 +13,8 @@
],
"scripts": {
"dev": "bun run --hot apps/web/src/index.ts",
- "i18n:compile": "paraglide-js compile --project ./packages/webui/project.inlang --outdir ./packages/webui/src/paraglide --emit-ts-declarations",
- "i18n:watch": "paraglide-js compile --project ./packages/webui/project.inlang --outdir ./packages/webui/src/paraglide --watch --emit-ts-declarations",
+ "i18n:compile": "paraglide-js compile --project ./packages/webui/project.inlang --outdir ./packages/webui/src/paraglide --emit-ts-declarations --no-emit-git-ignore",
+ "i18n:watch": "paraglide-js compile --project ./packages/webui/project.inlang --outdir ./packages/webui/src/paraglide --watch --emit-ts-declarations --no-emit-git-ignore",
"typecheck": "tsc --noEmit",
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"test": "bun --bun vitest run",
diff --git a/packages/webui/package.json b/packages/webui/package.json
index 30b32a9a..7beef393 100644
--- a/packages/webui/package.json
+++ b/packages/webui/package.json
@@ -86,8 +86,8 @@
"ulid": "3.0.2"
},
"scripts": {
- "i18n:compile": "paraglide-js compile --project ./project.inlang --outdir ./src/paraglide --emit-ts-declarations",
- "i18n:watch": "paraglide-js compile --project ./project.inlang --outdir ./src/paraglide --watch --emit-ts-declarations"
+ "i18n:compile": "paraglide-js compile --project ./project.inlang --outdir ./src/paraglide --emit-ts-declarations --no-emit-git-ignore",
+ "i18n:watch": "paraglide-js compile --project ./project.inlang --outdir ./src/paraglide --watch --emit-ts-declarations --no-emit-git-ignore"
},
"devDependencies": {
"typescript": "6.0.3",
diff --git a/packages/webui/src/paraglide/.prettierignore b/packages/webui/src/paraglide/.prettierignore
new file mode 100644
index 00000000..7e18fe45
--- /dev/null
+++ b/packages/webui/src/paraglide/.prettierignore
@@ -0,0 +1,3 @@
+# ignore everything because the directory is auto-generated by inlang paraglide-js
+# for more info visit https://paraglidejs.com
+*
diff --git a/packages/webui/src/paraglide/README.md b/packages/webui/src/paraglide/README.md
new file mode 100644
index 00000000..c9706762
--- /dev/null
+++ b/packages/webui/src/paraglide/README.md
@@ -0,0 +1,162 @@
+# Paraglide JS Compiled Output
+
+> Auto-generated i18n message functions. Import `messages.js` to use translated strings.
+
+Compiled from: `/Users/yiling/Projects/shumai/packages/webui/project.inlang`
+
+
+## What is this folder?
+
+This folder contains compiled [Paraglide JS](https://github.com/opral/paraglide-js) output. Paraglide JS compiles your translation messages into tree-shakeable JavaScript functions.
+
+## At a glance
+
+Purpose:
+- This folder stores compiled i18n message functions.
+- Source translations live outside this folder in your inlang project.
+
+Safe to import:
+- `messages.js` — all message functions
+- `runtime.js` — locale utilities
+- `server.js` — server-side middleware
+
+Do not edit:
+- All files in this folder are auto-generated.
+- Changes will be overwritten on next compilation.
+
+```
+paraglide/
+├── messages.js # Message exports (import this)
+├── messages/ # Individual message functions
+├── runtime.js # Locale detection & configuration
+├── registry.js # Formatting utilities (plural, number, datetime, relativetime)
+├── server.js # Server-side middleware
+└── .gitignore # Marks folder as generated
+```
+
+## Usage
+
+```js
+import * as m from "./paraglide/messages.js";
+
+// Messages are functions that return localized strings
+m.hello_world(); // "Hello, World!" (in current locale)
+m.greeting({ name: "Sam" }); // "Hello, Sam!"
+
+// Override locale per-call
+m.hello_world({}, { locale: "de" }); // "Hallo, Welt!"
+m.greeting({ name: "Sam" }, { locale: "de" }); // "Hallo, Sam!"
+```
+
+## Runtime API
+
+```js
+import { getLocale, getTextDirection, setLocale, locales, baseLocale } from "./paraglide/runtime.js";
+
+getLocale(); // Current locale, e.g., "en"
+getTextDirection(); // "ltr" | "rtl" for current locale
+setLocale("de"); // Set locale
+locales; // Available locales, e.g., ["en", "de", "fr"]
+baseLocale; // Default locale, e.g., "en"
+```
+
+## Strategy
+
+The strategy determines how the current locale is detected and persisted:
+
+- **Cookie**: Stores locale preference in a cookie.
+- **URL**: Derives locale from URL patterns (e.g., `/en/about`, `en.example.com`).
+- **GlobalVariable**: Uses a global variable (client-side only).
+- **BaseLocale**: Always returns the base locale.
+
+Strategies can be combined. The order defines precedence:
+
+```js
+await compile({
+ project: "./project.inlang",
+ outdir: "./src/paraglide",
+ strategy: ["url", "cookie", "baseLocale"],
+});
+```
+
+See the [strategy documentation](https://paraglidejs.com/strategy) for details.
+
+## Markup (Rich Text)
+
+Messages can contain markup tags for bold, links, and other inline elements. Translators control where tags appear; developers control how they render.
+
+Important:
+- Tag names are app-defined. There is no built-in list of HTML tags.
+- `{#b}...{/b}` does not automatically render as `...`.
+- Renderers/snippets are looked up by the same tag name used in the message.
+
+### Message syntax
+
+```json
+{
+ "cta": "{#link to=|/docs| rel=$relationship @track}Read the docs{/link}",
+ "welcome": "{#b}Hi {name}{/b}{#icon/}"
+}
+```
+
+- `{#tagName}` opens a tag, `{/tagName}` closes it.
+- `{#tagName/}` creates a standalone tag.
+- Options: `to=|/docs|` or `rel=$relationship` (accessed via `options.*`).
+- Attributes: `@track` or `@variant=|hero|` (accessed via `attributes.*`).
+
+This is the default inlang message syntax. Paraglide's message format is plugin-based — you can use [ICU MessageFormat 1](https://inlang.com/m/p7c8m1d2/plugin-inlang-icu-messageformat-1), [i18next](https://inlang.com/m/3i8bor92/plugin-inlang-i18next), or other [plugins](https://inlang.com/c/plugins) instead.
+
+### Rendering markup
+
+Calling the message function still returns **plain text** (markup stripped):
+
+```js
+m.cta({ relationship: "noopener" }); // "Read the docs"
+```
+
+To render markup, use the framework adapter or the low-level `parts()` API:
+
+```js
+const parts = m.cta.parts({ relationship: "noopener" });
+// [
+// { type: "markup-start", name: "link", options: { to: "/docs", rel: "noopener" }, attributes: { track: true } },
+// { type: "text", value: "Read the docs" },
+// { type: "markup-end", name: "link" }
+// ]
+```
+
+Framework adapters provide a `` component that accepts markup renderers:
+
+- `@inlang/paraglide-js-react`
+- `@inlang/paraglide-js-vue`
+- `@inlang/paraglide-js-svelte`
+- `@inlang/paraglide-js-solid`
+
+```jsx
+import { ParaglideMessage } from "@inlang/paraglide-js-react"; // or -vue, -svelte, -solid
+
+ {children},
+ icon: () => ,
+ }}
+/>
+```
+
+The available renderer/snippet names come from the message itself. You can inspect them through `message.parts()`, and TypeScript uses the same names to type-check your markup renderers.
+
+See the [markup documentation](https://paraglidejs.com/markup) for details.
+
+## Key concepts
+
+- **Tree-shakeable**: Each message is a function, enabling [up to 70% smaller i18n bundle sizes](https://paraglidejs.com/benchmark) than traditional i18n libraries.
+- **Typesafe**: Full TypeScript/JSDoc support with autocomplete.
+- **Variants**: Messages can have variants for pluralization, gender, etc.
+- **Fallbacks**: Missing translations fall back to the base locale.
+
+## Links
+
+- [Paraglide JS Documentation](https://paraglidejs.com)
+- [Source Repository](https://github.com/opral/paraglide-js)
diff --git a/packages/webui/src/paraglide/messages.d.ts b/packages/webui/src/paraglide/messages.d.ts
new file mode 100644
index 00000000..59e887e0
--- /dev/null
+++ b/packages/webui/src/paraglide/messages.d.ts
@@ -0,0 +1,2 @@
+export * from "./messages/_index.js";
+export * as m from "./messages/_index.js";
diff --git a/packages/webui/src/paraglide/messages.js b/packages/webui/src/paraglide/messages.js
new file mode 100644
index 00000000..608d20d4
--- /dev/null
+++ b/packages/webui/src/paraglide/messages.js
@@ -0,0 +1,4 @@
+/* eslint-disable */
+export * from './messages/_index.js'
+// enabling auto-import by exposing all messages as m
+export * as m from './messages/_index.js'
\ No newline at end of file
diff --git a/packages/webui/src/paraglide/messages/_index.d.ts b/packages/webui/src/paraglide/messages/_index.d.ts
new file mode 100644
index 00000000..e90b6717
--- /dev/null
+++ b/packages/webui/src/paraglide/messages/_index.d.ts
@@ -0,0 +1,20 @@
+export * from "./dashboard.js";
+export * from "./notifications.js";
+export * from "./uploads.js";
+export * from "./language.js";
+export * from "./personal_info.js";
+export * from "./language_settings.js";
+export * from "./select_preferred_language.js";
+export * from "./settings.js";
+export * from "./welcome_back.js";
+export * from "./create_account.js";
+export * from "./select_a_team.js";
+export * from "./projects.js";
+export * from "./select_asset_to_view_details.js";
+export * from "./all_collections.js";
+export * from "./file_not_found.js";
+export * from "./recently_deleted_notice.js";
+export * from "./all_share_links.js";
+export * from "./link_visibility.js";
+export * from "./password_protected.js";
+export type LocalizedString = import("../runtime.js").LocalizedString;
diff --git a/packages/webui/src/paraglide/messages/_index.js b/packages/webui/src/paraglide/messages/_index.js
new file mode 100644
index 00000000..14d6f326
--- /dev/null
+++ b/packages/webui/src/paraglide/messages/_index.js
@@ -0,0 +1,21 @@
+/* eslint-disable */
+/** @typedef {import('../runtime.js').LocalizedString} LocalizedString */
+export * from './dashboard.js'
+export * from './notifications.js'
+export * from './uploads.js'
+export * from './language.js'
+export * from './personal_info.js'
+export * from './language_settings.js'
+export * from './select_preferred_language.js'
+export * from './settings.js'
+export * from './welcome_back.js'
+export * from './create_account.js'
+export * from './select_a_team.js'
+export * from './projects.js'
+export * from './select_asset_to_view_details.js'
+export * from './all_collections.js'
+export * from './file_not_found.js'
+export * from './recently_deleted_notice.js'
+export * from './all_share_links.js'
+export * from './link_visibility.js'
+export * from './password_protected.js'
\ No newline at end of file
diff --git a/packages/webui/src/paraglide/messages/all_collections.d.ts b/packages/webui/src/paraglide/messages/all_collections.d.ts
new file mode 100644
index 00000000..be2b68d3
--- /dev/null
+++ b/packages/webui/src/paraglide/messages/all_collections.d.ts
@@ -0,0 +1,16 @@
+/**
+* | output |
+* | --- |
+* | "All Collections" |
+*
+* @param {All_CollectionsInputs} inputs
+* @param {{ locale?: "en" | "zh" }} options
+* @returns {LocalizedString}
+*/
+export const all_collections: ((inputs?: All_CollectionsInputs, options?: {
+ locale?: "en" | "zh";
+}) => LocalizedString) & import("../runtime.js").MessageMetadata;
+export type LocalizedString = import("../runtime.js").LocalizedString;
+export type All_CollectionsInputs = {};
diff --git a/packages/webui/src/paraglide/messages/all_collections.js b/packages/webui/src/paraglide/messages/all_collections.js
new file mode 100644
index 00000000..df77f554
--- /dev/null
+++ b/packages/webui/src/paraglide/messages/all_collections.js
@@ -0,0 +1,29 @@
+/* eslint-disable */
+import { getLocale, experimentalStaticLocale } from '../runtime.js';
+
+/** @typedef {import('../runtime.js').LocalizedString} LocalizedString */
+
+/** @typedef {{}} All_CollectionsInputs */
+
+const en_all_collections = /** @type {(inputs: All_CollectionsInputs) => LocalizedString} */ () => {
+ return /** @type {LocalizedString} */ (`All Collections`)
+};
+
+const zh_all_collections = /** @type {(inputs: All_CollectionsInputs) => LocalizedString} */ () => {
+ return /** @type {LocalizedString} */ (`所有收藏`)
+};
+
+/**
+* | output |
+* | --- |
+* | "All Collections" |
+*
+* @param {All_CollectionsInputs} inputs
+* @param {{ locale?: "en" | "zh" }} options
+* @returns {LocalizedString}
+*/
+export const all_collections = /** @type {((inputs?: All_CollectionsInputs, options?: { locale?: "en" | "zh" }) => LocalizedString) & import('../runtime.js').MessageMetadata} */ ((inputs = {}, options = {}) => {
+ const locale = experimentalStaticLocale ?? options.locale ?? getLocale()
+ if (locale === "en") return en_all_collections(inputs)
+ return zh_all_collections(inputs)
+});
\ No newline at end of file
diff --git a/packages/webui/src/paraglide/messages/all_share_links.d.ts b/packages/webui/src/paraglide/messages/all_share_links.d.ts
new file mode 100644
index 00000000..53c53466
--- /dev/null
+++ b/packages/webui/src/paraglide/messages/all_share_links.d.ts
@@ -0,0 +1,16 @@
+/**
+* | output |
+* | --- |
+* | "All Share Links" |
+*
+* @param {All_Share_LinksInputs} inputs
+* @param {{ locale?: "en" | "zh" }} options
+* @returns {LocalizedString}
+*/
+export const all_share_links: ((inputs?: All_Share_LinksInputs, options?: {
+ locale?: "en" | "zh";
+}) => LocalizedString) & import("../runtime.js").MessageMetadata;
+export type LocalizedString = import("../runtime.js").LocalizedString;
+export type All_Share_LinksInputs = {};
diff --git a/packages/webui/src/paraglide/messages/all_share_links.js b/packages/webui/src/paraglide/messages/all_share_links.js
new file mode 100644
index 00000000..25a26ea5
--- /dev/null
+++ b/packages/webui/src/paraglide/messages/all_share_links.js
@@ -0,0 +1,29 @@
+/* eslint-disable */
+import { getLocale, experimentalStaticLocale } from '../runtime.js';
+
+/** @typedef {import('../runtime.js').LocalizedString} LocalizedString */
+
+/** @typedef {{}} All_Share_LinksInputs */
+
+const en_all_share_links = /** @type {(inputs: All_Share_LinksInputs) => LocalizedString} */ () => {
+ return /** @type {LocalizedString} */ (`All Share Links`)
+};
+
+const zh_all_share_links = /** @type {(inputs: All_Share_LinksInputs) => LocalizedString} */ () => {
+ return /** @type {LocalizedString} */ (`所有分享链接`)
+};
+
+/**
+* | output |
+* | --- |
+* | "All Share Links" |
+*
+* @param {All_Share_LinksInputs} inputs
+* @param {{ locale?: "en" | "zh" }} options
+* @returns {LocalizedString}
+*/
+export const all_share_links = /** @type {((inputs?: All_Share_LinksInputs, options?: { locale?: "en" | "zh" }) => LocalizedString) & import('../runtime.js').MessageMetadata} */ ((inputs = {}, options = {}) => {
+ const locale = experimentalStaticLocale ?? options.locale ?? getLocale()
+ if (locale === "en") return en_all_share_links(inputs)
+ return zh_all_share_links(inputs)
+});
\ No newline at end of file
diff --git a/packages/webui/src/paraglide/messages/create_account.d.ts b/packages/webui/src/paraglide/messages/create_account.d.ts
new file mode 100644
index 00000000..75fc7e07
--- /dev/null
+++ b/packages/webui/src/paraglide/messages/create_account.d.ts
@@ -0,0 +1,16 @@
+/**
+* | output |
+* | --- |
+* | "Create Account" |
+*
+* @param {Create_AccountInputs} inputs
+* @param {{ locale?: "en" | "zh" }} options
+* @returns {LocalizedString}
+*/
+export const create_account: ((inputs?: Create_AccountInputs, options?: {
+ locale?: "en" | "zh";
+}) => LocalizedString) & import("../runtime.js").MessageMetadata;
+export type LocalizedString = import("../runtime.js").LocalizedString;
+export type Create_AccountInputs = {};
diff --git a/packages/webui/src/paraglide/messages/create_account.js b/packages/webui/src/paraglide/messages/create_account.js
new file mode 100644
index 00000000..755536ee
--- /dev/null
+++ b/packages/webui/src/paraglide/messages/create_account.js
@@ -0,0 +1,29 @@
+/* eslint-disable */
+import { getLocale, experimentalStaticLocale } from '../runtime.js';
+
+/** @typedef {import('../runtime.js').LocalizedString} LocalizedString */
+
+/** @typedef {{}} Create_AccountInputs */
+
+const en_create_account = /** @type {(inputs: Create_AccountInputs) => LocalizedString} */ () => {
+ return /** @type {LocalizedString} */ (`Create Account`)
+};
+
+const zh_create_account = /** @type {(inputs: Create_AccountInputs) => LocalizedString} */ () => {
+ return /** @type {LocalizedString} */ (`创建账户`)
+};
+
+/**
+* | output |
+* | --- |
+* | "Create Account" |
+*
+* @param {Create_AccountInputs} inputs
+* @param {{ locale?: "en" | "zh" }} options
+* @returns {LocalizedString}
+*/
+export const create_account = /** @type {((inputs?: Create_AccountInputs, options?: { locale?: "en" | "zh" }) => LocalizedString) & import('../runtime.js').MessageMetadata} */ ((inputs = {}, options = {}) => {
+ const locale = experimentalStaticLocale ?? options.locale ?? getLocale()
+ if (locale === "en") return en_create_account(inputs)
+ return zh_create_account(inputs)
+});
\ No newline at end of file
diff --git a/packages/webui/src/paraglide/messages/dashboard.d.ts b/packages/webui/src/paraglide/messages/dashboard.d.ts
new file mode 100644
index 00000000..aba907b4
--- /dev/null
+++ b/packages/webui/src/paraglide/messages/dashboard.d.ts
@@ -0,0 +1,16 @@
+/**
+* | output |
+* | --- |
+* | "Dashboard" |
+*
+* @param {DashboardInputs} inputs
+* @param {{ locale?: "en" | "zh" }} options
+* @returns {LocalizedString}
+*/
+export const dashboard: ((inputs?: DashboardInputs, options?: {
+ locale?: "en" | "zh";
+}) => LocalizedString) & import("../runtime.js").MessageMetadata;
+export type LocalizedString = import("../runtime.js").LocalizedString;
+export type DashboardInputs = {};
diff --git a/packages/webui/src/paraglide/messages/dashboard.js b/packages/webui/src/paraglide/messages/dashboard.js
new file mode 100644
index 00000000..85ab1d5d
--- /dev/null
+++ b/packages/webui/src/paraglide/messages/dashboard.js
@@ -0,0 +1,29 @@
+/* eslint-disable */
+import { getLocale, experimentalStaticLocale } from '../runtime.js';
+
+/** @typedef {import('../runtime.js').LocalizedString} LocalizedString */
+
+/** @typedef {{}} DashboardInputs */
+
+const en_dashboard = /** @type {(inputs: DashboardInputs) => LocalizedString} */ () => {
+ return /** @type {LocalizedString} */ (`Dashboard`)
+};
+
+const zh_dashboard = /** @type {(inputs: DashboardInputs) => LocalizedString} */ () => {
+ return /** @type {LocalizedString} */ (`控制台`)
+};
+
+/**
+* | output |
+* | --- |
+* | "Dashboard" |
+*
+* @param {DashboardInputs} inputs
+* @param {{ locale?: "en" | "zh" }} options
+* @returns {LocalizedString}
+*/
+export const dashboard = /** @type {((inputs?: DashboardInputs, options?: { locale?: "en" | "zh" }) => LocalizedString) & import('../runtime.js').MessageMetadata} */ ((inputs = {}, options = {}) => {
+ const locale = experimentalStaticLocale ?? options.locale ?? getLocale()
+ if (locale === "en") return en_dashboard(inputs)
+ return zh_dashboard(inputs)
+});
\ No newline at end of file
diff --git a/packages/webui/src/paraglide/messages/file_not_found.d.ts b/packages/webui/src/paraglide/messages/file_not_found.d.ts
new file mode 100644
index 00000000..1a1e477c
--- /dev/null
+++ b/packages/webui/src/paraglide/messages/file_not_found.d.ts
@@ -0,0 +1,16 @@
+/**
+* | output |
+* | --- |
+* | "File not found." |
+*
+* @param {File_Not_FoundInputs} inputs
+* @param {{ locale?: "en" | "zh" }} options
+* @returns {LocalizedString}
+*/
+export const file_not_found: ((inputs?: File_Not_FoundInputs, options?: {
+ locale?: "en" | "zh";
+}) => LocalizedString) & import("../runtime.js").MessageMetadata;
+export type LocalizedString = import("../runtime.js").LocalizedString;
+export type File_Not_FoundInputs = {};
diff --git a/packages/webui/src/paraglide/messages/file_not_found.js b/packages/webui/src/paraglide/messages/file_not_found.js
new file mode 100644
index 00000000..ab9f5af2
--- /dev/null
+++ b/packages/webui/src/paraglide/messages/file_not_found.js
@@ -0,0 +1,29 @@
+/* eslint-disable */
+import { getLocale, experimentalStaticLocale } from '../runtime.js';
+
+/** @typedef {import('../runtime.js').LocalizedString} LocalizedString */
+
+/** @typedef {{}} File_Not_FoundInputs */
+
+const en_file_not_found = /** @type {(inputs: File_Not_FoundInputs) => LocalizedString} */ () => {
+ return /** @type {LocalizedString} */ (`File not found.`)
+};
+
+const zh_file_not_found = /** @type {(inputs: File_Not_FoundInputs) => LocalizedString} */ () => {
+ return /** @type {LocalizedString} */ (`文件未找到。`)
+};
+
+/**
+* | output |
+* | --- |
+* | "File not found." |
+*
+* @param {File_Not_FoundInputs} inputs
+* @param {{ locale?: "en" | "zh" }} options
+* @returns {LocalizedString}
+*/
+export const file_not_found = /** @type {((inputs?: File_Not_FoundInputs, options?: { locale?: "en" | "zh" }) => LocalizedString) & import('../runtime.js').MessageMetadata} */ ((inputs = {}, options = {}) => {
+ const locale = experimentalStaticLocale ?? options.locale ?? getLocale()
+ if (locale === "en") return en_file_not_found(inputs)
+ return zh_file_not_found(inputs)
+});
\ No newline at end of file
diff --git a/packages/webui/src/paraglide/messages/language.d.ts b/packages/webui/src/paraglide/messages/language.d.ts
new file mode 100644
index 00000000..1dce30b1
--- /dev/null
+++ b/packages/webui/src/paraglide/messages/language.d.ts
@@ -0,0 +1,16 @@
+/**
+* | output |
+* | --- |
+* | "Language" |
+*
+* @param {LanguageInputs} inputs
+* @param {{ locale?: "en" | "zh" }} options
+* @returns {LocalizedString}
+*/
+export const language: ((inputs?: LanguageInputs, options?: {
+ locale?: "en" | "zh";
+}) => LocalizedString) & import("../runtime.js").MessageMetadata;
+export type LocalizedString = import("../runtime.js").LocalizedString;
+export type LanguageInputs = {};
diff --git a/packages/webui/src/paraglide/messages/language.js b/packages/webui/src/paraglide/messages/language.js
new file mode 100644
index 00000000..a1052f5e
--- /dev/null
+++ b/packages/webui/src/paraglide/messages/language.js
@@ -0,0 +1,29 @@
+/* eslint-disable */
+import { getLocale, experimentalStaticLocale } from '../runtime.js';
+
+/** @typedef {import('../runtime.js').LocalizedString} LocalizedString */
+
+/** @typedef {{}} LanguageInputs */
+
+const en_language = /** @type {(inputs: LanguageInputs) => LocalizedString} */ () => {
+ return /** @type {LocalizedString} */ (`Language`)
+};
+
+const zh_language = /** @type {(inputs: LanguageInputs) => LocalizedString} */ () => {
+ return /** @type {LocalizedString} */ (`语言`)
+};
+
+/**
+* | output |
+* | --- |
+* | "Language" |
+*
+* @param {LanguageInputs} inputs
+* @param {{ locale?: "en" | "zh" }} options
+* @returns {LocalizedString}
+*/
+export const language = /** @type {((inputs?: LanguageInputs, options?: { locale?: "en" | "zh" }) => LocalizedString) & import('../runtime.js').MessageMetadata} */ ((inputs = {}, options = {}) => {
+ const locale = experimentalStaticLocale ?? options.locale ?? getLocale()
+ if (locale === "en") return en_language(inputs)
+ return zh_language(inputs)
+});
\ No newline at end of file
diff --git a/packages/webui/src/paraglide/messages/language_settings.d.ts b/packages/webui/src/paraglide/messages/language_settings.d.ts
new file mode 100644
index 00000000..c41fe9c8
--- /dev/null
+++ b/packages/webui/src/paraglide/messages/language_settings.d.ts
@@ -0,0 +1,16 @@
+/**
+* | output |
+* | --- |
+* | "Language Settings" |
+*
+* @param {Language_SettingsInputs} inputs
+* @param {{ locale?: "en" | "zh" }} options
+* @returns {LocalizedString}
+*/
+export const language_settings: ((inputs?: Language_SettingsInputs, options?: {
+ locale?: "en" | "zh";
+}) => LocalizedString) & import("../runtime.js").MessageMetadata;
+export type LocalizedString = import("../runtime.js").LocalizedString;
+export type Language_SettingsInputs = {};
diff --git a/packages/webui/src/paraglide/messages/language_settings.js b/packages/webui/src/paraglide/messages/language_settings.js
new file mode 100644
index 00000000..fe99a99a
--- /dev/null
+++ b/packages/webui/src/paraglide/messages/language_settings.js
@@ -0,0 +1,29 @@
+/* eslint-disable */
+import { getLocale, experimentalStaticLocale } from '../runtime.js';
+
+/** @typedef {import('../runtime.js').LocalizedString} LocalizedString */
+
+/** @typedef {{}} Language_SettingsInputs */
+
+const en_language_settings = /** @type {(inputs: Language_SettingsInputs) => LocalizedString} */ () => {
+ return /** @type {LocalizedString} */ (`Language Settings`)
+};
+
+const zh_language_settings = /** @type {(inputs: Language_SettingsInputs) => LocalizedString} */ () => {
+ return /** @type {LocalizedString} */ (`语言设置`)
+};
+
+/**
+* | output |
+* | --- |
+* | "Language Settings" |
+*
+* @param {Language_SettingsInputs} inputs
+* @param {{ locale?: "en" | "zh" }} options
+* @returns {LocalizedString}
+*/
+export const language_settings = /** @type {((inputs?: Language_SettingsInputs, options?: { locale?: "en" | "zh" }) => LocalizedString) & import('../runtime.js').MessageMetadata} */ ((inputs = {}, options = {}) => {
+ const locale = experimentalStaticLocale ?? options.locale ?? getLocale()
+ if (locale === "en") return en_language_settings(inputs)
+ return zh_language_settings(inputs)
+});
\ No newline at end of file
diff --git a/packages/webui/src/paraglide/messages/link_visibility.d.ts b/packages/webui/src/paraglide/messages/link_visibility.d.ts
new file mode 100644
index 00000000..10c5b8e2
--- /dev/null
+++ b/packages/webui/src/paraglide/messages/link_visibility.d.ts
@@ -0,0 +1,16 @@
+/**
+* | output |
+* | --- |
+* | "Link Visibility" |
+*
+* @param {Link_VisibilityInputs} inputs
+* @param {{ locale?: "en" | "zh" }} options
+* @returns {LocalizedString}
+*/
+export const link_visibility: ((inputs?: Link_VisibilityInputs, options?: {
+ locale?: "en" | "zh";
+}) => LocalizedString) & import("../runtime.js").MessageMetadata;
+export type LocalizedString = import("../runtime.js").LocalizedString;
+export type Link_VisibilityInputs = {};
diff --git a/packages/webui/src/paraglide/messages/link_visibility.js b/packages/webui/src/paraglide/messages/link_visibility.js
new file mode 100644
index 00000000..e8cef864
--- /dev/null
+++ b/packages/webui/src/paraglide/messages/link_visibility.js
@@ -0,0 +1,29 @@
+/* eslint-disable */
+import { getLocale, experimentalStaticLocale } from '../runtime.js';
+
+/** @typedef {import('../runtime.js').LocalizedString} LocalizedString */
+
+/** @typedef {{}} Link_VisibilityInputs */
+
+const en_link_visibility = /** @type {(inputs: Link_VisibilityInputs) => LocalizedString} */ () => {
+ return /** @type {LocalizedString} */ (`Link Visibility`)
+};
+
+const zh_link_visibility = /** @type {(inputs: Link_VisibilityInputs) => LocalizedString} */ () => {
+ return /** @type {LocalizedString} */ (`链接可见性`)
+};
+
+/**
+* | output |
+* | --- |
+* | "Link Visibility" |
+*
+* @param {Link_VisibilityInputs} inputs
+* @param {{ locale?: "en" | "zh" }} options
+* @returns {LocalizedString}
+*/
+export const link_visibility = /** @type {((inputs?: Link_VisibilityInputs, options?: { locale?: "en" | "zh" }) => LocalizedString) & import('../runtime.js').MessageMetadata} */ ((inputs = {}, options = {}) => {
+ const locale = experimentalStaticLocale ?? options.locale ?? getLocale()
+ if (locale === "en") return en_link_visibility(inputs)
+ return zh_link_visibility(inputs)
+});
\ No newline at end of file
diff --git a/packages/webui/src/paraglide/messages/notifications.d.ts b/packages/webui/src/paraglide/messages/notifications.d.ts
new file mode 100644
index 00000000..e76b39fb
--- /dev/null
+++ b/packages/webui/src/paraglide/messages/notifications.d.ts
@@ -0,0 +1,16 @@
+/**
+* | output |
+* | --- |
+* | "Notifications" |
+*
+* @param {NotificationsInputs} inputs
+* @param {{ locale?: "en" | "zh" }} options
+* @returns {LocalizedString}
+*/
+export const notifications: ((inputs?: NotificationsInputs, options?: {
+ locale?: "en" | "zh";
+}) => LocalizedString) & import("../runtime.js").MessageMetadata;
+export type LocalizedString = import("../runtime.js").LocalizedString;
+export type NotificationsInputs = {};
diff --git a/packages/webui/src/paraglide/messages/notifications.js b/packages/webui/src/paraglide/messages/notifications.js
new file mode 100644
index 00000000..b5362452
--- /dev/null
+++ b/packages/webui/src/paraglide/messages/notifications.js
@@ -0,0 +1,29 @@
+/* eslint-disable */
+import { getLocale, experimentalStaticLocale } from '../runtime.js';
+
+/** @typedef {import('../runtime.js').LocalizedString} LocalizedString */
+
+/** @typedef {{}} NotificationsInputs */
+
+const en_notifications = /** @type {(inputs: NotificationsInputs) => LocalizedString} */ () => {
+ return /** @type {LocalizedString} */ (`Notifications`)
+};
+
+const zh_notifications = /** @type {(inputs: NotificationsInputs) => LocalizedString} */ () => {
+ return /** @type {LocalizedString} */ (`通知中心`)
+};
+
+/**
+* | output |
+* | --- |
+* | "Notifications" |
+*
+* @param {NotificationsInputs} inputs
+* @param {{ locale?: "en" | "zh" }} options
+* @returns {LocalizedString}
+*/
+export const notifications = /** @type {((inputs?: NotificationsInputs, options?: { locale?: "en" | "zh" }) => LocalizedString) & import('../runtime.js').MessageMetadata} */ ((inputs = {}, options = {}) => {
+ const locale = experimentalStaticLocale ?? options.locale ?? getLocale()
+ if (locale === "en") return en_notifications(inputs)
+ return zh_notifications(inputs)
+});
\ No newline at end of file
diff --git a/packages/webui/src/paraglide/messages/package.json b/packages/webui/src/paraglide/messages/package.json
new file mode 100644
index 00000000..330f44b1
--- /dev/null
+++ b/packages/webui/src/paraglide/messages/package.json
@@ -0,0 +1,4 @@
+{
+ "type": "module",
+ "sideEffects": false
+}
diff --git a/packages/webui/src/paraglide/messages/password_protected.d.ts b/packages/webui/src/paraglide/messages/password_protected.d.ts
new file mode 100644
index 00000000..827072e5
--- /dev/null
+++ b/packages/webui/src/paraglide/messages/password_protected.d.ts
@@ -0,0 +1,16 @@
+/**
+* | output |
+* | --- |
+* | "Password Protected" |
+*
+* @param {Password_ProtectedInputs} inputs
+* @param {{ locale?: "en" | "zh" }} options
+* @returns {LocalizedString}
+*/
+export const password_protected: ((inputs?: Password_ProtectedInputs, options?: {
+ locale?: "en" | "zh";
+}) => LocalizedString) & import("../runtime.js").MessageMetadata;
+export type LocalizedString = import("../runtime.js").LocalizedString;
+export type Password_ProtectedInputs = {};
diff --git a/packages/webui/src/paraglide/messages/password_protected.js b/packages/webui/src/paraglide/messages/password_protected.js
new file mode 100644
index 00000000..a575605f
--- /dev/null
+++ b/packages/webui/src/paraglide/messages/password_protected.js
@@ -0,0 +1,29 @@
+/* eslint-disable */
+import { getLocale, experimentalStaticLocale } from '../runtime.js';
+
+/** @typedef {import('../runtime.js').LocalizedString} LocalizedString */
+
+/** @typedef {{}} Password_ProtectedInputs */
+
+const en_password_protected = /** @type {(inputs: Password_ProtectedInputs) => LocalizedString} */ () => {
+ return /** @type {LocalizedString} */ (`Password Protected`)
+};
+
+const zh_password_protected = /** @type {(inputs: Password_ProtectedInputs) => LocalizedString} */ () => {
+ return /** @type {LocalizedString} */ (`密码保护`)
+};
+
+/**
+* | output |
+* | --- |
+* | "Password Protected" |
+*
+* @param {Password_ProtectedInputs} inputs
+* @param {{ locale?: "en" | "zh" }} options
+* @returns {LocalizedString}
+*/
+export const password_protected = /** @type {((inputs?: Password_ProtectedInputs, options?: { locale?: "en" | "zh" }) => LocalizedString) & import('../runtime.js').MessageMetadata} */ ((inputs = {}, options = {}) => {
+ const locale = experimentalStaticLocale ?? options.locale ?? getLocale()
+ if (locale === "en") return en_password_protected(inputs)
+ return zh_password_protected(inputs)
+});
\ No newline at end of file
diff --git a/packages/webui/src/paraglide/messages/personal_info.d.ts b/packages/webui/src/paraglide/messages/personal_info.d.ts
new file mode 100644
index 00000000..a2b0afd1
--- /dev/null
+++ b/packages/webui/src/paraglide/messages/personal_info.d.ts
@@ -0,0 +1,16 @@
+/**
+* | output |
+* | --- |
+* | "Personal Info" |
+*
+* @param {Personal_InfoInputs} inputs
+* @param {{ locale?: "en" | "zh" }} options
+* @returns {LocalizedString}
+*/
+export const personal_info: ((inputs?: Personal_InfoInputs, options?: {
+ locale?: "en" | "zh";
+}) => LocalizedString) & import("../runtime.js").MessageMetadata;
+export type LocalizedString = import("../runtime.js").LocalizedString;
+export type Personal_InfoInputs = {};
diff --git a/packages/webui/src/paraglide/messages/personal_info.js b/packages/webui/src/paraglide/messages/personal_info.js
new file mode 100644
index 00000000..9d8de790
--- /dev/null
+++ b/packages/webui/src/paraglide/messages/personal_info.js
@@ -0,0 +1,29 @@
+/* eslint-disable */
+import { getLocale, experimentalStaticLocale } from '../runtime.js';
+
+/** @typedef {import('../runtime.js').LocalizedString} LocalizedString */
+
+/** @typedef {{}} Personal_InfoInputs */
+
+const en_personal_info = /** @type {(inputs: Personal_InfoInputs) => LocalizedString} */ () => {
+ return /** @type {LocalizedString} */ (`Personal Info`)
+};
+
+const zh_personal_info = /** @type {(inputs: Personal_InfoInputs) => LocalizedString} */ () => {
+ return /** @type {LocalizedString} */ (`个人信息`)
+};
+
+/**
+* | output |
+* | --- |
+* | "Personal Info" |
+*
+* @param {Personal_InfoInputs} inputs
+* @param {{ locale?: "en" | "zh" }} options
+* @returns {LocalizedString}
+*/
+export const personal_info = /** @type {((inputs?: Personal_InfoInputs, options?: { locale?: "en" | "zh" }) => LocalizedString) & import('../runtime.js').MessageMetadata} */ ((inputs = {}, options = {}) => {
+ const locale = experimentalStaticLocale ?? options.locale ?? getLocale()
+ if (locale === "en") return en_personal_info(inputs)
+ return zh_personal_info(inputs)
+});
\ No newline at end of file
diff --git a/packages/webui/src/paraglide/messages/projects.d.ts b/packages/webui/src/paraglide/messages/projects.d.ts
new file mode 100644
index 00000000..9335f7bc
--- /dev/null
+++ b/packages/webui/src/paraglide/messages/projects.d.ts
@@ -0,0 +1,16 @@
+/**
+* | output |
+* | --- |
+* | "Projects" |
+*
+* @param {ProjectsInputs} inputs
+* @param {{ locale?: "en" | "zh" }} options
+* @returns {LocalizedString}
+*/
+export const projects: ((inputs?: ProjectsInputs, options?: {
+ locale?: "en" | "zh";
+}) => LocalizedString) & import("../runtime.js").MessageMetadata;
+export type LocalizedString = import("../runtime.js").LocalizedString;
+export type ProjectsInputs = {};
diff --git a/packages/webui/src/paraglide/messages/projects.js b/packages/webui/src/paraglide/messages/projects.js
new file mode 100644
index 00000000..b02b2363
--- /dev/null
+++ b/packages/webui/src/paraglide/messages/projects.js
@@ -0,0 +1,29 @@
+/* eslint-disable */
+import { getLocale, experimentalStaticLocale } from '../runtime.js';
+
+/** @typedef {import('../runtime.js').LocalizedString} LocalizedString */
+
+/** @typedef {{}} ProjectsInputs */
+
+const en_projects = /** @type {(inputs: ProjectsInputs) => LocalizedString} */ () => {
+ return /** @type {LocalizedString} */ (`Projects`)
+};
+
+const zh_projects = /** @type {(inputs: ProjectsInputs) => LocalizedString} */ () => {
+ return /** @type {LocalizedString} */ (`项目`)
+};
+
+/**
+* | output |
+* | --- |
+* | "Projects" |
+*
+* @param {ProjectsInputs} inputs
+* @param {{ locale?: "en" | "zh" }} options
+* @returns {LocalizedString}
+*/
+export const projects = /** @type {((inputs?: ProjectsInputs, options?: { locale?: "en" | "zh" }) => LocalizedString) & import('../runtime.js').MessageMetadata} */ ((inputs = {}, options = {}) => {
+ const locale = experimentalStaticLocale ?? options.locale ?? getLocale()
+ if (locale === "en") return en_projects(inputs)
+ return zh_projects(inputs)
+});
\ No newline at end of file
diff --git a/packages/webui/src/paraglide/messages/recently_deleted_notice.d.ts b/packages/webui/src/paraglide/messages/recently_deleted_notice.d.ts
new file mode 100644
index 00000000..80ea2628
--- /dev/null
+++ b/packages/webui/src/paraglide/messages/recently_deleted_notice.d.ts
@@ -0,0 +1,16 @@
+/**
+* | output |
+* | --- |
+* | "Items are automatically deleted after 30 days." |
+*
+* @param {Recently_Deleted_NoticeInputs} inputs
+* @param {{ locale?: "en" | "zh" }} options
+* @returns {LocalizedString}
+*/
+export const recently_deleted_notice: ((inputs?: Recently_Deleted_NoticeInputs, options?: {
+ locale?: "en" | "zh";
+}) => LocalizedString) & import("../runtime.js").MessageMetadata;
+export type LocalizedString = import("../runtime.js").LocalizedString;
+export type Recently_Deleted_NoticeInputs = {};
diff --git a/packages/webui/src/paraglide/messages/recently_deleted_notice.js b/packages/webui/src/paraglide/messages/recently_deleted_notice.js
new file mode 100644
index 00000000..1516330c
--- /dev/null
+++ b/packages/webui/src/paraglide/messages/recently_deleted_notice.js
@@ -0,0 +1,29 @@
+/* eslint-disable */
+import { getLocale, experimentalStaticLocale } from '../runtime.js';
+
+/** @typedef {import('../runtime.js').LocalizedString} LocalizedString */
+
+/** @typedef {{}} Recently_Deleted_NoticeInputs */
+
+const en_recently_deleted_notice = /** @type {(inputs: Recently_Deleted_NoticeInputs) => LocalizedString} */ () => {
+ return /** @type {LocalizedString} */ (`Items are automatically deleted after 30 days.`)
+};
+
+const zh_recently_deleted_notice = /** @type {(inputs: Recently_Deleted_NoticeInputs) => LocalizedString} */ () => {
+ return /** @type {LocalizedString} */ (`项目将在 30 天后自动删除。`)
+};
+
+/**
+* | output |
+* | --- |
+* | "Items are automatically deleted after 30 days." |
+*
+* @param {Recently_Deleted_NoticeInputs} inputs
+* @param {{ locale?: "en" | "zh" }} options
+* @returns {LocalizedString}
+*/
+export const recently_deleted_notice = /** @type {((inputs?: Recently_Deleted_NoticeInputs, options?: { locale?: "en" | "zh" }) => LocalizedString) & import('../runtime.js').MessageMetadata} */ ((inputs = {}, options = {}) => {
+ const locale = experimentalStaticLocale ?? options.locale ?? getLocale()
+ if (locale === "en") return en_recently_deleted_notice(inputs)
+ return zh_recently_deleted_notice(inputs)
+});
\ No newline at end of file
diff --git a/packages/webui/src/paraglide/messages/select_a_team.d.ts b/packages/webui/src/paraglide/messages/select_a_team.d.ts
new file mode 100644
index 00000000..30059d81
--- /dev/null
+++ b/packages/webui/src/paraglide/messages/select_a_team.d.ts
@@ -0,0 +1,16 @@
+/**
+* | output |
+* | --- |
+* | "Select a Team" |
+*
+* @param {Select_A_TeamInputs} inputs
+* @param {{ locale?: "en" | "zh" }} options
+* @returns {LocalizedString}
+*/
+export const select_a_team: ((inputs?: Select_A_TeamInputs, options?: {
+ locale?: "en" | "zh";
+}) => LocalizedString) & import("../runtime.js").MessageMetadata;
+export type LocalizedString = import("../runtime.js").LocalizedString;
+export type Select_A_TeamInputs = {};
diff --git a/packages/webui/src/paraglide/messages/select_a_team.js b/packages/webui/src/paraglide/messages/select_a_team.js
new file mode 100644
index 00000000..5a07bf8f
--- /dev/null
+++ b/packages/webui/src/paraglide/messages/select_a_team.js
@@ -0,0 +1,29 @@
+/* eslint-disable */
+import { getLocale, experimentalStaticLocale } from '../runtime.js';
+
+/** @typedef {import('../runtime.js').LocalizedString} LocalizedString */
+
+/** @typedef {{}} Select_A_TeamInputs */
+
+const en_select_a_team = /** @type {(inputs: Select_A_TeamInputs) => LocalizedString} */ () => {
+ return /** @type {LocalizedString} */ (`Select a Team`)
+};
+
+const zh_select_a_team = /** @type {(inputs: Select_A_TeamInputs) => LocalizedString} */ () => {
+ return /** @type {LocalizedString} */ (`选择团队`)
+};
+
+/**
+* | output |
+* | --- |
+* | "Select a Team" |
+*
+* @param {Select_A_TeamInputs} inputs
+* @param {{ locale?: "en" | "zh" }} options
+* @returns {LocalizedString}
+*/
+export const select_a_team = /** @type {((inputs?: Select_A_TeamInputs, options?: { locale?: "en" | "zh" }) => LocalizedString) & import('../runtime.js').MessageMetadata} */ ((inputs = {}, options = {}) => {
+ const locale = experimentalStaticLocale ?? options.locale ?? getLocale()
+ if (locale === "en") return en_select_a_team(inputs)
+ return zh_select_a_team(inputs)
+});
\ No newline at end of file
diff --git a/packages/webui/src/paraglide/messages/select_asset_to_view_details.d.ts b/packages/webui/src/paraglide/messages/select_asset_to_view_details.d.ts
new file mode 100644
index 00000000..2193122e
--- /dev/null
+++ b/packages/webui/src/paraglide/messages/select_asset_to_view_details.d.ts
@@ -0,0 +1,16 @@
+/**
+* | output |
+* | --- |
+* | "Select an asset to view details" |
+*
+* @param {Select_Asset_To_View_DetailsInputs} inputs
+* @param {{ locale?: "en" | "zh" }} options
+* @returns {LocalizedString}
+*/
+export const select_asset_to_view_details: ((inputs?: Select_Asset_To_View_DetailsInputs, options?: {
+ locale?: "en" | "zh";
+}) => LocalizedString) & import("../runtime.js").MessageMetadata;
+export type LocalizedString = import("../runtime.js").LocalizedString;
+export type Select_Asset_To_View_DetailsInputs = {};
diff --git a/packages/webui/src/paraglide/messages/select_asset_to_view_details.js b/packages/webui/src/paraglide/messages/select_asset_to_view_details.js
new file mode 100644
index 00000000..1e5aa002
--- /dev/null
+++ b/packages/webui/src/paraglide/messages/select_asset_to_view_details.js
@@ -0,0 +1,29 @@
+/* eslint-disable */
+import { getLocale, experimentalStaticLocale } from '../runtime.js';
+
+/** @typedef {import('../runtime.js').LocalizedString} LocalizedString */
+
+/** @typedef {{}} Select_Asset_To_View_DetailsInputs */
+
+const en_select_asset_to_view_details = /** @type {(inputs: Select_Asset_To_View_DetailsInputs) => LocalizedString} */ () => {
+ return /** @type {LocalizedString} */ (`Select an asset to view details`)
+};
+
+const zh_select_asset_to_view_details = /** @type {(inputs: Select_Asset_To_View_DetailsInputs) => LocalizedString} */ () => {
+ return /** @type {LocalizedString} */ (`选择资产查看详情`)
+};
+
+/**
+* | output |
+* | --- |
+* | "Select an asset to view details" |
+*
+* @param {Select_Asset_To_View_DetailsInputs} inputs
+* @param {{ locale?: "en" | "zh" }} options
+* @returns {LocalizedString}
+*/
+export const select_asset_to_view_details = /** @type {((inputs?: Select_Asset_To_View_DetailsInputs, options?: { locale?: "en" | "zh" }) => LocalizedString) & import('../runtime.js').MessageMetadata} */ ((inputs = {}, options = {}) => {
+ const locale = experimentalStaticLocale ?? options.locale ?? getLocale()
+ if (locale === "en") return en_select_asset_to_view_details(inputs)
+ return zh_select_asset_to_view_details(inputs)
+});
\ No newline at end of file
diff --git a/packages/webui/src/paraglide/messages/select_preferred_language.d.ts b/packages/webui/src/paraglide/messages/select_preferred_language.d.ts
new file mode 100644
index 00000000..56327cfe
--- /dev/null
+++ b/packages/webui/src/paraglide/messages/select_preferred_language.d.ts
@@ -0,0 +1,16 @@
+/**
+* | output |
+* | --- |
+* | "Select your preferred display language." |
+*
+* @param {Select_Preferred_LanguageInputs} inputs
+* @param {{ locale?: "en" | "zh" }} options
+* @returns {LocalizedString}
+*/
+export const select_preferred_language: ((inputs?: Select_Preferred_LanguageInputs, options?: {
+ locale?: "en" | "zh";
+}) => LocalizedString) & import("../runtime.js").MessageMetadata;
+export type LocalizedString = import("../runtime.js").LocalizedString;
+export type Select_Preferred_LanguageInputs = {};
diff --git a/packages/webui/src/paraglide/messages/select_preferred_language.js b/packages/webui/src/paraglide/messages/select_preferred_language.js
new file mode 100644
index 00000000..e77609fa
--- /dev/null
+++ b/packages/webui/src/paraglide/messages/select_preferred_language.js
@@ -0,0 +1,29 @@
+/* eslint-disable */
+import { getLocale, experimentalStaticLocale } from '../runtime.js';
+
+/** @typedef {import('../runtime.js').LocalizedString} LocalizedString */
+
+/** @typedef {{}} Select_Preferred_LanguageInputs */
+
+const en_select_preferred_language = /** @type {(inputs: Select_Preferred_LanguageInputs) => LocalizedString} */ () => {
+ return /** @type {LocalizedString} */ (`Select your preferred display language.`)
+};
+
+const zh_select_preferred_language = /** @type {(inputs: Select_Preferred_LanguageInputs) => LocalizedString} */ () => {
+ return /** @type {LocalizedString} */ (`选择您首选的显示语言。`)
+};
+
+/**
+* | output |
+* | --- |
+* | "Select your preferred display language." |
+*
+* @param {Select_Preferred_LanguageInputs} inputs
+* @param {{ locale?: "en" | "zh" }} options
+* @returns {LocalizedString}
+*/
+export const select_preferred_language = /** @type {((inputs?: Select_Preferred_LanguageInputs, options?: { locale?: "en" | "zh" }) => LocalizedString) & import('../runtime.js').MessageMetadata} */ ((inputs = {}, options = {}) => {
+ const locale = experimentalStaticLocale ?? options.locale ?? getLocale()
+ if (locale === "en") return en_select_preferred_language(inputs)
+ return zh_select_preferred_language(inputs)
+});
\ No newline at end of file
diff --git a/packages/webui/src/paraglide/messages/settings.d.ts b/packages/webui/src/paraglide/messages/settings.d.ts
new file mode 100644
index 00000000..0742055d
--- /dev/null
+++ b/packages/webui/src/paraglide/messages/settings.d.ts
@@ -0,0 +1,16 @@
+/**
+* | output |
+* | --- |
+* | "Settings" |
+*
+* @param {SettingsInputs} inputs
+* @param {{ locale?: "en" | "zh" }} options
+* @returns {LocalizedString}
+*/
+export const settings: ((inputs?: SettingsInputs, options?: {
+ locale?: "en" | "zh";
+}) => LocalizedString) & import("../runtime.js").MessageMetadata;
+export type LocalizedString = import("../runtime.js").LocalizedString;
+export type SettingsInputs = {};
diff --git a/packages/webui/src/paraglide/messages/settings.js b/packages/webui/src/paraglide/messages/settings.js
new file mode 100644
index 00000000..d678831d
--- /dev/null
+++ b/packages/webui/src/paraglide/messages/settings.js
@@ -0,0 +1,29 @@
+/* eslint-disable */
+import { getLocale, experimentalStaticLocale } from '../runtime.js';
+
+/** @typedef {import('../runtime.js').LocalizedString} LocalizedString */
+
+/** @typedef {{}} SettingsInputs */
+
+const en_settings = /** @type {(inputs: SettingsInputs) => LocalizedString} */ () => {
+ return /** @type {LocalizedString} */ (`Settings`)
+};
+
+const zh_settings = /** @type {(inputs: SettingsInputs) => LocalizedString} */ () => {
+ return /** @type {LocalizedString} */ (`设置`)
+};
+
+/**
+* | output |
+* | --- |
+* | "Settings" |
+*
+* @param {SettingsInputs} inputs
+* @param {{ locale?: "en" | "zh" }} options
+* @returns {LocalizedString}
+*/
+export const settings = /** @type {((inputs?: SettingsInputs, options?: { locale?: "en" | "zh" }) => LocalizedString) & import('../runtime.js').MessageMetadata} */ ((inputs = {}, options = {}) => {
+ const locale = experimentalStaticLocale ?? options.locale ?? getLocale()
+ if (locale === "en") return en_settings(inputs)
+ return zh_settings(inputs)
+});
\ No newline at end of file
diff --git a/packages/webui/src/paraglide/messages/uploads.d.ts b/packages/webui/src/paraglide/messages/uploads.d.ts
new file mode 100644
index 00000000..fe46dcb3
--- /dev/null
+++ b/packages/webui/src/paraglide/messages/uploads.d.ts
@@ -0,0 +1,16 @@
+/**
+* | output |
+* | --- |
+* | "Uploads" |
+*
+* @param {UploadsInputs} inputs
+* @param {{ locale?: "en" | "zh" }} options
+* @returns {LocalizedString}
+*/
+export const uploads: ((inputs?: UploadsInputs, options?: {
+ locale?: "en" | "zh";
+}) => LocalizedString) & import("../runtime.js").MessageMetadata;
+export type LocalizedString = import("../runtime.js").LocalizedString;
+export type UploadsInputs = {};
diff --git a/packages/webui/src/paraglide/messages/uploads.js b/packages/webui/src/paraglide/messages/uploads.js
new file mode 100644
index 00000000..56e4fbb4
--- /dev/null
+++ b/packages/webui/src/paraglide/messages/uploads.js
@@ -0,0 +1,29 @@
+/* eslint-disable */
+import { getLocale, experimentalStaticLocale } from '../runtime.js';
+
+/** @typedef {import('../runtime.js').LocalizedString} LocalizedString */
+
+/** @typedef {{}} UploadsInputs */
+
+const en_uploads = /** @type {(inputs: UploadsInputs) => LocalizedString} */ () => {
+ return /** @type {LocalizedString} */ (`Uploads`)
+};
+
+const zh_uploads = /** @type {(inputs: UploadsInputs) => LocalizedString} */ () => {
+ return /** @type {LocalizedString} */ (`上传管理`)
+};
+
+/**
+* | output |
+* | --- |
+* | "Uploads" |
+*
+* @param {UploadsInputs} inputs
+* @param {{ locale?: "en" | "zh" }} options
+* @returns {LocalizedString}
+*/
+export const uploads = /** @type {((inputs?: UploadsInputs, options?: { locale?: "en" | "zh" }) => LocalizedString) & import('../runtime.js').MessageMetadata} */ ((inputs = {}, options = {}) => {
+ const locale = experimentalStaticLocale ?? options.locale ?? getLocale()
+ if (locale === "en") return en_uploads(inputs)
+ return zh_uploads(inputs)
+});
\ No newline at end of file
diff --git a/packages/webui/src/paraglide/messages/welcome_back.d.ts b/packages/webui/src/paraglide/messages/welcome_back.d.ts
new file mode 100644
index 00000000..29788af4
--- /dev/null
+++ b/packages/webui/src/paraglide/messages/welcome_back.d.ts
@@ -0,0 +1,16 @@
+/**
+* | output |
+* | --- |
+* | "Welcome Back" |
+*
+* @param {Welcome_BackInputs} inputs
+* @param {{ locale?: "en" | "zh" }} options
+* @returns {LocalizedString}
+*/
+export const welcome_back: ((inputs?: Welcome_BackInputs, options?: {
+ locale?: "en" | "zh";
+}) => LocalizedString) & import("../runtime.js").MessageMetadata;
+export type LocalizedString = import("../runtime.js").LocalizedString;
+export type Welcome_BackInputs = {};
diff --git a/packages/webui/src/paraglide/messages/welcome_back.js b/packages/webui/src/paraglide/messages/welcome_back.js
new file mode 100644
index 00000000..f2551dcd
--- /dev/null
+++ b/packages/webui/src/paraglide/messages/welcome_back.js
@@ -0,0 +1,29 @@
+/* eslint-disable */
+import { getLocale, experimentalStaticLocale } from '../runtime.js';
+
+/** @typedef {import('../runtime.js').LocalizedString} LocalizedString */
+
+/** @typedef {{}} Welcome_BackInputs */
+
+const en_welcome_back = /** @type {(inputs: Welcome_BackInputs) => LocalizedString} */ () => {
+ return /** @type {LocalizedString} */ (`Welcome Back`)
+};
+
+const zh_welcome_back = /** @type {(inputs: Welcome_BackInputs) => LocalizedString} */ () => {
+ return /** @type {LocalizedString} */ (`欢迎回来`)
+};
+
+/**
+* | output |
+* | --- |
+* | "Welcome Back" |
+*
+* @param {Welcome_BackInputs} inputs
+* @param {{ locale?: "en" | "zh" }} options
+* @returns {LocalizedString}
+*/
+export const welcome_back = /** @type {((inputs?: Welcome_BackInputs, options?: { locale?: "en" | "zh" }) => LocalizedString) & import('../runtime.js').MessageMetadata} */ ((inputs = {}, options = {}) => {
+ const locale = experimentalStaticLocale ?? options.locale ?? getLocale()
+ if (locale === "en") return en_welcome_back(inputs)
+ return zh_welcome_back(inputs)
+});
\ No newline at end of file
diff --git a/packages/webui/src/paraglide/registry.d.ts b/packages/webui/src/paraglide/registry.d.ts
new file mode 100644
index 00000000..b9438f07
--- /dev/null
+++ b/packages/webui/src/paraglide/registry.d.ts
@@ -0,0 +1,34 @@
+/**
+ * @typedef {"year" | "years" | "quarter" | "quarters" | "month" | "months" | "week" | "weeks" | "day" | "days" | "hour" | "hours" | "minute" | "minutes" | "second" | "seconds"} RelativeTimeFormatUnit
+ */
+/**
+ * @param {import("./runtime.js").Locale} locale
+ * @param {unknown} input
+ * @param {Intl.PluralRulesOptions} [options]
+ * @returns {string}
+ */
+export function plural(locale: import("./runtime.js").Locale, input: unknown, options?: Intl.PluralRulesOptions): string;
+/**
+ * @param {import("./runtime.js").Locale} locale
+ * @param {unknown} input
+ * @param {Intl.NumberFormatOptions} [options]
+ * @returns {string}
+ */
+export function number(locale: import("./runtime.js").Locale, input: unknown, options?: Intl.NumberFormatOptions): string;
+/**
+ * @param {import("./runtime.js").Locale} locale
+ * @param {unknown} input
+ * @param {Intl.DateTimeFormatOptions} [options]
+ * @returns {string}
+ */
+export function datetime(locale: import("./runtime.js").Locale, input: unknown, options?: Intl.DateTimeFormatOptions): string;
+/**
+ * @param {import("./runtime.js").Locale} locale
+ * @param {unknown} input
+ * @param {Intl.RelativeTimeFormatOptions & { unit: RelativeTimeFormatUnit }} options
+ * @returns {string}
+ */
+export function relativetime(locale: import("./runtime.js").Locale, input: unknown, options: Intl.RelativeTimeFormatOptions & {
+ unit: RelativeTimeFormatUnit;
+}): string;
+export type RelativeTimeFormatUnit = "year" | "years" | "quarter" | "quarters" | "month" | "months" | "week" | "weeks" | "day" | "days" | "hour" | "hours" | "minute" | "minutes" | "second" | "seconds";
diff --git a/packages/webui/src/paraglide/registry.js b/packages/webui/src/paraglide/registry.js
new file mode 100644
index 00000000..46b5d428
--- /dev/null
+++ b/packages/webui/src/paraglide/registry.js
@@ -0,0 +1,46 @@
+/* eslint-disable */
+
+/**
+ * @typedef {"year" | "years" | "quarter" | "quarters" | "month" | "months" | "week" | "weeks" | "day" | "days" | "hour" | "hours" | "minute" | "minutes" | "second" | "seconds"} RelativeTimeFormatUnit
+ */
+
+/**
+ * @param {import("./runtime.js").Locale} locale
+ * @param {unknown} input
+ * @param {Intl.PluralRulesOptions} [options]
+ * @returns {string}
+ */
+export function plural(locale, input, options) {
+ return new Intl.PluralRules(locale, options).select(Number(input))
+};
+
+/**
+ * @param {import("./runtime.js").Locale} locale
+ * @param {unknown} input
+ * @param {Intl.NumberFormatOptions} [options]
+ * @returns {string}
+ */
+export function number(locale, input, options) {
+ return new Intl.NumberFormat(locale, options).format(Number(input))
+};
+
+/**
+ * @param {import("./runtime.js").Locale} locale
+ * @param {unknown} input
+ * @param {Intl.DateTimeFormatOptions} [options]
+ * @returns {string}
+ */
+export function datetime(locale, input, options) {
+ return new Intl.DateTimeFormat(locale, options).format(new Date(/** @type {string} */ (input)))
+};
+
+/**
+ * @param {import("./runtime.js").Locale} locale
+ * @param {unknown} input
+ * @param {Intl.RelativeTimeFormatOptions & { unit: RelativeTimeFormatUnit }} options
+ * @returns {string}
+ */
+export function relativetime(locale, input, options) {
+ const { unit, ...intlOptions } = options;
+ return new Intl.RelativeTimeFormat(locale, intlOptions).format(Number(input), unit);
+};
\ No newline at end of file
diff --git a/packages/webui/src/paraglide/runtime.d.ts b/packages/webui/src/paraglide/runtime.d.ts
new file mode 100644
index 00000000..7ebba567
--- /dev/null
+++ b/packages/webui/src/paraglide/runtime.d.ts
@@ -0,0 +1,758 @@
+/**
+ * Returns the strategy to use for a specific URL.
+ *
+ * If no route strategy matches (or the matching rule is `exclude: true`),
+ * the global strategy is returned.
+ *
+ * @param {string | URL} url
+ * @returns {typeof strategy}
+ */
+export function getStrategyForUrl(url: string | URL): typeof strategy;
+/**
+ * Returns whether the given URL is excluded from middleware i18n processing.
+ *
+ * @param {string | URL} url
+ * @returns {boolean}
+ */
+export function isExcludedByRouteStrategy(url: string | URL): boolean;
+/**
+ * Sets the server side async local storage.
+ *
+ * The function is needed because the `runtime.js` file
+ * must define the `serverAsyncLocalStorage` variable to
+ * avoid a circular import between `runtime.js` and
+ * `server.js` files.
+ *
+ * @param {ParaglideAsyncLocalStorage | undefined} value
+ */
+export function overwriteServerAsyncLocalStorage(value: ParaglideAsyncLocalStorage | undefined): void;
+/**
+ * Resolve locale for a given URL using route-aware strategies.
+ *
+ * @param {string | URL} url
+ * @returns {Locale}
+ */
+export function getLocaleForUrl(url: string | URL): Locale;
+/**
+ * Get writing direction for a locale.
+ *
+ * Uses `Intl.Locale` text info when available and falls back to a
+ * language-based RTL check for runtimes without `getTextInfo()`.
+ *
+ * @example
+ * getTextDirection(); // "ltr" or "rtl" for current locale
+ * getTextDirection("ar"); // "rtl"
+ * getTextDirection("en"); // "ltr"
+ *
+ * @param {string} [locale] - Target locale. If not provided, uses `getLocale()`
+ * @returns {"ltr" | "rtl"}
+ */
+export function getTextDirection(locale?: string): "ltr" | "rtl";
+/**
+ * Coerces a locale-like string to the canonical locale value used by the runtime.
+ *
+ * @param {unknown} value
+ * @returns {Locale | undefined}
+ */
+export function toLocale(value: unknown): Locale | undefined;
+/**
+ * Check if something is an available locale with the canonical project casing.
+ *
+ * @example
+ * if (isLocale(params.locale)) {
+ * setLocale(params.locale);
+ * } else {
+ * setLocale('en');
+ * }
+ *
+ * Use `toLocale()` when you want case-insensitive matching and canonicalization.
+ *
+ * @param {unknown} locale
+ * @returns {locale is Locale}
+ */
+export function isLocale(locale: unknown): locale is Locale;
+/**
+ * Asserts that the input can be normalized to a locale.
+ *
+ * @param {unknown} input - The input to check.
+ * @returns {Locale} The input normalized to a Locale.
+ * @throws {Error} If the input is not a locale.
+ */
+export function assertIsLocale(input: unknown): Locale;
+/**
+ * Extracts a cookie from the document.
+ *
+ * Will return undefined if the document is not available or if the cookie is not set.
+ * The `document` object is not available in server-side rendering, so this function should not be called in that context.
+ *
+ * @returns {Locale | undefined}
+ */
+export function extractLocaleFromCookie(): Locale | undefined;
+/**
+ * Extracts a locale from the accept-language header.
+ *
+ * Use the function on the server to extract the locale
+ * from the accept-language header that is sent by the client.
+ *
+ * @example
+ * const locale = extractLocaleFromHeader(request);
+ *
+ * @param {Request} request - The request object to extract the locale from.
+ * @returns {Locale | undefined} The negotiated preferred language.
+ */
+export function extractLocaleFromHeader(request: Request): Locale | undefined;
+/**
+ * Negotiates a preferred language from navigator.languages.
+ *
+ * Use the function on the client to extract the locale
+ * from the navigator.languages array.
+ *
+ * @example
+ * const locale = extractLocaleFromNavigator();
+ *
+ * @returns {Locale | undefined}
+ */
+export function extractLocaleFromNavigator(): Locale | undefined;
+/**
+ * Extracts the locale from a given URL using native URLPattern.
+ *
+ * The built-in default `/:locale/...` routing is case-insensitive because it
+ * canonicalizes the first path segment with `toLocale()`. Custom `urlPatterns`
+ * keep URLPattern's normal exact matching semantics for path segments.
+ *
+ * @param {URL|string} url - The full URL from which to extract the locale.
+ * @returns {Locale|undefined} The extracted locale, or undefined if no locale is found.
+ */
+export function extractLocaleFromUrl(url: URL | string): Locale | undefined;
+/**
+ * Lower-level URL localization function, primarily used in server contexts.
+ *
+ * This function is designed for server-side usage where you need precise control
+ * over URL localization, such as in middleware or request handlers. It works with
+ * URL objects and always returns absolute URLs.
+ *
+ * For client-side UI components, use `localizeHref()` instead, which provides
+ * a more convenient API with relative paths and automatic locale detection.
+ *
+ * @see https://paraglidejs.com/i18n-routing
+ *
+ * @example
+ * ```typescript
+ * // Server middleware example
+ * app.use((req, res, next) => {
+ * const url = new URL(req.url, `${req.protocol}://${req.headers.host}`);
+ * const localized = localizeUrl(url, { locale: "de" });
+ *
+ * if (localized.href !== url.href) {
+ * return res.redirect(localized.href);
+ * }
+ * next();
+ * });
+ * ```
+ *
+ * @example
+ * ```typescript
+ * // Using with URL patterns
+ * const url = new URL("https://example.com/about");
+ * localizeUrl(url, { locale: "de" });
+ * // => URL("https://example.com/de/about")
+ *
+ * // Using with domain-based localization
+ * const url = new URL("https://example.com/store");
+ * localizeUrl(url, { locale: "de" });
+ * // => URL("https://de.example.com/store")
+ * ```
+ *
+ * @param {string | URL} url - The URL to localize. If string, must be absolute.
+ * @param {object} [options] - Options for localization
+ * @param {Locale} [options.locale] - Target locale. If not provided, uses getLocale()
+ * @returns {URL} The localized URL, always absolute
+ */
+export function localizeUrl(url: string | URL, options?: {
+ locale?: Locale;
+}): URL;
+/**
+ * Low-level URL de-localization function, primarily used in server contexts.
+ *
+ * This function is designed for server-side usage where you need precise control
+ * over URL de-localization, such as in middleware or request handlers. It works with
+ * URL objects and always returns absolute URLs.
+ *
+ * For client-side UI components, use `deLocalizeHref()` instead, which provides
+ * a more convenient API with relative paths.
+ *
+ * @see https://paraglidejs.com/i18n-routing
+ *
+ * @example
+ * ```typescript
+ * // Server middleware example
+ * app.use((req, res, next) => {
+ * const url = new URL(req.url, `${req.protocol}://${req.headers.host}`);
+ * const baseUrl = deLocalizeUrl(url);
+ *
+ * // Store the base URL for later use
+ * req.baseUrl = baseUrl;
+ * next();
+ * });
+ * ```
+ *
+ * @example
+ * ```typescript
+ * // Using with URL patterns
+ * const url = new URL("https://example.com/de/about");
+ * deLocalizeUrl(url); // => URL("https://example.com/about")
+ *
+ * // Using with domain-based localization
+ * const url = new URL("https://de.example.com/store");
+ * deLocalizeUrl(url); // => URL("https://example.com/store")
+ * ```
+ *
+ * @param {string | URL} url - The URL to de-localize. If string, must be absolute.
+ * @returns {URL} The de-localized URL, always absolute
+ */
+export function deLocalizeUrl(url: string | URL): URL;
+/**
+ * Aggregates named groups from various parts of the URLPattern match result.
+ *
+ *
+ * @param {any} match - The URLPattern match result object.
+ * @returns {Record} An object containing all named groups from the match.
+ */
+export function aggregateGroups(match: any): Record;
+/**
+ * @typedef {object} ShouldRedirectServerInput
+ * @property {Request} request
+ * @property {string | URL} [effectiveRequestUrl] - Effective request URL to use for route matching, locale detection with the URL strategy, and redirect targets.
+ * @property {Locale} [locale]
+ *
+ * @typedef {object} ShouldRedirectClientInput
+ * @property {undefined} [request]
+ * @property {string | URL} [url]
+ * @property {Locale} [locale]
+ *
+ * @typedef {ShouldRedirectServerInput | ShouldRedirectClientInput} ShouldRedirectInput
+ *
+ * @typedef {object} ShouldRedirectResult
+ * @property {boolean} shouldRedirect - Indicates whether the consumer should perform a redirect.
+ * @property {Locale} locale - Locale resolved using the configured strategies.
+ * @property {URL | undefined} redirectUrl - Destination URL when a redirect is required.
+ */
+/**
+ * Determines whether a redirect is required to align the current URL with the active locale.
+ *
+ * This helper mirrors the logic that powers `paraglideMiddleware`, but works in both server
+ * and client environments. It evaluates the configured strategies in order, computes the
+ * canonical localized URL, and reports when the current URL does not match.
+ *
+ * When called in the browser without arguments, the current `window.location.href` is used.
+ *
+ * @see https://paraglidejs.com/i18n-routing#redirects
+ *
+ * @example
+ * // Client side usage (e.g. TanStack Router beforeLoad hook)
+ * async function beforeLoad({ location }) {
+ * const decision = await shouldRedirect({ url: location.href });
+ *
+ * if (decision.shouldRedirect) {
+ * throw redirect({ to: decision.redirectUrl.href });
+ * }
+ * }
+ *
+ * @example
+ * // Server side usage with a Request
+ * export async function handle(request) {
+ * const decision = await shouldRedirect({ request });
+ *
+ * if (decision.shouldRedirect) {
+ * return Response.redirect(decision.redirectUrl, 307);
+ * }
+ *
+ * return render(request, decision.locale);
+ * }
+ *
+ * @example
+ * // Server side usage behind a proxy where request.url is not public-facing
+ * export async function handle(request) {
+ * const effectiveRequestUrl = new URL(request.url);
+ * effectiveRequestUrl.protocol = "https:";
+ * effectiveRequestUrl.host = "example.com";
+ *
+ * const decision = await shouldRedirect({
+ * request,
+ * effectiveRequestUrl,
+ * });
+ *
+ * if (decision.shouldRedirect) {
+ * return Response.redirect(decision.redirectUrl, 307);
+ * }
+ * }
+ *
+ * @param {ShouldRedirectInput} [input]
+ * @returns {Promise}
+ */
+export function shouldRedirect(input?: ShouldRedirectInput): Promise;
+/**
+ * High-level URL localization function optimized for client-side UI usage.
+ *
+ * This is a convenience wrapper around `localizeUrl()` that provides features
+ * needed in UI:
+ *
+ * - Accepts relative paths (e.g., "/about")
+ * - Returns relative paths when possible
+ * - Automatically detects current locale if not specified
+ * - Handles string input/output instead of URL objects
+ *
+ * @see https://paraglidejs.com/i18n-routing
+ *
+ * @example
+ * ```typescript
+ * // In a React/Vue/Svelte component
+ * const NavLink = ({ href }) => {
+ * // Automatically uses current locale, keeps path relative
+ * return ...;
+ * };
+ *
+ * // Examples:
+ * localizeHref("/about")
+ * // => "/de/about" (if current locale is "de")
+ * localizeHref("/store", { locale: "fr" })
+ * // => "/fr/store" (explicit locale)
+ *
+ * // Cross-origin links remain absolute
+ * localizeHref("https://other-site.com/about")
+ * // => "https://other-site.com/de/about"
+ * ```
+ *
+ * For server-side URL localization (e.g., in middleware), use `localizeUrl()`
+ * which provides more precise control over URL handling.
+ *
+ * @param {string} href - The href to localize (can be relative or absolute)
+ * @param {object} [options] - Options for localization
+ * @param {Locale} [options.locale] - Target locale. If not provided, uses `getLocale()`
+ * @returns {string} The localized href, relative if input was relative
+ */
+export function localizeHref(href: string, options?: {
+ locale?: Locale;
+}): string;
+/**
+ * High-level URL de-localization function optimized for client-side UI usage.
+ *
+ * This is a convenience wrapper around `deLocalizeUrl()` that provides features
+ * needed in the UI:
+ *
+ * - Accepts relative paths (e.g., "/de/about")
+ * - Returns relative paths when possible
+ * - Handles string input/output instead of URL objects
+ *
+ * @see https://paraglidejs.com/i18n-routing
+ *
+ * @example
+ * ```typescript
+ * // In a React/Vue/Svelte component
+ * const LocaleSwitcher = ({ href }) => {
+ * // Remove locale prefix before switching
+ * const baseHref = deLocalizeHref(href);
+ * return locales.map(locale =>
+ *
+ * Switch to {locale}
+ *
+ * );
+ * };
+ *
+ * // Examples:
+ * deLocalizeHref("/de/about") // => "/about"
+ * deLocalizeHref("/fr/store") // => "/store"
+ *
+ * // Cross-origin links remain absolute
+ * deLocalizeHref("https://example.com/de/about")
+ * // => "https://example.com/about"
+ * ```
+ *
+ * For server-side URL de-localization (e.g., in middleware), use `deLocalizeUrl()`
+ * which provides more precise control over URL handling.
+ *
+ * @param {string} href - The href to de-localize (can be relative or absolute)
+ * @returns {string} The de-localized href, relative if input was relative
+ */
+export function deLocalizeHref(href: string): string;
+/**
+ * @param {string} safeModuleId
+ * @param {Locale} locale
+ */
+export function trackMessageCall(safeModuleId: string, locale: Locale): void;
+/**
+ * Generates localized URL variants for all provided URLs based on your configured locales and URL patterns.
+ *
+ * This function is essential for Static Site Generation (SSG) where you need to tell your framework
+ * which pages to pre-render at build time. It's also useful for generating sitemaps and
+ * `` tags for SEO.
+ *
+ * The function respects your `urlPatterns` configuration - if you have translated pathnames
+ * (e.g., `/about` → `/ueber-uns` for German), it will generate the correct localized paths.
+ *
+ * @see https://paraglidejs.com/static-site-generation
+ *
+ * @example
+ * // Basic usage - generate all locale variants for a list of paths
+ * const localizedUrls = generateStaticLocalizedUrls([
+ * "/",
+ * "/about",
+ * "/blog/post-1",
+ * ]);
+ * // Returns URL objects for each locale:
+ * // ["/en/", "/de/", "/en/about", "/de/about", "/en/blog/post-1", "/de/blog/post-1"]
+ *
+ * @example
+ * // Use with framework SSG APIs
+ * // SvelteKit
+ * export function entries() {
+ * const paths = ["/", "/about", "/contact"];
+ * return generateStaticLocalizedUrls(paths).map(url => ({
+ * locale: extractLocaleFromUrl(url)
+ * }));
+ * }
+ *
+ * @example
+ * // Sitemap generation
+ * const allPages = ["/", "/about", "/blog"];
+ * const sitemapUrls = generateStaticLocalizedUrls(allPages);
+ *
+ * @param {(string | URL)[]} urls - List of canonical URLs or paths to generate localized versions for.
+ * Can be absolute URLs (`https://example.com/about`) or paths (`/about`).
+ * Paths are resolved against `http://localhost` internally.
+ * @returns {URL[]} Array of URL objects representing all localized variants.
+ * The order follows each input URL with all its locale variants before moving to the next URL.
+ */
+export function generateStaticLocalizedUrls(urls: (string | URL)[]): URL[];
+/**
+ * Checks if the given strategy is a custom strategy.
+ *
+ * @param {unknown} strategy The name of the custom strategy to validate.
+ * Must be a string that starts with "custom-" followed by alphanumeric characters, hyphens, or underscores.
+ * @returns {boolean} Returns true if it is a custom strategy, false otherwise.
+ */
+export function isCustomStrategy(strategy: unknown): boolean;
+/**
+ * Defines a custom strategy that is executed on the server.
+ *
+ * @see https://paraglidejs.com/strategy#write-your-own-strategy
+ *
+ * @param {string} strategy The name of the custom strategy to define. Must follow the pattern custom-name with alphanumeric characters, hyphens, or underscores.
+ * @param {CustomServerStrategyHandler} handler The handler for the custom strategy, which should implement
+ * the method getLocale.
+ * @returns {void}
+ */
+export function defineCustomServerStrategy(strategy: string, handler: CustomServerStrategyHandler): void;
+/**
+ * Defines a custom strategy that is executed on the client.
+ *
+ * @see https://paraglidejs.com/strategy#write-your-own-strategy
+ *
+ * @param {string} strategy The name of the custom strategy to define. Must follow the pattern custom-name with alphanumeric characters, hyphens, or underscores.
+ * @param {CustomClientStrategyHandler} handler The handler for the custom strategy, which should implement the
+ * methods getLocale and setLocale.
+ * @returns {void}
+ */
+export function defineCustomClientStrategy(strategy: string, handler: CustomClientStrategyHandler): void;
+/**
+ * The project's base locale.
+ *
+ * @example
+ * if (locale === baseLocale) {
+ * // do something
+ * }
+ */
+export const baseLocale: "en";
+/**
+ * The project's locales that have been specified in the settings.
+ *
+ * @example
+ * if (locales.includes(userSelectedLocale) === false) {
+ * throw new Error('Locale is not available');
+ * }
+ */
+export const locales: readonly ["en", "zh"];
+/** @type {string} */
+export const cookieName: string;
+/** @type {number} */
+export const cookieMaxAge: number;
+/** @type {string} */
+export const cookieDomain: string;
+/** @type {string} */
+export const localStorageKey: string;
+/**
+ * @type {Array<"cookie" | "baseLocale" | "globalVariable" | "url" | "preferredLanguage" | "localStorage" | `custom-${string}`>}
+ */
+export const strategy: Array<"cookie" | "baseLocale" | "globalVariable" | "url" | "preferredLanguage" | "localStorage" | `custom-${string}`>;
+/**
+ * Route-level strategy overrides.
+ *
+ * `match` uses URLPattern syntax.
+ *
+ * @type {Array<{
+ * match: string;
+ * strategy?: Array<"cookie" | "baseLocale" | "globalVariable" | "url" | "preferredLanguage" | "localStorage" | `custom-${string}`>;
+ * exclude?: boolean;
+ * }>}
+ */
+export const routeStrategies: Array<{
+ match: string;
+ strategy?: Array<"cookie" | "baseLocale" | "globalVariable" | "url" | "preferredLanguage" | "localStorage" | `custom-${string}`>;
+ exclude?: boolean;
+}>;
+/**
+ * The used URL patterns.
+ *
+ * @type {Array<{ pattern: string, localized: Array<[Locale, string]> }>}
+ */
+export const urlPatterns: Array<{
+ pattern: string;
+ localized: Array<[Locale, string]>;
+}>;
+/**
+ * @typedef {{
+ * getStore(): {
+ * locale?: Locale,
+ * origin?: string,
+ * messageCalls?: Set
+ * } | undefined,
+ * run: (store: { locale?: Locale, origin?: string, messageCalls?: Set},
+ * cb: any) => any
+ * }} ParaglideAsyncLocalStorage
+ */
+/**
+ * Server side async local storage that is set by `serverMiddleware()`.
+ *
+ * The variable is used to retrieve the locale and origin in a server-side
+ * rendering context without effecting other requests.
+ *
+ * @type {ParaglideAsyncLocalStorage | undefined}
+ */
+export let serverAsyncLocalStorage: ParaglideAsyncLocalStorage | undefined;
+export const disableAsyncLocalStorage: false;
+export const experimentalMiddlewareLocaleSplitting: false;
+export const isServer: boolean;
+/** @type {Locale | undefined} */
+export const experimentalStaticLocale: Locale | undefined;
+export function getLocale(): Locale;
+export function overwriteGetLocale(fn: () => Locale): void;
+/**
+ * @typedef {(newLocale: Locale, options?: { reload?: boolean }) => void | Promise} SetLocaleFn
+ */
+/**
+ * Set the locale.
+ *
+ * Updates the locale using your configured strategies (cookie, localStorage, URL, etc.).
+ * By default, this reloads the page on the client to reflect the new locale. Reloading
+ * can be disabled by passing `reload: false` as an option, but you'll need to ensure
+ * the UI updates to reflect the new locale.
+ *
+ * If any custom strategy's `setLocale` function is async, then this function
+ * will become async as well.
+ *
+ * @see https://paraglidejs.com/strategy
+ *
+ * @example
+ * setLocale('en');
+ *
+ * @example
+ * setLocale('en', { reload: false });
+ *
+ * @type {SetLocaleFn}
+ */
+export let setLocale: SetLocaleFn;
+export function overwriteSetLocale(fn: SetLocaleFn): void;
+/**
+ * The origin of the current URL.
+ *
+ * Defaults to "http://y.com" in non-browser environments. If this
+ * behavior is not desired, the implementation can be overwritten
+ * by `overwriteGetUrlOrigin()`.
+ *
+ * @type {() => string}
+ */
+export let getUrlOrigin: () => string;
+export function overwriteGetUrlOrigin(fn: () => string): void;
+export function extractLocaleFromRequest(request: Request, options?: ExtractLocaleFromRequestOptions): Locale;
+export function extractLocaleFromRequestWithStrategies(request: Request, strategies: typeof strategy, url?: string | URL): Locale;
+export function extractLocaleFromRequestAsync(request: Request, options?: {
+ effectiveRequestUrl?: string | URL;
+}): Promise;
+/**
+ * @typedef {"cookie" | "baseLocale" | "globalVariable" | "url" | "preferredLanguage" | "localStorage"} BuiltInStrategy
+ */
+/**
+ * @typedef {`custom_${string}`} CustomStrategy
+ */
+/**
+ * @typedef {BuiltInStrategy | CustomStrategy} Strategy
+ */
+/**
+ * @typedef {Array} Strategies
+ */
+/**
+ * @typedef {{ getLocale: (request?: Request) => Promise | (string | undefined) }} CustomServerStrategyHandler
+ */
+/**
+ * @typedef {{ getLocale: () => Promise | (string | undefined), setLocale: (locale: string) => Promise | void }} CustomClientStrategyHandler
+ */
+/** @type {Map} */
+export const customServerStrategies: Map;
+/** @type {Map} */
+export const customClientStrategies: Map;
+export type ShouldRedirectServerInput = {
+ request: Request;
+ /**
+ * - Effective request URL to use for route matching, locale detection with the URL strategy, and redirect targets.
+ */
+ effectiveRequestUrl?: string | URL;
+ locale?: Locale;
+};
+export type ShouldRedirectClientInput = {
+ request?: undefined;
+ url?: string | URL;
+ locale?: Locale;
+};
+export type ShouldRedirectInput = ShouldRedirectServerInput | ShouldRedirectClientInput;
+export type ShouldRedirectResult = {
+ /**
+ * - Indicates whether the consumer should perform a redirect.
+ */
+ shouldRedirect: boolean;
+ /**
+ * - Locale resolved using the configured strategies.
+ */
+ locale: Locale;
+ /**
+ * - Destination URL when a redirect is required.
+ */
+ redirectUrl: URL | undefined;
+};
+export type ParaglideAsyncLocalStorage = {
+ getStore(): {
+ locale?: Locale;
+ origin?: string;
+ messageCalls?: Set;
+ } | undefined;
+ run: (store: {
+ locale?: Locale;
+ origin?: string;
+ messageCalls?: Set;
+ }, cb: any) => any;
+};
+export type SetLocaleFn = (newLocale: Locale, options?: {
+ reload?: boolean;
+}) => void | Promise;
+export type ExtractLocaleFromRequestOptions = {
+ /**
+ * - Effective request URL to use for route matching and locale detection with the URL strategy.
+ */
+ effectiveRequestUrl?: string | URL;
+};
+export type BuiltInStrategy = "cookie" | "baseLocale" | "globalVariable" | "url" | "preferredLanguage" | "localStorage";
+export type CustomStrategy = `custom_${string}`;
+export type Strategy = BuiltInStrategy | CustomStrategy;
+export type Strategies = Array;
+export type CustomServerStrategyHandler = {
+ getLocale: (request?: Request) => Promise | (string | undefined);
+};
+export type CustomClientStrategyHandler = {
+ getLocale: () => Promise | (string | undefined);
+ setLocale: (locale: string) => Promise | void;
+};
+/**
+ * A locale that is available in the project.
+ */
+export type Locale = (typeof locales)[number];
+/**
+ * A branded type representing a localized string.
+ *
+ * Message functions return this type instead of \`string\`, enabling TypeScript
+ * to distinguish translated strings from regular strings at compile time.
+ * This allows you to enforce that only properly localized content is used
+ * in your UI components.
+ *
+ * Since \`LocalizedString\` is a branded subtype of \`string\`, it remains fully
+ * backward compatible—you can pass it anywhere a \`string\` is expected.
+ */
+export type LocalizedString = string & {
+ readonly __brand: "LocalizedString";
+};
+/**
+ * A single markup option passed to a tag instance.
+ */
+export type MessageMarkupOption = {
+ name: string;
+ value: unknown;
+};
+/**
+ * A single static markup attribute attached to a tag instance.
+ */
+export type MessageMarkupAttribute = {
+ name: string;
+ value: string | true;
+};
+/**
+ * Record of markup options for a tag instance.
+ */
+export type MessageMarkupOptions = Record;
+/**
+ * Record of markup attributes for a tag instance.
+ */
+export type MessageMarkupAttributes = Record;
+/**
+ * Type-level schema for a single markup tag.
+ */
+export type MessageMarkupTag = {
+ options: MessageMarkupOptions;
+ attributes: MessageMarkupAttributes;
+ children: boolean;
+};
+/**
+ * Type-level schema for all markup tags in a message.
+ */
+export type MessageMarkupSchema = Record;
+/**
+ * Type-only metadata attached to compiled message functions.
+ */
+export type MessageMetadata> = {
+ readonly __paraglide?: {
+ inputs: Inputs;
+ options: Options;
+ markup: Markup;
+ };
+};
+/**
+ * A compiled, framework-neutral message part.
+ */
+export type MessagePart = {
+ type: "text";
+ value: string;
+} | {
+ type: "markup-start";
+ name: string;
+ options: MessageMarkupOptions;
+ attributes: MessageMarkupAttributes;
+} | {
+ type: "markup-end";
+ name: string;
+ options: MessageMarkupOptions;
+ attributes: MessageMarkupAttributes;
+} | {
+ type: "markup-standalone";
+ name: string;
+ options: MessageMarkupOptions;
+ attributes: MessageMarkupAttributes;
+};
+/**
+ * A message function is a message for a specific locale.
+ */
+export type MessageFunction = (inputs?: Record) => LocalizedString;
+/**
+ * A message bundle function that selects the message to be returned.
+ *
+ * Uses `getLocale()` under the hood to determine the locale with an option.
+ */
+export type MessageBundleFunction = (params: Record, options: {
+ locale: T;
+}) => LocalizedString;
diff --git a/packages/webui/src/paraglide/runtime.js b/packages/webui/src/paraglide/runtime.js
new file mode 100644
index 00000000..99279263
--- /dev/null
+++ b/packages/webui/src/paraglide/runtime.js
@@ -0,0 +1,1825 @@
+/* eslint-disable */
+
+/** @type {any} */
+const URLPattern = {}
+
+/**
+ * The project's base locale.
+ *
+ * @example
+ * if (locale === baseLocale) {
+ * // do something
+ * }
+ */
+export const baseLocale = "en";
+/**
+ * The project's locales that have been specified in the settings.
+ *
+ * @example
+ * if (locales.includes(userSelectedLocale) === false) {
+ * throw new Error('Locale is not available');
+ * }
+ */
+export const locales = /** @type {const} */ (["en","zh"]);
+/** @type {string} */
+export const cookieName = "PARAGLIDE_LOCALE";
+/** @type {number} */
+export const cookieMaxAge = 34560000;
+/** @type {string} */
+export const cookieDomain = "";
+/** @type {string} */
+export const localStorageKey = "PARAGLIDE_LOCALE";
+/**
+ * @type {Array<"cookie" | "baseLocale" | "globalVariable" | "url" | "preferredLanguage" | "localStorage" | `custom-${string}`>}
+ */
+export const strategy = [
+ "cookie",
+ "globalVariable",
+ "baseLocale"
+];
+/**
+ * Route-level strategy overrides.
+ *
+ * `match` uses URLPattern syntax.
+ *
+ * @type {Array<{
+ * match: string;
+ * strategy?: Array<"cookie" | "baseLocale" | "globalVariable" | "url" | "preferredLanguage" | "localStorage" | `custom-${string}`>;
+ * exclude?: boolean;
+ * }>}
+ */
+export const routeStrategies = [];
+/**
+ * The used URL patterns.
+ *
+ * @type {Array<{ pattern: string, localized: Array<[Locale, string]> }>}
+ */
+export const urlPatterns = [
+ {
+ "pattern": ":protocol://:domain(.*)::port?/:path(.*)?",
+ "localized": [
+ [
+ "zh",
+ ":protocol://:domain(.*)::port?/zh/:path(.*)?"
+ ],
+ [
+ "en",
+ ":protocol://:domain(.*)::port?/:path(.*)?"
+ ]
+ ]
+ }
+];
+/** @type {string | undefined} */
+let cachedRouteStrategyUrl;
+/** @type {{ match: string; strategy?: typeof strategy; exclude?: boolean } | undefined} */
+let cachedRouteStrategy;
+/**
+ * @param {string | URL} url
+ * @returns {{ match: string; strategy?: typeof strategy; exclude?: boolean } | undefined}
+ */
+function findMatchingRouteStrategy(url) {
+ if (routeStrategies.length === 0) {
+ return undefined;
+ }
+ const urlString = typeof url === "string" ? url : url.href;
+ if (cachedRouteStrategyUrl === urlString) {
+ return cachedRouteStrategy;
+ }
+ const urlObject = new URL(urlString, "http://dummy.com");
+ let match;
+ for (const routeStrategy of routeStrategies) {
+ const pattern = new URLPattern(routeStrategy.match, urlObject.href);
+ if (pattern.exec(urlObject.href)) {
+ match = routeStrategy;
+ break;
+ }
+ }
+ cachedRouteStrategyUrl = urlString;
+ cachedRouteStrategy = match;
+ return match;
+}
+/**
+ * Returns the strategy to use for a specific URL.
+ *
+ * If no route strategy matches (or the matching rule is `exclude: true`),
+ * the global strategy is returned.
+ *
+ * @param {string | URL} url
+ * @returns {typeof strategy}
+ */
+export function getStrategyForUrl(url) {
+ const routeStrategy = findMatchingRouteStrategy(url);
+ if (routeStrategy &&
+ routeStrategy.exclude !== true &&
+ Array.isArray(routeStrategy.strategy)) {
+ return routeStrategy.strategy;
+ }
+ return strategy;
+}
+/**
+ * Returns whether the given URL is excluded from middleware i18n processing.
+ *
+ * @param {string | URL} url
+ * @returns {boolean}
+ */
+export function isExcludedByRouteStrategy(url) {
+ return findMatchingRouteStrategy(url)?.exclude === true;
+}
+/**
+ * @typedef {{
+ * getStore(): {
+ * locale?: Locale,
+ * origin?: string,
+ * messageCalls?: Set
+ * } | undefined,
+ * run: (store: { locale?: Locale, origin?: string, messageCalls?: Set},
+ * cb: any) => any
+ * }} ParaglideAsyncLocalStorage
+ */
+/**
+ * Server side async local storage that is set by `serverMiddleware()`.
+ *
+ * The variable is used to retrieve the locale and origin in a server-side
+ * rendering context without effecting other requests.
+ *
+ * @type {ParaglideAsyncLocalStorage | undefined}
+ */
+export let serverAsyncLocalStorage = undefined;
+export const disableAsyncLocalStorage = false;
+export const experimentalMiddlewareLocaleSplitting = false;
+export const isServer = typeof window === 'undefined';
+/** @type {Locale | undefined} */
+export const experimentalStaticLocale = undefined;
+/**
+ * Sets the server side async local storage.
+ *
+ * The function is needed because the `runtime.js` file
+ * must define the `serverAsyncLocalStorage` variable to
+ * avoid a circular import between `runtime.js` and
+ * `server.js` files.
+ *
+ * @param {ParaglideAsyncLocalStorage | undefined} value
+ */
+export function overwriteServerAsyncLocalStorage(value) {
+ serverAsyncLocalStorage = value;
+}
+const TREE_SHAKE_COOKIE_STRATEGY_USED = true;
+const TREE_SHAKE_URL_STRATEGY_USED = false;
+const TREE_SHAKE_GLOBAL_VARIABLE_STRATEGY_USED = true;
+const TREE_SHAKE_PREFERRED_LANGUAGE_STRATEGY_USED = false;
+const TREE_SHAKE_DEFAULT_URL_PATTERN_USED = true;
+const TREE_SHAKE_LOCAL_STORAGE_STRATEGY_USED = false;
+
+/** @type {any} */ (globalThis).__paraglide =
+ /** @type {any} */ (globalThis).__paraglide ?? {};
+/** @type {any} */ (globalThis).__paraglide.ssr =
+ /** @type {any} */ (globalThis).__paraglide.ssr ?? {};
+
+/**
+ * This is a fallback to get started with a custom
+ * strategy and avoid type errors.
+ *
+ * The implementation is overwritten
+ * by `overwriteGetLocale()` and `defineSetLocale()`.
+ *
+ * @type {Locale | undefined}
+ */
+let _locale;
+let localeInitiallySet = false;
+/**
+ * Get the current locale.
+ *
+ * The locale is resolved using your configured strategies (URL, cookie, localStorage, etc.)
+ * in the order they are defined. In SSR contexts, the locale is retrieved from AsyncLocalStorage
+ * which is set by the `paraglideMiddleware()`.
+ *
+ * @see https://paraglidejs.com/strategy - Configure locale detection strategies
+ *
+ * @example
+ * if (getLocale() === 'de') {
+ * console.log('Germany 🇩🇪');
+ * } else if (getLocale() === 'nl') {
+ * console.log('Netherlands 🇳🇱');
+ * }
+ *
+ * @returns {Locale} The current locale.
+ */
+export let getLocale = () => {
+ if (experimentalStaticLocale !== undefined) {
+ return experimentalStaticLocale;
+ }
+ // if running in a server-side rendering context
+ // retrieve the locale from the async local storage
+ if (serverAsyncLocalStorage) {
+ const locale = serverAsyncLocalStorage?.getStore()?.locale;
+ if (locale) {
+ return locale;
+ }
+ }
+ let strategyToUse = strategy;
+ if (!isServer && typeof window !== "undefined" && window.location?.href) {
+ strategyToUse = getStrategyForUrl(window.location.href);
+ }
+ const resolved = resolveLocaleWithStrategies(strategyToUse, typeof window !== "undefined" ? window.location?.href : undefined);
+ if (resolved) {
+ if (!localeInitiallySet) {
+ _locale = resolved;
+ // https://github.com/opral/inlang-paraglide-js/issues/455
+ localeInitiallySet = true;
+ setLocale(resolved, { reload: false });
+ }
+ return resolved;
+ }
+ throw new Error("No locale found. Read the docs https://paraglidejs.com/errors#no-locale-found");
+};
+/**
+ * Resolve locale for a given URL using route-aware strategies.
+ *
+ * @param {string | URL} url
+ * @returns {Locale}
+ */
+export function getLocaleForUrl(url) {
+ if (experimentalStaticLocale !== undefined) {
+ return experimentalStaticLocale;
+ }
+ const strategyToUse = getStrategyForUrl(url);
+ const resolved = resolveLocaleWithStrategies(strategyToUse, typeof url === "string" ? url : url.href);
+ if (resolved) {
+ return resolved;
+ }
+ throw new Error("No locale found. Read the docs https://paraglidejs.com/errors#no-locale-found");
+}
+/**
+ * @param {typeof strategy} strategyToUse
+ * @param {string | undefined} urlForUrlStrategy
+ * @returns {Locale | undefined}
+ */
+function resolveLocaleWithStrategies(strategyToUse, urlForUrlStrategy) {
+ /** @type {string | undefined} */
+ let locale;
+ for (const strat of strategyToUse) {
+ if (TREE_SHAKE_COOKIE_STRATEGY_USED && strat === "cookie") {
+ locale = extractLocaleFromCookie();
+ }
+ else if (strat === "baseLocale") {
+ locale = baseLocale;
+ }
+ else if (TREE_SHAKE_URL_STRATEGY_USED &&
+ strat === "url" &&
+ !isServer &&
+ typeof urlForUrlStrategy === "string") {
+ locale = extractLocaleFromUrl(urlForUrlStrategy);
+ }
+ else if (TREE_SHAKE_GLOBAL_VARIABLE_STRATEGY_USED &&
+ strat === "globalVariable" &&
+ _locale !== undefined) {
+ locale = _locale;
+ }
+ else if (TREE_SHAKE_PREFERRED_LANGUAGE_STRATEGY_USED &&
+ strat === "preferredLanguage" &&
+ !isServer) {
+ locale = extractLocaleFromNavigator();
+ }
+ else if (TREE_SHAKE_LOCAL_STORAGE_STRATEGY_USED &&
+ strat === "localStorage" &&
+ !isServer) {
+ locale = localStorage.getItem(localStorageKey) ?? undefined;
+ }
+ else if (isCustomStrategy(strat) && customClientStrategies.has(strat)) {
+ const handler = customClientStrategies.get(strat);
+ if (handler) {
+ const result = handler.getLocale();
+ // Handle both sync and async results - skip async in sync getLocale
+ if (result instanceof Promise) {
+ // Can't await in sync function, skip async strategies
+ continue;
+ }
+ if (result !== undefined) {
+ return assertIsLocale(result);
+ }
+ }
+ }
+ const matchedLocale = toLocale(locale);
+ if (matchedLocale) {
+ return matchedLocale;
+ }
+ }
+ return undefined;
+}
+/**
+ * Overwrite the `getLocale()` function.
+ *
+ * Use this function to overwrite how the locale is resolved. This is useful
+ * for custom locale resolution or advanced use cases like SSG with concurrent rendering.
+ *
+ * @see https://paraglidejs.com/strategy
+ *
+ * @example
+ * overwriteGetLocale(() => {
+ * return Cookies.get('locale') ?? baseLocale
+ * });
+ *
+ * @param {() => Locale} fn - The new implementation for `getLocale()`.
+ */
+export const overwriteGetLocale = (fn) => {
+ getLocale = fn;
+};
+
+const rtlLanguages = new Set([
+ "ar",
+ "dv",
+ "fa",
+ "he",
+ "ks",
+ "ku",
+ "ps",
+ "sd",
+ "ug",
+ "ur",
+ "yi",
+]);
+/**
+ * Get writing direction for a locale.
+ *
+ * Uses `Intl.Locale` text info when available and falls back to a
+ * language-based RTL check for runtimes without `getTextInfo()`.
+ *
+ * @example
+ * getTextDirection(); // "ltr" or "rtl" for current locale
+ * getTextDirection("ar"); // "rtl"
+ * getTextDirection("en"); // "ltr"
+ *
+ * @param {string} [locale] - Target locale. If not provided, uses `getLocale()`
+ * @returns {"ltr" | "rtl"}
+ */
+export function getTextDirection(locale = getLocale()) {
+ try {
+ const intlLocale = /** @type {Intl.Locale & {
+ getTextInfo?: () => { direction?: string };
+ textInfo?: { direction?: string };
+ }} */ (new Intl.Locale(locale));
+ const direction = intlLocale.getTextInfo?.().direction ?? intlLocale.textInfo?.direction;
+ if (direction === "ltr" || direction === "rtl") {
+ return direction;
+ }
+ }
+ catch {
+ // Ignore Intl.Locale parsing/runtime errors and use fallback below.
+ }
+ const language = locale.split("-")[0]?.toLowerCase();
+ return rtlLanguages.has(language ?? "") ? "rtl" : "ltr";
+}
+
+/**
+ * Navigates to the localized URL, or reloads the current page
+ *
+ * @param {string} [newLocation] The new location
+ */
+const navigateOrReload = (newLocation) => {
+ if (newLocation) {
+ // reload the page by navigating to the new url
+ window.location.href = newLocation;
+ }
+ else {
+ // reload the page to reflect the new locale
+ window.location.reload();
+ }
+};
+/**
+ * @typedef {(newLocale: Locale, options?: { reload?: boolean }) => void | Promise} SetLocaleFn
+ */
+/**
+ * Set the locale.
+ *
+ * Updates the locale using your configured strategies (cookie, localStorage, URL, etc.).
+ * By default, this reloads the page on the client to reflect the new locale. Reloading
+ * can be disabled by passing `reload: false` as an option, but you'll need to ensure
+ * the UI updates to reflect the new locale.
+ *
+ * If any custom strategy's `setLocale` function is async, then this function
+ * will become async as well.
+ *
+ * @see https://paraglidejs.com/strategy
+ *
+ * @example
+ * setLocale('en');
+ *
+ * @example
+ * setLocale('en', { reload: false });
+ *
+ * @type {SetLocaleFn}
+ */
+export let setLocale = (newLocale, options) => {
+ const optionsWithDefaults = {
+ reload: true,
+ ...options,
+ };
+ // locale is already set
+ // https://github.com/opral/inlang-paraglide-js/issues/430
+ /** @type {Locale | undefined} */
+ let currentLocale;
+ try {
+ currentLocale = getLocale();
+ }
+ catch {
+ // do nothing, no locale has been set yet.
+ }
+ /** @type {Array>} */
+ const customSetLocalePromises = [];
+ /** @type {string | undefined} */
+ let newLocation = undefined;
+ let strategyToUse = strategy;
+ if (!isServer && typeof window !== "undefined" && window.location?.href) {
+ strategyToUse = getStrategyForUrl(window.location.href);
+ }
+ for (const strat of strategyToUse) {
+ if (TREE_SHAKE_GLOBAL_VARIABLE_STRATEGY_USED &&
+ strat === "globalVariable") {
+ // a default for a custom strategy to get started quickly
+ // is likely overwritten by `defineSetLocale()`
+ _locale = newLocale;
+ }
+ else if (TREE_SHAKE_COOKIE_STRATEGY_USED && strat === "cookie") {
+ if (isServer ||
+ typeof document === "undefined" ||
+ typeof window === "undefined") {
+ continue;
+ }
+ // set the cookie
+ const cookieString = `${cookieName}=${newLocale}; path=/; max-age=${cookieMaxAge}`;
+ document.cookie = cookieDomain
+ ? `${cookieString}; domain=${cookieDomain}`
+ : cookieString;
+ }
+ else if (strat === "baseLocale") {
+ // nothing to be set here. baseLocale is only a fallback
+ continue;
+ }
+ else if (TREE_SHAKE_URL_STRATEGY_USED &&
+ strat === "url" &&
+ typeof window !== "undefined") {
+ // route to the new url
+ //
+ // this triggers a page reload but a user rarely
+ // switches locales, so this should be fine.
+ //
+ // if the behavior is not desired, the implementation
+ // can be overwritten by `defineSetLocale()` to avoid
+ // a full page reload.
+ newLocation = localizeUrl(window.location.href, {
+ locale: newLocale,
+ }).href;
+ }
+ else if (TREE_SHAKE_LOCAL_STORAGE_STRATEGY_USED &&
+ strat === "localStorage" &&
+ typeof window !== "undefined") {
+ // set the localStorage
+ localStorage.setItem(localStorageKey, newLocale);
+ }
+ else if (isCustomStrategy(strat) && customClientStrategies.has(strat)) {
+ const handler = customClientStrategies.get(strat);
+ if (handler) {
+ let result = handler.setLocale(newLocale);
+ // Handle async setLocale
+ if (result instanceof Promise) {
+ result = result.catch((error) => {
+ throw new Error(`Custom strategy "${strat}" setLocale failed.`, {
+ cause: error,
+ });
+ });
+ customSetLocalePromises.push(result);
+ }
+ }
+ }
+ }
+ const runReload = () => {
+ if (!isServer &&
+ optionsWithDefaults.reload &&
+ window.location &&
+ newLocale !== currentLocale) {
+ navigateOrReload(newLocation);
+ }
+ };
+ if (customSetLocalePromises.length) {
+ return Promise.all(customSetLocalePromises).then(() => {
+ runReload();
+ });
+ }
+ runReload();
+ return;
+};
+/**
+ * Overwrite the `setLocale()` function.
+ *
+ * Use this function to overwrite how the locale is set. For example,
+ * modify a cookie, env variable, or a user's preference.
+ *
+ * @example
+ * overwriteSetLocale((newLocale) => {
+ * // set the locale in a cookie
+ * return Cookies.set('locale', newLocale)
+ * });
+ *
+ * @param {SetLocaleFn} fn
+ */
+export const overwriteSetLocale = (fn) => {
+ setLocale = fn;
+};
+
+/**
+ * The origin of the current URL.
+ *
+ * Defaults to "http://y.com" in non-browser environments. If this
+ * behavior is not desired, the implementation can be overwritten
+ * by `overwriteGetUrlOrigin()`.
+ *
+ * @type {() => string}
+ */
+export let getUrlOrigin = () => {
+ if (serverAsyncLocalStorage) {
+ return serverAsyncLocalStorage.getStore()?.origin ?? "http://fallback.com";
+ }
+ else if (typeof window !== "undefined") {
+ return window.location.origin;
+ }
+ return "http://fallback.com";
+};
+/**
+ * Overwrite the getUrlOrigin function.
+ *
+ * Use this function in server environments to
+ * define how the URL origin is resolved.
+ *
+ * @param {() => string} fn - The new implementation for `getUrlOrigin()`.
+ */
+export let overwriteGetUrlOrigin = (fn) => {
+ getUrlOrigin = fn;
+};
+
+/**
+ * Coerces a locale-like string to the canonical locale value used by the runtime.
+ *
+ * @param {unknown} value
+ * @returns {Locale | undefined}
+ */
+export function toLocale(value) {
+ if (typeof value !== "string") {
+ return undefined;
+ }
+ const lowerValue = value.toLowerCase();
+ for (const locale of locales) {
+ if (locale.toLowerCase() === lowerValue) {
+ return locale;
+ }
+ }
+ return undefined;
+}
+/**
+ * Check if something is an available locale with the canonical project casing.
+ *
+ * @example
+ * if (isLocale(params.locale)) {
+ * setLocale(params.locale);
+ * } else {
+ * setLocale('en');
+ * }
+ *
+ * Use `toLocale()` when you want case-insensitive matching and canonicalization.
+ *
+ * @param {unknown} locale
+ * @returns {locale is Locale}
+ */
+export function isLocale(locale) {
+ return !!locale && locales.some((item) => item === locale);
+}
+/**
+ * Asserts that the input can be normalized to a locale.
+ *
+ * @param {unknown} input - The input to check.
+ * @returns {Locale} The input normalized to a Locale.
+ * @throws {Error} If the input is not a locale.
+ */
+export function assertIsLocale(input) {
+ const locale = toLocale(input);
+ if (locale)
+ return locale;
+ throw new Error(`Invalid locale: ${input}. Expected one of: ${locales.join(", ")}`);
+}
+
+/**
+ * @typedef {object} ExtractLocaleFromRequestOptions
+ * @property {string | URL} [effectiveRequestUrl] - Effective request URL to use for route matching and locale detection with the URL strategy.
+ */
+/**
+ * Extracts a locale from a request.
+ *
+ * Use the function on the server to extract the locale
+ * from a request.
+ *
+ * The function goes through the strategies in the order
+ * they are defined. If a strategy returns an invalid locale,
+ * it will fall back to the next strategy.
+ *
+ * Note: Custom server strategies are not supported in this synchronous version.
+ * Use `extractLocaleFromRequestAsync` if you need custom server strategies with async getLocale methods.
+ *
+ * @example
+ * const locale = extractLocaleFromRequest(request);
+ *
+ * @param {Request} request
+ * @param {ExtractLocaleFromRequestOptions} [options]
+ * @returns {Locale}
+ */
+export const extractLocaleFromRequest = (request, options = {}) => {
+ const effectiveRequestUrl = resolveEffectiveRequestUrl(request, options.effectiveRequestUrl);
+ return extractLocaleFromRequestWithStrategies(request, getStrategyForUrl(effectiveRequestUrl), effectiveRequestUrl);
+};
+/**
+ * Extracts a locale from a request using the provided strategy order.
+ *
+ * @param {Request} request
+ * @param {typeof strategy} strategies
+ * @param {string | URL} [url]
+ * @returns {Locale}
+ */
+export const extractLocaleFromRequestWithStrategies = (request, strategies, url = request.url) => {
+ const effectiveRequestUrl = resolveEffectiveRequestUrl(request, url);
+ /** @type {string|undefined} */
+ let locale;
+ for (const strat of strategies) {
+ if (TREE_SHAKE_COOKIE_STRATEGY_USED && strat === "cookie") {
+ locale = request.headers
+ .get("cookie")
+ ?.split("; ")
+ .find((c) => c.startsWith(cookieName + "="))
+ ?.split("=")[1];
+ }
+ else if (TREE_SHAKE_URL_STRATEGY_USED && strat === "url") {
+ locale = extractLocaleFromUrl(effectiveRequestUrl);
+ }
+ else if (TREE_SHAKE_PREFERRED_LANGUAGE_STRATEGY_USED &&
+ strat === "preferredLanguage") {
+ locale = extractLocaleFromHeader(request);
+ }
+ else if (strat === "globalVariable") {
+ locale = _locale;
+ }
+ else if (strat === "baseLocale") {
+ return baseLocale;
+ }
+ else if (strat === "localStorage") {
+ continue;
+ }
+ else if (isCustomStrategy(strat)) {
+ // Custom strategies are not supported in sync version
+ // Use extractLocaleFromRequestAsync for custom server strategies
+ continue;
+ }
+ const matchedLocale = toLocale(locale);
+ if (matchedLocale) {
+ return matchedLocale;
+ }
+ }
+ throw new Error("No locale found. There is an error in your strategy. Try adding 'baseLocale' as the very last strategy. Read more here https://paraglidejs.com/errors#no-locale-found");
+};
+/**
+ * @param {Request} request
+ * @param {string | URL | undefined} effectiveRequestUrl
+ * @returns {URL}
+ */
+function resolveEffectiveRequestUrl(request, effectiveRequestUrl = request.url) {
+ if (effectiveRequestUrl instanceof URL) {
+ return new URL(effectiveRequestUrl.href);
+ }
+ return new URL(effectiveRequestUrl, request.url);
+}
+
+/**
+ * Asynchronously extracts a locale from a request.
+ *
+ * This function supports async custom server strategies, unlike the synchronous
+ * `extractLocaleFromRequest`. Use this function when you have custom server strategies
+ * that need to perform asynchronous operations (like database calls) in their getLocale method.
+ *
+ * The function first processes any custom server strategies asynchronously, then falls back
+ * to the synchronous `extractLocaleFromRequest` for all other strategies.
+ *
+ * @see {@link https://github.com/opral/inlang-paraglide-js/issues/527#issuecomment-2978151022}
+ *
+ * @example
+ * // Basic usage
+ * const locale = await extractLocaleFromRequestAsync(request);
+ *
+ * @example
+ * // With custom async server strategy
+ * defineCustomServerStrategy("custom-database", {
+ * getLocale: async (request) => {
+ * const userId = extractUserIdFromRequest(request);
+ * return await getUserLocaleFromDatabase(userId);
+ * }
+ * });
+ *
+ * const locale = await extractLocaleFromRequestAsync(request);
+ *
+ * @param {Request} request - The request object to extract the locale from.
+ * @param {{ effectiveRequestUrl?: string | URL }} [options] - Effective request URL to use for route matching and locale detection with the URL strategy.
+ * @returns {Promise} The extracted locale.
+ */
+export const extractLocaleFromRequestAsync = async (request, options = {}) => {
+ /** @type {string|undefined} */
+ let locale;
+ const effectiveRequestUrl = resolveEffectiveRequestUrlFromRequestAsync(request, options.effectiveRequestUrl);
+ const strategy = getStrategyForUrl(effectiveRequestUrl);
+ // Process custom strategies first, in order
+ for (const strat of strategy) {
+ if (isCustomStrategy(strat) && customServerStrategies.has(strat)) {
+ const handler = customServerStrategies.get(strat);
+ if (handler) {
+ /** @type {string|undefined} */
+ locale = await handler.getLocale(request);
+ }
+ // If we got a valid locale from this custom strategy, use it
+ const matchedLocale = toLocale(locale);
+ if (matchedLocale) {
+ return matchedLocale;
+ }
+ }
+ }
+ // If no custom strategy provided a valid locale, fall back to sync version
+ return extractLocaleFromRequestWithStrategies(request, strategy, effectiveRequestUrl);
+};
+/**
+ * @param {Request} request
+ * @param {string | URL | undefined} effectiveRequestUrl
+ * @returns {URL}
+ */
+function resolveEffectiveRequestUrlFromRequestAsync(request, effectiveRequestUrl = request.url) {
+ if (effectiveRequestUrl instanceof URL) {
+ return new URL(effectiveRequestUrl.href);
+ }
+ return new URL(effectiveRequestUrl, request.url);
+}
+
+/**
+ * Extracts a cookie from the document.
+ *
+ * Will return undefined if the document is not available or if the cookie is not set.
+ * The `document` object is not available in server-side rendering, so this function should not be called in that context.
+ *
+ * @returns {Locale | undefined}
+ */
+export function extractLocaleFromCookie() {
+ if (typeof document === "undefined" || !document.cookie) {
+ return;
+ }
+ const match = document.cookie.match(new RegExp(`(^| )${cookieName}=([^;]+)`));
+ const locale = match?.[2];
+ return toLocale(locale);
+}
+
+/**
+ * Extracts a locale from the accept-language header.
+ *
+ * Use the function on the server to extract the locale
+ * from the accept-language header that is sent by the client.
+ *
+ * @example
+ * const locale = extractLocaleFromHeader(request);
+ *
+ * @param {Request} request - The request object to extract the locale from.
+ * @returns {Locale | undefined} The negotiated preferred language.
+ */
+export function extractLocaleFromHeader(request) {
+ const acceptLanguageHeader = request.headers.get("accept-language");
+ if (acceptLanguageHeader) {
+ // Parse language preferences with their q-values and base language codes
+ const languages = acceptLanguageHeader
+ .split(",")
+ .map((lang) => {
+ const [tag, q = "1"] = lang.trim().split(";q=");
+ // Get both the full tag and base language code
+ const baseTag = tag?.split("-")[0];
+ return {
+ fullTag: tag,
+ baseTag,
+ q: Number(q),
+ };
+ })
+ .sort((a, b) => b.q - a.q);
+ for (const lang of languages) {
+ const fullLocale = toLocale(lang.fullTag);
+ if (fullLocale) {
+ return fullLocale;
+ }
+ const baseLocale = toLocale(lang.baseTag);
+ if (baseLocale) {
+ return baseLocale;
+ }
+ }
+ return undefined;
+ }
+ return undefined;
+}
+
+/**
+ * Negotiates a preferred language from navigator.languages.
+ *
+ * Use the function on the client to extract the locale
+ * from the navigator.languages array.
+ *
+ * @example
+ * const locale = extractLocaleFromNavigator();
+ *
+ * @returns {Locale | undefined}
+ */
+export function extractLocaleFromNavigator() {
+ if (!navigator?.languages?.length) {
+ return undefined;
+ }
+ const languages = navigator.languages.map((lang) => ({
+ fullTag: lang,
+ baseTag: lang.split("-")[0],
+ }));
+ for (const lang of languages) {
+ const fullLocale = toLocale(lang.fullTag);
+ if (fullLocale) {
+ return fullLocale;
+ }
+ const baseLocale = toLocale(lang.baseTag);
+ if (baseLocale) {
+ return baseLocale;
+ }
+ }
+ return undefined;
+}
+
+/**
+ * If extractLocaleFromUrl is called many times on the same page and the URL
+ * hasn't changed, we don't need to recompute it every time which can get expensive.
+ * We might use a LRU cache if needed, but for now storing only the last result is enough.
+ * https://github.com/opral/monorepo/pull/3575#discussion_r2066731243
+ */
+/** @type {string|undefined} */
+let cachedUrl;
+/** @type {Locale|undefined} */
+let cachedLocale;
+/**
+ * Extracts the locale from a given URL using native URLPattern.
+ *
+ * The built-in default `/:locale/...` routing is case-insensitive because it
+ * canonicalizes the first path segment with `toLocale()`. Custom `urlPatterns`
+ * keep URLPattern's normal exact matching semantics for path segments.
+ *
+ * @param {URL|string} url - The full URL from which to extract the locale.
+ * @returns {Locale|undefined} The extracted locale, or undefined if no locale is found.
+ */
+export function extractLocaleFromUrl(url) {
+ const urlString = typeof url === "string" ? url : url.href;
+ if (cachedUrl === urlString) {
+ return cachedLocale;
+ }
+ /** @type {Locale | undefined} */
+ let result;
+ if (TREE_SHAKE_DEFAULT_URL_PATTERN_USED) {
+ result = defaultUrlPatternExtractLocale(url);
+ }
+ else {
+ const urlObj = typeof url === "string" ? new URL(url) : url;
+ // Iterate over URL patterns
+ for (const element of urlPatterns) {
+ for (const [locale, localizedPattern] of element.localized) {
+ const match = new URLPattern(localizedPattern, urlObj.href).exec(urlObj.href);
+ if (match) {
+ result = locale;
+ break;
+ }
+ }
+ if (result)
+ break;
+ }
+ }
+ cachedUrl = urlString;
+ cachedLocale = result;
+ return result;
+}
+/**
+ * https://github.com/opral/inlang-paraglide-js/issues/381
+ *
+ * @param {URL | string} url - The full URL from which to extract the locale.
+ * @returns {Locale | undefined} The extracted locale, or undefined if no locale is found.
+ */
+function defaultUrlPatternExtractLocale(url) {
+ const urlObj = new URL(url, "http://dummy.com");
+ const pathSegments = urlObj.pathname.split("/").filter(Boolean);
+ return toLocale(pathSegments[0]) || baseLocale;
+}
+
+/**
+ * Lower-level URL localization function, primarily used in server contexts.
+ *
+ * This function is designed for server-side usage where you need precise control
+ * over URL localization, such as in middleware or request handlers. It works with
+ * URL objects and always returns absolute URLs.
+ *
+ * For client-side UI components, use `localizeHref()` instead, which provides
+ * a more convenient API with relative paths and automatic locale detection.
+ *
+ * @see https://paraglidejs.com/i18n-routing
+ *
+ * @example
+ * ```typescript
+ * // Server middleware example
+ * app.use((req, res, next) => {
+ * const url = new URL(req.url, `${req.protocol}://${req.headers.host}`);
+ * const localized = localizeUrl(url, { locale: "de" });
+ *
+ * if (localized.href !== url.href) {
+ * return res.redirect(localized.href);
+ * }
+ * next();
+ * });
+ * ```
+ *
+ * @example
+ * ```typescript
+ * // Using with URL patterns
+ * const url = new URL("https://example.com/about");
+ * localizeUrl(url, { locale: "de" });
+ * // => URL("https://example.com/de/about")
+ *
+ * // Using with domain-based localization
+ * const url = new URL("https://example.com/store");
+ * localizeUrl(url, { locale: "de" });
+ * // => URL("https://de.example.com/store")
+ * ```
+ *
+ * @param {string | URL} url - The URL to localize. If string, must be absolute.
+ * @param {object} [options] - Options for localization
+ * @param {Locale} [options.locale] - Target locale. If not provided, uses getLocale()
+ * @returns {URL} The localized URL, always absolute
+ */
+export function localizeUrl(url, options) {
+ const targetLocale = options?.locale
+ ? assertIsLocale(options?.locale)
+ : getLocale();
+ if (TREE_SHAKE_DEFAULT_URL_PATTERN_USED) {
+ return localizeUrlDefaultPattern(url, targetLocale);
+ }
+ const urlObj = typeof url === "string" ? new URL(url) : url;
+ // Iterate over URL patterns
+ for (const element of urlPatterns) {
+ // match localized patterns
+ for (const [, localizedPattern] of element.localized) {
+ const match = new URLPattern(localizedPattern, urlObj.href).exec(urlObj.href);
+ if (!match) {
+ continue;
+ }
+ const targetPattern = element.localized.find(([locale]) => locale === targetLocale)?.[1];
+ if (!targetPattern) {
+ continue;
+ }
+ const localizedUrl = fillPattern(targetPattern, aggregateGroups(match), urlObj.origin);
+ return fillMissingUrlParts(localizedUrl, match);
+ }
+ const unlocalizedMatch = new URLPattern(element.pattern, urlObj.href).exec(urlObj.href);
+ if (unlocalizedMatch) {
+ const targetPattern = element.localized.find(([locale]) => locale === targetLocale)?.[1];
+ if (targetPattern) {
+ const localizedUrl = fillPattern(targetPattern, aggregateGroups(unlocalizedMatch), urlObj.origin);
+ return fillMissingUrlParts(localizedUrl, unlocalizedMatch);
+ }
+ }
+ }
+ // If no match found, return the original URL
+ return urlObj;
+}
+/**
+ * https://github.com/opral/inlang-paraglide-js/issues/381
+ *
+ * @param {string | URL} url
+ * @param {Locale} locale
+ * @returns {URL}
+ */
+function localizeUrlDefaultPattern(url, locale) {
+ const urlObj = typeof url === "string" ? new URL(url, getUrlOrigin()) : new URL(url);
+ const currentLocale = extractLocaleFromUrl(urlObj);
+ // If current locale matches target locale, no change needed
+ if (currentLocale === locale) {
+ return urlObj;
+ }
+ const pathSegments = urlObj.pathname.split("/").filter(Boolean);
+ // If current path starts with a locale, remove it
+ if (pathSegments.length > 0 && toLocale(pathSegments[0])) {
+ pathSegments.shift();
+ }
+ // For base locale, don't add prefix
+ if (locale === baseLocale) {
+ urlObj.pathname = "/" + pathSegments.join("/");
+ }
+ else {
+ // For other locales, add prefix
+ urlObj.pathname = "/" + locale + "/" + pathSegments.join("/");
+ }
+ return urlObj;
+}
+/**
+ * Low-level URL de-localization function, primarily used in server contexts.
+ *
+ * This function is designed for server-side usage where you need precise control
+ * over URL de-localization, such as in middleware or request handlers. It works with
+ * URL objects and always returns absolute URLs.
+ *
+ * For client-side UI components, use `deLocalizeHref()` instead, which provides
+ * a more convenient API with relative paths.
+ *
+ * @see https://paraglidejs.com/i18n-routing
+ *
+ * @example
+ * ```typescript
+ * // Server middleware example
+ * app.use((req, res, next) => {
+ * const url = new URL(req.url, `${req.protocol}://${req.headers.host}`);
+ * const baseUrl = deLocalizeUrl(url);
+ *
+ * // Store the base URL for later use
+ * req.baseUrl = baseUrl;
+ * next();
+ * });
+ * ```
+ *
+ * @example
+ * ```typescript
+ * // Using with URL patterns
+ * const url = new URL("https://example.com/de/about");
+ * deLocalizeUrl(url); // => URL("https://example.com/about")
+ *
+ * // Using with domain-based localization
+ * const url = new URL("https://de.example.com/store");
+ * deLocalizeUrl(url); // => URL("https://example.com/store")
+ * ```
+ *
+ * @param {string | URL} url - The URL to de-localize. If string, must be absolute.
+ * @returns {URL} The de-localized URL, always absolute
+ */
+export function deLocalizeUrl(url) {
+ if (TREE_SHAKE_DEFAULT_URL_PATTERN_USED) {
+ return deLocalizeUrlDefaultPattern(url);
+ }
+ const urlObj = typeof url === "string" ? new URL(url) : url;
+ // Iterate over URL patterns
+ for (const element of urlPatterns) {
+ // Iterate over localized versions
+ for (const [, localizedPattern] of element.localized) {
+ const match = new URLPattern(localizedPattern, urlObj.href).exec(urlObj.href);
+ if (match) {
+ // Convert localized URL back to the base pattern
+ const groups = aggregateGroups(match);
+ const baseUrl = fillPattern(element.pattern, groups, urlObj.origin);
+ return fillMissingUrlParts(baseUrl, match);
+ }
+ }
+ // match unlocalized pattern
+ const unlocalizedMatch = new URLPattern(element.pattern, urlObj.href).exec(urlObj.href);
+ if (unlocalizedMatch) {
+ const baseUrl = fillPattern(element.pattern, aggregateGroups(unlocalizedMatch), urlObj.origin);
+ return fillMissingUrlParts(baseUrl, unlocalizedMatch);
+ }
+ }
+ // no match found return the original url
+ return urlObj;
+}
+/**
+ * De-localizes a URL using the default pattern (/:locale/*)
+ * @param {string|URL} url
+ * @returns {URL}
+ */
+function deLocalizeUrlDefaultPattern(url) {
+ const urlObj = typeof url === "string" ? new URL(url, getUrlOrigin()) : new URL(url);
+ const pathSegments = urlObj.pathname.split("/").filter(Boolean);
+ // If first segment is a locale, remove it
+ if (pathSegments.length > 0 && toLocale(pathSegments[0])) {
+ urlObj.pathname = "/" + pathSegments.slice(1).join("/");
+ }
+ return urlObj;
+}
+/**
+ * Takes matches of implicit wildcards in the UrlPattern (when a part is missing
+ * it is equal to '*') and adds them back to the result of fillPattern.
+ *
+ * At least protocol and hostname are required to create a valid URL inside fillPattern.
+ *
+ * @param {URL} url
+ * @param {any} match
+ * @returns {URL}
+ */
+function fillMissingUrlParts(url, match) {
+ if (match.protocol.groups["0"]) {
+ url.protocol = match.protocol.groups["0"] ?? "";
+ }
+ if (match.hostname.groups["0"]) {
+ url.hostname = match.hostname.groups["0"] ?? "";
+ }
+ if (match.username.groups["0"]) {
+ url.username = match.username.groups["0"] ?? "";
+ }
+ if (match.password.groups["0"]) {
+ url.password = match.password.groups["0"] ?? "";
+ }
+ if (match.port.groups["0"]) {
+ url.port = match.port.groups["0"] ?? "";
+ }
+ if (match.pathname.groups["0"]) {
+ url.pathname = match.pathname.groups["0"] ?? "";
+ }
+ if (match.search.groups["0"]) {
+ url.search = match.search.groups["0"] ?? "";
+ }
+ if (match.hash.groups["0"]) {
+ url.hash = match.hash.groups["0"] ?? "";
+ }
+ return url;
+}
+/**
+ * Fills a URL pattern with values for named groups, supporting all URLPattern-style modifiers.
+ *
+ * This function will eventually be replaced by https://github.com/whatwg/urlpattern/issues/73
+ *
+ * Matches:
+ * - :name -> Simple
+ * - :name? -> Optional
+ * - :name+ -> One or more
+ * - :name* -> Zero or more
+ * - :name(...) -> Regex group
+ * - {text} -> Group delimiter
+ * - {text}? -> Optional group delimiter
+ *
+ * If the value is `null`, the segment is removed.
+ *
+ * @param {string} pattern - The URL pattern containing named groups.
+ * @param {Record} values - Object of values for named groups.
+ * @param {string} origin - Base URL to use for URL construction.
+ * @returns {URL} - The constructed URL with named groups filled.
+ */
+function fillPattern(pattern, values, origin) {
+ // Pre-process the pattern to handle explicit port numbers
+ // This detects patterns like "http://localhost:5173" and protects the port number
+ // from being interpreted as a parameter
+ let processedPattern = pattern.replace(/(https?:\/\/[^:/]+):(\d+)(\/|$)/g, (_, protocol, port, slash) => {
+ // Replace ":5173" with "#PORT-5173#" to protect it from parameter replacement
+ return `${protocol}#PORT-${port}#${slash}`;
+ });
+ // First, handle group delimiters with curly braces
+ let processedGroupDelimiters = processedPattern.replace(/\{([^{}]*)\}([?+*]?)/g, (_, content, modifier) => {
+ // For optional group delimiters
+ if (modifier === "?") {
+ // For optional groups, we'll include the content
+ return content;
+ }
+ // For non-optional group delimiters, always include the content
+ return content;
+ });
+ // Then handle named groups
+ let filled = processedGroupDelimiters.replace(/(\/?):([a-zA-Z0-9_]+)(\([^)]*\))?([?+*]?)/g, (_, slash, name, __, modifier) => {
+ const value = values[name];
+ if (value === null) {
+ // If value is null, remove the entire segment including the preceding slash
+ return "";
+ }
+ if (modifier === "?") {
+ // Optional segment
+ return value !== undefined ? `${slash}${value}` : "";
+ }
+ if (modifier === "+" || modifier === "*") {
+ // Repeatable segments
+ if (value === undefined && modifier === "+") {
+ throw new Error(`Missing value for "${name}" (one or more required)`);
+ }
+ return value ? `${slash}${value}` : "";
+ }
+ // Simple named group (no modifier)
+ if (value === undefined) {
+ throw new Error(`Missing value for "${name}"`);
+ }
+ return `${slash}${value}`;
+ });
+ // Restore port numbers
+ filled = filled.replace(/#PORT-(\d+)#/g, ":$1");
+ return new URL(filled, origin);
+}
+/**
+ * Aggregates named groups from various parts of the URLPattern match result.
+ *
+ *
+ * @param {any} match - The URLPattern match result object.
+ * @returns {Record} An object containing all named groups from the match.
+ */
+export function aggregateGroups(match) {
+ return {
+ ...match.hash.groups,
+ ...match.hostname.groups,
+ ...match.password.groups,
+ ...match.pathname.groups,
+ ...match.port.groups,
+ ...match.protocol.groups,
+ ...match.search.groups,
+ ...match.username.groups,
+ };
+}
+
+/**
+ * @typedef {object} ShouldRedirectServerInput
+ * @property {Request} request
+ * @property {string | URL} [effectiveRequestUrl] - Effective request URL to use for route matching, locale detection with the URL strategy, and redirect targets.
+ * @property {Locale} [locale]
+ *
+ * @typedef {object} ShouldRedirectClientInput
+ * @property {undefined} [request]
+ * @property {string | URL} [url]
+ * @property {Locale} [locale]
+ *
+ * @typedef {ShouldRedirectServerInput | ShouldRedirectClientInput} ShouldRedirectInput
+ *
+ * @typedef {object} ShouldRedirectResult
+ * @property {boolean} shouldRedirect - Indicates whether the consumer should perform a redirect.
+ * @property {Locale} locale - Locale resolved using the configured strategies.
+ * @property {URL | undefined} redirectUrl - Destination URL when a redirect is required.
+ */
+/**
+ * Determines whether a redirect is required to align the current URL with the active locale.
+ *
+ * This helper mirrors the logic that powers `paraglideMiddleware`, but works in both server
+ * and client environments. It evaluates the configured strategies in order, computes the
+ * canonical localized URL, and reports when the current URL does not match.
+ *
+ * When called in the browser without arguments, the current `window.location.href` is used.
+ *
+ * @see https://paraglidejs.com/i18n-routing#redirects
+ *
+ * @example
+ * // Client side usage (e.g. TanStack Router beforeLoad hook)
+ * async function beforeLoad({ location }) {
+ * const decision = await shouldRedirect({ url: location.href });
+ *
+ * if (decision.shouldRedirect) {
+ * throw redirect({ to: decision.redirectUrl.href });
+ * }
+ * }
+ *
+ * @example
+ * // Server side usage with a Request
+ * export async function handle(request) {
+ * const decision = await shouldRedirect({ request });
+ *
+ * if (decision.shouldRedirect) {
+ * return Response.redirect(decision.redirectUrl, 307);
+ * }
+ *
+ * return render(request, decision.locale);
+ * }
+ *
+ * @example
+ * // Server side usage behind a proxy where request.url is not public-facing
+ * export async function handle(request) {
+ * const effectiveRequestUrl = new URL(request.url);
+ * effectiveRequestUrl.protocol = "https:";
+ * effectiveRequestUrl.host = "example.com";
+ *
+ * const decision = await shouldRedirect({
+ * request,
+ * effectiveRequestUrl,
+ * });
+ *
+ * if (decision.shouldRedirect) {
+ * return Response.redirect(decision.redirectUrl, 307);
+ * }
+ * }
+ *
+ * @param {ShouldRedirectInput} [input]
+ * @returns {Promise}
+ */
+export async function shouldRedirect(input = {}) {
+ const currentUrl = resolveUrl(input);
+ const locale = await resolveLocale(input, currentUrl);
+ const strategy = getStrategyForUrl(currentUrl.href);
+ if (isExcludedByRouteStrategy(currentUrl.href) || !strategy.includes("url")) {
+ return { shouldRedirect: false, locale, redirectUrl: undefined };
+ }
+ const localizedUrl = localizeUrl(currentUrl.href, { locale });
+ const shouldRedirectToLocalizedUrl = normalizeUrl(localizedUrl.href) !== normalizeUrl(currentUrl.href);
+ return {
+ shouldRedirect: shouldRedirectToLocalizedUrl,
+ locale,
+ redirectUrl: shouldRedirectToLocalizedUrl ? localizedUrl : undefined,
+ };
+}
+/**
+ * Resolves the locale either from the provided input or by using the configured strategies.
+ *
+ * @param {ShouldRedirectInput} input
+ * @param {URL} currentUrl
+ * @returns {Promise}
+ */
+async function resolveLocale(input, currentUrl) {
+ const locale = toLocale(input.locale);
+ if (locale) {
+ return locale;
+ }
+ if (input.request) {
+ return extractLocaleFromRequestAsync(input.request, {
+ effectiveRequestUrl: currentUrl,
+ });
+ }
+ if ("url" in input && typeof input.url !== "undefined") {
+ return getLocaleForUrl(currentUrl.href);
+ }
+ return getLocale();
+}
+/**
+ * Resolves the current URL from the provided input or runtime context.
+ *
+ * @param {ShouldRedirectInput} input
+ * @returns {URL}
+ */
+function resolveUrl(input) {
+ if ("effectiveRequestUrl" in input && input.effectiveRequestUrl instanceof URL) {
+ return new URL(input.effectiveRequestUrl.href);
+ }
+ if ("effectiveRequestUrl" in input && typeof input.effectiveRequestUrl === "string") {
+ return new URL(input.effectiveRequestUrl, input.request ? input.request.url : getUrlOrigin());
+ }
+ if (input.request) {
+ return new URL(input.request.url);
+ }
+ if ("url" in input && input.url instanceof URL) {
+ return new URL(input.url.href);
+ }
+ if ("url" in input && typeof input.url === "string") {
+ return new URL(input.url, getUrlOrigin());
+ }
+ if (typeof window !== "undefined" && window?.location?.href) {
+ return new URL(window.location.href);
+ }
+ throw new Error("shouldRedirect() requires either a request, an absolute URL, or must run in a browser environment.");
+}
+/**
+ * Normalize url for comparison by stripping the trailing slash.
+ *
+ * @param {string} url
+ * @returns {string}
+ */
+function normalizeUrl(url) {
+ const urlObj = new URL(url);
+ urlObj.pathname = urlObj.pathname.replace(/\/$/, "");
+ return urlObj.href;
+}
+
+/**
+ * High-level URL localization function optimized for client-side UI usage.
+ *
+ * This is a convenience wrapper around `localizeUrl()` that provides features
+ * needed in UI:
+ *
+ * - Accepts relative paths (e.g., "/about")
+ * - Returns relative paths when possible
+ * - Automatically detects current locale if not specified
+ * - Handles string input/output instead of URL objects
+ *
+ * @see https://paraglidejs.com/i18n-routing
+ *
+ * @example
+ * ```typescript
+ * // In a React/Vue/Svelte component
+ * const NavLink = ({ href }) => {
+ * // Automatically uses current locale, keeps path relative
+ * return ...;
+ * };
+ *
+ * // Examples:
+ * localizeHref("/about")
+ * // => "/de/about" (if current locale is "de")
+ * localizeHref("/store", { locale: "fr" })
+ * // => "/fr/store" (explicit locale)
+ *
+ * // Cross-origin links remain absolute
+ * localizeHref("https://other-site.com/about")
+ * // => "https://other-site.com/de/about"
+ * ```
+ *
+ * For server-side URL localization (e.g., in middleware), use `localizeUrl()`
+ * which provides more precise control over URL handling.
+ *
+ * @param {string} href - The href to localize (can be relative or absolute)
+ * @param {object} [options] - Options for localization
+ * @param {Locale} [options.locale] - Target locale. If not provided, uses `getLocale()`
+ * @returns {string} The localized href, relative if input was relative
+ */
+export function localizeHref(href, options) {
+ const currentLocale = getLocale();
+ const locale = options?.locale ?? currentLocale;
+ const url = new URL(href, getUrlOrigin());
+ const localized = localizeUrl(url, { locale });
+ // if the origin is identical and the href is relative,
+ // return the relative path
+ if (href.startsWith("/") && url.origin === localized.origin) {
+ // check for cross origin localization in which case an absolute URL must be returned.
+ if (locale !== currentLocale) {
+ const localizedCurrentLocale = localizeUrl(url, {
+ locale: currentLocale,
+ });
+ if (localizedCurrentLocale.origin !== localized.origin) {
+ return localized.href;
+ }
+ }
+ return localized.pathname + localized.search + localized.hash;
+ }
+ return localized.href;
+}
+/**
+ * High-level URL de-localization function optimized for client-side UI usage.
+ *
+ * This is a convenience wrapper around `deLocalizeUrl()` that provides features
+ * needed in the UI:
+ *
+ * - Accepts relative paths (e.g., "/de/about")
+ * - Returns relative paths when possible
+ * - Handles string input/output instead of URL objects
+ *
+ * @see https://paraglidejs.com/i18n-routing
+ *
+ * @example
+ * ```typescript
+ * // In a React/Vue/Svelte component
+ * const LocaleSwitcher = ({ href }) => {
+ * // Remove locale prefix before switching
+ * const baseHref = deLocalizeHref(href);
+ * return locales.map(locale =>
+ *
+ * Switch to {locale}
+ *
+ * );
+ * };
+ *
+ * // Examples:
+ * deLocalizeHref("/de/about") // => "/about"
+ * deLocalizeHref("/fr/store") // => "/store"
+ *
+ * // Cross-origin links remain absolute
+ * deLocalizeHref("https://example.com/de/about")
+ * // => "https://example.com/about"
+ * ```
+ *
+ * For server-side URL de-localization (e.g., in middleware), use `deLocalizeUrl()`
+ * which provides more precise control over URL handling.
+ *
+ * @param {string} href - The href to de-localize (can be relative or absolute)
+ * @returns {string} The de-localized href, relative if input was relative
+ */
+export function deLocalizeHref(href) {
+ const url = new URL(href, getUrlOrigin());
+ const deLocalized = deLocalizeUrl(url);
+ // If the origin is identical and the href is relative,
+ // return the relative path instead of the full URL.
+ if (href.startsWith("/") && url.origin === deLocalized.origin) {
+ return deLocalized.pathname + deLocalized.search + deLocalized.hash;
+ }
+ return deLocalized.href;
+}
+
+/**
+ * @param {string} safeModuleId
+ * @param {Locale} locale
+ */
+export function trackMessageCall(safeModuleId, locale) {
+ if (isServer === false)
+ return;
+ const store = serverAsyncLocalStorage?.getStore();
+ if (store) {
+ store.messageCalls?.add(`${safeModuleId}:${locale}`);
+ }
+}
+
+/**
+ * Generates localized URL variants for all provided URLs based on your configured locales and URL patterns.
+ *
+ * This function is essential for Static Site Generation (SSG) where you need to tell your framework
+ * which pages to pre-render at build time. It's also useful for generating sitemaps and
+ * `` tags for SEO.
+ *
+ * The function respects your `urlPatterns` configuration - if you have translated pathnames
+ * (e.g., `/about` → `/ueber-uns` for German), it will generate the correct localized paths.
+ *
+ * @see https://paraglidejs.com/static-site-generation
+ *
+ * @example
+ * // Basic usage - generate all locale variants for a list of paths
+ * const localizedUrls = generateStaticLocalizedUrls([
+ * "/",
+ * "/about",
+ * "/blog/post-1",
+ * ]);
+ * // Returns URL objects for each locale:
+ * // ["/en/", "/de/", "/en/about", "/de/about", "/en/blog/post-1", "/de/blog/post-1"]
+ *
+ * @example
+ * // Use with framework SSG APIs
+ * // SvelteKit
+ * export function entries() {
+ * const paths = ["/", "/about", "/contact"];
+ * return generateStaticLocalizedUrls(paths).map(url => ({
+ * locale: extractLocaleFromUrl(url)
+ * }));
+ * }
+ *
+ * @example
+ * // Sitemap generation
+ * const allPages = ["/", "/about", "/blog"];
+ * const sitemapUrls = generateStaticLocalizedUrls(allPages);
+ *
+ * @param {(string | URL)[]} urls - List of canonical URLs or paths to generate localized versions for.
+ * Can be absolute URLs (`https://example.com/about`) or paths (`/about`).
+ * Paths are resolved against `http://localhost` internally.
+ * @returns {URL[]} Array of URL objects representing all localized variants.
+ * The order follows each input URL with all its locale variants before moving to the next URL.
+ */
+export function generateStaticLocalizedUrls(urls) {
+ /** @type {Set} */
+ const localizedUrls = new Set();
+ // For default URL pattern, we can optimize the generation
+ if (TREE_SHAKE_DEFAULT_URL_PATTERN_USED) {
+ for (const urlInput of urls) {
+ const url = urlInput instanceof URL
+ ? urlInput
+ : new URL(urlInput, "http://localhost");
+ // Base locale doesn't get a prefix
+ localizedUrls.add(url);
+ // Other locales get their code as prefix
+ for (const locale of locales) {
+ if (locale !== baseLocale) {
+ const localizedPath = `/${locale}${url.pathname}${url.search}${url.hash}`;
+ const localizedUrl = new URL(localizedPath, url.origin);
+ localizedUrls.add(localizedUrl);
+ }
+ }
+ }
+ return Array.from(localizedUrls);
+ }
+ // For custom URL patterns, we need to use localizeUrl for each URL and locale
+ for (const urlInput of urls) {
+ const url = urlInput instanceof URL
+ ? urlInput
+ : new URL(urlInput, "http://localhost");
+ // Try each URL pattern to find one that matches
+ let patternFound = false;
+ for (const pattern of urlPatterns) {
+ try {
+ // Try to match the unlocalized pattern
+ const unlocalizedMatch = new URLPattern(pattern.pattern, url.href).exec(url.href);
+ if (!unlocalizedMatch)
+ continue;
+ patternFound = true;
+ // Track unique localized URLs to avoid duplicates when patterns are the same
+ const seenUrls = new Set();
+ // Generate localized URL for each locale
+ for (const [locale] of pattern.localized) {
+ try {
+ const localizedUrl = localizeUrl(url, { locale });
+ const urlString = localizedUrl.href;
+ // Only add if we haven't seen this exact URL before
+ if (!seenUrls.has(urlString)) {
+ seenUrls.add(urlString);
+ localizedUrls.add(localizedUrl);
+ }
+ }
+ catch {
+ // Skip if localization fails for this locale
+ continue;
+ }
+ }
+ break;
+ }
+ catch {
+ // Skip if pattern matching fails
+ continue;
+ }
+ }
+ // If no pattern matched, use the URL as is
+ if (!patternFound) {
+ localizedUrls.add(url);
+ }
+ }
+ return Array.from(localizedUrls);
+}
+
+/**
+ * @typedef {"cookie" | "baseLocale" | "globalVariable" | "url" | "preferredLanguage" | "localStorage"} BuiltInStrategy
+ */
+/**
+ * @typedef {`custom_${string}`} CustomStrategy
+ */
+/**
+ * @typedef {BuiltInStrategy | CustomStrategy} Strategy
+ */
+/**
+ * @typedef {Array} Strategies
+ */
+/**
+ * @typedef {{ getLocale: (request?: Request) => Promise | (string | undefined) }} CustomServerStrategyHandler
+ */
+/**
+ * @typedef {{ getLocale: () => Promise | (string | undefined), setLocale: (locale: string) => Promise | void }} CustomClientStrategyHandler
+ */
+/** @type {Map} */
+export const customServerStrategies = new Map();
+/** @type {Map} */
+export const customClientStrategies = new Map();
+/**
+ * Checks if the given strategy is a custom strategy.
+ *
+ * @param {unknown} strategy The name of the custom strategy to validate.
+ * Must be a string that starts with "custom-" followed by alphanumeric characters, hyphens, or underscores.
+ * @returns {boolean} Returns true if it is a custom strategy, false otherwise.
+ */
+export function isCustomStrategy(strategy) {
+ return (typeof strategy === "string" && /^custom-[A-Za-z0-9_-]+$/.test(strategy));
+}
+/**
+ * Defines a custom strategy that is executed on the server.
+ *
+ * @see https://paraglidejs.com/strategy#write-your-own-strategy
+ *
+ * @param {string} strategy The name of the custom strategy to define. Must follow the pattern custom-name with alphanumeric characters, hyphens, or underscores.
+ * @param {CustomServerStrategyHandler} handler The handler for the custom strategy, which should implement
+ * the method getLocale.
+ * @returns {void}
+ */
+export function defineCustomServerStrategy(strategy, handler) {
+ if (!isCustomStrategy(strategy)) {
+ throw new Error(`Invalid custom strategy: "${strategy}". Must be a custom strategy following the pattern custom-name.`);
+ }
+ customServerStrategies.set(strategy, handler);
+}
+/**
+ * Defines a custom strategy that is executed on the client.
+ *
+ * @see https://paraglidejs.com/strategy#write-your-own-strategy
+ *
+ * @param {string} strategy The name of the custom strategy to define. Must follow the pattern custom-name with alphanumeric characters, hyphens, or underscores.
+ * @param {CustomClientStrategyHandler} handler The handler for the custom strategy, which should implement the
+ * methods getLocale and setLocale.
+ * @returns {void}
+ */
+export function defineCustomClientStrategy(strategy, handler) {
+ if (!isCustomStrategy(strategy)) {
+ throw new Error(`Invalid custom strategy: "${strategy}". Must be a custom strategy following the pattern custom-name.`);
+ }
+ customClientStrategies.set(strategy, handler);
+}
+
+// ------ TYPES ------
+export {};
+/**
+ * A locale that is available in the project.
+ *
+ * @example
+ * setLocale(request.locale as Locale)
+ *
+ * @typedef {typeof locales[number]} Locale
+ */
+/**
+ * A branded type representing a localized string.
+ *
+ * Message functions return this type instead of \`string\`, enabling TypeScript
+ * to distinguish translated strings from regular strings at compile time.
+ * This allows you to enforce that only properly localized content is used
+ * in your UI components.
+ *
+ * Since \`LocalizedString\` is a branded subtype of \`string\`, it remains fully
+ * backward compatible—you can pass it anywhere a \`string\` is expected.
+ *
+ * @example
+ * // Enforce localized strings in your components
+ * function PageTitle(props: { title: LocalizedString }) {
+ * return {props.title}
+ * }
+ *
+ * // ✅ Correct: using a message function
+ *
+ *
+ * // ❌ Type error: raw strings are not LocalizedString
+ *
+ *
+ * @example
+ * // LocalizedString is assignable to string (backward compatible)
+ * const localized: LocalizedString = m.greeting()
+ * const str: string = localized // ✅ works fine
+ *
+ * // But string is not assignable to LocalizedString
+ * const raw: LocalizedString = "Hello" // ❌ Type error
+ *
+ * @example
+ * // Catches accidental string concatenation
+ * function showMessage(msg: LocalizedString) { ... }
+ *
+ * showMessage(m.hello()) // ✅
+ * showMessage("Hello " + userName) // ❌ Type error
+ * showMessage(m.hello_user({ name: userName })) // ✅ use params instead
+ *
+ * @typedef {string & { readonly __brand: 'LocalizedString' }} LocalizedString
+ */
+/**
+ * A single markup option passed to a tag instance.
+ *
+ * @typedef {{
+ * name: string;
+ * value: unknown;
+ * }} MessageMarkupOption
+ */
+/**
+ * A single static markup attribute attached to a tag instance.
+ *
+ * @typedef {{
+ * name: string;
+ * value: string | true;
+ * }} MessageMarkupAttribute
+ */
+/**
+ * Record of markup options for a tag instance.
+ *
+ * @typedef {Record} MessageMarkupOptions
+ */
+/**
+ * Record of markup attributes for a tag instance.
+ *
+ * @typedef {Record} MessageMarkupAttributes
+ */
+/**
+ * Type-level schema for a single markup tag.
+ *
+ * @typedef {{
+ * options: MessageMarkupOptions;
+ * attributes: MessageMarkupAttributes;
+ * children: boolean;
+ * }} MessageMarkupTag
+ */
+/**
+ * Type-level schema for all markup tags in a message.
+ *
+ * @typedef {Record} MessageMarkupSchema
+ */
+/**
+ * Type-only metadata attached to compiled message functions.
+ *
+ * @template Inputs
+ * @template Options
+ * @template {MessageMarkupSchema} [Markup = MessageMarkupSchema]
+ * @typedef {{
+ * readonly __paraglide?: {
+ * inputs: Inputs;
+ * options: Options;
+ * markup: Markup;
+ * };
+ * }} MessageMetadata
+ */
+/**
+ * A compiled, framework-neutral message part.
+ *
+ * @typedef {{
+ * type: "text";
+ * value: string;
+ * } | {
+ * type: "markup-start";
+ * name: string;
+ * options: MessageMarkupOptions;
+ * attributes: MessageMarkupAttributes;
+ * } | {
+ * type: "markup-end";
+ * name: string;
+ * options: MessageMarkupOptions;
+ * attributes: MessageMarkupAttributes;
+ * } | {
+ * type: "markup-standalone";
+ * name: string;
+ * options: MessageMarkupOptions;
+ * attributes: MessageMarkupAttributes;
+ * }} MessagePart
+ */
+/**
+ * A message function is a message for a specific locale.
+ *
+ * @example
+ * m.hello({ name: 'world' })
+ *
+ * @typedef {(inputs?: Record) => LocalizedString} MessageFunction
+ */
+/**
+ * A message bundle function that selects the message to be returned.
+ *
+ * Uses `getLocale()` under the hood to determine the locale with an option.
+ *
+ * @template {string} T
+ *
+ * @example
+ * * m.hello({ name: 'world' }, { locale: "en" })
+ *
+ * @typedef {(params: Record, options: { locale: T }) => LocalizedString} MessageBundleFunction
+ */
diff --git a/packages/webui/src/paraglide/server.d.ts b/packages/webui/src/paraglide/server.d.ts
new file mode 100644
index 00000000..a30dec15
--- /dev/null
+++ b/packages/webui/src/paraglide/server.d.ts
@@ -0,0 +1,96 @@
+/**
+ * Server middleware that handles locale-based routing and request processing.
+ *
+ * Configure `disableAsyncLocalStorage` when generating Paraglide with
+ * `paraglideVitePlugin()` or `compile()`, not when calling
+ * `paraglideMiddleware()`. Keep AsyncLocalStorage enabled by default and
+ * only disable it for runtimes that lack `AsyncLocalStorage` support and
+ * guarantee request isolation.
+ *
+ * This middleware performs several key functions:
+ *
+ * 1. Determines the locale for the incoming request using configured strategies
+ * 2. Handles URL localization and redirects (only for document requests)
+ * 3. Maintains locale state using AsyncLocalStorage to prevent request interference
+ *
+ * When URL strategy is used:
+ *
+ * - The locale is extracted from the URL for all request types
+ * - If URL doesn't match the determined locale, redirects to localized URL (only for document requests)
+ * - De-localizes URLs before passing to server (e.g., `/fr/about` → `/about`)
+ *
+ * @see https://paraglidejs.com/middleware
+ *
+ * @template T - The return type of the resolve function
+ *
+ * @param {Request} request - The incoming request object
+ * @param {(args: { request: Request, locale: import("./runtime.js").Locale }) => T | Promise} resolve - Function to handle the request. The callback receives:
+ * - `request`: A modified request with a delocalized URL when the URL strategy is used (e.g., `/fr/about` → `/about`).
+ * If your framework handles URL localization itself (e.g., TanStack Router's `rewrite` option), use the original
+ * request instead to avoid redirect loops.
+ * - `locale`: The determined locale for this request.
+ * @param {{
+ * effectiveRequestUrl?: string | URL | ((request: Request) => string | URL),
+ * onRedirect?: (response: Response) => void
+ * }} [options] - Options to control middleware behavior. `effectiveRequestUrl` sets the effective request URL used for route matching, URL-based locale detection, redirects, and `getUrlOrigin()`.
+ * @returns {Promise}
+ *
+ * @example
+ * ```typescript
+ * // Basic usage in metaframeworks like NextJS, SvelteKit, Astro, Nuxt, etc.
+ * export const handle = async ({ event, resolve }) => {
+ * return paraglideMiddleware(event.request, ({ request, locale }) => {
+ * // let the framework further resolve the request
+ * return resolve(request);
+ * });
+ * };
+ * ```
+ *
+ * @example
+ * ```typescript
+ * // Usage in a framework like Express JS or Hono
+ * app.use(async (req, res, next) => {
+ * const result = await paraglideMiddleware(req, ({ request, locale }) => {
+ * // If a redirect happens this won't be called
+ * return next(request);
+ * });
+ * });
+ * ```
+ *
+ * @example
+ * ```typescript
+ * // Usage with frameworks that handle URL localization/delocalization themselves
+ * //
+ * // Some frameworks like TanStack Router handle URL localization and delocalization
+ * // themselves via their own rewrite APIs (e.g., `rewrite.input`/`rewrite.output`).
+ * //
+ * // When the framework handles this, the middleware's URL delocalization is not needed.
+ * // Using the modified `request` from the callback would cause a redirect loop because
+ * // both the middleware and the framework would attempt to delocalize the URL.
+ * //
+ * // Solution: Pass the original request to the handler instead of the modified one.
+ * // The middleware still handles locale detection, cookies, and AsyncLocalStorage context.
+ * //
+ * // ❌ WRONG - causes redirect loop when framework handles URL rewriting:
+ * // paraglideMiddleware(req, ({ request }) => handler.fetch(request))
+ * //
+ * // ✅ CORRECT - use original request when framework handles URL localization:
+ * // paraglideMiddleware(req, () => handler.fetch(req))
+ *
+ * * *
+ * export default {
+ * fetch(req: Request): Promise {
+ * // TanStack Router handles URL rewriting via deLocalizeUrl/localizeUrl
+ * // so we pass the original `req` instead of the modified `request`
+ * return paraglideMiddleware(req, () => handler.fetch(req))
+ * },
+ * }
+ * ```
+ */
+export function paraglideMiddleware(request: Request, resolve: (args: {
+ request: Request;
+ locale: import("./runtime.js").Locale;
+}) => T | Promise, options?: {
+ effectiveRequestUrl?: string | URL | ((request: Request) => string | URL);
+ onRedirect?: (response: Response) => void;
+}): Promise;
diff --git a/packages/webui/src/paraglide/server.js b/packages/webui/src/paraglide/server.js
new file mode 100644
index 00000000..b068b6cd
--- /dev/null
+++ b/packages/webui/src/paraglide/server.js
@@ -0,0 +1,282 @@
+/* eslint-disable */
+
+import * as runtime from "./runtime.js";
+
+/**
+ * Server middleware that handles locale-based routing and request processing.
+ *
+ * Configure `disableAsyncLocalStorage` when generating Paraglide with
+ * `paraglideVitePlugin()` or `compile()`, not when calling
+ * `paraglideMiddleware()`. Keep AsyncLocalStorage enabled by default and
+ * only disable it for runtimes that lack `AsyncLocalStorage` support and
+ * guarantee request isolation.
+ *
+ * This middleware performs several key functions:
+ *
+ * 1. Determines the locale for the incoming request using configured strategies
+ * 2. Handles URL localization and redirects (only for document requests)
+ * 3. Maintains locale state using AsyncLocalStorage to prevent request interference
+ *
+ * When URL strategy is used:
+ *
+ * - The locale is extracted from the URL for all request types
+ * - If URL doesn't match the determined locale, redirects to localized URL (only for document requests)
+ * - De-localizes URLs before passing to server (e.g., `/fr/about` → `/about`)
+ *
+ * @see https://paraglidejs.com/middleware
+ *
+ * @template T - The return type of the resolve function
+ *
+ * @param {Request} request - The incoming request object
+ * @param {(args: { request: Request, locale: import("./runtime.js").Locale }) => T | Promise} resolve - Function to handle the request. The callback receives:
+ * - `request`: A modified request with a delocalized URL when the URL strategy is used (e.g., `/fr/about` → `/about`).
+ * If your framework handles URL localization itself (e.g., TanStack Router's `rewrite` option), use the original
+ * request instead to avoid redirect loops.
+ * - `locale`: The determined locale for this request.
+ * @param {{
+ * effectiveRequestUrl?: string | URL | ((request: Request) => string | URL),
+ * onRedirect?: (response: Response) => void
+ * }} [options] - Options to control middleware behavior. `effectiveRequestUrl` sets the effective request URL used for route matching, URL-based locale detection, redirects, and `getUrlOrigin()`.
+ * @returns {Promise}
+ *
+ * @example
+ * ```typescript
+ * // Basic usage in metaframeworks like NextJS, SvelteKit, Astro, Nuxt, etc.
+ * export const handle = async ({ event, resolve }) => {
+ * return paraglideMiddleware(event.request, ({ request, locale }) => {
+ * // let the framework further resolve the request
+ * return resolve(request);
+ * });
+ * };
+ * ```
+ *
+ * @example
+ * ```typescript
+ * // Usage in a framework like Express JS or Hono
+ * app.use(async (req, res, next) => {
+ * const result = await paraglideMiddleware(req, ({ request, locale }) => {
+ * // If a redirect happens this won't be called
+ * return next(request);
+ * });
+ * });
+ * ```
+ *
+ * @example
+ * ```typescript
+ * // Usage with frameworks that handle URL localization/delocalization themselves
+ * //
+ * // Some frameworks like TanStack Router handle URL localization and delocalization
+ * // themselves via their own rewrite APIs (e.g., `rewrite.input`/`rewrite.output`).
+ * //
+ * // When the framework handles this, the middleware's URL delocalization is not needed.
+ * // Using the modified `request` from the callback would cause a redirect loop because
+ * // both the middleware and the framework would attempt to delocalize the URL.
+ * //
+ * // Solution: Pass the original request to the handler instead of the modified one.
+ * // The middleware still handles locale detection, cookies, and AsyncLocalStorage context.
+ * //
+ * // ❌ WRONG - causes redirect loop when framework handles URL rewriting:
+ * // paraglideMiddleware(req, ({ request }) => handler.fetch(request))
+ * //
+ * // ✅ CORRECT - use original request when framework handles URL localization:
+ * // paraglideMiddleware(req, () => handler.fetch(req))
+ *
+ * * *
+ * export default {
+ * fetch(req: Request): Promise {
+ * // TanStack Router handles URL rewriting via deLocalizeUrl/localizeUrl
+ * // so we pass the original `req` instead of the modified `request`
+ * return paraglideMiddleware(req, () => handler.fetch(req))
+ * },
+ * }
+ * ```
+ */
+export async function paraglideMiddleware(request, resolve, options) {
+ if (!runtime.disableAsyncLocalStorage && !runtime.serverAsyncLocalStorage) {
+ const { AsyncLocalStorage } = await import("async_hooks");
+ runtime.overwriteServerAsyncLocalStorage(new AsyncLocalStorage());
+ } else if (!runtime.serverAsyncLocalStorage) {
+ runtime.overwriteServerAsyncLocalStorage(createMockAsyncLocalStorage());
+ }
+ const url = resolveMiddlewareUrl(request, options?.effectiveRequestUrl);
+ const origin = url.origin;
+ if (runtime.isExcludedByRouteStrategy(url.href)) {
+ const locale = runtime.baseLocale;
+ const newRequest = cloneRequestWithFallback(request, url);
+ /** @type {Set} */
+ const messageCalls = new Set();
+ return /** @type {Response} */ (await runtime.serverAsyncLocalStorage?.run({ locale, origin, messageCalls }, () => resolve({ locale, request: newRequest })));
+ }
+ const strategy = runtime.getStrategyForUrl(url.href);
+ const decision = await runtime.shouldRedirect({ request, effectiveRequestUrl: url });
+ const locale = decision.locale;
+ // if the client makes a request to a URL that doesn't match
+ // the localizedUrl, redirect the client to the localized URL
+ if (request.headers.get("Sec-Fetch-Dest") === "document" &&
+ decision.shouldRedirect &&
+ decision.redirectUrl) {
+ // Create headers object with Vary header if preferredLanguage strategy is used
+ /** @type {Record} */
+ const headers = {};
+ if (strategy.includes("preferredLanguage")) {
+ headers["Vary"] = "Accept-Language";
+ }
+ const response = new Response(null, {
+ status: 307,
+ headers: {
+ Location: decision.redirectUrl.href,
+ ...headers,
+ },
+ });
+ options?.onRedirect?.(response);
+ return response;
+ }
+ // If the strategy includes "url", we need to de-localize the URL
+ // before passing it to the server middleware.
+ //
+ // The middleware is responsible for mapping a localized URL to the
+ // de-localized URL e.g. `/en/about` to `/about`. Otherwise,
+ // the server can't render the correct page.
+ let newRequest;
+ if (strategy.includes("url")) {
+ newRequest = cloneRequestWithFallback(request, runtime.deLocalizeUrl(url));
+ }
+ else {
+ newRequest = cloneRequestWithFallback(request, url);
+ }
+ // the message functions that have been called in this request
+ /** @type {Set} */
+ const messageCalls = new Set();
+ const response = await runtime.serverAsyncLocalStorage?.run({ locale, origin, messageCalls }, () => resolve({ locale, request: newRequest }));
+ // Only modify HTML responses
+ if (runtime.experimentalMiddlewareLocaleSplitting &&
+ response.headers.get("Content-Type")?.includes("html")) {
+ const body = await response.text();
+ const messages = [];
+ // using .values() to avoid polyfilling in older projects. else the following error is thrown
+ // Type 'Set' can only be iterated through when using the '--downlevelIteration' flag or with a '--target' of 'es2015' or higher.
+ for (const messageCall of Array.from(messageCalls)) {
+ const [id, locale] =
+ /** @type {[string, import("./runtime.js").Locale]} */ (messageCall.split(":"));
+ messages.push(`${id}: ${compiledBundles[id]?.[locale]}`);
+ }
+ // Prevent translated content from terminating the inline script tag.
+ const escapedMessages = messages
+ .join(",")
+ .replace(/<\/(script)/gi, "<\\/$1");
+ // Reuse the request's CSP nonce (if any) so the injected script is allowed under a strict CSP
+ const nonce = response.headers
+ .get("Content-Security-Policy")
+ ?.match(/'nonce-([\w+/=-]+)'/)?.[1];
+ const nonceAttr = nonce ? `nonce="${nonce}"` : "";
+ const script = ``;
+ // Insert the script before the closing head tag
+ const newBody = body.replace("", `${script}`);
+ // Create a new response with the modified body
+ // Clone all headers except Content-Length which will be set automatically
+ const newHeaders = new Headers(response.headers);
+ newHeaders.delete("Content-Length"); // Let the browser calculate the correct length
+ return new Response(newBody, {
+ status: response.status,
+ statusText: response.statusText,
+ headers: newHeaders,
+ });
+ }
+ return response;
+}
+/**
+ * @param {Request} request
+ * @param {string | URL | ((request: Request) => string | URL) | undefined} effectiveRequestUrl
+ * @returns {URL}
+ */
+function resolveMiddlewareUrl(request, effectiveRequestUrl) {
+ if (typeof effectiveRequestUrl === "function") {
+ return new URL(effectiveRequestUrl(request), request.url);
+ }
+ if (typeof effectiveRequestUrl === "string" || effectiveRequestUrl instanceof URL) {
+ return new URL(effectiveRequestUrl, request.url);
+ }
+ return new URL(request.url);
+}
+/**
+ * Some metaframeworks (NextJS) require a new Request object.
+ * https://github.com/opral/inlang-paraglide-js/issues/411
+ *
+ * However, some frameworks (TanStack Start 1.143+) use custom Request
+ * implementations that cannot be cloned with `new Request(request)`.
+ * https://github.com/opral/paraglide-js/issues/573
+ *
+ * Effective request URL overrides behind proxies:
+ * https://github.com/opral/paraglide-js/issues/652
+ *
+ * @param {Request} request
+ * @param {string | URL} [url]
+ * @returns {Request}
+ */
+function cloneRequestWithFallback(request, url = request.url) {
+ const targetUrl = typeof url === "string" ? url : url.href;
+ if (targetUrl === request.url) {
+ try {
+ // Clone first so building a new Request does not consume the original body stream.
+ return new Request(request.clone());
+ }
+ catch {
+ try {
+ return new Request(request);
+ }
+ catch {
+ return request;
+ }
+ }
+ }
+ try {
+ // Clone first so building a new Request does not consume the original body stream.
+ return new Request(targetUrl, request.clone());
+ }
+ catch {
+ try {
+ return new Request(targetUrl, request);
+ }
+ catch {
+ return request;
+ }
+ }
+}
+/**
+ * Creates a mock AsyncLocalStorage implementation for environments where
+ * native AsyncLocalStorage is not available or disabled.
+ *
+ * This mock implementation mimics the behavior of the native AsyncLocalStorage
+ * but doesn't require the async_hooks module. It's used as a fallback when
+ * the runtime does not expose AsyncLocalStorage or when it has been disabled.
+ *
+ * @returns {import("./runtime.js").ParaglideAsyncLocalStorage}
+ */
+function createMockAsyncLocalStorage() {
+ /** @type {any} */
+ let currentStore = undefined;
+ return {
+ getStore() {
+ return currentStore;
+ },
+ async run(store, callback) {
+ currentStore = store;
+ try {
+ return await callback();
+ }
+ finally {
+ currentStore = undefined;
+ }
+ },
+ };
+}
+// Used in generated server.js when async local storage is disabled.
+void createMockAsyncLocalStorage;
+/**
+ * The compiled messages for the server middleware.
+ *
+ * Only populated if `enableMiddlewareOptimizations` is set to `true`.
+ *
+ * @type {Record>}
+ */
+const compiledBundles = {};