rune-lab 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/core/design-tokens/props.d.ts +52 -0
- package/dist/core/design-tokens/props.d.ts.map +1 -0
- package/dist/core/design-tokens/props.js +34 -0
- package/dist/core/exchange-rate/strategies.d.ts +52 -0
- package/dist/core/exchange-rate/strategies.d.ts.map +1 -0
- package/dist/core/exchange-rate/strategies.js +72 -0
- package/dist/core/index.d.ts +8 -3
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +8 -3
- package/dist/core/internal/message-resolver.d.ts +1 -1
- package/dist/core/internal/message-resolver.d.ts.map +1 -1
- package/dist/core/layout/types.d.ts +60 -0
- package/dist/core/layout/types.d.ts.map +1 -0
- package/dist/core/layout/types.js +4 -0
- package/dist/core/money/index.d.ts +1 -1
- package/dist/core/money/index.d.ts.map +1 -1
- package/dist/core/money/index.js +1 -1
- package/dist/core/money/money-primitive.d.ts +101 -0
- package/dist/core/money/money-primitive.d.ts.map +1 -0
- package/dist/core/money/money-primitive.js +161 -0
- package/dist/core/money/money.d.ts +74 -2
- package/dist/core/money/money.d.ts.map +1 -1
- package/dist/core/money/money.js +120 -2
- package/dist/core/shortcuts/types.d.ts +60 -0
- package/dist/core/shortcuts/types.d.ts.map +1 -0
- package/dist/core/shortcuts/types.js +4 -0
- package/dist/index.d.ts +4 -3
- package/dist/index.js +6 -4
- package/dist/state/api.svelte.js +2 -2
- package/dist/state/app.svelte.js +1 -1
- package/dist/state/auth/index.d.ts +2 -2
- package/dist/state/auth/index.js +1 -1
- package/dist/state/auth/session.svelte.d.ts +1 -1
- package/dist/state/auth/session.svelte.js +7 -5
- package/dist/state/auth/types.d.ts +1 -1
- package/dist/state/cart.svelte.d.ts +1 -1
- package/dist/state/cart.svelte.js +1 -1
- package/dist/state/commands.svelte.d.ts +7 -7
- package/dist/state/commands.svelte.js +1 -1
- package/dist/state/composables/useMoney.d.ts +19 -3
- package/dist/state/composables/useMoney.js +70 -6
- package/dist/state/composables/useMoneyFilter.d.ts +20 -0
- package/dist/state/composables/useMoneyFilter.js +81 -0
- package/dist/state/composables/usePersistence.d.ts +1 -1
- package/dist/state/composables/usePersistence.js +1 -1
- package/dist/state/composables/useRuneLab.d.ts +1 -1
- package/dist/state/composables/useRuneLab.js +2 -2
- package/dist/state/composables/useShortcuts.d.ts +33 -0
- package/dist/state/composables/useShortcuts.js +75 -0
- package/dist/state/context.d.ts +1 -0
- package/dist/state/context.js +1 -0
- package/dist/state/createConfigStore.svelte.d.ts +4 -31
- package/dist/state/createConfigStore.svelte.js +62 -51
- package/dist/state/currency.svelte.d.ts +13 -9
- package/dist/state/currency.svelte.js +26 -10
- package/dist/state/currency.test.d.ts +1 -0
- package/dist/state/currency.test.js +35 -0
- package/dist/state/exchange-rate.svelte.d.ts +43 -0
- package/dist/state/exchange-rate.svelte.js +145 -0
- package/dist/state/exchange-rate.test.d.ts +1 -0
- package/dist/state/exchange-rate.test.js +75 -0
- package/dist/state/index.d.ts +26 -19
- package/dist/state/index.js +25 -18
- package/dist/state/language.svelte.d.ts +3 -10
- package/dist/state/language.svelte.js +4 -5
- package/dist/state/layout.svelte.d.ts +1 -1
- package/dist/state/layout.svelte.js +4 -4
- package/dist/state/persistence/drivers.d.ts +1 -1
- package/dist/state/persistence/drivers.js +9 -7
- package/dist/state/persistence/drivers.test.d.ts +1 -0
- package/dist/state/persistence/drivers.test.js +79 -0
- package/dist/state/persistence/provider.d.ts +23 -0
- package/dist/state/persistence/provider.js +43 -0
- package/dist/state/persistence/provider.test.d.ts +1 -0
- package/dist/state/persistence/provider.test.js +51 -0
- package/dist/state/registry/index.d.ts +44 -0
- package/dist/state/registry/index.js +58 -0
- package/dist/state/registry/registry.test.d.ts +1 -0
- package/dist/state/registry/registry.test.js +112 -0
- package/dist/state/registry/types.d.ts +20 -0
- package/dist/state/registry/types.js +3 -0
- package/dist/state/shortcuts.svelte.js +4 -4
- package/dist/state/theme.svelte.d.ts +3 -10
- package/dist/state/theme.svelte.js +8 -8
- package/dist/state/toast-bridge.d.ts +1 -1
- package/dist/state/toast.svelte.js +1 -1
- package/dist/ui/components/ApiMonitor.svelte +2 -2
- package/dist/ui/components/Icon.svelte +1 -1
- package/dist/ui/components/RuneProvider.svelte +28 -8
- package/dist/ui/components/RuneProvider.svelte.d.ts +12 -5
- package/dist/ui/components/Toaster.svelte +1 -1
- package/dist/ui/components/money/MoneyDisplay.svelte +91 -18
- package/dist/ui/components/money/MoneyDisplay.svelte.d.ts +15 -3
- package/dist/ui/components/money/MoneyDisplay.svelte.test.d.ts +1 -1
- package/dist/ui/components/money/MoneyDisplay.svelte.test.js +45 -2
- package/dist/ui/components/money/MoneyInput.svelte +123 -42
- package/dist/ui/components/money/MoneyInput.svelte.d.ts +14 -5
- package/dist/ui/features/command-palette/CommandPalette.svelte +3 -3
- package/dist/ui/features/config/APP_CONFIGURATIONS.d.ts +29 -0
- package/dist/ui/features/config/APP_CONFIGURATIONS.js +38 -0
- package/dist/ui/features/config/CurrencySelector.svelte +10 -36
- package/dist/ui/features/config/LanguageSelector.svelte +10 -33
- package/dist/ui/features/config/ResourceSelector.svelte +92 -0
- package/dist/ui/features/config/ResourceSelector.svelte.d.ts +25 -0
- package/dist/ui/features/config/ThemeSelector.svelte +11 -34
- package/dist/ui/features/shortcuts/ShortcutBinder.svelte +17 -0
- package/dist/ui/features/shortcuts/ShortcutBinder.svelte.d.ts +7 -0
- package/dist/ui/features/shortcuts/ShortcutPalette.svelte +3 -3
- package/dist/ui/index.d.ts +5 -1
- package/dist/ui/index.js +8 -3
- package/dist/ui/layout/ConnectedNavigationPanel.svelte +7 -8
- package/dist/ui/layout/ConnectedNavigationPanel.svelte.d.ts +1 -1
- package/dist/ui/layout/ConnectedWorkspaceStrip.svelte +5 -3
- package/dist/ui/layout/ConnectedWorkspaceStrip.svelte.d.ts +1 -1
- package/dist/ui/layout/NavigationPanel.svelte +1 -1
- package/dist/ui/layout/NavigationPanel.svelte.d.ts +1 -1
- package/dist/ui/layout/WorkspaceLayout.svelte +9 -1
- package/dist/ui/layout/WorkspaceLayout.svelte.d.ts +7 -0
- package/dist/ui/layout/WorkspaceStrip.svelte +1 -1
- package/dist/ui/layout/WorkspaceStrip.svelte.d.ts +1 -1
- package/dist/ui/layout/connection-factory.d.ts +50 -0
- package/dist/ui/layout/connection-factory.js +58 -0
- package/dist/ui/layout/index.d.ts +2 -2
- package/dist/ui/layout/index.js +1 -1
- package/dist/ui/paraglide/README.md +53 -0
- package/dist/ui/paraglide/runtime.d.ts +105 -124
- package/dist/ui/paraglide/runtime.js +162 -127
- package/dist/ui/paraglide/server.d.ts +6 -17
- package/dist/ui/paraglide/server.js +11 -20
- package/dist/ui/primitives/DatePicker.svelte +1 -1
- package/package.json +8 -8
- package/dist/state/daisyui.d.ts +0 -4
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
// sdk/ui/src/lib/layout/connection-factory.ts
|
|
2
|
+
// Connection functions that generate reactive prop bindings from LayoutStore.
|
|
3
|
+
// Svelte 5 doesn't support React-style HOCs — this is the idiomatic alternative.
|
|
4
|
+
/**
|
|
5
|
+
* Creates reactive prop bindings for connecting NavigationPanel to LayoutStore.
|
|
6
|
+
* Returns an object with getter properties that track LayoutStore state.
|
|
7
|
+
*
|
|
8
|
+
* @param layoutStore - The LayoutStore instance from context
|
|
9
|
+
* @returns Prop bindings compatible with NavigationPanel
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```svelte
|
|
13
|
+
* <script>
|
|
14
|
+
* const layoutStore = getLayoutStore();
|
|
15
|
+
* const nav = createNavigationConnection(layoutStore);
|
|
16
|
+
* </script>
|
|
17
|
+
* <NavigationPanel {sections} activeId={nav.activeId} collapsedIds={nav.collapsedIds}
|
|
18
|
+
* onSelect={nav.onSelect} onToggle={nav.onToggle} />
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export function createNavigationConnection(layoutStore) {
|
|
22
|
+
return {
|
|
23
|
+
get activeId() {
|
|
24
|
+
return layoutStore.activeNavItemId;
|
|
25
|
+
},
|
|
26
|
+
get collapsedIds() {
|
|
27
|
+
return layoutStore.collapsedSections;
|
|
28
|
+
},
|
|
29
|
+
onSelect(item) {
|
|
30
|
+
if (item.id)
|
|
31
|
+
layoutStore.navigate(item.id);
|
|
32
|
+
},
|
|
33
|
+
onToggle(id, isOpen) {
|
|
34
|
+
if (isOpen) {
|
|
35
|
+
layoutStore.expandSection(id);
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
layoutStore.collapseSection(id);
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Creates reactive prop bindings for connecting WorkspaceStrip to LayoutStore.
|
|
45
|
+
*
|
|
46
|
+
* @param layoutStore - The LayoutStore instance from context
|
|
47
|
+
* @returns Prop bindings compatible with WorkspaceStrip
|
|
48
|
+
*/
|
|
49
|
+
export function createWorkspaceConnection(layoutStore) {
|
|
50
|
+
return {
|
|
51
|
+
get activeId() {
|
|
52
|
+
return layoutStore.activeWorkspaceId;
|
|
53
|
+
},
|
|
54
|
+
onSelect(id) {
|
|
55
|
+
layoutStore.activateWorkspace(id);
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
}
|
|
@@ -3,5 +3,5 @@ export { default as WorkspaceStrip } from "./WorkspaceStrip.svelte";
|
|
|
3
3
|
export { default as NavigationPanel } from "./NavigationPanel.svelte";
|
|
4
4
|
export { default as ContentArea } from "./ContentArea.svelte";
|
|
5
5
|
export { default as DetailPanel } from "./DetailPanel.svelte";
|
|
6
|
-
export { createLayoutStore, getLayoutStore } from "
|
|
7
|
-
export type { NavigationItem, NavigationSection, WorkspaceItem, } from "
|
|
6
|
+
export { createLayoutStore, getLayoutStore } from "@internal/state";
|
|
7
|
+
export type { NavigationItem, NavigationSection, WorkspaceItem, } from "@internal/state";
|
package/dist/ui/layout/index.js
CHANGED
|
@@ -4,4 +4,4 @@ export { default as WorkspaceStrip } from "./WorkspaceStrip.svelte";
|
|
|
4
4
|
export { default as NavigationPanel } from "./NavigationPanel.svelte";
|
|
5
5
|
export { default as ContentArea } from "./ContentArea.svelte";
|
|
6
6
|
export { default as DetailPanel } from "./DetailPanel.svelte";
|
|
7
|
-
export { createLayoutStore, getLayoutStore } from "
|
|
7
|
+
export { createLayoutStore, getLayoutStore } from "@internal/state";
|
|
@@ -81,6 +81,59 @@ await compile({
|
|
|
81
81
|
|
|
82
82
|
See the [strategy documentation](https://inlang.com/m/gerre34r/library-inlang-paraglideJs/strategy) for details.
|
|
83
83
|
|
|
84
|
+
## Markup (Rich Text)
|
|
85
|
+
|
|
86
|
+
Messages can contain markup tags for bold, links, and other inline elements. Translators control where tags appear; developers control how they render.
|
|
87
|
+
|
|
88
|
+
### Message syntax
|
|
89
|
+
|
|
90
|
+
```json
|
|
91
|
+
{
|
|
92
|
+
"cta": "{#link to=|/docs|}Read the docs{/link}",
|
|
93
|
+
"bold_text": "This is {#bold}important{/bold}"
|
|
94
|
+
}
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
- `{#tagName}` opens a tag, `{/tagName}` closes it.
|
|
98
|
+
- Options: `to=|/docs|` (accessed via `options.to`).
|
|
99
|
+
- Attributes: `@track` (boolean, accessed via `attributes.track`).
|
|
100
|
+
|
|
101
|
+
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.
|
|
102
|
+
|
|
103
|
+
### Rendering markup
|
|
104
|
+
|
|
105
|
+
Calling `m.cta()` returns **plain text** (markup stripped). To render markup, use the framework adapter or the low-level `parts()` API:
|
|
106
|
+
|
|
107
|
+
```js
|
|
108
|
+
const parts = m.cta.parts({});
|
|
109
|
+
// [
|
|
110
|
+
// { type: "markup-start", name: "link", options: { to: "/docs" }, attributes: {} },
|
|
111
|
+
// { type: "text", value: "Read the docs" },
|
|
112
|
+
// { type: "markup-end", name: "link" }
|
|
113
|
+
// ]
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
Framework adapters provide a `<ParaglideMessage>` component that accepts markup renderers:
|
|
117
|
+
|
|
118
|
+
- `@inlang/paraglide-js-react`
|
|
119
|
+
- `@inlang/paraglide-js-vue`
|
|
120
|
+
- `@inlang/paraglide-js-svelte`
|
|
121
|
+
- `@inlang/paraglide-js-solid`
|
|
122
|
+
|
|
123
|
+
```jsx
|
|
124
|
+
import { ParaglideMessage } from "@inlang/paraglide-js-react"; // or -vue, -svelte, -solid
|
|
125
|
+
|
|
126
|
+
<ParaglideMessage
|
|
127
|
+
message={m.cta}
|
|
128
|
+
inputs={{}}
|
|
129
|
+
markup={{
|
|
130
|
+
link: ({ children, options }) => <a href={options.to}>{children}</a>,
|
|
131
|
+
}}
|
|
132
|
+
/>
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
See the [markup documentation](https://inlang.com/m/gerre34r/library-inlang-paraglideJs/markup) for details.
|
|
136
|
+
|
|
84
137
|
## Key concepts
|
|
85
138
|
|
|
86
139
|
- **Tree-shakeable**: Each message is a function, enabling [up to 70% smaller i18n bundle sizes](https://inlang.com/m/gerre34r/library-inlang-paraglideJs/benchmark) than traditional i18n libraries.
|
|
@@ -49,7 +49,14 @@ export function getLocaleForUrl(url: string | URL): Locale;
|
|
|
49
49
|
*/
|
|
50
50
|
export function getTextDirection(locale?: string): "ltr" | "rtl";
|
|
51
51
|
/**
|
|
52
|
-
*
|
|
52
|
+
* Coerces a locale-like string to the canonical locale value used by the runtime.
|
|
53
|
+
*
|
|
54
|
+
* @param {unknown} value
|
|
55
|
+
* @returns {Locale | undefined}
|
|
56
|
+
*/
|
|
57
|
+
export function toLocale(value: unknown): Locale | undefined;
|
|
58
|
+
/**
|
|
59
|
+
* Check if something is an available locale with the canonical project casing.
|
|
53
60
|
*
|
|
54
61
|
* @example
|
|
55
62
|
* if (isLocale(params.locale)) {
|
|
@@ -58,32 +65,61 @@ export function getTextDirection(locale?: string): "ltr" | "rtl";
|
|
|
58
65
|
* setLocale('en');
|
|
59
66
|
* }
|
|
60
67
|
*
|
|
61
|
-
*
|
|
68
|
+
* Use `toLocale()` when you want case-insensitive matching and canonicalization.
|
|
69
|
+
*
|
|
70
|
+
* @param {unknown} locale
|
|
62
71
|
* @returns {locale is Locale}
|
|
63
72
|
*/
|
|
64
|
-
export function isLocale(locale:
|
|
73
|
+
export function isLocale(locale: unknown): locale is Locale;
|
|
65
74
|
/**
|
|
66
|
-
* Asserts that the input
|
|
75
|
+
* Asserts that the input can be normalized to a locale.
|
|
67
76
|
*
|
|
68
|
-
* @param {
|
|
69
|
-
* @returns {Locale} The input
|
|
77
|
+
* @param {unknown} input - The input to check.
|
|
78
|
+
* @returns {Locale} The input normalized to a Locale.
|
|
70
79
|
* @throws {Error} If the input is not a locale.
|
|
71
80
|
*/
|
|
72
|
-
export function assertIsLocale(input:
|
|
81
|
+
export function assertIsLocale(input: unknown): Locale;
|
|
73
82
|
/**
|
|
74
83
|
* Extracts a cookie from the document.
|
|
75
84
|
*
|
|
76
85
|
* Will return undefined if the document is not available or if the cookie is not set.
|
|
77
86
|
* The `document` object is not available in server-side rendering, so this function should not be called in that context.
|
|
78
87
|
*
|
|
79
|
-
* @returns {
|
|
88
|
+
* @returns {Locale | undefined}
|
|
89
|
+
*/
|
|
90
|
+
export function extractLocaleFromCookie(): Locale | undefined;
|
|
91
|
+
/**
|
|
92
|
+
* Extracts a locale from the accept-language header.
|
|
93
|
+
*
|
|
94
|
+
* Use the function on the server to extract the locale
|
|
95
|
+
* from the accept-language header that is sent by the client.
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* const locale = extractLocaleFromHeader(request);
|
|
99
|
+
*
|
|
100
|
+
* @param {Request} request - The request object to extract the locale from.
|
|
101
|
+
* @returns {Locale | undefined} The negotiated preferred language.
|
|
102
|
+
*/
|
|
103
|
+
export function extractLocaleFromHeader(request: Request): Locale | undefined;
|
|
104
|
+
/**
|
|
105
|
+
* Negotiates a preferred language from navigator.languages.
|
|
106
|
+
*
|
|
107
|
+
* Use the function on the client to extract the locale
|
|
108
|
+
* from the navigator.languages array.
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* const locale = extractLocaleFromNavigator();
|
|
112
|
+
*
|
|
113
|
+
* @returns {Locale | undefined}
|
|
80
114
|
*/
|
|
81
|
-
export function extractLocaleFromCookie(): string | undefined;
|
|
82
|
-
export function extractLocaleFromHeader(request: Request): Locale;
|
|
83
115
|
export function extractLocaleFromNavigator(): Locale | undefined;
|
|
84
116
|
/**
|
|
85
117
|
* Extracts the locale from a given URL using native URLPattern.
|
|
86
118
|
*
|
|
119
|
+
* The built-in default `/:locale/...` routing is case-insensitive because it
|
|
120
|
+
* canonicalizes the first path segment with `toLocale()`. Custom `urlPatterns`
|
|
121
|
+
* keep URLPattern's normal exact matching semantics for path segments.
|
|
122
|
+
*
|
|
87
123
|
* @param {URL|string} url - The full URL from which to extract the locale.
|
|
88
124
|
* @returns {Locale|undefined} The extracted locale, or undefined if no locale is found.
|
|
89
125
|
*/
|
|
@@ -128,12 +164,12 @@ export function extractLocaleFromUrl(url: URL | string): Locale | undefined;
|
|
|
128
164
|
* ```
|
|
129
165
|
*
|
|
130
166
|
* @param {string | URL} url - The URL to localize. If string, must be absolute.
|
|
131
|
-
* @param {
|
|
132
|
-
* @param {
|
|
167
|
+
* @param {object} [options] - Options for localization
|
|
168
|
+
* @param {Locale} [options.locale] - Target locale. If not provided, uses getLocale()
|
|
133
169
|
* @returns {URL} The localized URL, always absolute
|
|
134
170
|
*/
|
|
135
171
|
export function localizeUrl(url: string | URL, options?: {
|
|
136
|
-
locale?:
|
|
172
|
+
locale?: "es" | "fr" | "it" | "pt" | "en" | "de" | "ru" | "hi" | "ar" | "zh" | "ja" | "ko" | "vi" | undefined;
|
|
137
173
|
}): URL;
|
|
138
174
|
/**
|
|
139
175
|
* Low-level URL de-localization function, primarily used in server contexts.
|
|
@@ -175,23 +211,30 @@ export function localizeUrl(url: string | URL, options?: {
|
|
|
175
211
|
* @returns {URL} The de-localized URL, always absolute
|
|
176
212
|
*/
|
|
177
213
|
export function deLocalizeUrl(url: string | URL): URL;
|
|
214
|
+
/**
|
|
215
|
+
* Aggregates named groups from various parts of the URLPattern match result.
|
|
216
|
+
*
|
|
217
|
+
*
|
|
218
|
+
* @param {any} match - The URLPattern match result object.
|
|
219
|
+
* @returns {Record<string, string | null | undefined>} An object containing all named groups from the match.
|
|
220
|
+
*/
|
|
178
221
|
export function aggregateGroups(match: any): Record<string, string | null | undefined>;
|
|
179
222
|
/**
|
|
180
223
|
* @typedef {object} ShouldRedirectServerInput
|
|
181
224
|
* @property {Request} request
|
|
182
225
|
* @property {string | URL} [url]
|
|
183
|
-
* @property {
|
|
226
|
+
* @property {Locale} [locale]
|
|
184
227
|
*
|
|
185
228
|
* @typedef {object} ShouldRedirectClientInput
|
|
186
229
|
* @property {undefined} [request]
|
|
187
230
|
* @property {string | URL} [url]
|
|
188
|
-
* @property {
|
|
231
|
+
* @property {Locale} [locale]
|
|
189
232
|
*
|
|
190
233
|
* @typedef {ShouldRedirectServerInput | ShouldRedirectClientInput} ShouldRedirectInput
|
|
191
234
|
*
|
|
192
235
|
* @typedef {object} ShouldRedirectResult
|
|
193
236
|
* @property {boolean} shouldRedirect - Indicates whether the consumer should perform a redirect.
|
|
194
|
-
* @property {
|
|
237
|
+
* @property {Locale} locale - Locale resolved using the configured strategies.
|
|
195
238
|
* @property {URL | undefined} redirectUrl - Destination URL when a redirect is required.
|
|
196
239
|
*/
|
|
197
240
|
/**
|
|
@@ -267,12 +310,12 @@ export function shouldRedirect(input?: ShouldRedirectInput): Promise<ShouldRedir
|
|
|
267
310
|
* which provides more precise control over URL handling.
|
|
268
311
|
*
|
|
269
312
|
* @param {string} href - The href to localize (can be relative or absolute)
|
|
270
|
-
* @param {
|
|
271
|
-
* @param {
|
|
313
|
+
* @param {object} [options] - Options for localization
|
|
314
|
+
* @param {Locale} [options.locale] - Target locale. If not provided, uses `getLocale()`
|
|
272
315
|
* @returns {string} The localized href, relative if input was relative
|
|
273
316
|
*/
|
|
274
317
|
export function localizeHref(href: string, options?: {
|
|
275
|
-
locale?:
|
|
318
|
+
locale?: "es" | "fr" | "it" | "pt" | "en" | "de" | "ru" | "hi" | "ar" | "zh" | "ja" | "ko" | "vi" | undefined;
|
|
276
319
|
}): string;
|
|
277
320
|
/**
|
|
278
321
|
* High-level URL de-localization function optimized for client-side UI usage.
|
|
@@ -367,33 +410,33 @@ export function generateStaticLocalizedUrls(urls: (string | URL)[]): URL[];
|
|
|
367
410
|
/**
|
|
368
411
|
* Checks if the given strategy is a custom strategy.
|
|
369
412
|
*
|
|
370
|
-
* @param {
|
|
413
|
+
* @param {unknown} strategy The name of the custom strategy to validate.
|
|
371
414
|
* Must be a string that starts with "custom-" followed by alphanumeric characters, hyphens, or underscores.
|
|
372
415
|
* @returns {boolean} Returns true if it is a custom strategy, false otherwise.
|
|
373
416
|
*/
|
|
374
|
-
export function isCustomStrategy(strategy:
|
|
417
|
+
export function isCustomStrategy(strategy: unknown): boolean;
|
|
375
418
|
/**
|
|
376
419
|
* Defines a custom strategy that is executed on the server.
|
|
377
420
|
*
|
|
378
421
|
* @see https://inlang.com/m/gerre34r/library-inlang-paraglideJs/strategy#write-your-own-strategy
|
|
379
422
|
*
|
|
380
|
-
* @param {
|
|
423
|
+
* @param {string} strategy The name of the custom strategy to define. Must follow the pattern custom-name with alphanumeric characters, hyphens, or underscores.
|
|
381
424
|
* @param {CustomServerStrategyHandler} handler The handler for the custom strategy, which should implement
|
|
382
425
|
* the method getLocale.
|
|
383
426
|
* @returns {void}
|
|
384
427
|
*/
|
|
385
|
-
export function defineCustomServerStrategy(strategy:
|
|
428
|
+
export function defineCustomServerStrategy(strategy: string, handler: CustomServerStrategyHandler): void;
|
|
386
429
|
/**
|
|
387
430
|
* Defines a custom strategy that is executed on the client.
|
|
388
431
|
*
|
|
389
432
|
* @see https://inlang.com/m/gerre34r/library-inlang-paraglideJs/strategy#write-your-own-strategy
|
|
390
433
|
*
|
|
391
|
-
* @param {
|
|
434
|
+
* @param {string} strategy The name of the custom strategy to define. Must follow the pattern custom-name with alphanumeric characters, hyphens, or underscores.
|
|
392
435
|
* @param {CustomClientStrategyHandler} handler The handler for the custom strategy, which should implement the
|
|
393
436
|
* methods getLocale and setLocale.
|
|
394
437
|
* @returns {void}
|
|
395
438
|
*/
|
|
396
|
-
export function defineCustomClientStrategy(strategy:
|
|
439
|
+
export function defineCustomClientStrategy(strategy: string, handler: CustomClientStrategyHandler): void;
|
|
397
440
|
/**
|
|
398
441
|
* The project's base locale.
|
|
399
442
|
*
|
|
@@ -443,7 +486,7 @@ export const routeStrategies: Array<{
|
|
|
443
486
|
/**
|
|
444
487
|
* The used URL patterns.
|
|
445
488
|
*
|
|
446
|
-
* @type {Array<{ pattern: string, localized: Array<[Locale, string]> }>
|
|
489
|
+
* @type {Array<{ pattern: string, localized: Array<[Locale, string]> }>}
|
|
447
490
|
*/
|
|
448
491
|
export const urlPatterns: Array<{
|
|
449
492
|
pattern: string;
|
|
@@ -474,41 +517,8 @@ export const experimentalMiddlewareLocaleSplitting: false;
|
|
|
474
517
|
export const isServer: boolean;
|
|
475
518
|
/** @type {Locale | undefined} */
|
|
476
519
|
export const experimentalStaticLocale: Locale | undefined;
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
*
|
|
480
|
-
* The locale is resolved using your configured strategies (URL, cookie, localStorage, etc.)
|
|
481
|
-
* in the order they are defined. In SSR contexts, the locale is retrieved from AsyncLocalStorage
|
|
482
|
-
* which is set by the `paraglideMiddleware()`.
|
|
483
|
-
*
|
|
484
|
-
* @see https://inlang.com/m/gerre34r/library-inlang-paraglideJs/strategy - Configure locale detection strategies
|
|
485
|
-
*
|
|
486
|
-
* @example
|
|
487
|
-
* if (getLocale() === 'de') {
|
|
488
|
-
* console.log('Germany 🇩🇪');
|
|
489
|
-
* } else if (getLocale() === 'nl') {
|
|
490
|
-
* console.log('Netherlands 🇳🇱');
|
|
491
|
-
* }
|
|
492
|
-
*
|
|
493
|
-
* @type {() => Locale}
|
|
494
|
-
*/
|
|
495
|
-
export let getLocale: () => Locale;
|
|
496
|
-
/**
|
|
497
|
-
* Overwrite the `getLocale()` function.
|
|
498
|
-
*
|
|
499
|
-
* Use this function to overwrite how the locale is resolved. This is useful
|
|
500
|
-
* for custom locale resolution or advanced use cases like SSG with concurrent rendering.
|
|
501
|
-
*
|
|
502
|
-
* @see https://inlang.com/m/gerre34r/library-inlang-paraglideJs/strategy
|
|
503
|
-
*
|
|
504
|
-
* @example
|
|
505
|
-
* overwriteGetLocale(() => {
|
|
506
|
-
* return Cookies.get('locale') ?? baseLocale
|
|
507
|
-
* });
|
|
508
|
-
*
|
|
509
|
-
* @type {(fn: () => Locale) => void}
|
|
510
|
-
*/
|
|
511
|
-
export const overwriteGetLocale: (fn: () => Locale) => void;
|
|
520
|
+
export function getLocale(): Locale;
|
|
521
|
+
export function overwriteGetLocale(fn: () => Locale): void;
|
|
512
522
|
/**
|
|
513
523
|
* @typedef {(newLocale: Locale, options?: { reload?: boolean }) => void | Promise<void>} SetLocaleFn
|
|
514
524
|
*/
|
|
@@ -545,65 +555,10 @@ export function overwriteSetLocale(fn: SetLocaleFn): void;
|
|
|
545
555
|
* @type {() => string}
|
|
546
556
|
*/
|
|
547
557
|
export let getUrlOrigin: () => string;
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
*
|
|
551
|
-
* Use this function in server environments to
|
|
552
|
-
* define how the URL origin is resolved.
|
|
553
|
-
*
|
|
554
|
-
* @type {(fn: () => string) => void}
|
|
555
|
-
*/
|
|
556
|
-
export let overwriteGetUrlOrigin: (fn: () => string) => void;
|
|
557
|
-
/**
|
|
558
|
-
* Extracts a locale from a request.
|
|
559
|
-
*
|
|
560
|
-
* Use the function on the server to extract the locale
|
|
561
|
-
* from a request.
|
|
562
|
-
*
|
|
563
|
-
* The function goes through the strategies in the order
|
|
564
|
-
* they are defined. If a strategy returns an invalid locale,
|
|
565
|
-
* it will fall back to the next strategy.
|
|
566
|
-
*
|
|
567
|
-
* Note: Custom server strategies are not supported in this synchronous version.
|
|
568
|
-
* Use `extractLocaleFromRequestAsync` if you need custom server strategies with async getLocale methods.
|
|
569
|
-
*
|
|
570
|
-
* @example
|
|
571
|
-
* const locale = extractLocaleFromRequest(request);
|
|
572
|
-
*
|
|
573
|
-
* @type {(request: Request) => Locale}
|
|
574
|
-
*/
|
|
575
|
-
export const extractLocaleFromRequest: (request: Request) => Locale;
|
|
558
|
+
export function overwriteGetUrlOrigin(fn: () => string): void;
|
|
559
|
+
export function extractLocaleFromRequest(request: Request): Locale;
|
|
576
560
|
export function extractLocaleFromRequestWithStrategies(request: Request, strategies: typeof strategy): Locale;
|
|
577
|
-
|
|
578
|
-
* Asynchronously extracts a locale from a request.
|
|
579
|
-
*
|
|
580
|
-
* This function supports async custom server strategies, unlike the synchronous
|
|
581
|
-
* `extractLocaleFromRequest`. Use this function when you have custom server strategies
|
|
582
|
-
* that need to perform asynchronous operations (like database calls) in their getLocale method.
|
|
583
|
-
*
|
|
584
|
-
* The function first processes any custom server strategies asynchronously, then falls back
|
|
585
|
-
* to the synchronous `extractLocaleFromRequest` for all other strategies.
|
|
586
|
-
*
|
|
587
|
-
* @see {@link https://github.com/opral/inlang-paraglide-js/issues/527#issuecomment-2978151022}
|
|
588
|
-
*
|
|
589
|
-
* @example
|
|
590
|
-
* // Basic usage
|
|
591
|
-
* const locale = await extractLocaleFromRequestAsync(request);
|
|
592
|
-
*
|
|
593
|
-
* @example
|
|
594
|
-
* // With custom async server strategy
|
|
595
|
-
* defineCustomServerStrategy("custom-database", {
|
|
596
|
-
* getLocale: async (request) => {
|
|
597
|
-
* const userId = extractUserIdFromRequest(request);
|
|
598
|
-
* return await getUserLocaleFromDatabase(userId);
|
|
599
|
-
* }
|
|
600
|
-
* });
|
|
601
|
-
*
|
|
602
|
-
* const locale = await extractLocaleFromRequestAsync(request);
|
|
603
|
-
*
|
|
604
|
-
* @type {(request: Request) => Promise<Locale>}
|
|
605
|
-
*/
|
|
606
|
-
export const extractLocaleFromRequestAsync: (request: Request) => Promise<Locale>;
|
|
561
|
+
export function extractLocaleFromRequestAsync(request: Request): Promise<Locale>;
|
|
607
562
|
/**
|
|
608
563
|
* @typedef {"cookie" | "baseLocale" | "globalVariable" | "url" | "preferredLanguage" | "localStorage"} BuiltInStrategy
|
|
609
564
|
*/
|
|
@@ -645,7 +600,7 @@ export type ShouldRedirectResult = {
|
|
|
645
600
|
/**
|
|
646
601
|
* - Locale resolved using the configured strategies.
|
|
647
602
|
*/
|
|
648
|
-
locale:
|
|
603
|
+
locale: Locale;
|
|
649
604
|
/**
|
|
650
605
|
* - Destination URL when a redirect is required.
|
|
651
606
|
*/
|
|
@@ -684,17 +639,31 @@ export type Locale = (typeof locales)[number];
|
|
|
684
639
|
/**
|
|
685
640
|
* A branded type representing a localized string.
|
|
686
641
|
*
|
|
687
|
-
* Message functions return this type instead of
|
|
642
|
+
* Message functions return this type instead of \`string\`, enabling TypeScript
|
|
688
643
|
* to distinguish translated strings from regular strings at compile time.
|
|
689
644
|
* This allows you to enforce that only properly localized content is used
|
|
690
645
|
* in your UI components.
|
|
691
646
|
*
|
|
692
|
-
* Since
|
|
693
|
-
* backward compatible—you can pass it anywhere a
|
|
647
|
+
* Since \`LocalizedString\` is a branded subtype of \`string\`, it remains fully
|
|
648
|
+
* backward compatible—you can pass it anywhere a \`string\` is expected.
|
|
694
649
|
*/
|
|
695
650
|
export type LocalizedString = string & {
|
|
696
651
|
readonly __brand: "LocalizedString";
|
|
697
652
|
};
|
|
653
|
+
/**
|
|
654
|
+
* A single markup option passed to a tag instance.
|
|
655
|
+
*/
|
|
656
|
+
export type MessageMarkupOption = {
|
|
657
|
+
name: string;
|
|
658
|
+
value: unknown;
|
|
659
|
+
};
|
|
660
|
+
/**
|
|
661
|
+
* A single static markup attribute attached to a tag instance.
|
|
662
|
+
*/
|
|
663
|
+
export type MessageMarkupAttribute = {
|
|
664
|
+
name: string;
|
|
665
|
+
value: string | true;
|
|
666
|
+
};
|
|
698
667
|
/**
|
|
699
668
|
* Record of markup options for a tag instance.
|
|
700
669
|
*/
|
|
@@ -718,7 +687,7 @@ export type MessageMarkupSchema = Record<string, MessageMarkupTag>;
|
|
|
718
687
|
/**
|
|
719
688
|
* Type-only metadata attached to compiled message functions.
|
|
720
689
|
*/
|
|
721
|
-
export type MessageMetadata<Inputs, Options, Markup extends MessageMarkupSchema> = {
|
|
690
|
+
export type MessageMetadata<Inputs, Options, Markup extends MessageMarkupSchema = MessageMarkupSchema> = {
|
|
722
691
|
readonly __paraglide?: {
|
|
723
692
|
inputs: Inputs;
|
|
724
693
|
options: Options;
|
|
@@ -747,3 +716,15 @@ export type MessagePart = {
|
|
|
747
716
|
options: MessageMarkupOptions;
|
|
748
717
|
attributes: MessageMarkupAttributes;
|
|
749
718
|
};
|
|
719
|
+
/**
|
|
720
|
+
* A message function is a message for a specific locale.
|
|
721
|
+
*/
|
|
722
|
+
export type MessageFunction = (inputs?: Record<string, never>) => LocalizedString;
|
|
723
|
+
/**
|
|
724
|
+
* A message bundle function that selects the message to be returned.
|
|
725
|
+
*
|
|
726
|
+
* Uses `getLocale()` under the hood to determine the locale with an option.
|
|
727
|
+
*/
|
|
728
|
+
export type MessageBundleFunction<T extends string> = (params: Record<string, never>, options: {
|
|
729
|
+
locale: T;
|
|
730
|
+
}) => LocalizedString;
|